summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Conversion/GPUToCUDA
diff options
context:
space:
mode:
authorTres Popp <tpopp@google.com>2020-01-14 11:09:59 +0100
committerStephan Herhut <herhut@google.com>2020-01-14 12:05:47 +0100
commit4624a1e8ac8a3f69cc887403b976f538f587744a (patch)
tree13cb3b1371abedefbdbd7e09933633acc4aca44c /mlir/lib/Conversion/GPUToCUDA
parent9492e9d8cfd356109276da5aa926b297db0e16db (diff)
downloadbcm5719-llvm-4624a1e8ac8a3f69cc887403b976f538f587744a.tar.gz
bcm5719-llvm-4624a1e8ac8a3f69cc887403b976f538f587744a.zip
[mlir] Create a gpu.module operation for the GPU Dialect.
Summary: This is based on the use of code constantly checking for an attribute on a model and instead represents the distinct operaion with a different op. Instead, this op can be used to provide better filtering. Reviewers: herhut, mravishankar, antiagainst, rriddle Reviewed By: herhut, antiagainst, rriddle Subscribers: liufengdb, aartbik, jholewinski, mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, csigg, arpith-jacob, mgester, lucyrfox, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72336
Diffstat (limited to 'mlir/lib/Conversion/GPUToCUDA')
-rw-r--r--mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp21
-rw-r--r--mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp13
2 files changed, 15 insertions, 19 deletions
diff --git a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
index 66a2e66f99a..b111c96313c 100644
--- a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
+++ b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
@@ -46,18 +46,15 @@ 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 ModulePass<GpuKernelToCubinPass> {
+class GpuKernelToCubinPass
+ : public OperationPass<GpuKernelToCubinPass, gpu::GPUModuleOp> {
public:
GpuKernelToCubinPass(
CubinGenerator cubinGenerator = compilePtxToCubinForTesting)
: cubinGenerator(cubinGenerator) {}
- void runOnModule() override {
- ModuleOp module = getModule();
- if (!module.getAttrOfType<UnitAttr>(
- gpu::GPUDialect::getKernelModuleAttrName()) ||
- !module.getName())
- return;
+ void runOnOperation() override {
+ gpu::GPUModuleOp module = getOperation();
// Make sure the NVPTX target is initialized.
LLVMInitializeNVPTXTarget();
@@ -71,8 +68,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();
@@ -92,7 +89,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;
@@ -149,7 +146,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)
@@ -157,7 +154,7 @@ StringAttr GpuKernelToCubinPass::translateGpuModuleToCubinAnnotation(
return StringAttr::get({cubin->data(), cubin->size()}, loc->getContext());
}
-std::unique_ptr<OpPassBase<ModuleOp>>
+std::unique_ptr<OpPassBase<gpu::GPUModuleOp>>
mlir::createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator) {
return std::make_unique<GpuKernelToCubinPass>(cubinGenerator);
}
diff --git a/mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp b/mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp
index 41f69d6e21d..31024d2881b 100644
--- a/mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp
+++ b/mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp
@@ -132,9 +132,9 @@ public:
// GPU kernel modules are no longer necessary since we have a global
// constant with the CUBIN data.
- for (auto m : llvm::make_early_inc_range(getModule().getOps<ModuleOp>()))
- if (m.getAttrOfType<UnitAttr>(gpu::GPUDialect::getKernelModuleAttrName()))
- m.erase();
+ for (auto m :
+ llvm::make_early_inc_range(getModule().getOps<gpu::GPUModuleOp>()))
+ m.erase();
}
private:
@@ -343,8 +343,8 @@ void GpuLaunchFuncToCudaCallsPass::translateGpuLaunchCalls(
builder.getI32IntegerAttr(0));
// Create an LLVM global with CUBIN extracted from the kernel annotation and
// obtain a pointer to the first byte in it.
- auto kernelModule =
- getModule().lookupSymbol<ModuleOp>(launchOp.getKernelModuleName());
+ auto kernelModule = getModule().lookupSymbol<gpu::GPUModuleOp>(
+ launchOp.getKernelModuleName());
assert(kernelModule && "expected a kernel module");
auto cubinAttr = kernelModule.getAttrOfType<StringAttr>(kCubinAnnotation);
@@ -354,8 +354,7 @@ void GpuLaunchFuncToCudaCallsPass::translateGpuLaunchCalls(
return signalPassFailure();
}
- assert(kernelModule.getName() && "expected a named module");
- SmallString<128> nameBuffer(*kernelModule.getName());
+ SmallString<128> nameBuffer(kernelModule.getName());
nameBuffer.append(kCubinStorageSuffix);
Value data = LLVM::createGlobalString(
loc, builder, nameBuffer.str(), cubinAttr.getValue(),
OpenPOWER on IntegriCloud