[Mlir-commits] [mlir] 840ff84 - [mlir] Default for gpu-binary-annotation option.
Christian Sigg
llvmlistbot at llvm.org
Tue Mar 9 12:01:59 PST 2021
Author: Christian Sigg
Date: 2021-03-09T21:01:50+01:00
New Revision: 840ff84d33c797f0ab73e5f8cd402ce84c95538d
URL: https://github.com/llvm/llvm-project/commit/840ff84d33c797f0ab73e5f8cd402ce84c95538d
DIFF: https://github.com/llvm/llvm-project/commit/840ff84d33c797f0ab73e5f8cd402ce84c95538d.diff
LOG: [mlir] Default for gpu-binary-annotation option.
Provide default for gpuBinaryAnnotation so that we don't need to specify it in tests.
The annotation likely only needs to be target specific if we want to lower to e.g. both CUDA and ROCDL.
Reviewed By: herhut, bondhugula
Differential Revision: https://reviews.llvm.org/D98168
Added:
Modified:
mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
mlir/include/mlir/Conversion/Passes.td
mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp
mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
index 61d62a3ef78c..4ef1d8a811c3 100644
--- a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
+++ b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
@@ -26,6 +26,9 @@ class OperationPass;
namespace gpu {
class GPUModuleOp;
+
+/// Returns the default annotation name for GPU binary blobs.
+std::string getDefaultGpuBinaryAnnotation();
} // namespace gpu
namespace LLVM {
@@ -44,13 +47,17 @@ using LoweringCallback = std::function<std::unique_ptr<llvm::Module>(
/// This pass does not generate code to call GPU runtime APIs directly but
/// instead uses a small wrapper library that exports a stable and conveniently
/// typed ABI on top of GPU runtimes such as CUDA or ROCm (HIP).
+///
+/// A non-empty gpuBinaryAnnotation overrides the pass' command line option.
std::unique_ptr<OperationPass<ModuleOp>>
-createGpuToLLVMConversionPass(StringRef gpuBinaryAnnotation = "");
+createGpuToLLVMConversionPass(StringRef gpuBinaryAnnotation = {});
/// Collect a set of patterns to convert from the GPU dialect to LLVM.
+///
+/// A non-empty gpuBinaryAnnotation overrides the pass' command line option.
void populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter,
OwningRewritePatternList &patterns,
- StringRef gpuBinaryAnnotation);
+ StringRef gpuBinaryAnnotation = {});
/// Creates a pass to convert kernel functions into GPU target object blobs.
///
@@ -74,11 +81,13 @@ void populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter,
///
/// After the transformation, the body of the kernel function is removed (i.e.,
/// it is turned into a declaration).
+///
+/// A non-empty gpuBinaryAnnotation overrides the pass' command line option.
std::unique_ptr<OperationPass<gpu::GPUModuleOp>>
createConvertGPUKernelToBlobPass(LoweringCallback loweringCallback,
BlobGenerator blobGenerator, StringRef triple,
StringRef targetChip, StringRef features,
- StringRef gpuBinaryAnnotation);
+ StringRef gpuBinaryAnnotation = {});
} // namespace mlir
diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td
index f37283868a8e..b818c2b3ea23 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -106,10 +106,6 @@ def GpuToLLVMConversionPass : Pass<"gpu-to-llvm", "ModuleOp"> {
let summary = "Convert GPU dialect to LLVM dialect with GPU runtime calls";
let constructor = "mlir::createGpuToLLVMConversionPass()";
let dependentDialects = ["LLVM::LLVMDialect"];
- let options = [
- Option<"gpuBinaryAnnotation", "gpu-binary-annotation", "std::string",
- "", "Annotation attribute string for GPU binary">,
- ];
}
def LowerHostCodeToLLVM : Pass<"lower-host-to-llvm", "ModuleOp"> {
diff --git a/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp b/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp
index 35d8c9aeb246..9b5fc8f721da 100644
--- a/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp
+++ b/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp
@@ -52,8 +52,15 @@ class GpuKernelToBlobPass
StringRef targetChip, StringRef features,
StringRef gpuBinaryAnnotation)
: loweringCallback(loweringCallback), blobGenerator(blobGenerator),
- triple(triple), targetChip(targetChip), features(features),
- blobAnnotation(gpuBinaryAnnotation) {}
+ triple(triple), targetChip(targetChip), features(features) {
+ if (!gpuBinaryAnnotation.empty())
+ this->gpuBinaryAnnotation = gpuBinaryAnnotation.str();
+ }
+
+ GpuKernelToBlobPass(const GpuKernelToBlobPass &other)
+ : loweringCallback(other.loweringCallback),
+ blobGenerator(other.blobGenerator), triple(other.triple),
+ targetChip(other.targetChip), features(other.features) {}
void runOnOperation() override {
gpu::GPUModuleOp module = getOperation();
@@ -70,7 +77,7 @@ class GpuKernelToBlobPass
// attribute to the module.
if (auto blobAttr = translateGPUModuleToBinaryAnnotation(
*llvmModule, module.getLoc(), module.getName()))
- module->setAttr(blobAnnotation, blobAttr);
+ module->setAttr(gpuBinaryAnnotation, blobAttr);
else
signalPassFailure();
}
@@ -92,14 +99,21 @@ class GpuKernelToBlobPass
LoweringCallback loweringCallback;
BlobGenerator blobGenerator;
+
llvm::Triple triple;
std::string targetChip;
std::string features;
- std::string blobAnnotation;
+
+ Option<std::string> gpuBinaryAnnotation{
+ *this, "gpu-binary-annotation",
+ llvm::cl::desc("Annotation attribute string for GPU binary"),
+ llvm::cl::init(gpu::getDefaultGpuBinaryAnnotation())};
};
} // anonymous namespace
+std::string gpu::getDefaultGpuBinaryAnnotation() { return "gpu.binary"; }
+
std::string
GpuKernelToBlobPass::translateModuleToISA(llvm::Module &module,
llvm::TargetMachine &targetMachine) {
diff --git a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
index 3570dc741306..3a6cffd34268 100644
--- a/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
+++ b/mlir/lib/Conversion/GPUCommon/ConvertLaunchFuncToRuntimeCalls.cpp
@@ -48,8 +48,17 @@ class GpuToLLVMConversionPass
this->gpuBinaryAnnotation = gpuBinaryAnnotation.str();
}
+ GpuToLLVMConversionPass(const GpuToLLVMConversionPass &other)
+ : GpuToLLVMConversionPassBase(other) {}
+
// Run the dialect converter on the module.
void runOnOperation() override;
+
+private:
+ Option<std::string> gpuBinaryAnnotation{
+ *this, "gpu-binary-annotation",
+ llvm::cl::desc("Annotation attribute string for GPU binary"),
+ llvm::cl::init(gpu::getDefaultGpuBinaryAnnotation())};
};
struct FunctionCallBuilder {
diff --git a/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp b/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
index 22f15a67f481..541e1ba95990 100644
--- a/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
+++ b/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
@@ -114,7 +114,8 @@ struct GpuToCubinPipelineOptions
: public mlir::PassPipelineOptions<GpuToCubinPipelineOptions> {
Option<std::string> gpuBinaryAnnotation{
*this, "gpu-binary-annotation",
- llvm::cl::desc("Annotation attribute string for GPU binary")};
+ llvm::cl::desc("Annotation attribute string for GPU binary"),
+ llvm::cl::init(gpu::getDefaultGpuBinaryAnnotation())};
};
// Register cuda-runner specific passes.
More information about the Mlir-commits
mailing list