annotate mlir/test/mlir-cpu-runner/async.mlir @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
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
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 // RUN: | mlir-cpu-runner \
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // RUN: -e main -entry-point-result=void -O0 \
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
4 // RUN: -shared-libs=%mlir_c_runner_utils \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
5 // RUN: -shared-libs=%mlir_runner_utils \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
6 // RUN: -shared-libs=%mlir_async_runtime \
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 // RUN: | FileCheck %s
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
9 // FIXME: https://github.com/llvm/llvm-project/issues/57231
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
10 // UNSUPPORTED: asan
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
11 // UNSUPPORTED: hwasan
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
12 // FIXME: Windows does not have aligned_alloc
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
13 // UNSUPPORTED: system-windows
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
15 func.func @main() {
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
16 %i0 = arith.constant 0 : index
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
17 %i1 = arith.constant 1 : index
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
18 %i2 = arith.constant 2 : index
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
19 %i3 = arith.constant 3 : index
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
20
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
21 %c0 = arith.constant 0.0 : f32
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
22 %c1 = arith.constant 1.0 : f32
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
23 %c2 = arith.constant 2.0 : f32
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
24 %c3 = arith.constant 3.0 : f32
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
25 %c4 = arith.constant 4.0 : f32
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 %A = memref.alloc() : memref<4xf32>
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
28 linalg.fill ins(%c0 : f32) outs(%A : memref<4xf32>)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 // CHECK: [0, 0, 0, 0]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 %U = memref.cast %A : memref<4xf32> to memref<*xf32>
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
32 call @printMemrefF32(%U): (memref<*xf32>) -> ()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 // CHECK: Current thread id: [[MAIN:.*]]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 // CHECK: [1, 0, 0, 0]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 memref.store %c1, %A[%i0]: memref<4xf32>
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
38 call @printMemrefF32(%U): (memref<*xf32>) -> ()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 %outer = async.execute {
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 // CHECK: Current thread id: [[THREAD0:.*]]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 // CHECK: [1, 2, 0, 0]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 memref.store %c2, %A[%i1]: memref<4xf32>
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
44 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
45 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 // No op async region to create a token for testing async dependency.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 %noop = async.execute {
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 // CHECK: Current thread id: [[THREAD1:.*]]
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
50 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 async.yield
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 }
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 %inner = async.execute [%noop] {
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 // CHECK: Current thread id: [[THREAD2:.*]]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 // CHECK: [1, 2, 3, 0]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 memref.store %c3, %A[%i2]: memref<4xf32>
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
58 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
59 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 async.yield
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 }
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 async.await %inner : !async.token
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 // CHECK: Current thread id: [[THREAD3:.*]]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 // CHECK: [1, 2, 3, 4]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 memref.store %c4, %A[%i3]: memref<4xf32>
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
68 func.call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
69 func.call @printMemrefF32(%U): (memref<*xf32>) -> ()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 async.yield
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 }
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 async.await %outer : !async.token
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 // CHECK: Current thread id: [[MAIN]]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 // CHECK: [1, 2, 3, 4]
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
78 call @printMemrefF32(%U): (memref<*xf32>) -> ()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 memref.dealloc %A : memref<4xf32>
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 return
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 }
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
85 func.func private @mlirAsyncRuntimePrintCurrentThreadId() -> ()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
87 func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface }