1 // RUN: mlir-opt %s -async-parallel-for \
2 // RUN: -async-to-async-runtime \
3 // RUN: -async-runtime-ref-counting \
4 // RUN: -async-runtime-ref-counting-opt \
5 // RUN: -arith-expand \
6 // RUN: -convert-async-to-llvm \
7 // RUN: -convert-scf-to-std \
8 // RUN: -convert-memref-to-llvm \
9 // RUN: -convert-std-to-llvm \
10 // RUN: -reconcile-unrealized-casts \
11 // RUN: | mlir-cpu-runner \
12 // RUN: -e entry -entry-point-result=void -O0 \
13 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \
14 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_async_runtime%shlibext\
15 // RUN: | FileCheck %s --dump-input=always
17 // RUN: mlir-opt %s -async-parallel-for \
18 // RUN: -async-to-async-runtime \
19 // RUN: -async-runtime-policy-based-ref-counting \
20 // RUN: -arith-expand \
21 // RUN: -convert-async-to-llvm \
22 // RUN: -convert-scf-to-std \
23 // RUN: -convert-memref-to-llvm \
24 // RUN: -convert-std-to-llvm \
25 // RUN: -reconcile-unrealized-casts \
26 // RUN: | mlir-cpu-runner \
27 // RUN: -e entry -entry-point-result=void -O0 \
28 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \
29 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_async_runtime%shlibext\
30 // RUN: | FileCheck %s --dump-input=always
32 // RUN: mlir-opt %s -async-parallel-for="async-dispatch=false \
33 // RUN: num-workers=20 \
34 // RUN: min-task-size=1" \
35 // RUN: -async-to-async-runtime \
36 // RUN: -async-runtime-ref-counting \
37 // RUN: -async-runtime-ref-counting-opt \
38 // RUN: -arith-expand \
39 // RUN: -convert-async-to-llvm \
40 // RUN: -convert-scf-to-std \
41 // RUN: -convert-memref-to-llvm \
42 // RUN: -convert-std-to-llvm \
43 // RUN: -reconcile-unrealized-casts \
44 // RUN: | mlir-cpu-runner \
45 // RUN: -e entry -entry-point-result=void -O0 \
46 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \
47 // RUN: -shared-libs=%mlir_integration_test_dir/libmlir_async_runtime%shlibext\
48 // RUN: | FileCheck %s --dump-input=always
51 %c0 = arith.constant 0.0 : f32
52 %c1 = arith.constant 1 : index
53 %c2 = arith.constant 2 : index
54 %c8 = arith.constant 8 : index
56 %lb = arith.constant 0 : index
57 %ub = arith.constant 8 : index
59 %A = memref.alloc() : memref<8x8xf32>
60 %U = memref.cast %A : memref<8x8xf32> to memref<*xf32>
62 // Initialize memref with zeros because we do load and store to in every test
63 // to verify that we process each element of the iteration space once.
64 scf.parallel (%i, %j) = (%lb, %lb) to (%ub, %ub) step (%c1, %c1) {
65 memref.store %c0, %A[%i, %j] : memref<8x8xf32>
68 // 1. (%i, %i) = (0, 8) to (8, 8) step (1, 1)
69 scf.parallel (%i, %j) = (%lb, %lb) to (%ub, %ub) step (%c1, %c1) {
70 %0 = arith.muli %i, %c8 : index
71 %1 = arith.addi %j, %0 : index
72 %2 = arith.index_cast %1 : index to i32
73 %3 = arith.sitofp %2 : i32 to f32
74 %4 = memref.load %A[%i, %j] : memref<8x8xf32>
75 %5 = arith.addf %3, %4 : f32
76 memref.store %5, %A[%i, %j] : memref<8x8xf32>
79 // CHECK: [0, 1, 2, 3, 4, 5, 6, 7]
80 // CHECK-NEXT: [8, 9, 10, 11, 12, 13, 14, 15]
81 // CHECK-NEXT: [16, 17, 18, 19, 20, 21, 22, 23]
82 // CHECK-NEXT: [24, 25, 26, 27, 28, 29, 30, 31]
83 // CHECK-NEXT: [32, 33, 34, 35, 36, 37, 38, 39]
84 // CHECK-NEXT: [40, 41, 42, 43, 44, 45, 46, 47]
85 // CHECK-NEXT: [48, 49, 50, 51, 52, 53, 54, 55]
86 // CHECK-NEXT: [56, 57, 58, 59, 60, 61, 62, 63]
87 call @print_memref_f32(%U): (memref<*xf32>) -> ()
89 scf.parallel (%i, %j) = (%lb, %lb) to (%ub, %ub) step (%c1, %c1) {
90 memref.store %c0, %A[%i, %j] : memref<8x8xf32>
93 // 2. (%i, %i) = (0, 8) to (8, 8) step (2, 1)
94 scf.parallel (%i, %j) = (%lb, %lb) to (%ub, %ub) step (%c2, %c1) {
95 %0 = arith.muli %i, %c8 : index
96 %1 = arith.addi %j, %0 : index
97 %2 = arith.index_cast %1 : index to i32
98 %3 = arith.sitofp %2 : i32 to f32
99 %4 = memref.load %A[%i, %j] : memref<8x8xf32>
100 %5 = arith.addf %3, %4 : f32
101 memref.store %5, %A[%i, %j] : memref<8x8xf32>
104 // CHECK: [0, 1, 2, 3, 4, 5, 6, 7]
105 // CHECK-NEXT: [0, 0, 0, 0, 0, 0, 0, 0]
106 // CHECK-NEXT: [16, 17, 18, 19, 20, 21, 22, 23]
107 // CHECK-NEXT: [0, 0, 0, 0, 0, 0, 0, 0]
108 // CHECK-NEXT: [32, 33, 34, 35, 36, 37, 38, 39]
109 // CHECK-NEXT: [0, 0, 0, 0, 0, 0, 0, 0]
110 // CHECK-NEXT: [48, 49, 50, 51, 52, 53, 54, 55]
111 // CHECK-NEXT: [0, 0, 0, 0, 0, 0, 0, 0]
112 call @print_memref_f32(%U): (memref<*xf32>) -> ()
114 scf.parallel (%i, %j) = (%lb, %lb) to (%ub, %ub) step (%c1, %c1) {
115 memref.store %c0, %A[%i, %j] : memref<8x8xf32>
118 // 3. (%i, %i) = (0, 8) to (8, 8) step (1, 2)
119 scf.parallel (%i, %j) = (%lb, %lb) to (%ub, %ub) step (%c1, %c2) {
120 %0 = arith.muli %i, %c8 : index
121 %1 = arith.addi %j, %0 : index
122 %2 = arith.index_cast %1 : index to i32
123 %3 = arith.sitofp %2 : i32 to f32
124 %4 = memref.load %A[%i, %j] : memref<8x8xf32>
125 %5 = arith.addf %3, %4 : f32
126 memref.store %5, %A[%i, %j] : memref<8x8xf32>
129 // CHECK: [0, 0, 2, 0, 4, 0, 6, 0]
130 // CHECK-NEXT: [8, 0, 10, 0, 12, 0, 14, 0]
131 // CHECK-NEXT: [16, 0, 18, 0, 20, 0, 22, 0]
132 // CHECK-NEXT: [24, 0, 26, 0, 28, 0, 30, 0]
133 // CHECK-NEXT: [32, 0, 34, 0, 36, 0, 38, 0]
134 // CHECK-NEXT: [40, 0, 42, 0, 44, 0, 46, 0]
135 // CHECK-NEXT: [48, 0, 50, 0, 52, 0, 54, 0]
136 // CHECK-NEXT: [56, 0, 58, 0, 60, 0, 62, 0]
137 call @print_memref_f32(%U): (memref<*xf32>) -> ()
139 memref.dealloc %A : memref<8x8xf32>
144 func private @print_memref_f32(memref<*xf32>) attributes { llvm.emit_c_interface }