252
|
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)" \
|
221
|
2 // RUN: | mlir-cpu-runner \
|
|
3 // RUN: -e main -entry-point-result=void -O0 \
|
252
|
4 // RUN: -shared-libs=%mlir_c_runner_utils \
|
|
5 // RUN: -shared-libs=%mlir_runner_utils \
|
|
6 // RUN: -shared-libs=%mlir_async_runtime \
|
221
|
7 // RUN: | FileCheck %s
|
|
8
|
236
|
9 // FIXME: https://github.com/llvm/llvm-project/issues/57231
|
252
|
10 // UNSUPPORTED: asan
|
236
|
11 // UNSUPPORTED: hwasan
|
252
|
12 // FIXME: Windows does not have aligned_alloc
|
|
13 // UNSUPPORTED: system-windows
|
221
|
14
|
236
|
15 func.func @main() {
|
|
16 %i0 = arith.constant 0 : index
|
|
17 %i1 = arith.constant 1 : index
|
|
18 %i2 = arith.constant 2 : index
|
|
19 %i3 = arith.constant 3 : index
|
|
20
|
|
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
|
221
|
26
|
|
27 %A = memref.alloc() : memref<4xf32>
|
236
|
28 linalg.fill ins(%c0 : f32) outs(%A : memref<4xf32>)
|
221
|
29
|
|
30 // CHECK: [0, 0, 0, 0]
|
|
31 %U = memref.cast %A : memref<4xf32> to memref<*xf32>
|
236
|
32 call @printMemrefF32(%U): (memref<*xf32>) -> ()
|
221
|
33
|
|
34 // CHECK: Current thread id: [[MAIN:.*]]
|
|
35 // CHECK: [1, 0, 0, 0]
|
|
36 memref.store %c1, %A[%i0]: memref<4xf32>
|
|
37 call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
|
236
|
38 call @printMemrefF32(%U): (memref<*xf32>) -> ()
|
221
|
39
|
|
40 %outer = async.execute {
|
|
41 // CHECK: Current thread id: [[THREAD0:.*]]
|
|
42 // CHECK: [1, 2, 0, 0]
|
|
43 memref.store %c2, %A[%i1]: memref<4xf32>
|
236
|
44 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
|
|
45 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
|
221
|
46
|
|
47 // No op async region to create a token for testing async dependency.
|
|
48 %noop = async.execute {
|
|
49 // CHECK: Current thread id: [[THREAD1:.*]]
|
236
|
50 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
|
221
|
51 async.yield
|
|
52 }
|
|
53
|
|
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>
|
236
|
58 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
|
|
59 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
|
221
|
60
|
|
61 async.yield
|
|
62 }
|
|
63 async.await %inner : !async.token
|
|
64
|
|
65 // CHECK: Current thread id: [[THREAD3:.*]]
|
|
66 // CHECK: [1, 2, 3, 4]
|
|
67 memref.store %c4, %A[%i3]: memref<4xf32>
|
236
|
68 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
|
|
69 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
|
221
|
70
|
|
71 async.yield
|
|
72 }
|
|
73 async.await %outer : !async.token
|
|
74
|
|
75 // CHECK: Current thread id: [[MAIN]]
|
|
76 // CHECK: [1, 2, 3, 4]
|
|
77 call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
|
236
|
78 call @printMemrefF32(%U): (memref<*xf32>) -> ()
|
221
|
79
|
|
80 memref.dealloc %A : memref<4xf32>
|
|
81
|
|
82 return
|
|
83 }
|
|
84
|
236
|
85 func.func private @mlirAsyncRuntimePrintCurrentThreadId() -> ()
|
221
|
86
|
236
|
87 func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface }
|