MLIR 24.0.0git
GPUTransformOps.cpp File Reference
#include "mlir/Dialect/GPU/TransformOps/GPUTransformOps.h"
#include "mlir/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.h"
#include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
#include "mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h"
#include "mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Dialect/AMDGPU/IR/AMDGPUDialect.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/GPU/TransformOps/Utils.h"
#include "mlir/Dialect/GPU/Transforms/Passes.h"
#include "mlir/Dialect/GPU/Transforms/ROCDL/Passes.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/IR/DeviceMappingInterface.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/Transform/IR/TransformDialect.h"
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/Dialect/Vector/Transforms/VectorTransforms.h"
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/Visitors.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/DebugLog.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/InterleavedRange.h"
#include "llvm/Support/LogicalResult.h"
#include <optional>
#include <type_traits>
#include "mlir/Dialect/GPU/TransformOps/GPUTransformOps.cpp.inc"

Go to the source code of this file.

Classes

struct  ForallRewriteResult
 Struct to return the result of the rewrite of a forall operation. More...

Macros

#define DEBUG_TYPE   "gpu-transforms"
#define GET_OP_LIST
#define MLIR_IR_BUILDERS_H
#define MLIR_IR_OPDEFINITION_H
#define MLIR_IR_DIALECT_H
#define MLIR_IR_DIALECTREGISTRY_H
#define MLIR_IR_MLIRCONTEXT_H
#define MLIR_SUPPORT_LLVM_H
#define MLIR_SUPPORT_TYPEID_H
#define MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)
#define MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)
#define MLIR_DECLARE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME)
#define MLIR_DEFINE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME)
#define MLIR_USE_FALLBACK_TYPE_IDS   false
#define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME)
#define MLIR_DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME)
#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME)
#define MLIR_IR_OPERATIONSUPPORT_H
#define MLIR_IR_ATTRIBUTES_H
#define MLIR_IR_ATTRIBUTESUPPORT_H
#define MLIR_IR_STORAGEUNIQUERSUPPORT_H
#define MLIR_IR_ATTRTYPESUBELEMENTS_H
#define MLIR_IR_VISITORS_H
#define MLIR_SUPPORT_WALKRESULT_H
#define MLIR_SUPPORT_CYCLICREPLACERCACHE_H
#define MLIR_SUPPORT_INTERFACESUPPORT_H
#define MLIR_SUPPORT_STORAGEUNIQUER_H
#define MLIR_IR_TYPES_H
#define MLIR_IR_TYPESUPPORT_H
#define MLIR_IR_BLOCKSUPPORT_H
#define MLIR_IR_VALUE_H
#define MLIR_IR_USEDEFLISTS_H
#define MLIR_IR_LOCATION_H
#define GET_ATTRDEF_CLASSES
#define MLIR_IR_BUILTINATTRIBUTES_H
#define MLIR_IR_BUILTINATTRIBUTEINTERFACES_H
#define MLIR_IR_AFFINEMAP_H
#define MLIR_IR_AFFINEEXPR_H
#define MLIR_IR_BUILTINTYPEINTERFACES_H
#define MLIR_IR_OPASMSUPPORT_H_
#define MLIR_IR_BLOCK_H
#define MLIR_SUPPORT_COMPLEX_H
#define GET_ATTRDEF_CLASSES
#define MLIR_IR_DIAGNOSTICS_H
#define MLIR_IR_TYPERANGE_H
#define MLIR_IR_VALUERANGE_H
#define MLIR_IR_ODSSUPPORT_H
#define MLIR_IR_OPERATION_H
#define MLIR_IR_REGION_H
#define MLIR_IR_BUILTINTYPES_H
#define MLIR_SUPPORT_ADTEXTRAS_H
#define GET_TYPEDEF_CLASSES
#define MLIR_IR_QuantStorageTypeInterface_H
#define MLIR_IR_OPIMPLEMENTATION_H
#define MLIR_IR_DIALECTINTERFACE_H
#define GET_OP_CLASSES

Functions

static DiagnosedSilenceableFailure definiteFailureHelper (std::optional< TransformOpInterface > transformOp, Operation *target, const Twine &message)
template<typename MappingKindType>
static DiagnosedSilenceableFailure checkMappingAttributeTypes (std::optional< TransformOpInterface > transformOp, scf::ForallOp forallOp)
 Check if given mapping attributes are one of the desired attributes.
template<typename MappingKindType>
static DiagnosedSilenceableFailure verifyGpuMapping (std::optional< TransformOpInterface > transformOp, scf::ForallOp forallOp)
template<typename OpTy, typename OperationOrBlock>
static void replaceUnitMappingIdsHelper (RewriterBase &rewriter, Location loc, OperationOrBlock *parent, Value replacement, ArrayRef< int64_t > availableMappingSizes)
 Helper to replace ids of dimensions known to be 1 by 0 to simplify the IR.
static DiagnosedSilenceableFailure rewriteOneForallCommonImpl (RewriterBase &rewriter, std::optional< TransformOpInterface > transformOp, scf::ForallOp forallOp, ArrayRef< int64_t > availableMappingSizes, ForallRewriteResult &result, const GpuIdBuilder &gpuIdBuilder)
static DiagnosedSilenceableFailure checkMappingSpec (std::optional< TransformOpInterface > transformOp, scf::ForallOp forallOp, ArrayRef< int64_t > numParallelIterations, ArrayRef< int64_t > blockOrGridSizes, int factor, bool useLinearMapping=false)
static DiagnosedSilenceableFailure getThreadIdBuilder (std::optional< TransformOpInterface > transformOp, scf::ForallOp forallOp, ArrayRef< int64_t > blockSizes, int64_t warpSize, GpuIdBuilder &gpuIdBuilder)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "gpu-transforms"

Definition at line 54 of file GPUTransformOps.cpp.

◆ GET_ATTRDEF_CLASSES [1/2]

#define GET_ATTRDEF_CLASSES

◆ GET_ATTRDEF_CLASSES [2/2]

#define GET_ATTRDEF_CLASSES

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 852 of file GPUTransformOps.cpp.

◆ GET_OP_LIST

#define GET_OP_LIST

◆ GET_TYPEDEF_CLASSES

#define GET_TYPEDEF_CLASSES

◆ MLIR_DECLARE_EXPLICIT_FALLBACK_TYPE_ID

#define MLIR_DECLARE_EXPLICIT_FALLBACK_TYPE_ID ( CLASS_NAME)
Value:
namespace mlir { \
namespace detail { \
template <> \
class TypeIDResolver<CLASS_NAME> : public FallbackTypeIDResolver { \
public: \
static TypeID resolveTypeID() { \
static_assert(is_fully_resolved<CLASS_NAME>(), \
"TypeID::get<> requires the complete definition of `T`"); \
static TypeID id = \
registerImplicitTypeID(llvm::getTypeName<CLASS_NAME>()); \
return id; \
} \
}; \
} /* namespace detail */ \
} /* namespace mlir */
This class provides an efficient unique identifier for a specific C++ type.
Definition TypeID.h:107
AttrTypeReplacer.
Include the generated interface declarations.

◆ MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID

#define MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID ( CLASS_NAME)
Value:
namespace mlir { \
namespace detail { \
template <> \
class TypeIDResolver<CLASS_NAME> { \
public: \
static TypeID resolveTypeID() { return id; } \
\
private: \
static SelfOwningTypeID id; \
}; \
} /* namespace detail */ \
} /* namespace mlir */
Defines a TypeID for each instance of this class by using a pointer to the instance.
Definition TypeID.h:369

◆ MLIR_DECLARE_EXPLICIT_TYPE_ID

#define MLIR_DECLARE_EXPLICIT_TYPE_ID ( CLASS_NAME)
Value:
#define MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)
Definition TypeID.h:262

◆ MLIR_DEFINE_EXPLICIT_FALLBACK_TYPE_ID

#define MLIR_DEFINE_EXPLICIT_FALLBACK_TYPE_ID ( CLASS_NAME)

◆ MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID

