blob: 66765cf433b7eb2f0a1ac9c255818231915d90cd [file] [log] [blame]
Ben Vanike309cb32023-02-01 11:59:39 -08001// Tests that execution providing no outputs is ok.
2
3// RUN: (iree-compile --iree-hal-target-backends=vmvx %s | \
Ben Vanik9461d3b2023-04-18 16:39:25 -07004// RUN: iree-run-module --device=local-sync --module=- --function=no_output) | \
Ben Vanike309cb32023-02-01 11:59:39 -08005// RUN: FileCheck --check-prefix=NO-OUTPUT %s
6// NO-OUTPUT-LABEL: EXEC @no_output
7func.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 Vanik9461d3b2023-04-18 16:39:25 -070016// RUN: iree-run-module --device=local-sync --module=- --function=default) | \
Ben Vanike309cb32023-02-01 11:59:39 -080017// RUN: FileCheck --check-prefix=OUTPUT-DEFAULT %s
18// OUTPUT-DEFAULT-LABEL: EXEC @default
19func.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 Vanik55fafcf2024-04-12 14:58:38 -070027 %2 = flow.tensor.dynamic_constant dense<[[0,1,2,3],[4,5,6,7]]> : tensor<2x4xi32> -> tensor<?x4xi32>
Ben Vanike309cb32023-02-01 11:59:39 -080028 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 Vanik9461d3b2023-04-18 16:39:25 -070038// RUN: iree-run-module --device=local-sync --module=- --function=numpy \
Ben Vanike309cb32023-02-01 11:59:39 -080039// RUN: --output= \
Ben Vanik065e04a2024-02-01 16:29:33 -080040// RUN: --output=@%t.npy \
41// RUN: --output=+%t.npy) && \
42// RUN: "%PYTHON" %S/echo_npy.py %t.npy | \
Ben Vanike309cb32023-02-01 11:59:39 -080043// RUN: FileCheck --check-prefix=OUTPUT-NUMPY %s
44func.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 Vanik55fafcf2024-04-12 14:58:38 -070051 %2 = flow.tensor.dynamic_constant dense<[[0,1,2,3],[4,5,6,7]]> : tensor<2x4xi32> -> tensor<?x4xi32>
Ben Vanike309cb32023-02-01 11:59:39 -080052 return %0, %1, %2 : i32, tensor<f32>, tensor<?x4xi32>
53}
Ben Vanik065e04a2024-02-01 16:29:33 -080054
55// -----
56
57// Tests output to binary files by round-tripping the output of a function into
Ben Vanik30901f52024-02-08 11:23:21 -080058// another invocation reading from the binary files. Each output is written to
59// its own file (optimal for alignment/easier to inspect).
Ben Vanik065e04a2024-02-01 16:29:33 -080060
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 Vanik30901f52024-02-08 11:23:21 -080073
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 Vanik065e04a2024-02-01 16:29:33 -080091func.func @write_binary() -> (tensor<f32>, tensor<?x4xi32>) {
92 %0 = arith.constant dense<4.0> : tensor<f32>
Ben Vanik55fafcf2024-04-12 14:58:38 -070093 %1 = flow.tensor.dynamic_constant dense<[[0,1,2,3],[4,5,6,7]]> : tensor<2x4xi32> -> tensor<?x4xi32>
Ben Vanik065e04a2024-02-01 16:29:33 -080094 return %0, %1 : tensor<f32>, tensor<?x4xi32>
95}
96func.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}