Skip to content

Commit c03637b

Browse files
committed
[mlir][gpu] GPUToROCDL: Add C++ argument to populate allowedDialects
The `convert-gpu-to-rocdl` pass provides the option `allowed-dialects`, which allows users to control which dialects can be used to populate conversions. This PR adds a C++ argument to createLowerGpuOpsToROCDLOpsPass, so that this option can also be controlled programatically when creating the pass.
1 parent 93c2eec commit c03637b

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include "mlir/Conversion/GPUToROCDL/Runtimes.h"
1212
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
13+
#include "llvm/ADT/DenseSet.h"
14+
#include <cstddef>
1315
#include <memory>
1416

1517
namespace mlir {
@@ -50,7 +52,9 @@ createLowerGpuOpsToROCDLOpsPass(
5052
const std::string &chipset = "gfx900",
5153
unsigned indexBitwidth = kDeriveIndexBitwidthFromDataLayout,
5254
bool useBarePtrCallConv = false,
53-
gpu::amd::Runtime runtime = gpu::amd::Runtime::Unknown);
55+
gpu::amd::Runtime runtime = gpu::amd::Runtime::Unknown,
56+
const std::optional<llvm::SmallDenseSet<llvm::StringRef>> &allowedDialects =
57+
std::nullopt);
5458

5559
} // namespace mlir
5660

mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,10 @@ struct GPUShuffleOpLowering : public ConvertOpToLLVMPattern<gpu::ShuffleOp> {
288288
struct LowerGpuOpsToROCDLOpsPass final
289289
: public impl::ConvertGpuOpsToROCDLOpsBase<LowerGpuOpsToROCDLOpsPass> {
290290
LowerGpuOpsToROCDLOpsPass() = default;
291-
LowerGpuOpsToROCDLOpsPass(const std::string &chipset, unsigned indexBitwidth,
292-
bool useBarePtrCallConv,
293-
gpu::amd::Runtime runtime) {
291+
LowerGpuOpsToROCDLOpsPass(
292+
const std::string &chipset, unsigned indexBitwidth,
293+
bool useBarePtrCallConv, gpu::amd::Runtime runtime,
294+
std::optional<llvm::SmallDenseSet<StringRef>> allowedDialects) {
294295
if (this->chipset.getNumOccurrences() == 0)
295296
this->chipset = chipset;
296297
if (this->indexBitwidth.getNumOccurrences() == 0)
@@ -299,6 +300,12 @@ struct LowerGpuOpsToROCDLOpsPass final
299300
this->useBarePtrCallConv = useBarePtrCallConv;
300301
if (this->runtime.getNumOccurrences() == 0)
301302
this->runtime = runtime;
303+
if (this->allowedDialects.getNumOccurrences() == 0 &&
304+
allowedDialects.has_value()) {
305+
for (auto &str : allowedDialects.value()) {
306+
this->allowedDialects.push_back(str.str());
307+
}
308+
}
302309
}
303310

304311
void getDependentDialects(DialectRegistry &registry) const override {
@@ -501,10 +508,10 @@ void mlir::populateGpuToROCDLConversionPatterns(
501508
}
502509

503510
std::unique_ptr<OperationPass<gpu::GPUModuleOp>>
504-
mlir::createLowerGpuOpsToROCDLOpsPass(const std::string &chipset,
505-
unsigned indexBitwidth,
506-
bool useBarePtrCallConv,
507-
gpu::amd::Runtime runtime) {
511+
mlir::createLowerGpuOpsToROCDLOpsPass(
512+
const std::string &chipset, unsigned indexBitwidth, bool useBarePtrCallConv,
513+
gpu::amd::Runtime runtime,
514+
const std::optional<llvm::SmallDenseSet<StringRef>> &allowedDialects) {
508515
return std::make_unique<LowerGpuOpsToROCDLOpsPass>(
509-
chipset, indexBitwidth, useBarePtrCallConv, runtime);
516+
chipset, indexBitwidth, useBarePtrCallConv, runtime, allowedDialects);
510517
}

0 commit comments

Comments
 (0)