#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID ( CLASS_NAME)
Value:
static ::mlir::TypeID resolveTypeID() { \
static ::mlir::SelfOwningTypeID id; \
return id; \
} \
static_assert( \
CLASS_NAME>::value, \
"`MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID` must be placed in a " \
"public section of `" #CLASS_NAME "`");
llvm::is_detected< has_resolve_typeid_trait, T > has_resolve_typeid
Definition TypeID.h:224

◆ MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID

#define MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID ( CLASS_NAME)
Value:
namespace mlir { \
namespace detail { \
SelfOwningTypeID TypeIDResolver<CLASS_NAME>::id = {}; \
} /* namespace detail */ \
} /* namespace mlir */

◆ MLIR_DEFINE_EXPLICIT_TYPE_ID

#define MLIR_DEFINE_EXPLICIT_TYPE_ID ( CLASS_NAME)
Value:
#define MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)
Definition TypeID.h:276

◆ MLIR_IR_AFFINEEXPR_H

#define MLIR_IR_AFFINEEXPR_H

◆ MLIR_IR_AFFINEMAP_H

#define MLIR_IR_AFFINEMAP_H

◆ MLIR_IR_ATTRIBUTES_H

#define MLIR_IR_ATTRIBUTES_H

◆ MLIR_IR_ATTRIBUTESUPPORT_H

#define MLIR_IR_ATTRIBUTESUPPORT_H

◆ MLIR_IR_ATTRTYPESUBELEMENTS_H

#define MLIR_IR_ATTRTYPESUBELEMENTS_H

◆ MLIR_IR_BLOCK_H

#define MLIR_IR_BLOCK_H

◆ MLIR_IR_BLOCKSUPPORT_H

#define MLIR_IR_BLOCKSUPPORT_H

◆ MLIR_IR_BUILDERS_H

#define MLIR_IR_BUILDERS_H

◆ MLIR_IR_BUILTINATTRIBUTEINTERFACES_H

#define MLIR_IR_BUILTINATTRIBUTEINTERFACES_H

◆ MLIR_IR_BUILTINATTRIBUTES_H

#define MLIR_IR_BUILTINATTRIBUTES_H

◆ MLIR_IR_BUILTINTYPEINTERFACES_H

#define MLIR_IR_BUILTINTYPEINTERFACES_H

◆ MLIR_IR_BUILTINTYPES_H

#define MLIR_IR_BUILTINTYPES_H

◆ MLIR_IR_DIAGNOSTICS_H

#define MLIR_IR_DIAGNOSTICS_H

◆ MLIR_IR_DIALECT_H

#define MLIR_IR_DIALECT_H

◆ MLIR_IR_DIALECTINTERFACE_H

#define MLIR_IR_DIALECTINTERFACE_H

◆ MLIR_IR_DIALECTREGISTRY_H

#define MLIR_IR_DIALECTREGISTRY_H

◆ MLIR_IR_LOCATION_H

#define MLIR_IR_LOCATION_H

◆ MLIR_IR_MLIRCONTEXT_H

#define MLIR_IR_MLIRCONTEXT_H

◆ MLIR_IR_ODSSUPPORT_H

#define MLIR_IR_ODSSUPPORT_H

◆ MLIR_IR_OPASMSUPPORT_H_

#define MLIR_IR_OPASMSUPPORT_H_

◆ MLIR_IR_OPDEFINITION_H

#define MLIR_IR_OPDEFINITION_H

◆ MLIR_IR_OPERATION_H

#define MLIR_IR_OPERATION_H

◆ MLIR_IR_OPERATIONSUPPORT_H

#define MLIR_IR_OPERATIONSUPPORT_H

◆ MLIR_IR_OPIMPLEMENTATION_H

#define MLIR_IR_OPIMPLEMENTATION_H

◆ MLIR_IR_QuantStorageTypeInterface_H

#define MLIR_IR_QuantStorageTypeInterface_H

◆ MLIR_IR_REGION_H

#define MLIR_IR_REGION_H

◆ MLIR_IR_STORAGEUNIQUERSUPPORT_H

#define MLIR_IR_STORAGEUNIQUERSUPPORT_H

◆ MLIR_IR_TYPERANGE_H

#define MLIR_IR_TYPERANGE_H

◆ MLIR_IR_TYPES_H

#define MLIR_IR_TYPES_H

◆ MLIR_IR_TYPESUPPORT_H

#define MLIR_IR_TYPESUPPORT_H

◆ MLIR_IR_USEDEFLISTS_H

#define MLIR_IR_USEDEFLISTS_H

◆ MLIR_IR_VALUE_H

#define MLIR_IR_VALUE_H

◆ MLIR_IR_VALUERANGE_H

#define MLIR_IR_VALUERANGE_H

◆ MLIR_IR_VISITORS_H

#define MLIR_IR_VISITORS_H

◆ MLIR_SUPPORT_ADTEXTRAS_H

#define MLIR_SUPPORT_ADTEXTRAS_H

◆ MLIR_SUPPORT_COMPLEX_H

#define MLIR_SUPPORT_COMPLEX_H

◆ MLIR_SUPPORT_CYCLICREPLACERCACHE_H

#define MLIR_SUPPORT_CYCLICREPLACERCACHE_H

◆ MLIR_SUPPORT_INTERFACESUPPORT_H

#define MLIR_SUPPORT_INTERFACESUPPORT_H

◆ MLIR_SUPPORT_LLVM_H

#define MLIR_SUPPORT_LLVM_H

◆ MLIR_SUPPORT_STORAGEUNIQUER_H

#define MLIR_SUPPORT_STORAGEUNIQUER_H

◆ MLIR_SUPPORT_TYPEID_H

#define MLIR_SUPPORT_TYPEID_H

◆ MLIR_SUPPORT_WALKRESULT_H

#define MLIR_SUPPORT_WALKRESULT_H

◆ MLIR_USE_FALLBACK_TYPE_IDS

#define MLIR_USE_FALLBACK_TYPE_IDS   false

Function Documentation

◆ checkMappingAttributeTypes()

template<typename MappingKindType>
DiagnosedSilenceableFailure checkMappingAttributeTypes ( std::optional< TransformOpInterface > transformOp,
scf::ForallOp forallOp )
static

Check if given mapping attributes are one of the desired attributes.

Definition at line 191 of file GPUTransformOps.cpp.

References definiteFailureHelper(), and mlir::DiagnosedSilenceableFailure::success().

Referenced by verifyGpuMapping().

◆ checkMappingSpec()

DiagnosedSilenceableFailure checkMappingSpec ( std::optional< TransformOpInterface > transformOp,
scf::ForallOp forallOp,
ArrayRef< int64_t > numParallelIterations,
ArrayRef< int64_t > blockOrGridSizes,
int factor,
bool useLinearMapping = false )
static

◆ definiteFailureHelper()

DiagnosedSilenceableFailure definiteFailureHelper ( std::optional< TransformOpInterface > transformOp,
Operation * target,
const Twine & message )
static

◆ getThreadIdBuilder()

DiagnosedSilenceableFailure getThreadIdBuilder ( std::optional< TransformOpInterface > transformOp,
scf::ForallOp forallOp,
ArrayRef< int64_t > blockSizes,
int64_t warpSize,
GpuIdBuilder & gpuIdBuilder )
static

◆ replaceUnitMappingIdsHelper()

template<typename OpTy, typename OperationOrBlock>
void replaceUnitMappingIdsHelper ( RewriterBase & rewriter,
Location loc,
OperationOrBlock * parent,
Value replacement,
ArrayRef< int64_t > availableMappingSizes )
static

Helper to replace ids of dimensions known to be 1 by 0 to simplify the IR.

Definition at line 315 of file GPUTransformOps.cpp.

References mlir::RewriterBase::replaceAllUsesWith(), and replacement().

Referenced by mlir::transform::gpu::mapForallToBlocksImpl(), and mlir::transform::gpu::mapNestedForallToThreadsImpl().

◆ rewriteOneForallCommonImpl()

◆ verifyGpuMapping()

template<typename MappingKindType>
DiagnosedSilenceableFailure verifyGpuMapping ( std::optional< TransformOpInterface > transformOp,
scf::ForallOp forallOp )
static