1// RUN: mlir-opt %s \
2// RUN:   -gpu-kernel-outlining \
3// RUN:   -pass-pipeline='gpu.module(strip-debuginfo,convert-gpu-to-nvvm,gpu-to-cubin)' \
4// RUN:   -gpu-to-llvm \
5// RUN: | mlir-cpu-runner \
6// RUN:   --shared-libs=%linalg_test_lib_dir/libmlir_cuda_runtime%shlibext \
7// RUN:   --shared-libs=%linalg_test_lib_dir/libmlir_runner_utils%shlibext \
8// RUN:   --entry-point-result=void \
9// RUN: | FileCheck %s
10
11// CHECK: [4, 5, 6, 7, 0, 1, 2, 3, 12, -1, -1, -1, 8]
12func.func @main() {
13  %arg = memref.alloc() : memref<13xf32>
14  %dst = memref.cast %arg : memref<13xf32> to memref<?xf32>
15  %one = arith.constant 1 : index
16  %c0 = arith.constant 0 : index
17  %sx = memref.dim %dst, %c0 : memref<?xf32>
18  %cast_dst = memref.cast %dst : memref<?xf32> to memref<*xf32>
19  gpu.host_register %cast_dst : memref<*xf32>
20  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %one, %grid_y = %one, %grid_z = %one)
21             threads(%tx, %ty, %tz) in (%block_x = %sx, %block_y = %one, %block_z = %one) {
22    %t0 = arith.index_cast %tx : index to i32
23    %val = arith.sitofp %t0 : i32 to f32
24    %width = arith.index_cast %block_x : index to i32
25    %offset = arith.constant 4 : i32
26    %shfl, %valid = gpu.shuffle xor %val, %offset, %width : f32
27    cf.cond_br %valid, ^bb1(%shfl : f32), ^bb0
28  ^bb0:
29    %m1 = arith.constant -1.0 : f32
30    cf.br ^bb1(%m1 : f32)
31  ^bb1(%value : f32):
32    memref.store %value, %dst[%tx] : memref<?xf32>
33    gpu.terminator
34  }
35  call @printMemrefF32(%cast_dst) : (memref<*xf32>) -> ()
36  return
37}
38
39func.func private @printMemrefF32(%ptr : memref<*xf32>)
40