1// RUN:   mlir-opt %s                                                          \
2// RUN:               -async-parallel-for                                      \
3// RUN:               -async-to-async-runtime                                  \
4// RUN:               -async-runtime-ref-counting                              \
5// RUN:               -async-runtime-ref-counting-opt                          \
6// RUN:               -convert-async-to-llvm                                   \
7// RUN:               -convert-linalg-to-loops                                 \
8// RUN:               -convert-scf-to-cf                                      \
9// RUN:               -arith-expand                                            \
10// RUN:               -memref-expand                                              \
11// RUN:               -convert-vector-to-llvm                                  \
12// RUN:               -convert-memref-to-llvm                                  \
13// RUN:               -convert-func-to-llvm                                     \
14// RUN:               -reconcile-unrealized-casts                              \
15// RUN: | mlir-cpu-runner                                                      \
16// RUN: -e entry -entry-point-result=void -O3                                  \
17// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext  \
18// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext\
19// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_async_runtime%shlibext \
20// RUN: | FileCheck %s --dump-input=always
21
22// RUN:   mlir-opt %s                                                          \
23// RUN:               -async-parallel-for=async-dispatch=false                 \
24// RUN:               -async-to-async-runtime                                  \
25// RUN:               -async-runtime-ref-counting                              \
26// RUN:               -async-runtime-ref-counting-opt                          \
27// RUN:               -convert-async-to-llvm                                   \
28// RUN:               -convert-linalg-to-loops                                 \
29// RUN:               -convert-scf-to-cf                                      \
30// RUN:               -arith-expand                                            \
31// RUN:               -memref-expand                                              \
32// RUN:               -convert-vector-to-llvm                                  \
33// RUN:               -convert-memref-to-llvm                                  \
34// RUN:               -convert-func-to-llvm                                     \
35// RUN:               -reconcile-unrealized-casts                              \
36// RUN: | mlir-cpu-runner                                                      \
37// RUN: -e entry -entry-point-result=void -O3                                  \
38// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext  \
39// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext\
40// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_async_runtime%shlibext \
41// RUN: | FileCheck %s --dump-input=always
42
43// RUN:   mlir-opt %s                                                          \
44// RUN:               -convert-linalg-to-loops                                 \
45// RUN:               -convert-scf-to-cf                                      \
46// RUN:               -convert-vector-to-llvm                                  \
47// RUN:               -convert-memref-to-llvm                                  \
48// RUN:               -convert-func-to-llvm                                     \
49// RUN:               -reconcile-unrealized-casts                              \
50// RUN: | mlir-cpu-runner                                                      \
51// RUN: -e entry -entry-point-result=void -O3                                  \
52// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext  \
53// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext\
54// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_async_runtime%shlibext \
55// RUN: | FileCheck %s --dump-input=always
56
57#map0 = affine_map<(d0, d1) -> (d0, d1)>
58
59func @scf_parallel(%lhs: memref<?x?xf32>,
60                   %rhs: memref<?x?xf32>,
61                   %sum: memref<?x?xf32>) {
62  %c0 = arith.constant 0 : index
63  %c1 = arith.constant 1 : index
64
65  %d0 = memref.dim %lhs, %c0 : memref<?x?xf32>
66  %d1 = memref.dim %lhs, %c1 : memref<?x?xf32>
67
68  scf.parallel (%i, %j) = (%c0, %c0) to (%d0, %d1) step (%c1, %c1) {
69    %lv = memref.load %lhs[%i, %j] : memref<?x?xf32>
70    %rv = memref.load %lhs[%i, %j] : memref<?x?xf32>
71    %r = arith.addf %lv, %rv : f32
72    memref.store %r, %sum[%i, %j] : memref<?x?xf32>
73  }
74
75  return
76}
77
78func @entry() {
79  %f1 = arith.constant 1.0 : f32
80  %f4 = arith.constant 4.0 : f32
81  %c0 = arith.constant 0 : index
82  %c1 = arith.constant 1 : index
83  %cN = arith.constant 50 : index
84
85  //
86  // Sanity check for the function under test.
87  //
88
89  %LHS10 = memref.alloc() {alignment = 64} : memref<1x10xf32>
90  %RHS10 = memref.alloc() {alignment = 64} : memref<1x10xf32>
91  %DST10 = memref.alloc() {alignment = 64} : memref<1x10xf32>
92
93  linalg.fill ins(%f1 : f32) outs(%LHS10 : memref<1x10xf32>)
94  linalg.fill ins(%f1 : f32) outs(%RHS10 : memref<1x10xf32>)
95
96  %LHS = memref.cast %LHS10 : memref<1x10xf32> to memref<?x?xf32>
97  %RHS = memref.cast %RHS10 : memref<1x10xf32> to memref<?x?xf32>
98  %DST = memref.cast %DST10 : memref<1x10xf32> to memref<?x?xf32>
99
100  call @scf_parallel(%LHS, %RHS, %DST)
101    : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> ()
102
103  // CHECK: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
104  %U = memref.cast %DST10 :  memref<1x10xf32> to memref<*xf32>
105  call @print_memref_f32(%U): (memref<*xf32>) -> ()
106
107  memref.dealloc %LHS10: memref<1x10xf32>
108  memref.dealloc %RHS10: memref<1x10xf32>
109  memref.dealloc %DST10: memref<1x10xf32>
110
111  //
112  // Allocate data for microbenchmarks.
113  //
114
115  %LHS1024 = memref.alloc() {alignment = 64} : memref<1024x1024xf32>
116  %RHS1024 = memref.alloc() {alignment = 64} : memref<1024x1024xf32>
117  %DST1024 = memref.alloc() {alignment = 64} : memref<1024x1024xf32>
118
119  %LHS0 = memref.cast %LHS1024 : memref<1024x1024xf32> to memref<?x?xf32>
120  %RHS0 = memref.cast %RHS1024 : memref<1024x1024xf32> to memref<?x?xf32>
121  %DST0 = memref.cast %DST1024 : memref<1024x1024xf32> to memref<?x?xf32>
122
123  //
124  // Warm up.
125  //
126
127  call @scf_parallel(%LHS0, %RHS0, %DST0)
128    : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> ()
129
130  //
131  // Measure execution time.
132  //
133
134  %t0 = call @rtclock() : () -> f64
135  scf.for %i = %c0 to %cN step %c1 {
136    call @scf_parallel(%LHS0, %RHS0, %DST0)
137      : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> ()
138  }
139  %t1 = call @rtclock() : () -> f64
140  %t1024 = arith.subf %t1, %t0 : f64
141
142  // Print timings.
143  vector.print %t1024 : f64
144
145  // Free.
146  memref.dealloc %LHS1024: memref<1024x1024xf32>
147  memref.dealloc %RHS1024: memref<1024x1024xf32>
148  memref.dealloc %DST1024: memref<1024x1024xf32>
149
150  return
151}
152
153func private @rtclock() -> f64
154
155func private @print_memref_f32(memref<*xf32>)
156  attributes { llvm.emit_c_interface }
157