[Mlir-commits] [mlir] f3b4c00 - [mlir][gpu] Add builder to `gpu.launch_func` (#95541)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jun 15 10:40:17 PDT 2024
Author: Fabian Mora
Date: 2024-06-15T12:40:14-05:00
New Revision: f3b4c00304ef3aa737097684502a419b5e89d4e9
URL: https://github.com/llvm/llvm-project/commit/f3b4c00304ef3aa737097684502a419b5e89d4e9
DIFF: https://github.com/llvm/llvm-project/commit/f3b4c00304ef3aa737097684502a419b5e89d4e9.diff
LOG: [mlir][gpu] Add builder to `gpu.launch_func` (#95541)
This patch adds a builder to `gpu.launch_func` allowing it to be created
using `SymbolRefAttr` instead of `GPUFuncOp`. This allows creating
`launch_func` when only a `gpu.binary` is present, instead of the full
`gpu.module {...}`.
Added:
Modified:
mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
index 9c5f7ecd8cbe8..5943de103beba 100644
--- a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
+++ b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
@@ -653,6 +653,12 @@ def GPU_LaunchFuncOp :GPU_Op<"launch_func", [
CArg<"Type", "nullptr">:$asyncTokenType,
CArg<"ValueRange", "{}">:$asyncDependencies,
CArg<"std::optional<KernelDim3>", "std::nullopt">:$clusterSize)>,
+ OpBuilder<(ins "SymbolRefAttr":$kernel, "KernelDim3":$gridSize,
+ "KernelDim3":$blockSize, "Value":$dynamicSharedMemorySize,
+ "ValueRange":$kernelOperands,
+ "Type":$asyncTokenType,
+ CArg<"ValueRange", "{}">:$asyncDependencies,
+ CArg<"std::optional<KernelDim3>", "std::nullopt">:$clusterSize)>,
OpBuilder<(ins "SymbolRefAttr":$kernel, "KernelDim3":$gridSize,
"KernelDim3":$blockSize, "Value":$dynamicSharedMemorySize,
"ValueRange":$kernelOperands,
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index d8e29da6512d4..17bf254b64b4d 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -1081,11 +1081,13 @@ BlockArgument LaunchOp::addPrivateAttribution(Type type, Location loc) {
//===----------------------------------------------------------------------===//
void LaunchFuncOp::build(OpBuilder &builder, OperationState &result,
- GPUFuncOp kernelFunc, KernelDim3 gridSize,
+ SymbolRefAttr kernelSymbol, KernelDim3 gridSize,
KernelDim3 getBlockSize, Value dynamicSharedMemorySize,
ValueRange kernelOperands, Type asyncTokenType,
ValueRange asyncDependencies,
std::optional<KernelDim3> clusterSize) {
+ assert(kernelSymbol.getNestedReferences().size() == 1 &&
+ "expected a symbol reference with a single nested reference");
result.addOperands(asyncDependencies);
if (asyncTokenType)
result.types.push_back(builder.getType<AsyncTokenType>());
@@ -1098,10 +1100,6 @@ void LaunchFuncOp::build(OpBuilder &builder, OperationState &result,
if (dynamicSharedMemorySize)
result.addOperands(dynamicSharedMemorySize);
result.addOperands(kernelOperands);
- auto kernelModule = kernelFunc->getParentOfType<GPUModuleOp>();
- auto kernelSymbol =
- SymbolRefAttr::get(kernelModule.getNameAttr(),
- {SymbolRefAttr::get(kernelFunc.getNameAttr())});
Properties &prop = result.getOrAddProperties<Properties>();
prop.kernel = kernelSymbol;
@@ -1122,6 +1120,21 @@ void LaunchFuncOp::build(OpBuilder &builder, OperationState &result,
prop.operandSegmentSizes[segmentSizesLen - 1] = 0;
}
+void LaunchFuncOp::build(OpBuilder &builder, OperationState &result,
+ GPUFuncOp kernelFunc, KernelDim3 gridSize,
+ KernelDim3 getBlockSize, Value dynamicSharedMemorySize,
+ ValueRange kernelOperands, Type asyncTokenType,
+ ValueRange asyncDependencies,
+ std::optional<KernelDim3> clusterSize) {
+ auto kernelModule = kernelFunc->getParentOfType<GPUModuleOp>();
+ auto kernelSymbol =
+ SymbolRefAttr::get(kernelModule.getNameAttr(),
+ {SymbolRefAttr::get(kernelFunc.getNameAttr())});
+ build(builder, result, kernelSymbol, gridSize, getBlockSize,
+ dynamicSharedMemorySize, kernelOperands, asyncTokenType,
+ asyncDependencies, clusterSize);
+}
+
void LaunchFuncOp::build(OpBuilder &builder, OperationState &result,
SymbolRefAttr kernel, KernelDim3 gridSize,
KernelDim3 getBlockSize, Value dynamicSharedMemorySize,
More information about the Mlir-commits
mailing list