1// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s 2 3func @main() { 4 %data = alloc() : memref<2x6xf32> 5 %sum = alloc() : memref<2xf32> 6 %mul = alloc() : memref<2xf32> 7 %cst0 = constant 0.0 : f32 8 %cst1 = constant 1.0 : f32 9 %cst2 = constant 2.0 : f32 10 %cst4 = constant 4.0 : f32 11 %cst8 = constant 8.0 : f32 12 %cst16 = constant 16.0 : f32 13 14 %cst3 = constant 3.0 : f32 15 %cst6 = constant 6.0 : f32 16 %cst7 = constant 7.0 : f32 17 %cst10 = constant 10.0 : f32 18 %cst11 = constant 11.0 : f32 19 20 %c0 = constant 0 : index 21 %c1 = constant 1 : index 22 %c2 = constant 2 : index 23 %c3 = constant 3 : index 24 %c4 = constant 4 : index 25 %c5 = constant 5 : index 26 %c6 = constant 6 : index 27 28 %cast_data = memref_cast %data : memref<2x6xf32> to memref<*xf32> 29 gpu.host_register %cast_data : memref<*xf32> 30 %cast_sum = memref_cast %sum : memref<2xf32> to memref<*xf32> 31 gpu.host_register %cast_sum : memref<*xf32> 32 %cast_mul = memref_cast %mul : memref<2xf32> to memref<*xf32> 33 gpu.host_register %cast_mul : memref<*xf32> 34 35 store %cst0, %data[%c0, %c0] : memref<2x6xf32> 36 store %cst1, %data[%c0, %c1] : memref<2x6xf32> 37 store %cst2, %data[%c0, %c2] : memref<2x6xf32> 38 store %cst4, %data[%c0, %c3] : memref<2x6xf32> 39 store %cst8, %data[%c0, %c4] : memref<2x6xf32> 40 store %cst16, %data[%c0, %c5] : memref<2x6xf32> 41 42 store %cst2, %data[%c1, %c0] : memref<2x6xf32> 43 store %cst3, %data[%c1, %c1] : memref<2x6xf32> 44 store %cst6, %data[%c1, %c2] : memref<2x6xf32> 45 store %cst7, %data[%c1, %c3] : memref<2x6xf32> 46 store %cst10, %data[%c1, %c4] : memref<2x6xf32> 47 store %cst11, %data[%c1, %c5] : memref<2x6xf32> 48 49 // ADD + MUL 50 gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %c2, %grid_y = %c1, %grid_z = %c1) 51 threads(%tx, %ty, %tz) in (%block_x = %c6, %block_y = %c1, %block_z = %c1) { 52 %val = load %data[%bx, %tx] : memref<2x6xf32> 53 %reduced0 = "gpu.all_reduce"(%val) ({}) { op = "add" } : (f32) -> (f32) 54 store %reduced0, %sum[%bx] : memref<2xf32> 55 %reduced1 = "gpu.all_reduce"(%val) ({}) { op = "mul" } : (f32) -> (f32) 56 store %reduced1, %mul[%bx] : memref<2xf32> 57 gpu.terminator 58 } 59 60 call @print_memref_f32(%cast_sum) : (memref<*xf32>) -> () 61 // CHECK: [31, 39] 62 63 call @print_memref_f32(%cast_mul) : (memref<*xf32>) -> () 64 // CHECK: [0, 27720] 65 66 return 67} 68 69func private @print_memref_f32(memref<*xf32>) 70