[Mlir-commits] [mlir] [MLIR][NVVM] Reduce the scope of the LLVM_HAS_NVPTX_TARGET guard (PR #97349)
Mehdi Amini
llvmlistbot at llvm.org
Mon Jul 1 15:35:45 PDT 2024
https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/97349
>From 3af11cc5765e28a60ac1c90165eaf485e3682504 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Mon, 1 Jul 2024 14:04:04 -0700
Subject: [PATCH] [MLIR][NVVM] Reduce the scope of the LLVM_HAS_NVPTX_TARGET
guard
Most of the code here does not depend on the NVPTX target. In particular
the simple offload can just emit LLVM IR and we can use this without
the NVVM backend being built, which can be useful for a frontend that
just need to serialize the IR and leave it up to the runtime to JIT
further.
---
.../lib/Dialect/GPU/Transforms/ModuleToBinary.cpp | 15 ---------------
mlir/lib/Target/LLVM/NVVM/Target.cpp | 14 ++++++--------
2 files changed, 6 insertions(+), 23 deletions(-)
diff --git a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
index 1e7596e8cc4af..adae3bef763ff 100644
--- a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
@@ -38,25 +38,10 @@ class GpuModuleToBinaryPass
: public impl::GpuModuleToBinaryPassBase<GpuModuleToBinaryPass> {
public:
using Base::Base;
- void getDependentDialects(DialectRegistry ®istry) const override;
void runOnOperation() final;
};
} // namespace
-void GpuModuleToBinaryPass::getDependentDialects(
- DialectRegistry ®istry) const {
- // Register all GPU related translations.
- registry.insert<gpu::GPUDialect>();
- registry.insert<LLVM::LLVMDialect>();
-#if LLVM_HAS_NVPTX_TARGET
- registry.insert<NVVM::NVVMDialect>();
-#endif
-#if MLIR_ENABLE_ROCM_CONVERSIONS
- registry.insert<ROCDL::ROCDLDialect>();
-#endif
- registry.insert<spirv::SPIRVDialect>();
-}
-
void GpuModuleToBinaryPass::runOnOperation() {
RewritePatternSet patterns(&getContext());
auto targetFormat =
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index acb903aa37caf..e608d26e8d2ec 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -157,7 +157,6 @@ SerializeGPUModuleBase::loadBitcodeFiles(llvm::Module &module) {
return std::move(bcFiles);
}
-#if LLVM_HAS_NVPTX_TARGET
namespace {
class NVPTXSerializer : public SerializeGPUModuleBase {
public:
@@ -532,6 +531,12 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
if (targetOptions.getCompilationTarget() == gpu::CompilationTarget::Offload)
return SerializeGPUModuleBase::moduleToObject(llvmModule);
+#if !LLVM_HAS_NVPTX_TARGET
+ getOperation()->emitError(
+ "The `NVPTX` target was not built. Please enable it when building LLVM.");
+ return std::nullopt;
+#endif // LLVM_HAS_NVPTX_TARGET
+
// Emit PTX code.
std::optional<llvm::TargetMachine *> targetMachine =
getOrCreateTargetMachine();
@@ -569,7 +574,6 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
return compileToBinary(*serializedISA);
#endif // MLIR_ENABLE_NVPTXCOMPILER
}
-#endif // LLVM_HAS_NVPTX_TARGET
std::optional<SmallVector<char, 0>>
NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
@@ -581,15 +585,9 @@ NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
module->emitError("Module must be a GPU module.");
return std::nullopt;
}
-#if LLVM_HAS_NVPTX_TARGET
NVPTXSerializer serializer(*module, cast<NVVMTargetAttr>(attribute), options);
serializer.init();
return serializer.run();
-#else
- module->emitError(
- "The `NVPTX` target was not built. Please enable it when building LLVM.");
- return std::nullopt;
-#endif // LLVM_HAS_NVPTX_TARGET
}
Attribute
More information about the Mlir-commits
mailing list