xref: /llvm-project/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-32b.mlir (revision 7030280329c3a723a42304e92f9c207acb8ea731)
1// RUN: mlir-opt %s -convert-gpu-to-nvvm='index-bitwidth=32' -split-input-file | FileCheck %s
2
3// RUN: mlir-opt %s -transform-interpreter | FileCheck %s
4
5gpu.module @test_module_0 {
6  // CHECK-LABEL: func @gpu_index_ops()
7  func.func @gpu_index_ops()
8      -> (index, index, index, index, index, index,
9          index, index, index, index, index, index,
10          index) {
11    %tIdX = gpu.thread_id x
12    %tIdY = gpu.thread_id y
13    %tIdZ = gpu.thread_id z
14
15    %bDimX = gpu.block_dim x
16    %bDimY = gpu.block_dim y
17    %bDimZ = gpu.block_dim z
18
19    %bIdX = gpu.block_id x
20    %bIdY = gpu.block_id y
21    %bIdZ = gpu.block_id z
22
23    %gDimX = gpu.grid_dim x
24    %gDimY = gpu.grid_dim y
25    %gDimZ = gpu.grid_dim z
26
27    // CHECK-NOT: = llvm.sext %{{.*}} : i32 to i64
28    %laneId = gpu.lane_id
29
30    func.return %tIdX, %tIdY, %tIdZ, %bDimX, %bDimY, %bDimZ,
31               %bIdX, %bIdY, %bIdZ, %gDimX, %gDimY, %gDimZ,
32               %laneId
33        : index, index, index, index, index, index,
34          index, index, index, index, index, index,
35          index
36  }
37}
38
39
40
41gpu.module @test_module_1 {
42  // CHECK-LABEL: func @gpu_index_comp
43  func.func @gpu_index_comp(%idx : index) -> index {
44    // CHECK: = llvm.add %{{.*}}, %{{.*}} : i32
45    %0 = arith.addi %idx, %idx : index
46    // CHECK: llvm.return %{{.*}} : i32
47    func.return %0 : index
48  }
49}
50
51module attributes {transform.with_named_sequence} {
52  transform.named_sequence @__transform_main(%toplevel_module: !transform.any_op {transform.readonly}) {
53    %gpu_module = transform.structured.match ops{["gpu.module"]} in %toplevel_module
54      : (!transform.any_op) -> !transform.any_op
55    transform.apply_conversion_patterns to %gpu_module {
56      transform.apply_conversion_patterns.dialect_to_llvm "arith"
57      transform.apply_conversion_patterns.dialect_to_llvm "cf"
58      transform.apply_conversion_patterns.vector.vector_to_llvm
59      transform.apply_conversion_patterns.func.func_to_llvm
60      transform.apply_conversion_patterns.dialect_to_llvm "memref"
61      transform.apply_conversion_patterns.gpu.gpu_to_nvvm
62      transform.apply_conversion_patterns.gpu.gpu_wmma_to_nvvm
63      transform.apply_conversion_patterns.gpu.gpu_subgroup_reduce_to_nvvm {has_redux = true}
64      transform.apply_conversion_patterns.nvgpu.nvgpu_to_nvvm
65    } with type_converter {
66      transform.apply_conversion_patterns.memref.memref_to_llvm_type_converter
67        {index_bitwidth = 32, use_opaque_pointers = true}
68    } {
69      legal_dialects = ["llvm", "memref", "nvvm"],
70      legal_ops = ["func.func", "gpu.module", "gpu.yield"],
71      illegal_dialects = ["gpu"],
72      illegal_ops = ["llvm.cos", "llvm.exp", "llvm.exp2", "llvm.fabs", "llvm.fceil",
73                    "llvm.ffloor", "llvm.log", "llvm.log10", "llvm.log2", "llvm.pow",
74                    "llvm.sin", "llvm.sqrt"],
75      partial_conversion
76    } : !transform.any_op
77    transform.yield
78  }
79}
80