38 lines · plain
1// RUN: mlir-opt %s \2// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-format=%gpu_compilation_format allow-pattern-rollback=0" \3// RUN: | mlir-runner \4// RUN: --shared-libs=%mlir_cuda_runtime \5// RUN: --shared-libs=%mlir_runner_utils \6// RUN: --entry-point-result=void \7// RUN: | FileCheck %s8 9// CHECK-COUNT-8: [{{(5356, ){12}5356}}]10func.func @main() {11 %arg = memref.alloc() : memref<2x4x13xf32>12 %dst = memref.cast %arg : memref<2x4x13xf32> to memref<?x?x?xf32>13 %c0 = arith.constant 0 : index14 %c1 = arith.constant 1 : index15 %c2 = arith.constant 2 : index16 %sx = memref.dim %dst, %c2 : memref<?x?x?xf32>17 %sy = memref.dim %dst, %c1 : memref<?x?x?xf32>18 %sz = memref.dim %dst, %c0 : memref<?x?x?xf32>19 %cast_dst = memref.cast %dst : memref<?x?x?xf32> to memref<*xf32>20 gpu.host_register %cast_dst : memref<*xf32>21 gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %c1, %grid_y = %c1, %grid_z = %c1)22 threads(%tx, %ty, %tz) in (%block_x = %sx, %block_y = %sy, %block_z = %sz) {23 %t0 = arith.muli %tz, %block_y : index24 %t1 = arith.addi %ty, %t0 : index25 %t2 = arith.muli %t1, %block_x : index26 %idx = arith.addi %tx, %t2 : index27 %t3 = arith.index_cast %idx : index to i3228 %val = arith.sitofp %t3 : i32 to f3229 %sum = gpu.all_reduce add %val uniform {} : (f32) -> (f32)30 memref.store %sum, %dst[%tz, %ty, %tx] : memref<?x?x?xf32>31 gpu.terminator32 }33 call @printMemrefF32(%cast_dst) : (memref<*xf32>) -> ()34 return35}36 37func.func private @printMemrefF32(%ptr : memref<*xf32>)38