#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Interfaces/FunctionImplementation.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/StringSaver.h"
#include <cassert>
usingnamespacemlir;
usingnamespacemlir::gpu;
#include "mlir/Dialect/GPU/IR/GPUOpsDialect.cpp.inc"
int64_t GPUBlockMappingAttr::getMappingId() const { … }
bool GPUBlockMappingAttr::isLinearMapping() const { … }
int64_t GPUBlockMappingAttr::getRelativeIndex() const { … }
int64_t GPUWarpgroupMappingAttr::getMappingId() const { … }
bool GPUWarpgroupMappingAttr::isLinearMapping() const { … }
int64_t GPUWarpgroupMappingAttr::getRelativeIndex() const { … }
int64_t GPUWarpMappingAttr::getMappingId() const { … }
bool GPUWarpMappingAttr::isLinearMapping() const { … }
int64_t GPUWarpMappingAttr::getRelativeIndex() const { … }
int64_t GPUThreadMappingAttr::getMappingId() const { … }
bool GPUThreadMappingAttr::isLinearMapping() const { … }
int64_t GPUThreadMappingAttr::getRelativeIndex() const { … }
int64_t GPUMemorySpaceMappingAttr::getMappingId() const { … }
bool GPUMemorySpaceMappingAttr::isLinearMapping() const { … }
int64_t GPUMemorySpaceMappingAttr::getRelativeIndex() const { … }
MMAMatrixType MMAMatrixType::get(ArrayRef<int64_t> shape, Type elementType,
StringRef operand) { … }
MMAMatrixType
MMAMatrixType::getChecked(function_ref<InFlightDiagnostic()> emitError,
ArrayRef<int64_t> shape, Type elementType,
StringRef operand) { … }
unsigned MMAMatrixType::getNumDims() const { … }
ArrayRef<int64_t> MMAMatrixType::getShape() const { … }
Type MMAMatrixType::getElementType() const { … }
StringRef MMAMatrixType::getOperand() const { … }
bool MMAMatrixType::isValidElementType(Type elementType) { … }
LogicalResult
MMAMatrixType::verifyInvariants(function_ref<InFlightDiagnostic()> emitError,
ArrayRef<int64_t> shape, Type elementType,
StringRef operand) { … }
bool GPUDialect::isWorkgroupMemoryAddressSpace(Attribute memorySpace) { … }
bool GPUDialect::hasWorkgroupMemoryAddressSpace(MemRefType type) { … }
bool GPUDialect::isKernel(Operation *op) { … }
namespace {
struct GPUInlinerInterface : public DialectInlinerInterface { … };
}
void GPUDialect::initialize() { … }
static std::string getSparseHandleKeyword(SparseHandleKind kind) { … }
Type GPUDialect::parseType(DialectAsmParser &parser) const { … }
void GPUDialect::printType(Type type, DialectAsmPrinter &os) const { … }
static LogicalResult verifyKnownLaunchSizeAttr(Operation *op,
NamedAttribute attr) { … }
LogicalResult GPUDialect::verifyOperationAttribute(Operation *op,
NamedAttribute attr) { … }
static ParseResult parseAsyncDependencies(
OpAsmParser &parser, Type &asyncTokenType,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &asyncDependencies) { … }
static void printAsyncDependencies(OpAsmPrinter &printer, Operation *op,
Type asyncTokenType,
OperandRange asyncDependencies) { … }
static ParseResult
parseAttributions(OpAsmParser &parser, StringRef keyword,
SmallVectorImpl<OpAsmParser::Argument> &args) { … }
static void printAttributions(OpAsmPrinter &p, StringRef keyword,
ArrayRef<BlockArgument> values) { … }
static LogicalResult verifyAttributions(Operation *op,
ArrayRef<BlockArgument> attributions,
gpu::AddressSpace memorySpace) { … }
static LogicalResult verifyReduceOpAndType(gpu::AllReduceOperation opName,
Type resType) { … }
LogicalResult gpu::AllReduceOp::verifyRegions() { … }
static bool canMakeGroupOpUniform(Operation *op) { … }
OpFoldResult gpu::AllReduceOp::fold(FoldAdaptor ) { … }
static ParseResult parseAllReduceOperation(AsmParser &parser,
AllReduceOperationAttr &attr) { … }
static void printAllReduceOperation(AsmPrinter &printer, Operation *op,
AllReduceOperationAttr attr) { … }
LogicalResult gpu::SubgroupReduceOp::verify() { … }
OpFoldResult gpu::SubgroupReduceOp::fold(FoldAdaptor ) { … }
void gpu::addAsyncDependency(Operation *op, Value token) { … }
void LaunchOp::build(OpBuilder &builder, OperationState &result,
Value gridSizeX, Value gridSizeY, Value gridSizeZ,
Value getBlockSizeX, Value getBlockSizeY,
Value getBlockSizeZ, Value dynamicSharedMemorySize,
Type asyncTokenType, ValueRange asyncDependencies,
TypeRange workgroupAttributions,
TypeRange privateAttributions, Value clusterSizeX,
Value clusterSizeY, Value clusterSizeZ) { … }
KernelDim3 LaunchOp::getBlockIds() { … }
KernelDim3 LaunchOp::getThreadIds() { … }
KernelDim3 LaunchOp::getGridSize() { … }
KernelDim3 LaunchOp::getBlockSize() { … }
std::optional<KernelDim3> LaunchOp::getClusterIds() { … }
std::optional<KernelDim3> LaunchOp::getClusterSize() { … }
KernelDim3 LaunchOp::getGridSizeOperandValues() { … }
KernelDim3 LaunchOp::getBlockSizeOperandValues() { … }
std::optional<KernelDim3> LaunchOp::getClusterSizeOperandValues() { … }
LogicalResult LaunchOp::verify() { … }
LogicalResult LaunchOp::verifyRegions() { … }
static void printSizeAssignment(OpAsmPrinter &p, KernelDim3 size,
KernelDim3 operands, KernelDim3 ids) { … }
void LaunchOp::print(OpAsmPrinter &p) { … }
static ParseResult
parseSizeAssignment(OpAsmParser &parser,
MutableArrayRef<OpAsmParser::UnresolvedOperand> sizes,
MutableArrayRef<OpAsmParser::UnresolvedOperand> regionSizes,
MutableArrayRef<OpAsmParser::UnresolvedOperand> indices) { … }
ParseResult LaunchOp::parse(OpAsmParser &parser, OperationState &result) { … }
struct FoldLaunchArguments : public OpRewritePattern<LaunchOp> { … };
void LaunchOp::getCanonicalizationPatterns(RewritePatternSet &rewrites,
MLIRContext *context) { … }
BlockArgument LaunchOp::addWorkgroupAttribution(Type type, Location loc) { … }
BlockArgument LaunchOp::addPrivateAttribution(Type type, Location loc) { … }
void LaunchFuncOp::build(OpBuilder &builder, OperationState &result,
SymbolRefAttr kernelSymbol, KernelDim3 gridSize,
KernelDim3 getBlockSize, Value dynamicSharedMemorySize,
ValueRange kernelOperands, Type asyncTokenType,
ValueRange asyncDependencies,
std::optional<KernelDim3> clusterSize) { … }
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) { … }
void LaunchFuncOp::build(OpBuilder &builder, OperationState &result,
SymbolRefAttr kernel, KernelDim3 gridSize,
KernelDim3 getBlockSize, Value dynamicSharedMemorySize,
ValueRange kernelOperands, Value asyncObject,
std::optional<KernelDim3> clusterSize) { … }
StringAttr LaunchFuncOp::getKernelModuleName() { … }
StringAttr LaunchFuncOp::getKernelName() { … }
unsigned LaunchFuncOp::getNumKernelOperands() { … }
Value LaunchFuncOp::getKernelOperand(unsigned i) { … }
KernelDim3 LaunchFuncOp::getGridSizeOperandValues() { … }
KernelDim3 LaunchFuncOp::getBlockSizeOperandValues() { … }
KernelDim3 LaunchFuncOp::getClusterSizeOperandValues() { … }
LogicalResult LaunchFuncOp::verify() { … }
static ParseResult
parseLaunchDimType(OpAsmParser &parser, Type &dimTy,
std::optional<OpAsmParser::UnresolvedOperand> clusterValue,
Type &clusterXTy, Type &clusterYTy, Type &clusterZTy) { … }
static void printLaunchDimType(OpAsmPrinter &printer, Operation *op, Type dimTy,
Value clusterValue, Type clusterXTy,
Type clusterYTy, Type clusterZTy) { … }
static ParseResult parseLaunchFuncOperands(
OpAsmParser &parser,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &argNames,
SmallVectorImpl<Type> &argTypes) { … }
static void printLaunchFuncOperands(OpAsmPrinter &printer, Operation *,
OperandRange operands, TypeRange types) { … }
void ShuffleOp::build(OpBuilder &builder, OperationState &result, Value value,
int32_t offset, int32_t width, ShuffleMode mode) { … }
namespace {
LogicalResult eraseRedundantGpuBarrierOps(BarrierOp op,
PatternRewriter &rewriter) { … }
}
void BarrierOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) { … }
BlockArgument GPUFuncOp::addWorkgroupAttribution(Type type, Location loc) { … }
BlockArgument GPUFuncOp::addPrivateAttribution(Type type, Location loc) { … }
void GPUFuncOp::build(OpBuilder &builder, OperationState &result,
StringRef name, FunctionType type,
TypeRange workgroupAttributions,
TypeRange privateAttributions,
ArrayRef<NamedAttribute> attrs) { … }
static ParseResult
parseAttributions(OpAsmParser &parser, StringRef keyword,
SmallVectorImpl<OpAsmParser::Argument> &args,
Attribute &attributionAttrs) { … }
ParseResult GPUFuncOp::parse(OpAsmParser &parser, OperationState &result) { … }
static void printAttributions(OpAsmPrinter &p, StringRef keyword,
ArrayRef<BlockArgument> values,
ArrayAttr attributes) { … }
void GPUFuncOp::print(OpAsmPrinter &p) { … }
static DictionaryAttr getAttributionAttrs(GPUFuncOp op, unsigned index,
StringAttr attrName) { … }
DictionaryAttr GPUFuncOp::getworkgroupAttributionAttrs(unsigned index) { … }
DictionaryAttr GPUFuncOp::getPrivateAttributionAttrs(unsigned index) { … }
static void setAttributionAttrs(GPUFuncOp op, unsigned index,
DictionaryAttr value, StringAttr attrName) { … }
void GPUFuncOp::setworkgroupAttributionAttrs(unsigned index,
DictionaryAttr value) { … }
void GPUFuncOp::setPrivateAttributionAttrs(unsigned int index,
DictionaryAttr value) { … }
static Attribute getAttributionAttr(GPUFuncOp op, unsigned index,
StringAttr name, StringAttr attrsName) { … }
Attribute GPUFuncOp::getWorkgroupAttributionAttr(unsigned index,
StringAttr name) { … }
Attribute GPUFuncOp::getPrivateAttributionAttr(unsigned index,
StringAttr name) { … }
static void setAttributionAttr(GPUFuncOp op, unsigned index, StringAttr name,
Attribute value, StringAttr attrsName) { … }
void GPUFuncOp::setWorkgroupAttributionAttr(unsigned index, StringAttr name,
Attribute value) { … }
void GPUFuncOp::setPrivateAttributionAttr(unsigned index, StringAttr name,
Attribute value) { … }
LogicalResult GPUFuncOp::verifyType() { … }
LogicalResult GPUFuncOp::verifyBody() { … }
LogicalResult gpu::ReturnOp::verify() { … }
void GPUModuleOp::build(OpBuilder &builder, OperationState &result,
StringRef name, ArrayAttr targets,
Attribute offloadingHandler) { … }
void GPUModuleOp::build(OpBuilder &builder, OperationState &result,
StringRef name, ArrayRef<Attribute> targets,
Attribute offloadingHandler) { … }
bool GPUModuleOp::hasTarget(Attribute target) { … }
void GPUModuleOp::setTargets(ArrayRef<TargetAttrInterface> targets) { … }
void BinaryOp::build(OpBuilder &builder, OperationState &result, StringRef name,
Attribute offloadingHandler, ArrayAttr objects) { … }
void BinaryOp::build(OpBuilder &builder, OperationState &result, StringRef name,
Attribute offloadingHandler, ArrayRef<Attribute> objects) { … }
static ParseResult parseOffloadingHandler(OpAsmParser &parser,
Attribute &offloadingHandler) { … }
static void printOffloadingHandler(OpAsmPrinter &printer, Operation *op,
Attribute offloadingHandler) { … }
LogicalResult MemcpyOp::verify() { … }
namespace {
struct EraseTrivialCopyOp : public OpRewritePattern<MemcpyOp> { … };
}
void MemcpyOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) { … }
LogicalResult SubgroupMmaLoadMatrixOp::verify() { … }
LogicalResult SubgroupMmaStoreMatrixOp::verify() { … }
LogicalResult SubgroupMmaComputeOp::verify() { … }
LogicalResult MemcpyOp::fold(FoldAdaptor adaptor,
SmallVectorImpl<::mlir::OpFoldResult> &results) { … }
LogicalResult MemsetOp::fold(FoldAdaptor adaptor,
SmallVectorImpl<::mlir::OpFoldResult> &results) { … }
namespace {
struct EraseRedundantGpuWaitOpPairs : public OpRewritePattern<WaitOp> { … };
struct SimplifyGpuWaitOp : public OpRewritePattern<WaitOp> { … };
}
void WaitOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) { … }
LogicalResult AllocOp::verify() { … }
namespace {
struct SimplifyDimOfAllocOp : public OpRewritePattern<memref::DimOp> { … };
}
void AllocOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) { … }
LogicalResult ObjectAttr::verify(function_ref<InFlightDiagnostic()> emitError,
Attribute target, CompilationTarget format,
StringAttr object, DictionaryAttr properties,
KernelTableAttr kernels) { … }
namespace {
LogicalResult parseObject(AsmParser &odsParser, CompilationTarget &format,
StringAttr &object) { … }
void printObject(AsmPrinter &odsParser, CompilationTarget format,
StringAttr object) { … }
}
LogicalResult
gpu::SelectObjectAttr::verify(function_ref<InFlightDiagnostic()> emitError,
Attribute target) { … }
LogicalResult gpu::DynamicSharedMemoryOp::verify() { … }
KernelMetadataAttr KernelMetadataAttr::get(FunctionOpInterface kernel,
DictionaryAttr metadata) { … }
KernelMetadataAttr
KernelMetadataAttr::getChecked(function_ref<InFlightDiagnostic()> emitError,
FunctionOpInterface kernel,
DictionaryAttr metadata) { … }
KernelMetadataAttr
KernelMetadataAttr::appendMetadata(ArrayRef<NamedAttribute> attrs) const { … }
LogicalResult
KernelMetadataAttr::verify(function_ref<InFlightDiagnostic()> emitError,
StringAttr name, Type functionType,
ArrayAttr argAttrs, DictionaryAttr metadata) { … }
KernelTableAttr KernelTableAttr::get(MLIRContext *context,
ArrayRef<KernelMetadataAttr> kernels,
bool isSorted) { … }
KernelTableAttr KernelTableAttr::getChecked(
function_ref<InFlightDiagnostic()> emitError, MLIRContext *context,
ArrayRef<KernelMetadataAttr> kernels, bool isSorted) { … }
LogicalResult
KernelTableAttr::verify(function_ref<InFlightDiagnostic()> emitError,
ArrayRef<KernelMetadataAttr> kernels) { … }
KernelMetadataAttr KernelTableAttr::lookup(StringRef key) const { … }
KernelMetadataAttr KernelTableAttr::lookup(StringAttr key) const { … }
TargetOptions::TargetOptions(
StringRef toolkitPath, ArrayRef<std::string> linkFiles,
StringRef cmdOptions, CompilationTarget compilationTarget,
function_ref<SymbolTable *()> getSymbolTableCallback)
: … { … }
TargetOptions::TargetOptions(
TypeID typeID, StringRef toolkitPath, ArrayRef<std::string> linkFiles,
StringRef cmdOptions, CompilationTarget compilationTarget,
function_ref<SymbolTable *()> getSymbolTableCallback)
: … { … }
TypeID TargetOptions::getTypeID() const { … }
StringRef TargetOptions::getToolkitPath() const { … }
ArrayRef<std::string> TargetOptions::getLinkFiles() const { … }
StringRef TargetOptions::getCmdOptions() const { … }
SymbolTable *TargetOptions::getSymbolTable() const { … }
CompilationTarget TargetOptions::getCompilationTarget() const { … }
CompilationTarget TargetOptions::getDefaultCompilationTarget() { … }
std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>>
TargetOptions::tokenizeCmdOptions() const { … }
MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::gpu::TargetOptions)
#include "mlir/Dialect/GPU/IR/GPUOpInterfaces.cpp.inc"
#include "mlir/Dialect/GPU/IR/GPUOpsEnums.cpp.inc"
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/GPU/IR/GPUOpsAttributes.cpp.inc"
#define GET_OP_CLASSES
#include "mlir/Dialect/GPU/IR/GPUOps.cpp.inc"
#include "mlir/Dialect/GPU/IR/CompilationAttrInterfaces.cpp.inc"