summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp')
-rw-r--r--mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
index b111c96313c..66a2e66f99a 100644
--- a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
+++ b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
@@ -46,15 +46,18 @@ static constexpr const char *kCubinAnnotation = "nvvm.cubin";
/// IR and further to PTX. A user provided CubinGenerator compiles the PTX to
/// GPU binary code, which is then attached as an attribute to the function. The
/// function body is erased.
-class GpuKernelToCubinPass
- : public OperationPass<GpuKernelToCubinPass, gpu::GPUModuleOp> {
+class GpuKernelToCubinPass : public ModulePass<GpuKernelToCubinPass> {
public:
GpuKernelToCubinPass(
CubinGenerator cubinGenerator = compilePtxToCubinForTesting)
: cubinGenerator(cubinGenerator) {}
- void runOnOperation() override {
- gpu::GPUModuleOp module = getOperation();
+ void runOnModule() override {
+ ModuleOp module = getModule();
+ if (!module.getAttrOfType<UnitAttr>(
+ gpu::GPUDialect::getKernelModuleAttrName()) ||
+ !module.getName())
+ return;
// Make sure the NVPTX target is initialized.
LLVMInitializeNVPTXTarget();
@@ -68,8 +71,8 @@ public:
// Translate the module to CUBIN and attach the result as attribute to the
// module.
- if (auto cubinAttr = translateGPUModuleToCubinAnnotation(
- *llvmModule, module.getLoc(), module.getName()))
+ if (auto cubinAttr = translateGpuModuleToCubinAnnotation(
+ *llvmModule, module.getLoc(), *module.getName()))
module.setAttr(kCubinAnnotation, cubinAttr);
else
signalPassFailure();
@@ -89,7 +92,7 @@ private:
StringRef name);
/// Translates llvmModule to cubin and returns the result as attribute.
- StringAttr translateGPUModuleToCubinAnnotation(llvm::Module &llvmModule,
+ StringAttr translateGpuModuleToCubinAnnotation(llvm::Module &llvmModule,
Location loc, StringRef name);
CubinGenerator cubinGenerator;
@@ -146,7 +149,7 @@ OwnedCubin GpuKernelToCubinPass::convertModuleToCubin(llvm::Module &llvmModule,
return cubinGenerator(ptx, loc, name);
}
-StringAttr GpuKernelToCubinPass::translateGPUModuleToCubinAnnotation(
+StringAttr GpuKernelToCubinPass::translateGpuModuleToCubinAnnotation(
llvm::Module &llvmModule, Location loc, StringRef name) {
auto cubin = convertModuleToCubin(llvmModule, loc, name);
if (!cubin)
@@ -154,7 +157,7 @@ StringAttr GpuKernelToCubinPass::translateGPUModuleToCubinAnnotation(
return StringAttr::get({cubin->data(), cubin->size()}, loc->getContext());
}
-std::unique_ptr<OpPassBase<gpu::GPUModuleOp>>
+std::unique_ptr<OpPassBase<ModuleOp>>
mlir::createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator) {
return std::make_unique<GpuKernelToCubinPass>(cubinGenerator);
}
OpenPOWER on IntegriCloud