xref: /llvm-project/mlir/test/Integration/GPU/ROCM/two-modules.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1// RUN: mlir-opt %s \
2// RUN: | mlir-opt -gpu-kernel-outlining \
3// RUN: | mlir-opt -pass-pipeline='builtin.module(gpu.module(strip-debuginfo,convert-gpu-to-rocdl),rocdl-attach-target{chip=%chip})' \
4// RUN: | mlir-opt -gpu-to-llvm -reconcile-unrealized-casts -gpu-module-to-binary \
5// RUN: | mlir-runner \
6// RUN:   --shared-libs=%mlir_rocm_runtime \
7// RUN:   --shared-libs=%mlir_runner_utils \
8// RUN:   --entry-point-result=void \
9// RUN: | FileCheck %s
10
11// CHECK: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
12func.func @main() {
13  %arg = memref.alloc() : memref<13xi32>
14  %dst = memref.cast %arg : memref<13xi32> to memref<?xi32>
15  %c0 = arith.constant 0 : index
16  %c1 = arith.constant 1 : index
17  %sx = memref.dim %dst, %c0 : memref<?xi32>
18  %cast_dst = memref.cast %dst : memref<?xi32> to memref<*xi32>
19  gpu.host_register %cast_dst : memref<*xi32>
20  %dst_device = call @mgpuMemGetDeviceMemRef1dInt32(%dst) : (memref<?xi32>) -> (memref<?xi32>)
21  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %c1, %grid_y = %c1, %grid_z = %c1)
22             threads(%tx, %ty, %tz) in (%block_x = %sx, %block_y = %c1, %block_z = %c1) {
23    %t0 = arith.index_cast %tx : index to i32
24    memref.store %t0, %dst_device[%tx] : memref<?xi32>
25    gpu.terminator
26  }
27  gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %c1, %grid_y = %c1, %grid_z = %c1)
28             threads(%tx, %ty, %tz) in (%block_x = %sx, %block_y = %c1, %block_z = %c1) {
29    %t0 = arith.index_cast %tx : index to i32
30    memref.store %t0, %dst_device[%tx] : memref<?xi32>
31    gpu.terminator
32  }
33  call @printMemrefI32(%cast_dst) : (memref<*xi32>) -> ()
34  return
35}
36
37func.func private @mgpuMemGetDeviceMemRef1dInt32(%ptr : memref<?xi32>) -> (memref<?xi32>)
38func.func private @printMemrefI32(%ptr : memref<*xi32>)
39