Skip to content

Commit d7da0ae

Browse files
authored
[MLIR][NVVM] Reduce the scope of the LLVM_HAS_NVPTX_TARGET guard (#97349)
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.
1 parent 54811a9 commit d7da0ae

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,10 @@ class GpuModuleToBinaryPass
3838
: public impl::GpuModuleToBinaryPassBase<GpuModuleToBinaryPass> {
3939
public:
4040
using Base::Base;
41-
void getDependentDialects(DialectRegistry &registry) const override;
4241
void runOnOperation() final;
4342
};
4443
} // namespace
4544

46-
void GpuModuleToBinaryPass::getDependentDialects(
47-
DialectRegistry &registry) const {
48-
// Register all GPU related translations.
49-
registry.insert<gpu::GPUDialect>();
50-
registry.insert<LLVM::LLVMDialect>();
51-
#if LLVM_HAS_NVPTX_TARGET
52-
registry.insert<NVVM::NVVMDialect>();
53-
#endif
54-
#if MLIR_ENABLE_ROCM_CONVERSIONS
55-
registry.insert<ROCDL::ROCDLDialect>();
56-
#endif
57-
registry.insert<spirv::SPIRVDialect>();
58-
}
59-
6045
void GpuModuleToBinaryPass::runOnOperation() {
6146
RewritePatternSet patterns(&getContext());
6247
auto targetFormat =

mlir/lib/Target/LLVM/NVVM/Target.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ SerializeGPUModuleBase::loadBitcodeFiles(llvm::Module &module) {
157157
return std::move(bcFiles);
158158
}
159159

160-
#if LLVM_HAS_NVPTX_TARGET
161160
namespace {
162161
class NVPTXSerializer : public SerializeGPUModuleBase {
163162
public:
@@ -532,6 +531,12 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
532531
if (targetOptions.getCompilationTarget() == gpu::CompilationTarget::Offload)
533532
return SerializeGPUModuleBase::moduleToObject(llvmModule);
534533

534+
#if !LLVM_HAS_NVPTX_TARGET
535+
getOperation()->emitError(
536+
"The `NVPTX` target was not built. Please enable it when building LLVM.");
537+
return std::nullopt;
538+
#endif // LLVM_HAS_NVPTX_TARGET
539+
535540
// Emit PTX code.
536541
std::optional<llvm::TargetMachine *> targetMachine =
537542
getOrCreateTargetMachine();
@@ -569,7 +574,6 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) {
569574
return compileToBinary(*serializedISA);
570575
#endif // MLIR_ENABLE_NVPTXCOMPILER
571576
}
572-
#endif // LLVM_HAS_NVPTX_TARGET
573577

574578
std::optional<SmallVector<char, 0>>
575579
NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
@@ -581,15 +585,9 @@ NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
581585
module->emitError("Module must be a GPU module.");
582586
return std::nullopt;
583587
}
584-
#if LLVM_HAS_NVPTX_TARGET
585588
NVPTXSerializer serializer(*module, cast<NVVMTargetAttr>(attribute), options);
586589
serializer.init();
587590
return serializer.run();
588-
#else
589-
module->emitError(
590-
"The `NVPTX` target was not built. Please enable it when building LLVM.");
591-
return std::nullopt;
592-
#endif // LLVM_HAS_NVPTX_TARGET
593591
}
594592

595593
Attribute

0 commit comments

Comments
 (0)