Skip to content

Commit 3fde4ae

Browse files
committed
Make forcing opencl address spaces the default behavior
1 parent 598f9b1 commit 3fde4ae

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

mlir/include/mlir/Conversion/Passes.td

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,7 @@ def ConvertGpuOpsToLLVMSPVOps : Pass<"convert-gpu-to-llvm-spv", "gpu::GPUModuleO
541541
let options = [
542542
Option<"indexBitwidth", "index-bitwidth", "unsigned",
543543
/*default=kDeriveIndexBitwidthFromDataLayout*/"0",
544-
"Bitwidth of the index type, 0 to use size of machine word">,
545-
Option<"forceOpenclAddressSpaces", "force-opencl-address-spaces",
546-
"bool", /*default=*/"false",
547-
"Force kernel argument pointers to have address space global.">,
544+
"Bitwidth of the index type, 0 to use size of machine word">
548545
];
549546
}
550547

mlir/lib/Conversion/GPUToLLVMSPV/GPUToLLVMSPV.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ struct GPUToLLVMSPVConversionPass final
359359
LLVMTypeConverter converter(context, options);
360360
LLVMConversionTarget target(*context);
361361

362-
if (forceOpenclAddressSpaces) {
362+
// Force OpenCL address spaces when they are not present
363+
{
363364
MemorySpaceToOpenCLMemorySpaceConverter converter;
364365
AttrTypeReplacer replacer;
365366
replacer.addReplacement([&converter](BaseMemRefType origType)

mlir/test/Conversion/GPUToLLVMSPV/gpu-to-llvm-spv.mlir

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// RUN: | FileCheck --check-prefixes=CHECK-64,CHECK %s
33
// RUN: mlir-opt -pass-pipeline="builtin.module(gpu.module(convert-gpu-to-llvm-spv{index-bitwidth=32}))" -split-input-file -verify-diagnostics %s \
44
// RUN: | FileCheck --check-prefixes=CHECK-32,CHECK %s
5-
// RUN: mlir-opt -pass-pipeline="builtin.module(gpu.module(convert-gpu-to-llvm-spv{force-opencl-address-spaces}))" -split-input-file -verify-diagnostics %s \
6-
// RUN: | FileCheck --check-prefixes=CHECK-OPENCL %s
75

86
gpu.module @builtins {
97
// CHECK-64: llvm.func spir_funccc @_Z14get_num_groupsj(i32) -> i64 attributes {
@@ -398,20 +396,20 @@ gpu.module @kernels {
398396
gpu.return
399397
}
400398

401-
// CHECK-64: llvm.func spir_kernelcc @kernel_with_conv_args(%{{.*}}: i64, %{{.*}}: !llvm.ptr, %{{.*}}: !llvm.ptr, %{{.*}}: i64) attributes {gpu.kernel} {
402-
// CHECK-32: llvm.func spir_kernelcc @kernel_with_conv_args(%{{.*}}: i32, %{{.*}}: !llvm.ptr, %{{.*}}: !llvm.ptr, %{{.*}}: i32) attributes {gpu.kernel} {
399+
// CHECK-64: llvm.func spir_kernelcc @kernel_with_conv_args(%{{.*}}: i64, %{{.*}}: !llvm.ptr<1>, %{{.*}}: !llvm.ptr<1>, %{{.*}}: i64) attributes {gpu.kernel} {
400+
// CHECK-32: llvm.func spir_kernelcc @kernel_with_conv_args(%{{.*}}: i32, %{{.*}}: !llvm.ptr<1>, %{{.*}}: !llvm.ptr<1>, %{{.*}}: i32) attributes {gpu.kernel} {
403401
gpu.func @kernel_with_conv_args(%arg0: index, %arg1: memref<index>) kernel {
404402
gpu.return
405403
}
406404

407-
// CHECK-64: llvm.func spir_kernelcc @kernel_with_sized_memref(%{{.*}}: !llvm.ptr, %{{.*}}: !llvm.ptr, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64) attributes {gpu.kernel} {
408-
// CHECK-32: llvm.func spir_kernelcc @kernel_with_sized_memref(%{{.*}}: !llvm.ptr, %{{.*}}: !llvm.ptr, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32) attributes {gpu.kernel} {
405+
// CHECK-64: llvm.func spir_kernelcc @kernel_with_sized_memref(%{{.*}}: !llvm.ptr<1>, %{{.*}}: !llvm.ptr<1>, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64) attributes {gpu.kernel} {
406+
// CHECK-32: llvm.func spir_kernelcc @kernel_with_sized_memref(%{{.*}}: !llvm.ptr<1>, %{{.*}}: !llvm.ptr<1>, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32) attributes {gpu.kernel} {
409407
gpu.func @kernel_with_sized_memref(%arg0: memref<1xindex>) kernel {
410408
gpu.return
411409
}
412410

413-
// CHECK-64: llvm.func spir_kernelcc @kernel_with_ND_memref(%{{.*}}: !llvm.ptr, %{{.*}}: !llvm.ptr, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64) attributes {gpu.kernel} {
414-
// CHECK-32: llvm.func spir_kernelcc @kernel_with_ND_memref(%{{.*}}: !llvm.ptr, %{{.*}}: !llvm.ptr, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32) attributes {gpu.kernel} {
411+
// CHECK-64: llvm.func spir_kernelcc @kernel_with_ND_memref(%{{.*}}: !llvm.ptr<1>, %{{.*}}: !llvm.ptr<1>, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64, %{{.*}}: i64) attributes {gpu.kernel} {
412+
// CHECK-32: llvm.func spir_kernelcc @kernel_with_ND_memref(%{{.*}}: !llvm.ptr<1>, %{{.*}}: !llvm.ptr<1>, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32, %{{.*}}: i32) attributes {gpu.kernel} {
415413
gpu.func @kernel_with_ND_memref(%arg0: memref<128x128x128xindex>) kernel {
416414
gpu.return
417415
}
@@ -521,30 +519,30 @@ gpu.module @kernels {
521519
// -----
522520

523521
gpu.module @kernels {
524-
// CHECK-OPENCL: llvm.func spir_funccc @_Z12get_group_idj(i32)
525-
// CHECK-OPENCL-LABEL: llvm.func spir_funccc @no_address_spaces(
526-
// CHECK-OPENCL-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
527-
// CHECK-OPENCL-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
528-
// CHECK-OPENCL-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
522+
// CHECK: llvm.func spir_funccc @_Z12get_group_idj(i32)
523+
// CHECK-LABEL: llvm.func spir_funccc @no_address_spaces(
524+
// CHECK-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
525+
// CHECK-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
526+
// CHECK-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
529527
gpu.func @no_address_spaces(%arg0: memref<f32>, %arg1: memref<f32, #gpu.address_space<global>>, %arg2: memref<f32>) {
530528
gpu.return
531529
}
532530

533-
// CHECK-OPENCL-LABEL: llvm.func spir_kernelcc @no_address_spaces_complex(
534-
// CHECK-OPENCL-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
535-
// CHECK-OPENCL-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
536-
// CHECK-OPENCL: llvm.call spir_funccc @no_address_spaces_callee
531+
// CHECK-LABEL: llvm.func spir_kernelcc @no_address_spaces_complex(
532+
// CHECK-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
533+
// CHECK-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
534+
// CHECK: llvm.call @no_address_spaces_callee
537535
gpu.func @no_address_spaces_complex(%arg0: memref<2x2xf32>, %arg1: memref<4xf32>) kernel {
538536
func.call @no_address_spaces_callee(%arg0, %arg1) : (memref<2x2xf32>, memref<4xf32>) -> ()
539537
gpu.return
540538
}
541-
// CHECK-OPENCL-LABEL: llvm.func @no_address_spaces_callee(
542-
// CHECK-OPENCL-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
543-
// CHECK-OPENCL-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
544-
// CHECK-OPENCL: [[C0:%.*]] = llvm.mlir.constant(0 : i32) : i32
545-
// CHECK-OPENCL: llvm.call @_Z12get_group_idj([[C0]]) {
546-
// CHECK-OPENCL: [[LD:%.*]] = llvm.load
547-
// CHECK-OPENCL: llvm.store [[LD]]
539+
// CHECK-LABEL: llvm.func @no_address_spaces_callee(
540+
// CHECK-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
541+
// CHECK-SAME: %{{[a-zA-Z_][a-zA-Z0-9_]*}}: !llvm.ptr<1>
542+
// CHECK: [[C0:%.*]] = llvm.mlir.constant(0 : i32) : i32
543+
// CHECK: llvm.call spir_funccc @_Z12get_group_idj([[C0]]) {
544+
// CHECK: [[LD:%.*]] = llvm.load
545+
// CHECK: llvm.store [[LD]]
548546
func.func @no_address_spaces_callee(%arg0: memref<2x2xf32>, %arg1: memref<4xf32>) {
549547
%block_id = gpu.block_id x
550548
%0 = memref.load %arg0[%block_id, %block_id] : memref<2x2xf32>

0 commit comments

Comments
 (0)