brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · f1a48ae Raw
69 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 9func.func @main() {10  %data = memref.alloc() : memref<2x6xi32>11  %sum = memref.alloc() : memref<2xi32>12  %cst0 = arith.constant 0 : i3213  %cst1 = arith.constant 1 : i3214  %cst2 = arith.constant 2 : i3215  %cst4 = arith.constant 4 : i3216  %cst8 = arith.constant 8 : i3217  %cst16 = arith.constant 16 : i3218 19  %cst3 = arith.constant 3 : i3220  %cst6 = arith.constant 6 : i3221  %cst7 = arith.constant 7 : i3222  %cst10 = arith.constant 10 : i3223  %cst11 = arith.constant 11 : i3224 25  %c0 = arith.constant 0 : index26  %c1 = arith.constant 1 : index27  %c2 = arith.constant 2 : index28  %c3 = arith.constant 3 : index29  %c4 = arith.constant 4 : index30  %c5 = arith.constant 5 : index31  %c6 = arith.constant 6 : index32 33  %cast_data = memref.cast %data : memref<2x6xi32> to memref<*xi32>34  gpu.host_register %cast_data : memref<*xi32>35  %cast_sum = memref.cast %sum : memref<2xi32> to memref<*xi32>36  gpu.host_register %cast_sum : memref<*xi32>37 38  memref.store %cst0, %data[%c0, %c0] : memref<2x6xi32>39  memref.store %cst1, %data[%c0, %c1] : memref<2x6xi32>40  memref.store %cst2, %data[%c0, %c2] : memref<2x6xi32>41  memref.store %cst4, %data[%c0, %c3] : memref<2x6xi32>42  memref.store %cst8, %data[%c0, %c4] : memref<2x6xi32>43  memref.store %cst16, %data[%c0, %c5] : memref<2x6xi32>44 45  memref.store %cst2, %data[%c1, %c0] : memref<2x6xi32>46  memref.store %cst3, %data[%c1, %c1] : memref<2x6xi32>47  memref.store %cst6, %data[%c1, %c2] : memref<2x6xi32>48  memref.store %cst7, %data[%c1, %c3] : memref<2x6xi32>49  memref.store %cst10, %data[%c1, %c4] : memref<2x6xi32>50  memref.store %cst11, %data[%c1, %c5] : memref<2x6xi32>51 52  // OR53  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %c2, %grid_y = %c1, %grid_z = %c1)54             threads(%tx, %ty, %tz) in (%block_x = %c6, %block_y = %c1, %block_z = %c1) {55    %val = memref.load %data[%bx, %tx] : memref<2x6xi32>56    %reduced = gpu.all_reduce or %val uniform {} : (i32) -> (i32)57    memref.store %reduced, %sum[%bx] : memref<2xi32>58    gpu.terminator59  }60 61  call @printMemrefI32(%cast_sum) : (memref<*xi32>) -> ()62  // CHECK: [31, 15]63 64  return65}66 67func.func private @printMemrefI32(memref<*xi32>)68 69