163 lines · plain
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: -finalize-memref-to-llvm \13// RUN: -convert-func-to-llvm \14// RUN: -convert-arith-to-llvm \15// RUN: -convert-cf-to-llvm \16// RUN: -reconcile-unrealized-casts \17// RUN: | mlir-runner \18// RUN: -e entry -entry-point-result=void -O3 \19// RUN: -shared-libs=%mlir_runner_utils \20// RUN: -shared-libs=%mlir_c_runner_utils\21// RUN: -shared-libs=%mlir_async_runtime \22// RUN: | FileCheck %s --dump-input=always23 24// RUN: mlir-opt %s \25// RUN: -async-parallel-for=async-dispatch=false \26// RUN: -async-to-async-runtime \27// RUN: -async-runtime-ref-counting \28// RUN: -async-runtime-ref-counting-opt \29// RUN: -convert-async-to-llvm \30// RUN: -convert-linalg-to-loops \31// RUN: -convert-scf-to-cf \32// RUN: -arith-expand \33// RUN: -memref-expand \34// RUN: -convert-vector-to-llvm \35// RUN: -finalize-memref-to-llvm \36// RUN: -convert-func-to-llvm \37// RUN: -convert-arith-to-llvm \38// RUN: -convert-cf-to-llvm \39// RUN: -reconcile-unrealized-casts \40// RUN: | mlir-runner \41// RUN: -e entry -entry-point-result=void -O3 \42// RUN: -shared-libs=%mlir_runner_utils \43// RUN: -shared-libs=%mlir_c_runner_utils\44// RUN: -shared-libs=%mlir_async_runtime \45// RUN: | FileCheck %s --dump-input=always46 47// RUN: mlir-opt %s \48// RUN: -convert-linalg-to-loops \49// RUN: -convert-scf-to-cf \50// RUN: -convert-vector-to-llvm \51// RUN: -finalize-memref-to-llvm \52// RUN: -convert-func-to-llvm \53// RUN: -convert-arith-to-llvm \54// RUN: -convert-cf-to-llvm \55// RUN: -reconcile-unrealized-casts \56// RUN: | mlir-runner \57// RUN: -e entry -entry-point-result=void -O3 \58// RUN: -shared-libs=%mlir_runner_utils \59// RUN: -shared-libs=%mlir_c_runner_utils\60// RUN: -shared-libs=%mlir_async_runtime \61// RUN: | FileCheck %s --dump-input=always62 63#map0 = affine_map<(d0, d1) -> (d0, d1)>64 65func.func @scf_parallel(%lhs: memref<?x?xf32>,66 %rhs: memref<?x?xf32>,67 %sum: memref<?x?xf32>) {68 %c0 = arith.constant 0 : index69 %c1 = arith.constant 1 : index70 71 %d0 = memref.dim %lhs, %c0 : memref<?x?xf32>72 %d1 = memref.dim %lhs, %c1 : memref<?x?xf32>73 74 scf.parallel (%i, %j) = (%c0, %c0) to (%d0, %d1) step (%c1, %c1) {75 %lv = memref.load %lhs[%i, %j] : memref<?x?xf32>76 %rv = memref.load %lhs[%i, %j] : memref<?x?xf32>77 %r = arith.addf %lv, %rv : f3278 memref.store %r, %sum[%i, %j] : memref<?x?xf32>79 }80 81 return82}83 84func.func @entry() {85 %f1 = arith.constant 1.0 : f3286 %f4 = arith.constant 4.0 : f3287 %c0 = arith.constant 0 : index88 %c1 = arith.constant 1 : index89 %cN = arith.constant 50 : index90 91 //92 // Sanity check for the function under test.93 //94 95 %LHS10 = memref.alloc() {alignment = 64} : memref<1x10xf32>96 %RHS10 = memref.alloc() {alignment = 64} : memref<1x10xf32>97 %DST10 = memref.alloc() {alignment = 64} : memref<1x10xf32>98 99 linalg.fill ins(%f1 : f32) outs(%LHS10 : memref<1x10xf32>)100 linalg.fill ins(%f1 : f32) outs(%RHS10 : memref<1x10xf32>)101 102 %LHS = memref.cast %LHS10 : memref<1x10xf32> to memref<?x?xf32>103 %RHS = memref.cast %RHS10 : memref<1x10xf32> to memref<?x?xf32>104 %DST = memref.cast %DST10 : memref<1x10xf32> to memref<?x?xf32>105 106 call @scf_parallel(%LHS, %RHS, %DST)107 : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> ()108 109 // CHECK: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]110 %U = memref.cast %DST10 : memref<1x10xf32> to memref<*xf32>111 call @printMemrefF32(%U): (memref<*xf32>) -> ()112 113 memref.dealloc %LHS10: memref<1x10xf32>114 memref.dealloc %RHS10: memref<1x10xf32>115 memref.dealloc %DST10: memref<1x10xf32>116 117 //118 // Allocate data for microbenchmarks.119 //120 121 %LHS1024 = memref.alloc() {alignment = 64} : memref<1024x1024xf32>122 %RHS1024 = memref.alloc() {alignment = 64} : memref<1024x1024xf32>123 %DST1024 = memref.alloc() {alignment = 64} : memref<1024x1024xf32>124 125 %LHS0 = memref.cast %LHS1024 : memref<1024x1024xf32> to memref<?x?xf32>126 %RHS0 = memref.cast %RHS1024 : memref<1024x1024xf32> to memref<?x?xf32>127 %DST0 = memref.cast %DST1024 : memref<1024x1024xf32> to memref<?x?xf32>128 129 //130 // Warm up.131 //132 133 call @scf_parallel(%LHS0, %RHS0, %DST0)134 : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> ()135 136 //137 // Measure execution time.138 //139 140 %t0 = call @rtclock() : () -> f64141 scf.for %i = %c0 to %cN step %c1 {142 func.call @scf_parallel(%LHS0, %RHS0, %DST0)143 : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> ()144 }145 %t1 = call @rtclock() : () -> f64146 %t1024 = arith.subf %t1, %t0 : f64147 148 // Print timings.149 vector.print %t1024 : f64150 151 // Free.152 memref.dealloc %LHS1024: memref<1024x1024xf32>153 memref.dealloc %RHS1024: memref<1024x1024xf32>154 memref.dealloc %DST1024: memref<1024x1024xf32>155 156 return157}158 159func.func private @rtclock() -> f64160 161func.func private @printMemrefF32(memref<*xf32>)162 attributes { llvm.emit_c_interface }163