76 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<2x6xf32>11 %sum = memref.alloc() : memref<2xf32>12 %mul = memref.alloc() : memref<2xf32>13 %cst0 = arith.constant 0.0 : f3214 %cst1 = arith.constant 1.0 : f3215 %cst2 = arith.constant 2.0 : f3216 %cst4 = arith.constant 4.0 : f3217 %cst8 = arith.constant 8.0 : f3218 %cst16 = arith.constant 16.0 : f3219 20 %cst3 = arith.constant 3.0 : f3221 %cst6 = arith.constant 6.0 : f3222 %cst7 = arith.constant 7.0 : f3223 %cst10 = arith.constant 10.0 : f3224 %cst11 = arith.constant 11.0 : f3225 26 %c0 = arith.constant 0 : index27 %c1 = arith.constant 1 : index28 %c2 = arith.constant 2 : index29 %c3 = arith.constant 3 : index30 %c4 = arith.constant 4 : index31 %c5 = arith.constant 5 : index32 %c6 = arith.constant 6 : index33 34 %cast_data = memref.cast %data : memref<2x6xf32> to memref<*xf32>35 gpu.host_register %cast_data : memref<*xf32>36 %cast_sum = memref.cast %sum : memref<2xf32> to memref<*xf32>37 gpu.host_register %cast_sum : memref<*xf32>38 %cast_mul = memref.cast %mul : memref<2xf32> to memref<*xf32>39 gpu.host_register %cast_mul : memref<*xf32>40 41 memref.store %cst0, %data[%c0, %c0] : memref<2x6xf32>42 memref.store %cst1, %data[%c0, %c1] : memref<2x6xf32>43 memref.store %cst2, %data[%c0, %c2] : memref<2x6xf32>44 memref.store %cst4, %data[%c0, %c3] : memref<2x6xf32>45 memref.store %cst8, %data[%c0, %c4] : memref<2x6xf32>46 memref.store %cst16, %data[%c0, %c5] : memref<2x6xf32>47 48 memref.store %cst2, %data[%c1, %c0] : memref<2x6xf32>49 memref.store %cst3, %data[%c1, %c1] : memref<2x6xf32>50 memref.store %cst6, %data[%c1, %c2] : memref<2x6xf32>51 memref.store %cst7, %data[%c1, %c3] : memref<2x6xf32>52 memref.store %cst10, %data[%c1, %c4] : memref<2x6xf32>53 memref.store %cst11, %data[%c1, %c5] : memref<2x6xf32>54 55 // ADD + MUL56 gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %c2, %grid_y = %c1, %grid_z = %c1)57 threads(%tx, %ty, %tz) in (%block_x = %c6, %block_y = %c1, %block_z = %c1) {58 %val = memref.load %data[%bx, %tx] : memref<2x6xf32>59 %reduced0 = gpu.all_reduce add %val uniform {} : (f32) -> (f32)60 memref.store %reduced0, %sum[%bx] : memref<2xf32>61 %reduced1 = gpu.all_reduce mul %val uniform {} : (f32) -> (f32)62 memref.store %reduced1, %mul[%bx] : memref<2xf32>63 gpu.terminator64 }65 66 call @printMemrefF32(%cast_sum) : (memref<*xf32>) -> ()67 // CHECK: [31, 39]68 69 call @printMemrefF32(%cast_mul) : (memref<*xf32>) -> ()70 // CHECK: [0, 27720]71 72 return73}74 75func.func private @printMemrefF32(memref<*xf32>)76