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