xref: /llvm-project/mlir/test/Integration/GPU/CUDA/two-modules.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1// RUN: mlir-opt %s \
2// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-format=%gpu_compilation_format" \
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 %s
8
9// CHECK: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
10func.func @main() {
11  %arg = memref.alloc() : memref<13xi32>
12  %dst = memref.cast %arg : memref<13xi32> to memref<?xi32>
13  %one = arith.constant 1 : index
14  %c0 = arith.constant 0 : index
15  %sx = memref.dim %dst, %c0 : memref<?xi32>
16  %cast_dst = memref.cast %dst : memref<?xi32> to memref<*xi32>
17  gpu.host_register %cast_dst : memref<*xi32>
18  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %one, %grid_y = %one, %grid_z = %one)
19             threads(%tx, %ty, %tz) in (%block_x = %sx, %block_y = %one, %block_z = %one) {
20    %t0 = arith.index_cast %tx : index to i32
21    memref.store %t0, %dst[%tx] : memref<?xi32>
22    gpu.terminator
23  }
24  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %one, %grid_y = %one, %grid_z = %one)
25             threads(%tx, %ty, %tz) in (%block_x = %sx, %block_y = %one, %block_z = %one) {
26    %t0 = arith.index_cast %tx : index to i32
27    memref.store %t0, %dst[%tx] : memref<?xi32>
28    gpu.terminator
29  }
30  call @printMemrefI32(%cast_dst) : (memref<*xi32>) -> ()
31  return
32}
33
34func.func private @printMemrefI32(%memref : memref<*xi32>)
35