1 //===- GPUDialect.cpp - MLIR Dialect for GPU Kernels implementation -------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the GPU kernel-related dialect and its operations. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "mlir/Dialect/GPU/GPUDialect.h" 14 15 #include "mlir/Dialect/LLVMIR/LLVMDialect.h" 16 #include "mlir/Dialect/MemRef/IR/MemRef.h" 17 #include "mlir/Dialect/StandardOps/IR/Ops.h" 18 #include "mlir/IR/Attributes.h" 19 #include "mlir/IR/Builders.h" 20 #include "mlir/IR/BuiltinOps.h" 21 #include "mlir/IR/BuiltinTypes.h" 22 #include "mlir/IR/DialectImplementation.h" 23 #include "mlir/IR/FunctionImplementation.h" 24 #include "mlir/IR/Matchers.h" 25 #include "mlir/IR/OpImplementation.h" 26 #include "mlir/IR/PatternMatch.h" 27 #include "mlir/IR/TypeUtilities.h" 28 #include "llvm/ADT/TypeSwitch.h" 29 30 using namespace mlir; 31 using namespace mlir::gpu; 32 33 #include "mlir/Dialect/GPU/GPUOpsDialect.cpp.inc" 34 35 //===----------------------------------------------------------------------===// 36 // MMAMatrixType 37 //===----------------------------------------------------------------------===// 38 39 MMAMatrixType MMAMatrixType::get(ArrayRef<int64_t> shape, Type elementType, 40 StringRef operand) { 41 return Base::get(elementType.getContext(), shape, elementType, operand); 42 } 43 44 MMAMatrixType 45 MMAMatrixType::getChecked(function_ref<InFlightDiagnostic()> emitError, 46 ArrayRef<int64_t> shape, Type elementType, 47 StringRef operand) { 48 return Base::getChecked(emitError, elementType.getContext(), shape, 49 elementType, operand); 50 } 51 52 unsigned MMAMatrixType::getNumDims() const { return getImpl()->numDims; } 53 54 ArrayRef<int64_t> MMAMatrixType::getShape() const { 55 return getImpl()->getShape(); 56 } 57 58 Type MMAMatrixType::getElementType() const { return getImpl()->elementType; } 59 60 StringRef MMAMatrixType::getOperand() const { return getImpl()->getOperand(); } 61 62 bool MMAMatrixType::isValidElementType(Type elementType) { 63 return elementType.isF16() || elementType.isF32(); 64 } 65 66 LogicalResult 67 MMAMatrixType::verify(function_ref<InFlightDiagnostic()> emitError, 68 ArrayRef<int64_t> shape, Type elementType, 69 StringRef operand) { 70 if (!operand.equals("AOp") && !operand.equals("BOp") && 71 !operand.equals("COp")) 72 return emitError() << "operand expected to be one of AOp, BOp or COp"; 73 74 if (shape.size() != 2) 75 return emitError() << "MMAMatrixType must have exactly two dimensions"; 76 77 if (!MMAMatrixType::isValidElementType(elementType)) 78 return emitError() << "MMAMatrixType elements must be F16 or F32"; 79 80 return success(); 81 } 82 83 //===----------------------------------------------------------------------===// 84 // GPUDialect 85 //===----------------------------------------------------------------------===// 86 87 /// GPU memory space identifiers. 88 enum GPUMemorySpace { 89 /// Generic memory space identifier. 90 kGenericMemorySpace = 0, 91 92 /// Global memory space identifier. 93 kGlobalMemorySpace = 1, 94 95 /// Shared memory space identifier. 96 kSharedMemorySpace = 3 97 }; 98 99 bool GPUDialect::isKernel(Operation *op) { 100 UnitAttr isKernelAttr = op->getAttrOfType<UnitAttr>(getKernelFuncAttrName()); 101 return static_cast<bool>(isKernelAttr); 102 } 103 104 void GPUDialect::initialize() { 105 addTypes<AsyncTokenType>(); 106 addTypes<MMAMatrixType>(); 107 addOperations< 108 #define GET_OP_LIST 109 #include "mlir/Dialect/GPU/GPUOps.cpp.inc" 110 >(); 111 } 112 113 Type GPUDialect::parseType(DialectAsmParser &parser) const { 114 // Parse the main keyword for the type. 115 StringRef keyword; 116 if (parser.parseKeyword(&keyword)) 117 return Type(); 118 MLIRContext *context = getContext(); 119 120 // Handle 'async token' types. 121 if (keyword == "async.token") 122 return AsyncTokenType::get(context); 123 124 if (keyword == "mma_matrix") { 125 llvm::SMLoc beginLoc = parser.getNameLoc(); 126 127 // Parse '<'. 128 if (parser.parseLess()) 129 return nullptr; 130 131 // Parse the size and elementType. 132 SmallVector<int64_t> shape; 133 Type elementType; 134 if (parser.parseDimensionList(shape, /*allowDynamic=*/false) || 135 parser.parseType(elementType)) 136 return nullptr; 137 138 // Parse ',' 139 if (parser.parseComma()) 140 return nullptr; 141 142 // Parse operand. 143 std::string operand; 144 if (failed(parser.parseOptionalString(&operand))) 145 return nullptr; 146 147 // Parse '>'. 148 if (parser.parseGreater()) 149 return nullptr; 150 151 return MMAMatrixType::getChecked(mlir::detail::getDefaultDiagnosticEmitFn( 152 parser.getEncodedSourceLoc(beginLoc)), 153 shape, elementType, operand); 154 } 155 156 parser.emitError(parser.getNameLoc(), "unknown gpu type: " + keyword); 157 return Type(); 158 } 159 160 void GPUDialect::printType(Type type, DialectAsmPrinter &os) const { 161 TypeSwitch<Type>(type) 162 .Case<AsyncTokenType>([&](Type) { os << "async.token"; }) 163 .Case<MMAMatrixType>([&](MMAMatrixType fragTy) { 164 os << "mma_matrix<"; 165 auto shape = fragTy.getShape(); 166 for (auto dim = shape.begin(), e = shape.end() - 1; dim != e; ++dim) 167 os << *dim << 'x'; 168 os << shape.back() << 'x' << fragTy.getElementType(); 169 os << ", \"" << fragTy.getOperand() << "\"" << '>'; 170 }) 171 .Default([](Type) { llvm_unreachable("unexpected 'gpu' type kind"); }); 172 } 173 174 LogicalResult GPUDialect::verifyOperationAttribute(Operation *op, 175 NamedAttribute attr) { 176 if (!attr.second.isa<UnitAttr>() || 177 attr.first != getContainerModuleAttrName()) 178 return success(); 179 180 auto module = dyn_cast<ModuleOp>(op); 181 if (!module) 182 return op->emitError("expected '") 183 << getContainerModuleAttrName() << "' attribute to be attached to '" 184 << ModuleOp::getOperationName() << '\''; 185 186 auto walkResult = module.walk([&module](LaunchFuncOp launchOp) -> WalkResult { 187 // Ignore launches that are nested more or less deep than functions in the 188 // module we are currently checking. 189 if (!launchOp->getParentOp() || 190 launchOp->getParentOp()->getParentOp() != module) 191 return success(); 192 193 // Ignore launch ops with missing attributes here. The errors will be 194 // reported by the verifiers of those ops. 195 if (!launchOp->getAttrOfType<SymbolRefAttr>( 196 LaunchFuncOp::getKernelAttrName())) 197 return success(); 198 199 // Check that `launch_func` refers to a well-formed GPU kernel module. 200 StringAttr kernelModuleName = launchOp.getKernelModuleName(); 201 auto kernelModule = module.lookupSymbol<GPUModuleOp>(kernelModuleName); 202 if (!kernelModule) 203 return launchOp.emitOpError() 204 << "kernel module '" << kernelModuleName.getValue() 205 << "' is undefined"; 206 207 // Check that `launch_func` refers to a well-formed kernel function. 208 Operation *kernelFunc = module.lookupSymbol(launchOp.kernelAttr()); 209 auto kernelGPUFunction = dyn_cast_or_null<gpu::GPUFuncOp>(kernelFunc); 210 auto kernelLLVMFunction = dyn_cast_or_null<LLVM::LLVMFuncOp>(kernelFunc); 211 if (!kernelGPUFunction && !kernelLLVMFunction) 212 return launchOp.emitOpError("kernel function '") 213 << launchOp.kernel() << "' is undefined"; 214 if (!kernelFunc->getAttrOfType<mlir::UnitAttr>( 215 GPUDialect::getKernelFuncAttrName())) 216 return launchOp.emitOpError("kernel function is missing the '") 217 << GPUDialect::getKernelFuncAttrName() << "' attribute"; 218 219 // TODO: if the kernel function has been converted to 220 // the LLVM dialect but the caller hasn't (which happens during the 221 // separate compilation), do not check type correspondence as it would 222 // require the verifier to be aware of the LLVM type conversion. 223 if (kernelLLVMFunction) 224 return success(); 225 226 unsigned actualNumArguments = launchOp.getNumKernelOperands(); 227 unsigned expectedNumArguments = kernelGPUFunction.getNumArguments(); 228 if (expectedNumArguments != actualNumArguments) 229 return launchOp.emitOpError("got ") 230 << actualNumArguments << " kernel operands but expected " 231 << expectedNumArguments; 232 233 auto functionType = kernelGPUFunction.getType(); 234 for (unsigned i = 0; i < expectedNumArguments; ++i) { 235 if (launchOp.getKernelOperand(i).getType() != functionType.getInput(i)) { 236 return launchOp.emitOpError("type of function argument ") 237 << i << " does not match"; 238 } 239 } 240 241 return success(); 242 }); 243 244 return walkResult.wasInterrupted() ? failure() : success(); 245 } 246 247 template <typename T> 248 static LogicalResult verifyIndexOp(T op) { 249 auto dimension = op.dimension(); 250 if (dimension != "x" && dimension != "y" && dimension != "z") 251 return op.emitError("dimension \"") << dimension << "\" is invalid"; 252 return success(); 253 } 254 255 static LogicalResult verifyAllReduce(gpu::AllReduceOp allReduce) { 256 if (allReduce.body().empty() != allReduce.op().hasValue()) 257 return allReduce.emitError( 258 "expected either an op attribute or a non-empty body"); 259 if (!allReduce.body().empty()) { 260 if (allReduce.body().getNumArguments() != 2) 261 return allReduce.emitError("expected two region arguments"); 262 for (auto argument : allReduce.body().getArguments()) { 263 if (argument.getType() != allReduce.getType()) 264 return allReduce.emitError("incorrect region argument type"); 265 } 266 unsigned yieldCount = 0; 267 for (Block &block : allReduce.body()) { 268 if (auto yield = dyn_cast<gpu::YieldOp>(block.getTerminator())) { 269 if (yield.getNumOperands() != 1) 270 return allReduce.emitError("expected one gpu.yield operand"); 271 if (yield.getOperand(0).getType() != allReduce.getType()) 272 return allReduce.emitError("incorrect gpu.yield type"); 273 ++yieldCount; 274 } 275 } 276 if (yieldCount == 0) 277 return allReduce.emitError("expected gpu.yield op in region"); 278 } else { 279 StringRef opName = *allReduce.op(); 280 if ((opName == "and" || opName == "or" || opName == "xor") && 281 !allReduce.getType().isa<IntegerType>()) { 282 return allReduce.emitError() 283 << '`' << opName << '`' 284 << " accumulator is only compatible with Integer type"; 285 } 286 } 287 return success(); 288 } 289 290 static LogicalResult verifyShuffleOp(gpu::ShuffleOp shuffleOp) { 291 auto type = shuffleOp.value().getType(); 292 if (shuffleOp.result().getType() != type) { 293 return shuffleOp.emitOpError() 294 << "requires the same type for value operand and result"; 295 } 296 if (!type.isSignlessIntOrFloat() || type.getIntOrFloatBitWidth() != 32) { 297 return shuffleOp.emitOpError() 298 << "requires value operand type to be f32 or i32"; 299 } 300 return success(); 301 } 302 303 static void printShuffleOp(OpAsmPrinter &p, ShuffleOp op) { 304 p << ' ' << op.getOperands() << ' ' << op.mode() << " : " 305 << op.value().getType(); 306 } 307 308 static ParseResult parseShuffleOp(OpAsmParser &parser, OperationState &state) { 309 SmallVector<OpAsmParser::OperandType, 3> operandInfo; 310 if (parser.parseOperandList(operandInfo, 3)) 311 return failure(); 312 313 StringRef mode; 314 if (parser.parseKeyword(&mode)) 315 return failure(); 316 state.addAttribute("mode", parser.getBuilder().getStringAttr(mode)); 317 318 Type valueType; 319 Type int32Type = parser.getBuilder().getIntegerType(32); 320 Type int1Type = parser.getBuilder().getI1Type(); 321 if (parser.parseColonType(valueType) || 322 parser.resolveOperands(operandInfo, {valueType, int32Type, int32Type}, 323 parser.getCurrentLocation(), state.operands) || 324 parser.addTypesToList({valueType, int1Type}, state.types)) 325 return failure(); 326 return success(); 327 } 328 329 //===----------------------------------------------------------------------===// 330 // AsyncOpInterface 331 //===----------------------------------------------------------------------===// 332 333 void gpu::addAsyncDependency(Operation *op, Value token) { 334 op->insertOperands(0, {token}); 335 if (!op->template hasTrait<OpTrait::AttrSizedOperandSegments>()) 336 return; 337 auto attrName = 338 OpTrait::AttrSizedOperandSegments<void>::getOperandSegmentSizeAttr(); 339 auto sizeAttr = op->template getAttrOfType<DenseIntElementsAttr>(attrName); 340 341 // Async dependencies is the only variadic operand. 342 if (!sizeAttr) 343 return; 344 345 SmallVector<int32_t, 8> sizes(sizeAttr.getValues<int32_t>()); 346 ++sizes.front(); 347 op->setAttr(attrName, Builder(op->getContext()).getI32VectorAttr(sizes)); 348 } 349 350 //===----------------------------------------------------------------------===// 351 // LaunchOp 352 //===----------------------------------------------------------------------===// 353 354 void LaunchOp::build(OpBuilder &builder, OperationState &result, 355 Value gridSizeX, Value gridSizeY, Value gridSizeZ, 356 Value blockSizeX, Value blockSizeY, Value blockSizeZ) { 357 // Add grid and block sizes as op operands, followed by the data operands. 358 result.addOperands( 359 {gridSizeX, gridSizeY, gridSizeZ, blockSizeX, blockSizeY, blockSizeZ}); 360 361 // Create a kernel body region with kNumConfigRegionAttributes + N arguments, 362 // where the first kNumConfigRegionAttributes arguments have `index` type and 363 // the rest have the same types as the data operands. 364 Region *kernelRegion = result.addRegion(); 365 Block *body = new Block(); 366 body->addArguments( 367 std::vector<Type>(kNumConfigRegionAttributes, builder.getIndexType())); 368 kernelRegion->push_back(body); 369 } 370 371 KernelDim3 LaunchOp::getBlockIds() { 372 assert(!body().empty() && "LaunchOp body must not be empty."); 373 auto args = body().getArguments(); 374 return KernelDim3{args[0], args[1], args[2]}; 375 } 376 377 KernelDim3 LaunchOp::getThreadIds() { 378 assert(!body().empty() && "LaunchOp body must not be empty."); 379 auto args = body().getArguments(); 380 return KernelDim3{args[3], args[4], args[5]}; 381 } 382 383 KernelDim3 LaunchOp::getGridSize() { 384 assert(!body().empty() && "LaunchOp body must not be empty."); 385 auto args = body().getArguments(); 386 return KernelDim3{args[6], args[7], args[8]}; 387 } 388 389 KernelDim3 LaunchOp::getBlockSize() { 390 assert(!body().empty() && "LaunchOp body must not be empty."); 391 auto args = body().getArguments(); 392 return KernelDim3{args[9], args[10], args[11]}; 393 } 394 395 KernelDim3 LaunchOp::getGridSizeOperandValues() { 396 return KernelDim3{getOperand(0), getOperand(1), getOperand(2)}; 397 } 398 399 KernelDim3 LaunchOp::getBlockSizeOperandValues() { 400 return KernelDim3{getOperand(3), getOperand(4), getOperand(5)}; 401 } 402 403 static LogicalResult verify(LaunchOp op) { 404 // Kernel launch takes kNumConfigOperands leading operands for grid/block 405 // sizes and transforms them into kNumConfigRegionAttributes region arguments 406 // for block/thread identifiers and grid/block sizes. 407 if (!op.body().empty()) { 408 if (op.body().getNumArguments() != 409 LaunchOp::kNumConfigOperands + op.getNumOperands()) 410 return op.emitOpError("unexpected number of region arguments"); 411 } 412 413 // Block terminators without successors are expected to exit the kernel region 414 // and must be `gpu.terminator`. 415 for (Block &block : op.body()) { 416 if (block.empty()) 417 continue; 418 if (block.back().getNumSuccessors() != 0) 419 continue; 420 if (!isa<gpu::TerminatorOp>(&block.back())) { 421 return block.back() 422 .emitError() 423 .append("expected '", gpu::TerminatorOp::getOperationName(), 424 "' or a terminator with successors") 425 .attachNote(op.getLoc()) 426 .append("in '", LaunchOp::getOperationName(), "' body region"); 427 } 428 } 429 430 return success(); 431 } 432 433 // Pretty-print the kernel grid/block size assignment as 434 // (%iter-x, %iter-y, %iter-z) in 435 // (%size-x = %ssa-use, %size-y = %ssa-use, %size-z = %ssa-use) 436 // where %size-* and %iter-* will correspond to the body region arguments. 437 static void printSizeAssignment(OpAsmPrinter &p, KernelDim3 size, 438 KernelDim3 operands, KernelDim3 ids) { 439 p << '(' << ids.x << ", " << ids.y << ", " << ids.z << ") in ("; 440 p << size.x << " = " << operands.x << ", "; 441 p << size.y << " = " << operands.y << ", "; 442 p << size.z << " = " << operands.z << ')'; 443 } 444 445 static void printLaunchOp(OpAsmPrinter &p, LaunchOp op) { 446 // Print the launch configuration. 447 p << ' ' << op.getBlocksKeyword(); 448 printSizeAssignment(p, op.getGridSize(), op.getGridSizeOperandValues(), 449 op.getBlockIds()); 450 p << ' ' << op.getThreadsKeyword(); 451 printSizeAssignment(p, op.getBlockSize(), op.getBlockSizeOperandValues(), 452 op.getThreadIds()); 453 454 p.printRegion(op.body(), /*printEntryBlockArgs=*/false); 455 p.printOptionalAttrDict(op->getAttrs()); 456 } 457 458 // Parse the size assignment blocks for blocks and threads. These have the form 459 // (%region_arg, %region_arg, %region_arg) in 460 // (%region_arg = %operand, %region_arg = %operand, %region_arg = %operand) 461 // where %region_arg are percent-identifiers for the region arguments to be 462 // introduced further (SSA defs), and %operand are percent-identifiers for the 463 // SSA value uses. 464 static ParseResult 465 parseSizeAssignment(OpAsmParser &parser, 466 MutableArrayRef<OpAsmParser::OperandType> sizes, 467 MutableArrayRef<OpAsmParser::OperandType> regionSizes, 468 MutableArrayRef<OpAsmParser::OperandType> indices) { 469 assert(indices.size() == 3 && "space for three indices expected"); 470 SmallVector<OpAsmParser::OperandType, 3> args; 471 if (parser.parseRegionArgumentList(args, /*requiredOperandCount=*/3, 472 OpAsmParser::Delimiter::Paren) || 473 parser.parseKeyword("in") || parser.parseLParen()) 474 return failure(); 475 std::move(args.begin(), args.end(), indices.begin()); 476 477 for (int i = 0; i < 3; ++i) { 478 if (i != 0 && parser.parseComma()) 479 return failure(); 480 if (parser.parseRegionArgument(regionSizes[i]) || parser.parseEqual() || 481 parser.parseOperand(sizes[i])) 482 return failure(); 483 } 484 485 return parser.parseRParen(); 486 } 487 488 // Parses a Launch operation. 489 // operation ::= `gpu.launch` `blocks` `(` ssa-id-list `)` `in` ssa-reassignment 490 // `threads` `(` ssa-id-list `)` `in` ssa-reassignment 491 // region attr-dict? 492 // ssa-reassignment ::= `(` ssa-id `=` ssa-use (`,` ssa-id `=` ssa-use)* `)` 493 static ParseResult parseLaunchOp(OpAsmParser &parser, OperationState &result) { 494 // Sizes of the grid and block. 495 SmallVector<OpAsmParser::OperandType, LaunchOp::kNumConfigOperands> sizes( 496 LaunchOp::kNumConfigOperands); 497 MutableArrayRef<OpAsmParser::OperandType> sizesRef(sizes); 498 499 // Actual (data) operands passed to the kernel. 500 SmallVector<OpAsmParser::OperandType, 4> dataOperands; 501 502 // Region arguments to be created. 503 SmallVector<OpAsmParser::OperandType, 16> regionArgs( 504 LaunchOp::kNumConfigRegionAttributes); 505 MutableArrayRef<OpAsmParser::OperandType> regionArgsRef(regionArgs); 506 507 // Parse the size assignment segments: the first segment assigns grid sizes 508 // and defines values for block identifiers; the second segment assigns block 509 // sizes and defines values for thread identifiers. In the region argument 510 // list, identifiers precede sizes, and block-related values precede 511 // thread-related values. 512 if (parser.parseKeyword(LaunchOp::getBlocksKeyword().data()) || 513 parseSizeAssignment(parser, sizesRef.take_front(3), 514 regionArgsRef.slice(6, 3), 515 regionArgsRef.slice(0, 3)) || 516 parser.parseKeyword(LaunchOp::getThreadsKeyword().data()) || 517 parseSizeAssignment(parser, sizesRef.drop_front(3), 518 regionArgsRef.slice(9, 3), 519 regionArgsRef.slice(3, 3)) || 520 parser.resolveOperands(sizes, parser.getBuilder().getIndexType(), 521 result.operands)) 522 return failure(); 523 524 // Introduce the body region and parse it. The region has 525 // kNumConfigRegionAttributes arguments that correspond to 526 // block/thread identifiers and grid/block sizes, all of the `index` type. 527 Type index = parser.getBuilder().getIndexType(); 528 SmallVector<Type, LaunchOp::kNumConfigRegionAttributes> dataTypes( 529 LaunchOp::kNumConfigRegionAttributes, index); 530 Region *body = result.addRegion(); 531 return failure(parser.parseRegion(*body, regionArgs, dataTypes) || 532 parser.parseOptionalAttrDict(result.attributes)); 533 } 534 535 /// Simplify the gpu.launch when the range of a thread or block ID is 536 /// trivially known to be one. 537 struct FoldLaunchArguments : public OpRewritePattern<LaunchOp> { 538 using OpRewritePattern<LaunchOp>::OpRewritePattern; 539 LogicalResult matchAndRewrite(LaunchOp op, 540 PatternRewriter &rewriter) const override { 541 // If the range implies a single value for `id`, replace `id`'s uses by 542 // zero. 543 Value zero; 544 bool simplified = false; 545 auto constPropIdUses = [&](Value id, Value size) { 546 // Check if size is trivially one. 547 if (!matchPattern(size, m_One())) 548 return; 549 if (!simplified) { 550 // Create a zero value the first time. 551 OpBuilder::InsertionGuard guard(rewriter); 552 rewriter.setInsertionPointToStart(&op.body().front()); 553 zero = rewriter.create<ConstantIndexOp>(op.getLoc(), /*value=*/0); 554 } 555 id.replaceAllUsesWith(zero); 556 simplified = true; 557 }; 558 constPropIdUses(op.getBlockIds().x, op.gridSizeX()); 559 constPropIdUses(op.getBlockIds().y, op.gridSizeY()); 560 constPropIdUses(op.getBlockIds().z, op.gridSizeZ()); 561 constPropIdUses(op.getThreadIds().x, op.blockSizeX()); 562 constPropIdUses(op.getThreadIds().y, op.blockSizeY()); 563 constPropIdUses(op.getThreadIds().z, op.blockSizeZ()); 564 565 return success(simplified); 566 } 567 }; 568 569 void LaunchOp::getCanonicalizationPatterns(RewritePatternSet &rewrites, 570 MLIRContext *context) { 571 rewrites.add<FoldLaunchArguments>(context); 572 } 573 574 //===----------------------------------------------------------------------===// 575 // LaunchFuncOp 576 //===----------------------------------------------------------------------===// 577 578 void LaunchFuncOp::build(OpBuilder &builder, OperationState &result, 579 GPUFuncOp kernelFunc, KernelDim3 gridSize, 580 KernelDim3 blockSize, ValueRange kernelOperands) { 581 // Add grid and block sizes as op operands, followed by the data operands. 582 result.addOperands({gridSize.x, gridSize.y, gridSize.z, blockSize.x, 583 blockSize.y, blockSize.z}); 584 result.addOperands(kernelOperands); 585 auto kernelModule = kernelFunc->getParentOfType<GPUModuleOp>(); 586 auto kernelSymbol = 587 SymbolRefAttr::get(kernelModule.getNameAttr(), 588 {SymbolRefAttr::get(kernelFunc.getNameAttr())}); 589 result.addAttribute(getKernelAttrName(), kernelSymbol); 590 SmallVector<int32_t, 8> segmentSizes(8, 1); 591 segmentSizes.front() = 0; // Initially no async dependencies. 592 segmentSizes.back() = static_cast<int32_t>(kernelOperands.size()); 593 result.addAttribute(getOperandSegmentSizeAttr(), 594 builder.getI32VectorAttr(segmentSizes)); 595 } 596 597 unsigned LaunchFuncOp::getNumKernelOperands() { 598 return getNumOperands() - asyncDependencies().size() - kNumConfigOperands; 599 } 600 601 StringAttr LaunchFuncOp::getKernelModuleName() { 602 return kernel().getRootReference(); 603 } 604 605 StringAttr LaunchFuncOp::getKernelName() { return kernel().getLeafReference(); } 606 607 Value LaunchFuncOp::getKernelOperand(unsigned i) { 608 return getOperand(asyncDependencies().size() + kNumConfigOperands + i); 609 } 610 611 KernelDim3 LaunchFuncOp::getGridSizeOperandValues() { 612 auto operands = getOperands().drop_front(asyncDependencies().size()); 613 return KernelDim3{operands[0], operands[1], operands[2]}; 614 } 615 616 KernelDim3 LaunchFuncOp::getBlockSizeOperandValues() { 617 auto operands = getOperands().drop_front(asyncDependencies().size()); 618 return KernelDim3{operands[3], operands[4], operands[5]}; 619 } 620 621 static LogicalResult verify(LaunchFuncOp op) { 622 auto module = op->getParentOfType<ModuleOp>(); 623 if (!module) 624 return op.emitOpError("expected to belong to a module"); 625 626 if (!module->getAttrOfType<UnitAttr>( 627 GPUDialect::getContainerModuleAttrName())) 628 return op.emitOpError( 629 "expected the closest surrounding module to have the '" + 630 GPUDialect::getContainerModuleAttrName() + "' attribute"); 631 632 auto kernelAttr = op->getAttrOfType<SymbolRefAttr>(op.getKernelAttrName()); 633 if (!kernelAttr) 634 return op.emitOpError("symbol reference attribute '" + 635 op.getKernelAttrName() + "' must be specified"); 636 637 return success(); 638 } 639 640 static ParseResult 641 parseLaunchFuncOperands(OpAsmParser &parser, 642 SmallVectorImpl<OpAsmParser::OperandType> &argNames, 643 SmallVectorImpl<Type> &argTypes) { 644 if (parser.parseOptionalKeyword("args")) 645 return success(); 646 SmallVector<NamedAttrList, 4> argAttrs; 647 bool isVariadic = false; 648 return function_like_impl::parseFunctionArgumentList( 649 parser, /*allowAttributes=*/false, 650 /*allowVariadic=*/false, argNames, argTypes, argAttrs, isVariadic); 651 } 652 653 static void printLaunchFuncOperands(OpAsmPrinter &printer, Operation *, 654 OperandRange operands, TypeRange types) { 655 if (operands.empty()) 656 return; 657 printer << "args("; 658 llvm::interleaveComma(llvm::zip(operands, types), printer, 659 [&](const auto &pair) { 660 printer.printOperand(std::get<0>(pair)); 661 printer << " : "; 662 printer.printType(std::get<1>(pair)); 663 }); 664 printer << ")"; 665 } 666 667 //===----------------------------------------------------------------------===// 668 // GPUFuncOp 669 //===----------------------------------------------------------------------===// 670 671 /// Adds a new block argument that corresponds to buffers located in 672 /// workgroup memory. 673 BlockArgument GPUFuncOp::addWorkgroupAttribution(Type type) { 674 auto attrName = getNumWorkgroupAttributionsAttrName(); 675 auto attr = (*this)->getAttrOfType<IntegerAttr>(attrName); 676 (*this)->setAttr(attrName, 677 IntegerAttr::get(attr.getType(), attr.getValue() + 1)); 678 return getBody().insertArgument(getType().getNumInputs() + attr.getInt(), 679 type); 680 } 681 682 /// Adds a new block argument that corresponds to buffers located in 683 /// private memory. 684 BlockArgument GPUFuncOp::addPrivateAttribution(Type type) { 685 // Buffers on the private memory always come after buffers on the workgroup 686 // memory. 687 return getBody().addArgument(type); 688 } 689 690 void GPUFuncOp::build(OpBuilder &builder, OperationState &result, 691 StringRef name, FunctionType type, 692 TypeRange workgroupAttributions, 693 TypeRange privateAttributions, 694 ArrayRef<NamedAttribute> attrs) { 695 result.addAttribute(SymbolTable::getSymbolAttrName(), 696 builder.getStringAttr(name)); 697 result.addAttribute(getTypeAttrName(), TypeAttr::get(type)); 698 result.addAttribute(getNumWorkgroupAttributionsAttrName(), 699 builder.getI64IntegerAttr(workgroupAttributions.size())); 700 result.addAttributes(attrs); 701 Region *body = result.addRegion(); 702 Block *entryBlock = new Block; 703 entryBlock->addArguments(type.getInputs()); 704 entryBlock->addArguments(workgroupAttributions); 705 entryBlock->addArguments(privateAttributions); 706 707 body->getBlocks().push_back(entryBlock); 708 } 709 710 /// Parses a GPU function memory attribution. 711 /// 712 /// memory-attribution ::= (`workgroup` `(` ssa-id-and-type-list `)`)? 713 /// (`private` `(` ssa-id-and-type-list `)`)? 714 /// 715 /// Note that this function parses only one of the two similar parts, with the 716 /// keyword provided as argument. 717 static ParseResult 718 parseAttributions(OpAsmParser &parser, StringRef keyword, 719 SmallVectorImpl<OpAsmParser::OperandType> &args, 720 SmallVectorImpl<Type> &argTypes) { 721 // If we could not parse the keyword, just assume empty list and succeed. 722 if (failed(parser.parseOptionalKeyword(keyword))) 723 return success(); 724 725 if (failed(parser.parseLParen())) 726 return failure(); 727 728 // Early exit for an empty list. 729 if (succeeded(parser.parseOptionalRParen())) 730 return success(); 731 732 do { 733 OpAsmParser::OperandType arg; 734 Type type; 735 736 if (parser.parseRegionArgument(arg) || parser.parseColonType(type)) 737 return failure(); 738 739 args.push_back(arg); 740 argTypes.push_back(type); 741 } while (succeeded(parser.parseOptionalComma())); 742 743 return parser.parseRParen(); 744 } 745 746 /// Parses a GPU function. 747 /// 748 /// <operation> ::= `gpu.func` symbol-ref-id `(` argument-list `)` 749 /// (`->` function-result-list)? memory-attribution `kernel`? 750 /// function-attributes? region 751 static ParseResult parseGPUFuncOp(OpAsmParser &parser, OperationState &result) { 752 SmallVector<OpAsmParser::OperandType, 8> entryArgs; 753 SmallVector<NamedAttrList, 1> argAttrs; 754 SmallVector<NamedAttrList, 1> resultAttrs; 755 SmallVector<Type, 8> argTypes; 756 SmallVector<Type, 4> resultTypes; 757 bool isVariadic; 758 759 // Parse the function name. 760 StringAttr nameAttr; 761 if (parser.parseSymbolName(nameAttr, ::mlir::SymbolTable::getSymbolAttrName(), 762 result.attributes)) 763 return failure(); 764 765 auto signatureLocation = parser.getCurrentLocation(); 766 if (failed(function_like_impl::parseFunctionSignature( 767 parser, /*allowVariadic=*/false, entryArgs, argTypes, argAttrs, 768 isVariadic, resultTypes, resultAttrs))) 769 return failure(); 770 771 if (entryArgs.empty() && !argTypes.empty()) 772 return parser.emitError(signatureLocation) 773 << "gpu.func requires named arguments"; 774 775 // Construct the function type. More types will be added to the region, but 776 // not to the function type. 777 Builder &builder = parser.getBuilder(); 778 auto type = builder.getFunctionType(argTypes, resultTypes); 779 result.addAttribute(GPUFuncOp::getTypeAttrName(), TypeAttr::get(type)); 780 781 // Parse workgroup memory attributions. 782 if (failed(parseAttributions(parser, GPUFuncOp::getWorkgroupKeyword(), 783 entryArgs, argTypes))) 784 return failure(); 785 786 // Store the number of operands we just parsed as the number of workgroup 787 // memory attributions. 788 unsigned numWorkgroupAttrs = argTypes.size() - type.getNumInputs(); 789 result.addAttribute(GPUFuncOp::getNumWorkgroupAttributionsAttrName(), 790 builder.getI64IntegerAttr(numWorkgroupAttrs)); 791 792 // Parse private memory attributions. 793 if (failed(parseAttributions(parser, GPUFuncOp::getPrivateKeyword(), 794 entryArgs, argTypes))) 795 return failure(); 796 797 // Parse the kernel attribute if present. 798 if (succeeded(parser.parseOptionalKeyword(GPUFuncOp::getKernelKeyword()))) 799 result.addAttribute(GPUDialect::getKernelFuncAttrName(), 800 builder.getUnitAttr()); 801 802 // Parse attributes. 803 if (failed(parser.parseOptionalAttrDictWithKeyword(result.attributes))) 804 return failure(); 805 function_like_impl::addArgAndResultAttrs(builder, result, argAttrs, 806 resultAttrs); 807 808 // Parse the region. If no argument names were provided, take all names 809 // (including those of attributions) from the entry block. 810 auto *body = result.addRegion(); 811 return parser.parseRegion(*body, entryArgs, argTypes); 812 } 813 814 static void printAttributions(OpAsmPrinter &p, StringRef keyword, 815 ArrayRef<BlockArgument> values) { 816 if (values.empty()) 817 return; 818 819 p << ' ' << keyword << '('; 820 llvm::interleaveComma( 821 values, p, [&p](BlockArgument v) { p << v << " : " << v.getType(); }); 822 p << ')'; 823 } 824 825 /// Prints a GPU Func op. 826 static void printGPUFuncOp(OpAsmPrinter &p, GPUFuncOp op) { 827 p << ' '; 828 p.printSymbolName(op.getName()); 829 830 FunctionType type = op.getType(); 831 function_like_impl::printFunctionSignature( 832 p, op.getOperation(), type.getInputs(), 833 /*isVariadic=*/false, type.getResults()); 834 835 printAttributions(p, op.getWorkgroupKeyword(), op.getWorkgroupAttributions()); 836 printAttributions(p, op.getPrivateKeyword(), op.getPrivateAttributions()); 837 if (op.isKernel()) 838 p << ' ' << op.getKernelKeyword(); 839 840 function_like_impl::printFunctionAttributes( 841 p, op.getOperation(), type.getNumInputs(), type.getNumResults(), 842 {op.getNumWorkgroupAttributionsAttrName(), 843 GPUDialect::getKernelFuncAttrName()}); 844 p.printRegion(op.getBody(), /*printEntryBlockArgs=*/false); 845 } 846 847 /// Hook for FunctionLike verifier. 848 LogicalResult GPUFuncOp::verifyType() { 849 Type type = getTypeAttr().getValue(); 850 if (!type.isa<FunctionType>()) 851 return emitOpError("requires '" + getTypeAttrName() + 852 "' attribute of function type"); 853 854 if (isKernel() && getType().getNumResults() != 0) 855 return emitOpError() << "expected void return type for kernel function"; 856 857 return success(); 858 } 859 860 static LogicalResult verifyAttributions(Operation *op, 861 ArrayRef<BlockArgument> attributions, 862 unsigned memorySpace) { 863 for (Value v : attributions) { 864 auto type = v.getType().dyn_cast<MemRefType>(); 865 if (!type) 866 return op->emitOpError() << "expected memref type in attribution"; 867 868 if (type.getMemorySpaceAsInt() != memorySpace) { 869 return op->emitOpError() 870 << "expected memory space " << memorySpace << " in attribution"; 871 } 872 } 873 return success(); 874 } 875 876 /// Verifies the body of the function. 877 LogicalResult GPUFuncOp::verifyBody() { 878 unsigned numFuncArguments = getNumArguments(); 879 unsigned numWorkgroupAttributions = getNumWorkgroupAttributions(); 880 unsigned numBlockArguments = front().getNumArguments(); 881 if (numBlockArguments < numFuncArguments + numWorkgroupAttributions) 882 return emitOpError() << "expected at least " 883 << numFuncArguments + numWorkgroupAttributions 884 << " arguments to body region"; 885 886 ArrayRef<Type> funcArgTypes = getType().getInputs(); 887 for (unsigned i = 0; i < numFuncArguments; ++i) { 888 Type blockArgType = front().getArgument(i).getType(); 889 if (funcArgTypes[i] != blockArgType) 890 return emitOpError() << "expected body region argument #" << i 891 << " to be of type " << funcArgTypes[i] << ", got " 892 << blockArgType; 893 } 894 895 if (failed(verifyAttributions(getOperation(), getWorkgroupAttributions(), 896 GPUDialect::getWorkgroupAddressSpace())) || 897 failed(verifyAttributions(getOperation(), getPrivateAttributions(), 898 GPUDialect::getPrivateAddressSpace()))) 899 return failure(); 900 901 return success(); 902 } 903 904 //===----------------------------------------------------------------------===// 905 // ReturnOp 906 //===----------------------------------------------------------------------===// 907 908 static LogicalResult verify(gpu::ReturnOp returnOp) { 909 GPUFuncOp function = returnOp->getParentOfType<GPUFuncOp>(); 910 911 FunctionType funType = function.getType(); 912 913 if (funType.getNumResults() != returnOp.operands().size()) 914 return returnOp.emitOpError() 915 .append("expected ", funType.getNumResults(), " result operands") 916 .attachNote(function.getLoc()) 917 .append("return type declared here"); 918 919 for (auto pair : llvm::enumerate( 920 llvm::zip(function.getType().getResults(), returnOp.operands()))) { 921 Type type; 922 Value operand; 923 std::tie(type, operand) = pair.value(); 924 if (type != operand.getType()) 925 return returnOp.emitOpError() << "unexpected type `" << operand.getType() 926 << "' for operand #" << pair.index(); 927 } 928 return success(); 929 } 930 931 //===----------------------------------------------------------------------===// 932 // GPUModuleOp 933 //===----------------------------------------------------------------------===// 934 935 void GPUModuleOp::build(OpBuilder &builder, OperationState &result, 936 StringRef name) { 937 ensureTerminator(*result.addRegion(), builder, result.location); 938 result.attributes.push_back(builder.getNamedAttr( 939 ::mlir::SymbolTable::getSymbolAttrName(), builder.getStringAttr(name))); 940 } 941 942 static ParseResult parseGPUModuleOp(OpAsmParser &parser, 943 OperationState &result) { 944 StringAttr nameAttr; 945 if (parser.parseSymbolName(nameAttr, SymbolTable::getSymbolAttrName(), 946 result.attributes)) 947 return failure(); 948 949 // If module attributes are present, parse them. 950 if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) 951 return failure(); 952 953 // Parse the module body. 954 auto *body = result.addRegion(); 955 if (parser.parseRegion(*body, None, None)) 956 return failure(); 957 958 // Ensure that this module has a valid terminator. 959 GPUModuleOp::ensureTerminator(*body, parser.getBuilder(), result.location); 960 return success(); 961 } 962 963 static void print(OpAsmPrinter &p, GPUModuleOp op) { 964 p << ' '; 965 p.printSymbolName(op.getName()); 966 p.printOptionalAttrDictWithKeyword(op->getAttrs(), 967 {SymbolTable::getSymbolAttrName()}); 968 p.printRegion(op->getRegion(0), /*printEntryBlockArgs=*/false, 969 /*printBlockTerminators=*/false); 970 } 971 972 //===----------------------------------------------------------------------===// 973 // GPUMemcpyOp 974 //===----------------------------------------------------------------------===// 975 976 static LogicalResult verify(MemcpyOp op) { 977 auto srcType = op.src().getType(); 978 auto dstType = op.dst().getType(); 979 980 if (getElementTypeOrSelf(srcType) != getElementTypeOrSelf(dstType)) 981 return op.emitOpError("arguments have incompatible element type"); 982 983 if (failed(verifyCompatibleShape(srcType, dstType))) 984 return op.emitOpError("arguments have incompatible shape"); 985 986 return success(); 987 } 988 989 static ParseResult parseAsyncDependencies( 990 OpAsmParser &parser, Type &asyncTokenType, 991 SmallVectorImpl<OpAsmParser::OperandType> &asyncDependencies) { 992 auto loc = parser.getCurrentLocation(); 993 if (succeeded(parser.parseOptionalKeyword("async"))) { 994 if (parser.getNumResults() == 0) 995 return parser.emitError(loc, "needs to be named when marked 'async'"); 996 asyncTokenType = parser.getBuilder().getType<AsyncTokenType>(); 997 } 998 return parser.parseOperandList(asyncDependencies, 999 OpAsmParser::Delimiter::OptionalSquare); 1000 } 1001 1002 static void printAsyncDependencies(OpAsmPrinter &printer, Operation *op, 1003 Type asyncTokenType, 1004 OperandRange asyncDependencies) { 1005 if (asyncTokenType) 1006 printer << "async "; 1007 if (asyncDependencies.empty()) 1008 return; 1009 printer << "["; 1010 llvm::interleaveComma(asyncDependencies, printer); 1011 printer << "]"; 1012 } 1013 1014 //===----------------------------------------------------------------------===// 1015 // GPU_SubgroupMmaLoadMatrixOp 1016 //===----------------------------------------------------------------------===// 1017 1018 static LogicalResult verify(SubgroupMmaLoadMatrixOp op) { 1019 auto srcType = op.srcMemref().getType(); 1020 auto resType = op.res().getType(); 1021 auto resMatrixType = resType.cast<gpu::MMAMatrixType>(); 1022 auto operand = resMatrixType.getOperand(); 1023 auto srcMemrefType = srcType.cast<MemRefType>(); 1024 auto srcMemSpace = srcMemrefType.getMemorySpaceAsInt(); 1025 1026 if (!srcMemrefType.getAffineMaps().empty() && 1027 !srcMemrefType.getAffineMaps().front().isIdentity()) 1028 return op.emitError("expected identity layout map for source memref"); 1029 1030 if (srcMemSpace != kGenericMemorySpace && srcMemSpace != kSharedMemorySpace && 1031 srcMemSpace != kGlobalMemorySpace) 1032 return op.emitError( 1033 "source memorySpace kGenericMemorySpace, kSharedMemorySpace or " 1034 "kGlobalMemorySpace only allowed"); 1035 1036 if (!operand.equals("AOp") && !operand.equals("BOp") && 1037 !operand.equals("COp")) 1038 return op.emitError("only AOp, BOp and COp can be loaded"); 1039 1040 return success(); 1041 } 1042 1043 //===----------------------------------------------------------------------===// 1044 // GPU_SubgroupMmaStoreMatrixOp 1045 //===----------------------------------------------------------------------===// 1046 1047 static LogicalResult verify(SubgroupMmaStoreMatrixOp op) { 1048 auto srcType = op.src().getType(); 1049 auto dstType = op.dstMemref().getType(); 1050 auto srcMatrixType = srcType.cast<gpu::MMAMatrixType>(); 1051 auto dstMemrefType = dstType.cast<MemRefType>(); 1052 auto dstMemSpace = dstMemrefType.getMemorySpaceAsInt(); 1053 1054 if (!dstMemrefType.getAffineMaps().empty() && 1055 !dstMemrefType.getAffineMaps().front().isIdentity()) 1056 return op.emitError("expected identity layout map for destination memref"); 1057 1058 if (dstMemSpace != kGenericMemorySpace && dstMemSpace != kSharedMemorySpace && 1059 dstMemSpace != kGlobalMemorySpace) 1060 return op.emitError( 1061 "destination memorySpace of kGenericMemorySpace, " 1062 "kGlobalMemorySpace or kSharedMemorySpace only allowed"); 1063 1064 if (!srcMatrixType.getOperand().equals("COp")) 1065 return op.emitError( 1066 "expected the operand matrix being stored to have 'COp' operand type"); 1067 1068 return success(); 1069 } 1070 1071 //===----------------------------------------------------------------------===// 1072 // GPU_SubgroupMmaComputeOp 1073 //===----------------------------------------------------------------------===// 1074 1075 static LogicalResult verify(SubgroupMmaComputeOp op) { 1076 enum OperandMap { A, B, C }; 1077 SmallVector<MMAMatrixType, 3> opTypes; 1078 1079 auto populateOpInfo = [&opTypes, &op]() { 1080 opTypes.push_back(op.opA().getType().cast<MMAMatrixType>()); 1081 opTypes.push_back(op.opB().getType().cast<MMAMatrixType>()); 1082 opTypes.push_back(op.opC().getType().cast<MMAMatrixType>()); 1083 }; 1084 populateOpInfo(); 1085 1086 if (!opTypes[A].getOperand().equals("AOp") || 1087 !opTypes[B].getOperand().equals("BOp") || 1088 !opTypes[C].getOperand().equals("COp")) 1089 return op.emitError("operands must be in the order AOp, BOp, COp"); 1090 1091 ArrayRef<int64_t> aShape, bShape, cShape; 1092 aShape = opTypes[A].getShape(); 1093 bShape = opTypes[B].getShape(); 1094 cShape = opTypes[C].getShape(); 1095 1096 if (aShape[1] != bShape[0] || aShape[0] != cShape[0] || 1097 bShape[1] != cShape[1]) 1098 return op.emitError("operand shapes do not satisfy matmul constraints"); 1099 1100 return success(); 1101 } 1102 1103 /// This is a common class used for patterns of the form 1104 /// "someop(memrefcast) -> someop". It folds the source of any memref.cast 1105 /// into the root operation directly. 1106 static LogicalResult foldMemRefCast(Operation *op) { 1107 bool folded = false; 1108 for (OpOperand &operand : op->getOpOperands()) { 1109 auto cast = operand.get().getDefiningOp<mlir::memref::CastOp>(); 1110 if (cast) { 1111 operand.set(cast.getOperand()); 1112 folded = true; 1113 } 1114 } 1115 return success(folded); 1116 } 1117 1118 LogicalResult MemcpyOp::fold(ArrayRef<Attribute> operands, 1119 SmallVectorImpl<::mlir::OpFoldResult> &results) { 1120 return foldMemRefCast(*this); 1121 } 1122 1123 LogicalResult MemsetOp::fold(ArrayRef<Attribute> operands, 1124 SmallVectorImpl<::mlir::OpFoldResult> &results) { 1125 return foldMemRefCast(*this); 1126 } 1127 1128 //===----------------------------------------------------------------------===// 1129 // GPU_AllocOp 1130 //===----------------------------------------------------------------------===// 1131 namespace { 1132 1133 /// Folding of memref.dim(gpu.alloc(%size), %idx) -> %size similar to 1134 /// `memref::AllocOp`. 1135 struct SimplifyDimOfAllocOp : public OpRewritePattern<memref::DimOp> { 1136 using OpRewritePattern<memref::DimOp>::OpRewritePattern; 1137 1138 LogicalResult matchAndRewrite(memref::DimOp dimOp, 1139 PatternRewriter &rewriter) const override { 1140 auto index = dimOp.index().getDefiningOp<ConstantIndexOp>(); 1141 if (!index) 1142 return failure(); 1143 1144 auto memrefType = dimOp.source().getType().dyn_cast<MemRefType>(); 1145 if (!memrefType || !memrefType.isDynamicDim(index.getValue())) 1146 return failure(); 1147 1148 auto alloc = dimOp.source().getDefiningOp<AllocOp>(); 1149 if (!alloc) 1150 return failure(); 1151 1152 Value substituteOp = *(alloc.dynamicSizes().begin() + 1153 memrefType.getDynamicDimIndex(index.getValue())); 1154 rewriter.replaceOp(dimOp, substituteOp); 1155 return success(); 1156 } 1157 }; 1158 1159 } // end anonymous namespace. 1160 1161 void AllocOp::getCanonicalizationPatterns(RewritePatternSet &results, 1162 MLIRContext *context) { 1163 results.add<SimplifyDimOfAllocOp>(context); 1164 } 1165 1166 #include "mlir/Dialect/GPU/GPUOpInterfaces.cpp.inc" 1167 1168 #define GET_OP_CLASSES 1169 #include "mlir/Dialect/GPU/GPUOps.cpp.inc" 1170