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),finalize-memref-to-llvm,func.func(convert-arith-to-llvm),convert-func-to-llvm,reconcile-unrealized-casts)" \
2 // RUN: | mlir-cpu-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 \
9 // FIXME: https://github.com/llvm/llvm-project/issues/57231
11 // UNSUPPORTED: hwasan
12 // FIXME: Windows does not have aligned_alloc
13 // UNSUPPORTED: system-windows
16 %i0 = arith.constant 0 : index
17 %i1 = arith.constant 1 : index
18 %i2 = arith.constant 2 : index
19 %i3 = arith.constant 3 : index
21 %c0 = arith.constant 0.0 : f32
22 %c1 = arith.constant 1.0 : f32
23 %c2 = arith.constant 2.0 : f32
24 %c3 = arith.constant 3.0 : f32
25 %c4 = arith.constant 4.0 : f32
27 %A = memref.alloc() : memref<4xf32>
28 linalg.fill ins(%c0 : f32) outs(%A : memref<4xf32>)
30 // CHECK: [0, 0, 0, 0]
31 %U = memref.cast %A : memref<4xf32> to memref<*xf32>
32 call @printMemrefF32(%U): (memref<*xf32>) -> ()
34 // CHECK: Current thread id: [[MAIN:.*]]
35 // CHECK: [1, 0, 0, 0]
36 memref.store %c1, %A[%i0]: memref<4xf32>
37 call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
38 call @printMemrefF32(%U): (memref<*xf32>) -> ()
40 %outer = async.execute {
41 // CHECK: Current thread id: [[THREAD0:.*]]
42 // CHECK: [1, 2, 0, 0]
43 memref.store %c2, %A[%i1]: memref<4xf32>
44 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
45 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
47 // No op async region to create a token for testing async dependency.
48 %noop = async.execute {
49 // CHECK: Current thread id: [[THREAD1:.*]]
50 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
54 %inner = async.execute [%noop] {
55 // CHECK: Current thread id: [[THREAD2:.*]]
56 // CHECK: [1, 2, 3, 0]
57 memref.store %c3, %A[%i2]: memref<4xf32>
58 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
59 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
63 async.await %inner : !async.token
65 // CHECK: Current thread id: [[THREAD3:.*]]
66 // CHECK: [1, 2, 3, 4]
67 memref.store %c4, %A[%i3]: memref<4xf32>
68 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
69 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
73 async.await %outer : !async.token
75 // CHECK: Current thread id: [[MAIN]]
76 // CHECK: [1, 2, 3, 4]
77 call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
78 call @printMemrefF32(%U): (memref<*xf32>) -> ()
80 memref.dealloc %A : memref<4xf32>
85 func.func private @mlirAsyncRuntimePrintCurrentThreadId() -> ()
87 func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface }