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<2x6xi32>
5  %sum = alloc() : memref<2xi32>
6  %cst0 = constant 0 : i32
7  %cst1 = constant 1 : i32
8  %cst2 = constant 2 : i32
9  %cst4 = constant 4 : i32
10  %cst8 = constant 8 : i32
11  %cst16 = constant 16 : i32
12
13  %cst3 = constant 3 : i32
14  %cst6 = constant 6 : i32
15  %cst7 = constant 7 : i32
16  %cst10 = constant 10 : i32
17  %cst11 = constant 11 : i32
18
19  %c0 = constant 0 : index
20  %c1 = constant 1 : index
21  %c2 = constant 2 : index
22  %c3 = constant 3 : index
23  %c4 = constant 4 : index
24  %c5 = constant 5 : index
25  %c6 = constant 6 : index
26
27  %cast_data = memref_cast %data : memref<2x6xi32> to memref<*xi32>
28  gpu.host_register %cast_data : memref<*xi32>
29  %cast_sum = memref_cast %sum : memref<2xi32> to memref<*xi32>
30  gpu.host_register %cast_sum : memref<*xi32>
31
32  store %cst0, %data[%c0, %c0] : memref<2x6xi32>
33  store %cst1, %data[%c0, %c1] : memref<2x6xi32>
34  store %cst2, %data[%c0, %c2] : memref<2x6xi32>
35  store %cst4, %data[%c0, %c3] : memref<2x6xi32>
36  store %cst8, %data[%c0, %c4] : memref<2x6xi32>
37  store %cst16, %data[%c0, %c5] : memref<2x6xi32>
38
39  store %cst2, %data[%c1, %c0] : memref<2x6xi32>
40  store %cst3, %data[%c1, %c1] : memref<2x6xi32>
41  store %cst6, %data[%c1, %c2] : memref<2x6xi32>
42  store %cst7, %data[%c1, %c3] : memref<2x6xi32>
43  store %cst10, %data[%c1, %c4] : memref<2x6xi32>
44  store %cst11, %data[%c1, %c5] : memref<2x6xi32>
45
46  // XOR
47  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %c2, %grid_y = %c1, %grid_z = %c1)
48             threads(%tx, %ty, %tz) in (%block_x = %c6, %block_y = %c1, %block_z = %c1) {
49    %val = load %data[%bx, %tx] : memref<2x6xi32>
50    %reduced = "gpu.all_reduce"(%val) ({}) { op = "xor" } : (i32) -> (i32)
51    store %reduced, %sum[%bx] : memref<2xi32>
52    gpu.terminator
53  }
54
55  call @print_memref_i32(%cast_sum) : (memref<*xi32>) -> ()
56  // CHECK: [31, 1]
57
58  return
59}
60
61func private @print_memref_i32(memref<*xi32>)
62
63