Skip to content

Commit 9b2b51e

Browse files
committed
Use attached target on the GPU module when lowering GPU ops to ROCDL
1 parent 9bf02a8 commit 9b2b51e

File tree

17 files changed

+42
-25
lines changed

17 files changed

+42
-25
lines changed

mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void configureGpuToROCDLConversionLegality(ConversionTarget &target);
4242
/// is configurable.
4343
std::unique_ptr<OperationPass<gpu::GPUModuleOp>>
4444
createLowerGpuOpsToROCDLOpsPass(
45-
const std::string &chipset = "gfx900",
45+
const std::string &chipset = "infer",
4646
unsigned indexBitwidth = kDeriveIndexBitwidthFromDataLayout,
4747
bool useBarePtrCallConv = false,
4848
gpu::amd::Runtime runtime = gpu::amd::Runtime::Unknown);

mlir/include/mlir/Conversion/Passes.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ def ConvertGpuOpsToROCDLOps : Pass<"convert-gpu-to-rocdl", "gpu::GPUModuleOp"> {
592592
];
593593
let options = [
594594
Option<"chipset", "chipset", "std::string",
595-
/*default=*/"\"gfx000\"",
596-
"Chipset that these operations will run on">,
595+
/*default=*/"\"infer\"",
596+
"Chipset that these operations will run on. By Default it will infer target from attached target attribute on GPU module on which it operates">,
597597
Option<"indexBitwidth", "index-bitwidth", "unsigned",
598598
/*default=kDeriveIndexBitwidthFromDataLayout*/"0",
599599
"Bitwidth of the index type, 0 to use size of machine word">,

mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,29 @@ struct LowerGpuOpsToROCDLOpsPass
219219
gpu::GPUModuleOp m = getOperation();
220220
MLIRContext *ctx = m.getContext();
221221

222+
ArrayAttr targets = m.getTargetsAttr();
223+
if (chipset == "infer") {
224+
if (!targets) {
225+
emitError(UnknownLoc::get(ctx),
226+
"ROCDLTargetAttr is empty on GPU module");
227+
return signalPassFailure();
228+
}
229+
if (targets.size() != 1) {
230+
emitError(UnknownLoc::get(ctx), "ROCDLTargetAttrs has more specified "
231+
"more than one gpu-arch on GPU module");
232+
return signalPassFailure();
233+
}
234+
const ROCDL::ROCDLTargetAttr targetAttr =
235+
mlir::dyn_cast<ROCDL::ROCDLTargetAttr>(targets.getValue().front());
236+
chipset = targetAttr.getChip().str();
237+
}
238+
239+
FailureOr<amdgpu::Chipset> maybeChipset = amdgpu::Chipset::parse(chipset);
240+
if (failed(maybeChipset)) {
241+
emitError(UnknownLoc::get(ctx), "Invalid chipset name: " + chipset);
242+
return signalPassFailure();
243+
}
244+
222245
auto llvmDataLayout = m->getAttrOfType<StringAttr>(
223246
LLVM::LLVMDialect::getDataLayoutAttrName());
224247
if (!llvmDataLayout) {
@@ -231,12 +254,6 @@ struct LowerGpuOpsToROCDLOpsPass
231254
UnitAttr::get(ctx));
232255
}
233256

234-
FailureOr<amdgpu::Chipset> maybeChipset = amdgpu::Chipset::parse(chipset);
235-
if (failed(maybeChipset)) {
236-
emitError(UnknownLoc::get(ctx), "Invalid chipset name: " + chipset);
237-
return signalPassFailure();
238-
}
239-
240257
/// Customize the bitwidth used for the device side index computations.
241258
LowerToLLVMOptions options(
242259
ctx, DataLayout(cast<DataLayoutOpInterface>(m.getOperation())));

mlir/test/Conversion/GPUCommon/lower-memory-space-attrs.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-rocdl | FileCheck %s --check-prefixes=CHECK,ROCDL
1+
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-rocdl='chipset=gfx900' | FileCheck %s --check-prefixes=CHECK,ROCDL
22
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-nvvm | FileCheck %s --check-prefixes=CHECK,NVVM
33

44
gpu.module @kernel {

mlir/test/Conversion/GPUCommon/memory-attrbution.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: mlir-opt -allow-unregistered-dialect --convert-gpu-to-nvvm --split-input-file %s | FileCheck --check-prefix=NVVM %s
2-
// RUN: mlir-opt -allow-unregistered-dialect --convert-gpu-to-rocdl --split-input-file %s | FileCheck --check-prefix=ROCDL %s
2+
// RUN: mlir-opt -allow-unregistered-dialect --convert-gpu-to-rocdl='chipset=gfx900' --split-input-file %s | FileCheck --check-prefix=ROCDL %s
33

44
gpu.module @kernel {
55
// NVVM-LABEL: llvm.func @private

mlir/test/Conversion/GPUCommon/memref-arg-attrs.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-rocdl='use-bare-ptr-memref-call-conv=0' | FileCheck %s --check-prefixes=CHECK,ROCDL
1+
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-rocdl='chipset=gfx900 use-bare-ptr-memref-call-conv=0' | FileCheck %s --check-prefixes=CHECK,ROCDL
22
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-nvvm='use-bare-ptr-memref-call-conv=0' | FileCheck %s --check-prefixes=CHECK,NVVM
33

44
gpu.module @kernel {

mlir/test/Conversion/GPUCommon/memref-arg-noalias-attrs.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-rocdl='use-bare-ptr-memref-call-conv=1' | FileCheck %s --check-prefixes=CHECK,ROCDL
1+
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-rocdl='chipset=gfx900 use-bare-ptr-memref-call-conv=1' | FileCheck %s --check-prefixes=CHECK,ROCDL
22
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-nvvm='use-bare-ptr-memref-call-conv=1' | FileCheck %s --check-prefixes=CHECK,NVVM
33

44
gpu.module @kernel {

mlir/test/Conversion/GPUCommon/memref-arg-noalias-warning.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-rocdl='use-bare-ptr-memref-call-conv=0' -verify-diagnostics
1+
// RUN: mlir-opt %s -split-input-file -convert-gpu-to-rocdl='chipset=gfx900 use-bare-ptr-memref-call-conv=0' -verify-diagnostics
22

33
gpu.module @kernel {
44
// expected-warning @+1 {{Cannot copy noalias with non-bare pointers.}}

mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl-hip.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -convert-gpu-to-rocdl='runtime=HIP' -split-input-file | FileCheck %s
1+
// RUN: mlir-opt %s -convert-gpu-to-rocdl='chipset=gfx900 runtime=HIP' -split-input-file | FileCheck %s
22

33
gpu.module @test_module {
44
// CHECK-DAG: llvm.mlir.global internal constant @[[$PRINT_GLOBAL0:[A-Za-z0-9_]+]]("Hello, world\0A\00")

mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl-opencl.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -convert-gpu-to-rocdl='runtime=OpenCL' | FileCheck %s
1+
// RUN: mlir-opt %s -convert-gpu-to-rocdl='chipset=gfx900 runtime=OpenCL' | FileCheck %s
22

33
gpu.module @test_module {
44
// CHECK: llvm.mlir.global internal constant @[[$PRINT_GLOBAL:[A-Za-z0-9_]+]]("Hello: %d\0A\00") {addr_space = 4 : i32}

0 commit comments

Comments
 (0)