MLIR
22.0.0git
|
Namespaces | |
targetinfo | |
HW dependent constants. | |
Classes | |
struct | UnrollOptions |
Options to control the XeGPU unrolling. More... | |
struct | FoldConvertLayoutOp |
Functions | |
void | populateXeGPUFoldAliasOpsPatterns (RewritePatternSet &patterns) |
Appends patterns for folding aliasing ops into XeGPU ops into patterns . More... | |
void | populateXeGPUSubgroupDistributePatterns (RewritePatternSet &patterns) |
Appends patterns for XeGPU SIMT distribution into patterns . More... | |
void | populateXeGPUWgToSgDistributePatterns (RewritePatternSet &patterns) |
void | populateXeGPUUnrollPatterns (RewritePatternSet &patterns, const UnrollOptions &options) |
Collect a set of patterns to unroll xegpu operations to a smaller shapes. More... | |
SmallVector< Value > | flattenValues (ArrayRef< ValueRange > values) |
Flatten a set of ValueRange into a single SmallVector<Value> More... | |
FailureOr< VectorType > | getDistributedVectorType (xegpu::TensorDescType tdescTy) |
If tensor descriptor has a layout attribute it is used in SIMT mode. More... | |
FailureOr< VectorType > | getDistributedVectorType (VectorType originalType, LayoutAttr layout) |
Helper to get the distributed vector type for a given vector type according to a given LayoutAttr. More... | |
std::string | getLayoutName (const OpOperand &operand) |
Return the attribute name for the OpOperand to attach DistributeLayoutAttr. More... | |
std::string | getLayoutName (const OpResult result) |
Return the attribute name for the OpResult to attach DistributeLayoutAttr. More... | |
DistributeLayoutAttr | getDistributeLayoutAttr (const Value value) |
Retrieves the DistributeLayoutAttr associated with a given Value. More... | |
template<typename AttrTy > | |
AttrTy | getDistributeLayoutAttrOfType (const Value value) |
DistributeLayoutAttr | getDistributeLayoutAttr (const OpOperand &opr) |
Retrieves the DistributeLayoutAttr associated with a given OpOperand. More... | |
template<typename AttrTy > | |
AttrTy | getDistributeLayoutAttrOfType (const OpOperand &opr) |
template<typename T , typename = std::enable_if_t<std::is_same_v<T, OpOperand> || std::is_same_v<T, OpResult>>> | |
void | removeLayoutAttr (const T &operandOrResult) |
Removes the LayoutAttr for a given OpOperand or OpResult if it exists. More... | |
void | removeLayoutAttrs (Operation *op) |
Removes the DistributeLayoutAttr for each OpOperand and OpResult of the given operation if they exist. More... | |
template<typename T , typename = std::enable_if_t<std::is_same_v<T, OpOperand> || std::is_same_v<T, OpResult>>> | |
void | setDistributeLayoutAttr (const T &operandOrResult, const DistributeLayoutAttr layout) |
Sets the DistributeLayoutAttr for a given OpOperand or OpResult by attaching it to the owner's dictionary attributes. More... | |
void | setDistributeLayoutAttrs (Operation *op, function_ref< DistributeLayoutAttr(Value)> getLayoutImpl) |
Set the DistributeLayoutAttr for each OpOperand and OpResult of the given operation. More... | |
SmallVector< Value > | extractVectorsWithShapeFromValue (OpBuilder &builder, Location loc, Value value, ArrayRef< int64_t > shape) |
Extract a set of small vectors from a value with a given shape using vector.extract_stride_slice. More... | |
Value | createVectorWithShapeFromValues (OpBuilder &builder, Location loc, ValueRange values, ArrayRef< int64_t > shape) |
Create a vector of shape from a set of values using vector.insert_stride_slice. More... | |
void | doSCFStructuralTypeConversionWithTensorType (Operation *op, TypeConverter converter) |
Do type conversion for SCF structural ops, e.g., scf.for using SCF structure type convertion patterns. More... | |
std::optional< std::string > | getChipStr (Operation *op) |
Retrieves the chip string from the XeVM target attribute of the parent GPU module operation. More... | |
SmallVector< OpFoldResult > | addWithRightAligned (OpBuilder &builder, Location loc, ArrayRef< OpFoldResult > lhs, ArrayRef< OpFoldResult > rhs) |
Generates element-wise addition ops of two arrays with automatic alignment. More... | |
static SmallVector< SmallVector< Value > > | genOffsetsComputingInsts (OpBuilder &builder, Location loc, SmallVector< Value > sgId, ArrayRef< int64_t > sgLayout, ArrayRef< int64_t > sizePerSg, ArrayRef< int64_t > sizePerWg) |
Generates instructions to compute offsets for a subgroup identified by its multidimensional indices (sgId), using the specified subgroup layout (sgLayout), subgroup data dimensions (sizePerSg), and the overall data dimensions (sizePerWg). More... | |
bool | isSharedMemory (const MemRefType &memrefTy) |
template<typename T > | |
static std::string | makeString (T array, bool breakline=false) |
static SmallVector< int64_t > | getShapeOf (Type type) |
static bool | isReadHintOrNone (const CachePolicyAttr &attr) |
static bool | isWriteHintOrNone (const CachePolicyAttr &attr) |
static LogicalResult | isValidGatherScatterParams (Type maskTy, VectorType valueTy, TensorDescType tdescTy, function_ref< InFlightDiagnostic()> emitError) |
static LogicalResult | isValidGatherScatterBufferParams (Type offsetsTy, Type maskTy, VectorType valueTy, int64_t chunkSize, function_ref< InFlightDiagnostic()> emitError) |
ParseResult | parseOptionalDynamicIndexList (OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &values, DenseI64ArrayAttr &integers, SmallVectorImpl< Type > *valueTypes=nullptr, AsmParser::Delimiter delimiter=AsmParser::Delimiter::Square) |
void | printOptionalDynamicIndexList (OpAsmPrinter &printer, Operation *op, OperandRange values, DenseI64ArrayAttr integers) |
SmallVector< OpFoldResult > mlir::xegpu::addWithRightAligned | ( | OpBuilder & | builder, |
Location | loc, | ||
ArrayRef< OpFoldResult > | lhs, | ||
ArrayRef< OpFoldResult > | rhs | ||
) |
Generates element-wise addition ops of two arrays with automatic alignment.
When the input arrays have different sizes, the shorter array is right-aligned with the longer array, and the unmatched leading elements from the longer array are preserved unchanged. This is commonly used for offset computation where higher-dimensional offsets need to be added to lower-dimensional adjustments.
Example: lhs = [l1, l2, l3], rhs = [r1, r2] Result: [11, l2+r1, l3+r2]
Definition at line 443 of file XeGPUUtils.cpp.
References mlir::OpBuilder::createOrFold(), and mlir::getValueOrCreateConstantIndexOp().
Value mlir::xegpu::createVectorWithShapeFromValues | ( | OpBuilder & | builder, |
Location | loc, | ||
ValueRange | values, | ||
ArrayRef< int64_t > | shape | ||
) |
Create a vector of shape from a set of values using vector.insert_stride_slice.
Definition at line 242 of file XeGPUUtils.cpp.
References mlir::get(), mlir::DenseElementsAttr::get(), mlir::getType(), mlir::ValueRange::getTypes(), and mlir::Builder::getZeroAttr().
void mlir::xegpu::doSCFStructuralTypeConversionWithTensorType | ( | Operation * | op, |
TypeConverter | converter | ||
) |
Do type conversion for SCF structural ops, e.g., scf.for using SCF structure type convertion patterns.
Since VectorType cannot carry the layout attribute, which is needed to guide the type conversion for XeGPU, they are first converted into RankedTensorType, where the layout attribute can be attached. And then upstream SCF structural type conversion patterns are applied with the provided converter. TODO: This is a temporary solution. We should refactor it when context-aware type conversion is available.
Definition at line 267 of file XeGPUUtils.cpp.
References mlir::TypeConverter::addConversion(), mlir::ConversionTarget::addDynamicallyLegalOp(), mlir::ConversionTarget::addLegalOp(), mlir::TypeConverter::addSourceMaterialization(), mlir::TypeConverter::addTargetMaterialization(), mlir::WalkResult::advance(), mlir::applyPartialConversion(), flattenValues(), mlir::get(), mlir::Operation::getContext(), getDistributeLayoutAttr(), mlir::Operation::getOperandTypes(), mlir::Operation::getOpResults(), mlir::Operation::getParentOp(), mlir::Operation::getResultTypes(), mlir::Value::getType(), mlir::Value::getUses(), mlir::patterns, mlir::scf::populateSCFStructuralTypeConversionsAndLegality(), mlir::ConversionPatternRewriter::replaceOp(), mlir::ConversionPatternRewriter::replaceOpWithMultiple(), mlir::Value::setType(), mlir::WalkResult::skip(), and mlir::Operation::walk().
SmallVector< Value > mlir::xegpu::extractVectorsWithShapeFromValue | ( | OpBuilder & | builder, |
Location | loc, | ||
Value | value, | ||
ArrayRef< int64_t > | shape | ||
) |
Extract a set of small vectors from a value with a given shape using vector.extract_stride_slice.
Definition at line 222 of file XeGPUUtils.cpp.
References mlir::computeShapeRatio(), and mlir::Value::getType().
SmallVector< Value > mlir::xegpu::flattenValues | ( | ArrayRef< ValueRange > | values | ) |
Flatten a set of ValueRange into a single SmallVector<Value>
convert ArrayRef<ValueRange> into SmallVector<Value>
Definition at line 32 of file XeGPUUtils.cpp.
Referenced by doSCFStructuralTypeConversionWithTensorType().
|
static |
Generates instructions to compute offsets for a subgroup identified by its multidimensional indices (sgId), using the specified subgroup layout (sgLayout), subgroup data dimensions (sizePerSg), and the overall data dimensions (sizePerWg).
Definition at line 45 of file XeGPUDialect.cpp.
References mlir::computeElementwiseMul(), mlir::arith::ConstantIndexOp::create(), mlir::OpBuilder::createOrFold(), and min().
std::optional< std::string > mlir::xegpu::getChipStr | ( | Operation * | op | ) |
Retrieves the chip string from the XeVM target attribute of the parent GPU module operation.
Returns the chip identifier if found, or nullopt if no GPU module parent or XeVM target attribute exists.
Definition at line 414 of file XeGPUUtils.cpp.
References mlir::Operation::getParentOfType().
FailureOr<VectorType> mlir::xegpu::getDistributedVectorType | ( | VectorType | originalType, |
LayoutAttr | layout | ||
) |
Helper to get the distributed vector type for a given vector type according to a given LayoutAttr.
FailureOr< VectorType > mlir::xegpu::getDistributedVectorType | ( | xegpu::TensorDescType | tdescTy | ) |
If tensor descriptor has a layout attribute it is used in SIMT mode.
In this mode, the distributed vector shape is determined as follows: Definitions: lane_data_size = lane_data[0] × lane_data[1] subgroup_size = lane_layout[0] × lane_layout[1] distribution_unit_size = subgroup_size × lane_data_size
Case 1: Regular loads/stores. The following conditions must be met:
Case 2: Block loads/stores Additional definitions: tensor_size = tensor_desc[0] * .. * tensor_desc[r-1] * array_length n_distribution_units = tensor_size / distribution_unit_size fragment_size = n_distribution_units * lane_data_size Given above definitions, the following conditions must be met:
Definition at line 40 of file XeGPUUtils.cpp.
References mlir::get().
xegpu::DistributeLayoutAttr mlir::xegpu::getDistributeLayoutAttr | ( | const OpOperand & | opr | ) |
Retrieves the DistributeLayoutAttr associated with a given OpOperand.
It will first check the operand_layout_{id} of the owner operation. If not found, it will check the operand itself and its defining op.
Definition at line 155 of file XeGPUUtils.cpp.
References mlir::IROperand< DerivedT, IRValueT >::get(), mlir::Operation::getAttrOfType(), getDistributeLayoutAttr(), getLayoutName(), mlir::detail::IROperandBase::getOwner(), and mlir::Operation::hasAttr().
xegpu::DistributeLayoutAttr mlir::xegpu::getDistributeLayoutAttr | ( | const Value | value | ) |
Retrieves the DistributeLayoutAttr associated with a given Value.
For TensorDescType values, the DistributeLayoutAttr is extracted from the TensorDescType itself. For other values, it is obtained from the attributes of the defining operation. Returns nullptr if no DistributeLayoutAttr is found.
Definition at line 117 of file XeGPUUtils.cpp.
References mlir::IROperand< DerivedT, IRValueT >::get(), mlir::Operation::getAttrOfType(), getLayoutName(), mlir::Value::getType(), and mlir::Operation::hasAttr().
Referenced by doSCFStructuralTypeConversionWithTensorType(), getDistributeLayoutAttr(), and getDistributeLayoutAttrOfType().
AttrTy mlir::xegpu::getDistributeLayoutAttrOfType | ( | const OpOperand & | opr | ) |
Definition at line 89 of file XeGPUUtils.h.
References getDistributeLayoutAttr().
AttrTy mlir::xegpu::getDistributeLayoutAttrOfType | ( | const Value | value | ) |
Definition at line 79 of file XeGPUUtils.h.
References getDistributeLayoutAttr().
std::string mlir::xegpu::getLayoutName | ( | const OpOperand & | operand | ) |
Return the attribute name for the OpOperand to attach DistributeLayoutAttr.
Definition at line 106 of file XeGPUUtils.cpp.
Referenced by getDistributeLayoutAttr(), removeLayoutAttr(), and setDistributeLayoutAttr().
std::string mlir::xegpu::getLayoutName | ( | const OpResult | result | ) |
Return the attribute name for the OpResult to attach DistributeLayoutAttr.
Definition at line 112 of file XeGPUUtils.cpp.
References mlir::OpResult::getResultNumber().
|
static |
Definition at line 52 of file XeGPUOps.cpp.
Referenced by isValidGatherScatterBufferParams(), and isValidGatherScatterParams().
|
static |
Definition at line 61 of file XeGPUOps.cpp.
References kind.
bool mlir::xegpu::isSharedMemory | ( | const MemRefType & | memrefTy | ) |
Definition at line 26 of file XeGPUOps.cpp.
|
static |
Definition at line 125 of file XeGPUOps.cpp.
References mlir::emitError(), and getShapeOf().
|
static |
Definition at line 78 of file XeGPUOps.cpp.
References mlir::emitError(), getShapeOf(), and makeString().
|
static |
Definition at line 69 of file XeGPUOps.cpp.
References kind.
|
static |
Definition at line 38 of file XeGPUOps.cpp.
Referenced by isValidGatherScatterParams().
ParseResult mlir::xegpu::parseOptionalDynamicIndexList | ( | OpAsmParser & | parser, |
SmallVectorImpl< OpAsmParser::UnresolvedOperand > & | values, | ||
DenseI64ArrayAttr & | integers, | ||
SmallVectorImpl< Type > * | valueTypes = nullptr , |
||
AsmParser::Delimiter | delimiter = AsmParser::Delimiter::Square |
||
) |
Definition at line 343 of file XeGPUOps.cpp.
References mlir::AsmParser::emitError(), mlir::remark::failed(), mlir::AsmParser::getBuilder(), mlir::Builder::getDenseI64ArrayAttr(), mlir::AsmParser::getNameLoc(), mlir::AsmParser::parseColonType(), mlir::AsmParser::parseCommaSeparatedList(), mlir::AsmParser::parseInteger(), mlir::AsmParser::parseOptionalLSquare(), mlir::OpAsmParser::parseOptionalOperand(), and mlir::AsmParser::parseRSquare().
void mlir::xegpu::populateXeGPUFoldAliasOpsPatterns | ( | RewritePatternSet & | patterns | ) |
Appends patterns for folding aliasing ops into XeGPU ops into patterns
.
Definition at line 63 of file XeGPUFoldAliasOps.cpp.
References mlir::patterns.
void mlir::xegpu::populateXeGPUSubgroupDistributePatterns | ( | RewritePatternSet & | patterns | ) |
Appends patterns for XeGPU SIMT distribution into patterns
.
Definition at line 820 of file XeGPUSubgroupDistribute.cpp.
References mlir::patterns.
void mlir::xegpu::populateXeGPUUnrollPatterns | ( | RewritePatternSet & | patterns, |
const UnrollOptions & | options | ||
) |
Collect a set of patterns to unroll xegpu operations to a smaller shapes.
Users can control whether an operation to be unrolled or not, as well as its target shape via options
structure. (via setting filterConstraint and nativeShape respectively, both of them are function refs taking op
as input). An op
is unrolled to the targetShape
as follows, for each of its operands:
unrolledType
and number of unrolled instances numUnrolledInstances
are computed from the targetShape
.numUnrolledInstances
times, once for each result.Definition at line 687 of file XeGPUUnroll.cpp.
References options, and mlir::patterns.
void mlir::xegpu::populateXeGPUWgToSgDistributePatterns | ( | RewritePatternSet & | patterns | ) |
Definition at line 822 of file XeGPUWgToSgDistribute.cpp.
References mlir::patterns.
void mlir::xegpu::printOptionalDynamicIndexList | ( | OpAsmPrinter & | printer, |
Operation * | op, | ||
OperandRange | values, | ||
DenseI64ArrayAttr | integers | ||
) |
Definition at line 381 of file XeGPUOps.cpp.
References mlir::printDynamicIndexList(), and mlir::AsmParser::Square.
void mlir::xegpu::removeLayoutAttr | ( | const T & | operandOrResult | ) |
Removes the LayoutAttr for a given OpOperand or OpResult if it exists.
Definition at line 197 of file XeGPUUtils.cpp.
References getLayoutName(), mlir::Operation::hasAttrOfType(), and mlir::Operation::removeAttr().
Referenced by removeLayoutAttrs().
void mlir::xegpu::removeLayoutAttrs | ( | Operation * | op | ) |
Removes the DistributeLayoutAttr for each OpOperand and OpResult of the given operation if they exist.
If the operation contains regions, it is also applied recursively to the contained operations
Definition at line 212 of file XeGPUUtils.cpp.
References mlir::Operation::getOpOperands(), mlir::Operation::getOpResults(), removeLayoutAttr(), and mlir::Operation::walk().
void mlir::xegpu::setDistributeLayoutAttr | ( | const T & | operandOrResult, |
const DistributeLayoutAttr | layout | ||
) |
Sets the DistributeLayoutAttr for a given OpOperand or OpResult by attaching it to the owner's dictionary attributes.
Definition at line 164 of file XeGPUUtils.cpp.
References getLayoutName(), mlir::Operation::hasAttrOfType(), and mlir::Operation::setAttr().
Referenced by updateControlFlowOps(), and updateOp().
void mlir::xegpu::setDistributeLayoutAttrs | ( | Operation * | op, |
function_ref< DistributeLayoutAttr(Value)> | getLayoutImpl | ||
) |
Set the DistributeLayoutAttr for each OpOperand and OpResult of the given operation.
If the operation contains regions, it is also applied recursively to the contained operations
Definition at line 182 of file XeGPUUtils.cpp.
References mlir::Operation::getOpOperands(), mlir::Operation::getOpResults(), and mlir::Operation::walk().