Ben Vanik | e309cb3 | 2023-02-01 11:59:39 -0800 | [diff] [blame] | 1 | // Tests that execution providing no outputs is ok. |
| 2 | |
| 3 | // RUN: (iree-compile --iree-hal-target-backends=vmvx %s | \ |
Ben Vanik | 9461d3b | 2023-04-18 16:39:25 -0700 | [diff] [blame] | 4 | // RUN: iree-run-module --device=local-sync --module=- --function=no_output) | \ |
Ben Vanik | e309cb3 | 2023-02-01 11:59:39 -0800 | [diff] [blame] | 5 | // RUN: FileCheck --check-prefix=NO-OUTPUT %s |
| 6 | // NO-OUTPUT-LABEL: EXEC @no_output |
| 7 | func.func @no_output() { |
| 8 | return |
| 9 | } |
| 10 | |
| 11 | // ----- |
| 12 | |
| 13 | // Tests the default output printing to stdout. |
| 14 | |
| 15 | // RUN: (iree-compile --iree-hal-target-backends=vmvx %s | \ |
Ben Vanik | 9461d3b | 2023-04-18 16:39:25 -0700 | [diff] [blame] | 16 | // RUN: iree-run-module --device=local-sync --module=- --function=default) | \ |
Ben Vanik | e309cb3 | 2023-02-01 11:59:39 -0800 | [diff] [blame] | 17 | // RUN: FileCheck --check-prefix=OUTPUT-DEFAULT %s |
| 18 | // OUTPUT-DEFAULT-LABEL: EXEC @default |
| 19 | func.func @default() -> (i32, tensor<f32>, tensor<?x4xi32>) { |
| 20 | // OUTPUT-DEFAULT: result[0]: i32=123 |
| 21 | %0 = arith.constant 123 : i32 |
| 22 | // OUTPUT-DEFAULT: result[1]: hal.buffer_view |
| 23 | // OUTPUT-DEFAULT-NEXT: f32=4 |
| 24 | %1 = arith.constant dense<4.0> : tensor<f32> |
| 25 | // OUTPUT-DEFAULT: result[2]: hal.buffer_view |
| 26 | // OUTPUT-DEFAULT-NEXT: 2x4xi32=[0 1 2 3][4 5 6 7] |
Ben Vanik | 55fafcf | 2024-04-12 14:58:38 -0700 | [diff] [blame] | 27 | %2 = flow.tensor.dynamic_constant dense<[[0,1,2,3],[4,5,6,7]]> : tensor<2x4xi32> -> tensor<?x4xi32> |
Ben Vanik | e309cb3 | 2023-02-01 11:59:39 -0800 | [diff] [blame] | 28 | return %0, %1, %2 : i32, tensor<f32>, tensor<?x4xi32> |
| 29 | } |
| 30 | |
| 31 | // ----- |
| 32 | |
| 33 | // Tests explicit output to npy files by producing a concatenated .npy and then |
| 34 | // printing the results in python. This also verifies our npy files can be |
| 35 | // parsed by numpy. |
| 36 | |
| 37 | // RUN: (iree-compile --iree-hal-target-backends=vmvx %s | \ |
Ben Vanik | 9461d3b | 2023-04-18 16:39:25 -0700 | [diff] [blame] | 38 | // RUN: iree-run-module --device=local-sync --module=- --function=numpy \ |
Ben Vanik | e309cb3 | 2023-02-01 11:59:39 -0800 | [diff] [blame] | 39 | // RUN: --output= \ |
Ben Vanik | 065e04a | 2024-02-01 16:29:33 -0800 | [diff] [blame] | 40 | // RUN: --output=@%t.npy \ |
| 41 | // RUN: --output=+%t.npy) && \ |
| 42 | // RUN: "%PYTHON" %S/echo_npy.py %t.npy | \ |
Ben Vanik | e309cb3 | 2023-02-01 11:59:39 -0800 | [diff] [blame] | 43 | // RUN: FileCheck --check-prefix=OUTPUT-NUMPY %s |
| 44 | func.func @numpy() -> (i32, tensor<f32>, tensor<?x4xi32>) { |
| 45 | // Output skipped: |
| 46 | %0 = arith.constant 123 : i32 |
| 47 | // OUTPUT-NUMPY{LITERAL}: 4.0 |
| 48 | %1 = arith.constant dense<4.0> : tensor<f32> |
| 49 | // OUTPUT-NUMPY-NEXT{LITERAL}: [[0 1 2 3] |
| 50 | // OUTPUT-NUMPY-NEXT{LITERAL}: [4 5 6 7]] |
Ben Vanik | 55fafcf | 2024-04-12 14:58:38 -0700 | [diff] [blame] | 51 | %2 = flow.tensor.dynamic_constant dense<[[0,1,2,3],[4,5,6,7]]> : tensor<2x4xi32> -> tensor<?x4xi32> |
Ben Vanik | e309cb3 | 2023-02-01 11:59:39 -0800 | [diff] [blame] | 52 | return %0, %1, %2 : i32, tensor<f32>, tensor<?x4xi32> |
| 53 | } |
Ben Vanik | 065e04a | 2024-02-01 16:29:33 -0800 | [diff] [blame] | 54 | |
| 55 | // ----- |
| 56 | |
| 57 | // Tests output to binary files by round-tripping the output of a function into |
Ben Vanik | 30901f5 | 2024-02-08 11:23:21 -0800 | [diff] [blame] | 58 | // another invocation reading from the binary files. Each output is written to |
| 59 | // its own file (optimal for alignment/easier to inspect). |
Ben Vanik | 065e04a | 2024-02-01 16:29:33 -0800 | [diff] [blame] | 60 | |
| 61 | // RUN: (iree-compile --iree-hal-target-backends=vmvx %s -o=%t.vmfb && \ |
| 62 | // RUN: iree-run-module --device=local-sync \ |
| 63 | // RUN: --module=%t.vmfb \ |
| 64 | // RUN: --function=write_binary \ |
| 65 | // RUN: --output=@%t.0.bin \ |
| 66 | // RUN: --output=@%t.1.bin && \ |
| 67 | // RUN: iree-run-module --device=local-sync \ |
| 68 | // RUN: --module=%t.vmfb \ |
| 69 | // RUN: --function=echo_binary \ |
| 70 | // RUN: --input=f32=@%t.0.bin \ |
| 71 | // RUN: --input=2x4xi32=@%t.1.bin) | \ |
| 72 | // RUN: FileCheck --check-prefix=OUTPUT-BINARY %s |
Ben Vanik | 30901f5 | 2024-02-08 11:23:21 -0800 | [diff] [blame] | 73 | |
| 74 | // Tests output to binary files by round-tripping the output of a function into |
| 75 | // another invocation reading from the binary files. The values are appended to |
| 76 | // a single file and read from the single file. |
| 77 | |
| 78 | // RUN: (iree-compile --iree-hal-target-backends=vmvx %s -o=%t.vmfb && \ |
| 79 | // RUN: iree-run-module --device=local-sync \ |
| 80 | // RUN: --module=%t.vmfb \ |
| 81 | // RUN: --function=write_binary \ |
| 82 | // RUN: --output=@%t.bin \ |
| 83 | // RUN: --output=+%t.bin && \ |
| 84 | // RUN: iree-run-module --device=local-sync \ |
| 85 | // RUN: --module=%t.vmfb \ |
| 86 | // RUN: --function=echo_binary \ |
| 87 | // RUN: --input=f32=@%t.bin \ |
| 88 | // RUN: --input=2x4xi32=+%t.bin) | \ |
| 89 | // RUN: FileCheck --check-prefix=OUTPUT-BINARY %s |
| 90 | |
Ben Vanik | 065e04a | 2024-02-01 16:29:33 -0800 | [diff] [blame] | 91 | func.func @write_binary() -> (tensor<f32>, tensor<?x4xi32>) { |
| 92 | %0 = arith.constant dense<4.0> : tensor<f32> |
Ben Vanik | 55fafcf | 2024-04-12 14:58:38 -0700 | [diff] [blame] | 93 | %1 = flow.tensor.dynamic_constant dense<[[0,1,2,3],[4,5,6,7]]> : tensor<2x4xi32> -> tensor<?x4xi32> |
Ben Vanik | 065e04a | 2024-02-01 16:29:33 -0800 | [diff] [blame] | 94 | return %0, %1 : tensor<f32>, tensor<?x4xi32> |
| 95 | } |
| 96 | func.func @echo_binary(%arg0: tensor<f32>, %arg1: tensor<?x4xi32>) -> (tensor<f32>, tensor<?x4xi32>) { |
| 97 | // OUTPUT-BINARY{LITERAL}: f32=4 |
| 98 | // OUTPUT-BINARY{LITERAL}: 2x4xi32=[0 1 2 3][4 5 6 7] |
| 99 | return %arg0, %arg1 : tensor<f32>, tensor<?x4xi32> |
| 100 | } |