xref: /llvm-project/mlir/test/mlir-runner/async-error.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1// RUN:   mlir-opt %s -pass-pipeline="builtin.module(async-to-async-runtime,func.func(async-runtime-ref-counting,async-runtime-ref-counting-opt),convert-async-to-llvm,func.func(convert-linalg-to-loops,convert-scf-to-cf),convert-vector-to-llvm,func.func(convert-arith-to-llvm),convert-func-to-llvm,convert-cf-to-llvm,reconcile-unrealized-casts)" \
2// RUN: | mlir-runner                                                      \
3// RUN:     -e main -entry-point-result=void -O0                               \
4// RUN:     -shared-libs=%mlir_c_runner_utils  \
5// RUN:     -shared-libs=%mlir_runner_utils    \
6// RUN:     -shared-libs=%mlir_async_runtime   \
7// RUN: | FileCheck %s --dump-input=always
8
9// FIXME: https://github.com/llvm/llvm-project/issues/57231
10// UNSUPPORTED: hwasan
11// FIXME: Windows does not have aligned_alloc
12// UNSUPPORTED: system-windows
13
14func.func @main() {
15  %false = arith.constant 0 : i1
16
17  // ------------------------------------------------------------------------ //
18  // Check that simple async region completes without errors.
19  // ------------------------------------------------------------------------ //
20  %token0 = async.execute {
21    async.yield
22  }
23  async.runtime.await %token0 : !async.token
24
25  // CHECK: 0
26  %err0 = async.runtime.is_error %token0 : !async.token
27  vector.print %err0 : i1
28
29  // ------------------------------------------------------------------------ //
30  // Check that assertion in the async region converted to async error.
31  // ------------------------------------------------------------------------ //
32  %token1 = async.execute {
33    cf.assert %false, "error"
34    async.yield
35  }
36  async.runtime.await %token1 : !async.token
37
38  // CHECK: 1
39  %err1 = async.runtime.is_error %token1 : !async.token
40  vector.print %err1 : i1
41
42  // ------------------------------------------------------------------------ //
43  // Check error propagation from the nested region.
44  // ------------------------------------------------------------------------ //
45  %token2 = async.execute {
46    %token = async.execute {
47      cf.assert %false, "error"
48      async.yield
49    }
50    async.await %token : !async.token
51    async.yield
52  }
53  async.runtime.await %token2 : !async.token
54
55  // CHECK: 1
56  %err2 = async.runtime.is_error %token2 : !async.token
57  vector.print %err2 : i1
58
59  // ------------------------------------------------------------------------ //
60  // Check error propagation from the nested region with async values.
61  // ------------------------------------------------------------------------ //
62  %token3, %value3 = async.execute -> !async.value<f32> {
63    %token, %value = async.execute -> !async.value<f32> {
64      cf.assert %false, "error"
65      %0 = arith.constant 123.45 : f32
66      async.yield %0 : f32
67    }
68    %ret = async.await %value : !async.value<f32>
69    async.yield %ret : f32
70  }
71  async.runtime.await %token3 : !async.token
72  async.runtime.await %value3 : !async.value<f32>
73
74  // CHECK: 1
75  // CHECK: 1
76  %err3_0 = async.runtime.is_error %token3 : !async.token
77  %err3_1 = async.runtime.is_error %value3 : !async.value<f32>
78  vector.print %err3_0 : i1
79  vector.print %err3_1 : i1
80
81  // ------------------------------------------------------------------------ //
82  // Check error propagation from a token to the group.
83  // ------------------------------------------------------------------------ //
84
85  %c2 = arith.constant 2 : index
86  %group0 = async.create_group %c2 : !async.group
87
88  %token4 = async.execute {
89    async.yield
90  }
91
92  %token5 = async.execute {
93    cf.assert %false, "error"
94    async.yield
95  }
96
97  %idx0 = async.add_to_group %token4, %group0 : !async.token
98  %idx1 = async.add_to_group %token5, %group0 : !async.token
99
100  async.runtime.await %group0 : !async.group
101
102  // CHECK: 1
103  %err4 = async.runtime.is_error %group0 : !async.group
104  vector.print %err4 : i1
105
106  return
107}
108