brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · d0001f6 Raw
77 lines · plain
1// RUN: mlir-opt %s \2// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="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// Same as above but with the memref bare pointer lowering convention.10// RUN: mlir-opt %s \11// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="kernel-bare-ptr-calling-convention=1 cubin-format=%gpu_compilation_format" \12// RUN: | mlir-runner \13// RUN:   --shared-libs=%mlir_cuda_runtime \14// RUN:   --shared-libs=%mlir_runner_utils \15// RUN:   --entry-point-result=void \16// RUN: | FileCheck %s17 18func.func @main() {19  %data = memref.alloc() : memref<2x6xi32>20  %sum = memref.alloc() : memref<2xi32>21  %cst0 = arith.constant 0 : i3222  %cst1 = arith.constant 1 : i3223  %cst2 = arith.constant 2 : i3224  %cst4 = arith.constant 4 : i3225  %cst8 = arith.constant 8 : i3226  %cst16 = arith.constant 16 : i3227 28  %cst3 = arith.constant 3 : i3229  %cst6 = arith.constant 6 : i3230  %cst7 = arith.constant 7 : i3231  %cst10 = arith.constant 10 : i3232  %cst11 = arith.constant 11 : i3233 34  %c0 = arith.constant 0 : index35  %c1 = arith.constant 1 : index36  %c2 = arith.constant 2 : index37  %c3 = arith.constant 3 : index38  %c4 = arith.constant 4 : index39  %c5 = arith.constant 5 : index40  %c6 = arith.constant 6 : index41 42  %cast_data = memref.cast %data : memref<2x6xi32> to memref<*xi32>43  gpu.host_register %cast_data : memref<*xi32>44  %cast_sum = memref.cast %sum : memref<2xi32> to memref<*xi32>45  gpu.host_register %cast_sum : memref<*xi32>46 47  memref.store %cst0, %data[%c0, %c0] : memref<2x6xi32>48  memref.store %cst1, %data[%c0, %c1] : memref<2x6xi32>49  memref.store %cst2, %data[%c0, %c2] : memref<2x6xi32>50  memref.store %cst4, %data[%c0, %c3] : memref<2x6xi32>51  memref.store %cst8, %data[%c0, %c4] : memref<2x6xi32>52  memref.store %cst16, %data[%c0, %c5] : memref<2x6xi32>53 54  memref.store %cst2, %data[%c1, %c0] : memref<2x6xi32>55  memref.store %cst3, %data[%c1, %c1] : memref<2x6xi32>56  memref.store %cst6, %data[%c1, %c2] : memref<2x6xi32>57  memref.store %cst7, %data[%c1, %c3] : memref<2x6xi32>58  memref.store %cst10, %data[%c1, %c4] : memref<2x6xi32>59  memref.store %cst11, %data[%c1, %c5] : memref<2x6xi32>60 61  // AND62  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %c2, %grid_y = %c1, %grid_z = %c1)63             threads(%tx, %ty, %tz) in (%block_x = %c6, %block_y = %c1, %block_z = %c1) {64    %val = memref.load %data[%bx, %tx] : memref<2x6xi32>65    %reduced = gpu.all_reduce and %val uniform {} : (i32) -> (i32)66    memref.store %reduced, %sum[%bx] : memref<2xi32>67    gpu.terminator68  }69 70  call @printMemrefI32(%cast_sum) : (memref<*xi32>) -> ()71  // CHECK: [0, 2]72 73  return74}75 76func.func private @printMemrefI32(memref<*xi32>)77