summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/GPU
diff options
context:
space:
mode:
authorAlex Zinenko <zinenko@google.com>2019-12-06 14:23:06 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-12-06 14:23:37 -0800
commit3230267d0dbdc908d7be5886e20c2ee5f0e942fe (patch)
treeb2bcf44fc2b2770f642e2489b6300a349b87c62c /mlir/lib/Dialect/GPU
parent6e0a2e4e2fedbbfea4cb95b8d5ac7a85ff3a2911 (diff)
downloadbcm5719-llvm-3230267d0dbdc908d7be5886e20c2ee5f0e942fe.tar.gz
bcm5719-llvm-3230267d0dbdc908d7be5886e20c2ee5f0e942fe.zip
Move GPU::LaunchOp to ODS. NFC.
Move the definition of the GPU launch opreation from hand-rolled C++ code to ODS framework. This only does the moves, a follow-up is necessary to clean up users of custom functions that could be auto-generated by ODS. PiperOrigin-RevId: 284261856
Diffstat (limited to 'mlir/lib/Dialect/GPU')
-rw-r--r--mlir/lib/Dialect/GPU/IR/GPUDialect.cpp64
1 files changed, 35 insertions, 29 deletions
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 38998b968ad..87b170b6da8 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -46,7 +46,7 @@ bool GPUDialect::isKernel(Operation *op) {
GPUDialect::GPUDialect(MLIRContext *context)
: Dialect(getDialectName(), context) {
- addOperations<LaunchOp, LaunchFuncOp,
+ addOperations<LaunchFuncOp,
#define GET_OP_LIST
#include "mlir/Dialect/GPU/GPUOps.cpp.inc"
>();
@@ -244,19 +244,20 @@ llvm::iterator_range<Block::args_iterator> LaunchOp::getKernelArguments() {
return llvm::drop_begin(args, LaunchOp::kNumConfigRegionAttributes);
}
-LogicalResult LaunchOp::verify() {
+LogicalResult verify(LaunchOp op) {
// Kernel launch takes kNumConfigOperands leading operands for grid/block
// sizes and transforms them into kNumConfigRegionAttributes region arguments
// for block/thread identifiers and grid/block sizes.
- if (!getBody().empty()) {
- Block &entryBlock = getBody().front();
- if (entryBlock.getNumArguments() != kNumConfigOperands + getNumOperands())
- return emitOpError("unexpected number of region arguments");
+ if (!op.getBody().empty()) {
+ Block &entryBlock = op.getBody().front();
+ if (entryBlock.getNumArguments() !=
+ LaunchOp::kNumConfigOperands + op.getNumOperands())
+ return op.emitOpError("unexpected number of region arguments");
}
// Block terminators without successors are expected to exit the kernel region
// and must be `gpu.launch`.
- for (Block &block : getBody()) {
+ for (Block &block : op.getBody()) {
if (block.empty())
continue;
if (block.back().getNumSuccessors() != 0)
@@ -265,8 +266,8 @@ LogicalResult LaunchOp::verify() {
return block.back()
.emitError("expected 'gpu.terminator' or a terminator with "
"successors")
- .attachNote(getLoc())
- << "in '" << getOperationName() << "' body region";
+ .attachNote(op.getLoc())
+ << "in '" << LaunchOp::getOperationName() << "' body region";
}
}
@@ -285,27 +286,31 @@ static void printSizeAssignment(OpAsmPrinter &p, KernelDim3 size,
p << *size.z << " = " << *operands[2] << ')';
}
-void LaunchOp::print(OpAsmPrinter &p) {
- SmallVector<Value *, 12> operandContainer(operand_begin(), operand_end());
+void printLaunchOp(OpAsmPrinter &p, LaunchOp op) {
+ SmallVector<Value *, 12> operandContainer(op.operand_begin(),
+ op.operand_end());
ArrayRef<Value *> operands(operandContainer);
// Print the launch configuration.
- p << getOperationName() << ' ' << getBlocksKeyword();
- printSizeAssignment(p, getGridSize(), operands.take_front(3), getBlockIds());
- p << ' ' << getThreadsKeyword();
- printSizeAssignment(p, getBlockSize(), operands.slice(3, 3), getThreadIds());
+ p << LaunchOp::getOperationName() << ' ' << op.getBlocksKeyword();
+ printSizeAssignment(p, op.getGridSize(), operands.take_front(3),
+ op.getBlockIds());
+ p << ' ' << op.getThreadsKeyword();
+ printSizeAssignment(p, op.getBlockSize(), operands.slice(3, 3),
+ op.getThreadIds());
// From now on, the first kNumConfigOperands operands corresponding to grid
// and block sizes are irrelevant, so we can drop them.
- operands = operands.drop_front(kNumConfigOperands);
+ operands = operands.drop_front(LaunchOp::kNumConfigOperands);
// Print the data argument remapping.
- if (!getBody().empty() && !operands.empty()) {
- p << ' ' << getArgsKeyword() << '(';
+ if (!op.getBody().empty() && !operands.empty()) {
+ p << ' ' << op.getArgsKeyword() << '(';
for (unsigned i = 0, e = operands.size(); i < e; ++i) {
if (i != 0)
p << ", ";
- p << *getBody().front().getArgument(kNumConfigRegionAttributes + i)
+ p << *op.getBody().front().getArgument(
+ LaunchOp::kNumConfigRegionAttributes + i)
<< " = " << *operands[i];
}
p << ") ";
@@ -321,8 +326,8 @@ void LaunchOp::print(OpAsmPrinter &p) {
}
}
- p.printRegion(getBody(), /*printEntryBlockArgs=*/false);
- p.printOptionalAttrDict(getAttrs());
+ p.printRegion(op.getBody(), /*printEntryBlockArgs=*/false);
+ p.printOptionalAttrDict(op.getAttrs());
}
// Parse the size assignment blocks for blocks and threads. These have the form
@@ -361,10 +366,10 @@ parseSizeAssignment(OpAsmParser &parser,
// (`args` ssa-reassignment `:` type-list)?
// region attr-dict?
// ssa-reassignment ::= `(` ssa-id `=` ssa-use (`,` ssa-id `=` ssa-use)* `)`
-ParseResult LaunchOp::parse(OpAsmParser &parser, OperationState &result) {
+ParseResult parseLaunchOp(OpAsmParser &parser, OperationState &result) {
// Sizes of the grid and block.
- SmallVector<OpAsmParser::OperandType, kNumConfigOperands> sizes(
- kNumConfigOperands);
+ SmallVector<OpAsmParser::OperandType, LaunchOp::kNumConfigOperands> sizes(
+ LaunchOp::kNumConfigOperands);
MutableArrayRef<OpAsmParser::OperandType> sizesRef(sizes);
// Actual (data) operands passed to the kernel.
@@ -372,7 +377,7 @@ ParseResult LaunchOp::parse(OpAsmParser &parser, OperationState &result) {
// Region arguments to be created.
SmallVector<OpAsmParser::OperandType, 16> regionArgs(
- kNumConfigRegionAttributes);
+ LaunchOp::kNumConfigRegionAttributes);
MutableArrayRef<OpAsmParser::OperandType> regionArgsRef(regionArgs);
// Parse the size assignment segments: the first segment assigns grid sizes
@@ -380,11 +385,11 @@ ParseResult LaunchOp::parse(OpAsmParser &parser, OperationState &result) {
// sizes and defines values for thread identifiers. In the region argument
// list, identifiers precede sizes, and block-related values precede
// thread-related values.
- if (parser.parseKeyword(getBlocksKeyword().data()) ||
+ if (parser.parseKeyword(LaunchOp::getBlocksKeyword().data()) ||
parseSizeAssignment(parser, sizesRef.take_front(3),
regionArgsRef.slice(6, 3),
regionArgsRef.slice(0, 3)) ||
- parser.parseKeyword(getThreadsKeyword().data()) ||
+ parser.parseKeyword(LaunchOp::getThreadsKeyword().data()) ||
parseSizeAssignment(parser, sizesRef.drop_front(3),
regionArgsRef.slice(9, 3),
regionArgsRef.slice(3, 3)) ||
@@ -397,7 +402,7 @@ ParseResult LaunchOp::parse(OpAsmParser &parser, OperationState &result) {
// so is the trailing type list. Parse it as well and use the parsed types
// to resolve the operands passed to the kernel arguments.
SmallVector<Type, 4> dataTypes;
- if (!parser.parseOptionalKeyword(getArgsKeyword())) {
+ if (!parser.parseOptionalKeyword(LaunchOp::getArgsKeyword())) {
llvm::SMLoc argsLoc = parser.getCurrentLocation();
regionArgs.push_back({});
@@ -425,7 +430,8 @@ ParseResult LaunchOp::parse(OpAsmParser &parser, OperationState &result) {
// block/thread identifiers and grid/block sizes, all of the `index` type.
// Follow the actual kernel arguments.
Type index = parser.getBuilder().getIndexType();
- dataTypes.insert(dataTypes.begin(), kNumConfigRegionAttributes, index);
+ dataTypes.insert(dataTypes.begin(), LaunchOp::kNumConfigRegionAttributes,
+ index);
Region *body = result.addRegion();
return failure(parser.parseRegion(*body, regionArgs, dataTypes) ||
parser.parseOptionalAttrDict(result.attributes));
OpenPOWER on IntegriCloud