MLIR 24.0.0git
XeGPULayoutImpl.cpp File Reference
#include "mlir/Dialect/XeGPU/Transforms/XeGPULayoutImpl.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/LLVMIR/XeVMDialect.h"
#include "mlir/Dialect/SCF/Transforms/Patterns.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/Dialect/XeGPU/IR/XeGPU.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/ValueRange.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Support/FormatVariadic.h"
#include <cstdint>
#include <functional>
#include <numeric>

Go to the source code of this file.

Typedefs

using LayoutRepresentation = SmallVector<int64_t>

Functions

static bool isReady (Region *region, const DenseMap< Region *, SmallPtrSet< Region *, 2 > > &targets, const SetVector< Region * > &visitedRegions)
 Return whether every target recorded for region has been visited.
static SmallVector< Region * > getBackwardRegionOrder (Operation *op)
 Order regions for walkBackward, preferring successors before predecessors and breaking ties by reverse region order.
static void walkRegionBackward (Region &region, xegpu::BackwardLayoutVisitor &visitor)
 Visits the ops of region backward; see xegpu::walkBackward.
static xegpu::DistributeLayoutAttr getLayoutFromUsePoints (Value result)
static bool isLayoutPreservingVectorProducer (Operation *op)
 Accept pure vector generators and elementwise ops that preserve vector shape.
static bool collectRematerializableChain (Operation *root, SmallVectorImpl< Operation * > &chain)
 Collect each eligible producer once, producers first, for cloning with an IRMapping.
static void propagateResultsToRegularOperands (Operation *op)
template void xegpu::removeLayoutAttr< mlir::OpResult > (const mlir::OpResult &result)
template void xegpu::removeLayoutAttr< mlir::OpOperand > (const mlir::OpOperand &operand)
static xegpu::LayoutAttr buildInstDataLayoutWithLane (mlir::MLIRContext *context, ArrayRef< int64_t > instData, ArrayRef< int64_t > laneLayout, ArrayRef< int64_t > laneData, DenseI32ArrayAttr orderAttr=nullptr)
static bool isValidLaneLayout (ArrayRef< int64_t > dataShape, ArrayRef< int64_t > laneLayout, ArrayRef< int64_t > laneData)
static xegpu::LayoutAttr buildLaneLayout (mlir::MLIRContext *context, ArrayRef< int64_t > laneLayout, ArrayRef< int64_t > laneData, DenseI32ArrayAttr orderAttr=nullptr)
static xegpu::LayoutAttr buildLayout (mlir::MLIRContext *context, ArrayRef< int64_t > sgLayout, ArrayRef< int64_t > sgData, ArrayRef< int64_t > instData, ArrayRef< int64_t > laneLayout, ArrayRef< int64_t > laneData, DenseI32ArrayAttr orderAttr=nullptr)
static xegpu::LayoutAttr buildSgLayout (mlir::MLIRContext *context, ArrayRef< int64_t > wgTileShape, ArrayRef< int64_t > sgLayout, int dimK=-1, DenseI32ArrayAttr orderAttr=nullptr)
static SmallVector< LayoutRepresentation > enumerateFactorizations (int64_t total, int64_t rank)
 Enumerates all ways to split total into rank factors whose product equals total.
static SmallVector< LayoutRepresentation > getSgLayoutCandidates (ArrayRef< int64_t > wgShape, ArrayRef< int64_t > instData, int64_t sgCount, int64_t broadcastDim=-1)
static std::optional< SmallVector< int64_t > > get2DBlockIOInstDataLayout (ArrayRef< int64_t > dataShape, Type elemTy, const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction, bool transform=false, bool transpose=false)
 Helper function to compute inst_data vectors for DPAS operands A, B, and C/D.
static xegpu::DistributeLayoutAttr get2DBlockIOSubgroupLayout (MLIRContext *context, ArrayRef< int64_t > dataShape, Type elemTy, const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction, int numSg)
 Picks the subgroup layout for a 2D block IO op (store_nd / prefetch_nd).
static std::optional< std::tuple< SmallVector< int64_t >, SmallVector< int64_t >, SmallVector< int64_t > > > getDpasInstDataLayouts (VectorType aTy, VectorType bTy, VectorType cdTy, const xegpu::uArch::MMAInstructionInterface *uArchInstruction)
 Helper function to compute inst_data vectors for DPAS operands A, B, and C/D.
static std::pair< SmallVector< int64_t >, SmallVector< int64_t > > computeScatterIOLaneLayoutAndData (ArrayRef< int64_t > instShape, int64_t subgroupSize, int64_t maxChunkSize)
 Computes lane_layout and lane_data for scatter-style store anchor layouts (store scatter, store matrix).
static std::tuple< SmallVector< int64_t >, SmallVector< int64_t >, SmallVector< int64_t > > compute2DBlockIOLaneLayout (ArrayRef< int64_t > instShape, int64_t subgroupSize, int64_t bitwidth, int64_t packingSize, bool transform=false, bool transpose=false)
static std::tuple< SmallVector< int64_t >, SmallVector< int64_t >, SmallVector< int64_t > > computeReductionLaneLayoutAndData (ArrayRef< int64_t > srcShape, ArrayRef< int64_t > reductionDims, int subgroupSize, int64_t maxReduceVectorSize, xegpu::DistributeLayoutAttr consumerLayout=nullptr)
 Derives (lane_layout, lane_data, inst_data) for a vector.multi_reduction source from the layout requested by its result's consumer.
static std::optional< std::tuple< xegpu::DistributeLayoutAttr, xegpu::DistributeLayoutAttr, xegpu::DistributeLayoutAttr > > getDpasSubgroupLayouts (mlir::MLIRContext *context, VectorType aTy, VectorType bTy, VectorType cdTy, xegpu::DistributeLayoutAttr consumerLayout, int numSg, std::tuple< SmallVector< int64_t >, SmallVector< int64_t >, SmallVector< int64_t > > instDataVecs, const xegpu::uArch::MMAInstructionInterface *uArchInstruction)
 Helper function to set up subgroup layouts for DPAS operands A, B, and C/D.
static xegpu::DistributeLayoutAttr createScaleLayout (mlir::MLIRContext *context, VectorType matrixTy, VectorType scaleTy, xegpu::DistributeLayoutAttr matrixLayout, bool isBScale, const xegpu::uArch::uArch *uArch)
 Helper to create a scale layout derived from a matrix operand layout.
static xegpu::DistributeLayoutAttr setupDefault2DBlockIOLayout (xegpu::LayoutKind layoutKind, ArrayRef< int64_t > dataShape, Type elemTy, int numSg, const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction, const xegpu::uArch::uArch *uArch)
 Select a default 2D block IO layout without transpose or transform.
static xegpu::DistributeLayoutAttr getDefaultScatterIOSubgroupLayout (mlir::MLIRContext *context, ArrayRef< int64_t > wgShape, ArrayRef< int64_t > instData, int numSg)
 Select the most balanced numSg factorization of wgShape whose sg_data is a multiple of instData.
static xegpu::DistributeLayoutAttr setupDefaultScatterIOLayout (xegpu::LayoutKind layoutKind, mlir::MLIRContext *context, int maxChunkSize, ArrayRef< int64_t > srcShape, int subgroupSize, int numSg)
 Select a default scatter IO layout with at most maxChunkSize elements per lane.
static xegpu::DistributeLayoutAttr setupGenericLoadAnchorLayout (xegpu::LayoutKind layoutKind, mlir::MLIRContext *context, xegpu::DistributeLayoutAttr consumerLayout, int maxChunkSize, ArrayRef< int64_t > resShape, int subgroupSize, int numSg)
 Select a layout for load_gather or load_matrix.
static xegpu::DistributeLayoutAttr adjustInnermostDimForDivisibility (xegpu::DistributeLayoutAttr consumerLayout, xegpu::LayoutKind layoutKind, size_t innerMostDim, int ratio, int64_t bound, const xegpu::uArch::uArch *uArch)
 Adjusts consumerLayout's innermost-dim data field selected by layoutKind so that the source layout can be safely inferred by dividing that value by ratio.
static bool isContiguousTiling (ArrayRef< int64_t > dimGroup, ArrayRef< int64_t > shape, ArrayRef< int64_t > counts, ArrayRef< int64_t > tileShape, int64_t expectedStride)
 Checks that the tiles a split group is cut into walk the collapsed source dim with one constant stride, which is what collapseDims assumes when it multiplies a layout field across the group.
static bool isCollapsibleSgGroup (ArrayRef< int64_t > dimGroup, ArrayRef< int64_t > shape, ArrayRef< int64_t > sgLayout, ArrayRef< int64_t > sgData, ArrayRef< int64_t > order)
 Checks that collapsing dimGroup of a subgroup layout, which multiplies sg_layout and sg_data across the group, distributes the collapsed dim exactly like the group does.
static xegpu::DistributeLayoutAttr setupShapeCastSgResultLayout (ArrayRef< int64_t > resShape, ArrayRef< SmallVector< int64_t > > splitDimGroups, xegpu::DistributeLayoutAttr consumerLayout)
 Subgroup level of setupShapeCastResultLayout.
static xegpu::DistributeLayoutAttr getLoopCarriedLayoutForYieldOperand (RegionBranchTerminatorOpInterface terminator, OpOperand &operand)
static xegpu::DistributeLayoutAttr getParentResultLayoutForYieldOperand (RegionBranchTerminatorOpInterface terminator, OpOperand &operand)

Variables

static constexpr unsigned kMaxRematerializableChainOps = 16

Typedef Documentation

◆ LayoutRepresentation

Definition at line 1077 of file XeGPULayoutImpl.cpp.

Function Documentation

◆ adjustInnermostDimForDivisibility()

xegpu::DistributeLayoutAttr adjustInnermostDimForDivisibility ( xegpu::DistributeLayoutAttr consumerLayout,
xegpu::LayoutKind layoutKind,
size_t innerMostDim,
int ratio,
int64_t bound,
const xegpu::uArch::uArch * uArch )
static

Adjusts consumerLayout's innermost-dim data field selected by layoutKind so that the source layout can be safely inferred by dividing that value by ratio.

Doubles the value until the divisibility constraint is met, bounded above by bound like result-shape.

Used by ops whose source relates to the result by a fixed factor along the innermost dim (e.g., bitcast: bitwidth ratio; interleave: 2x).

Divisibility constraints per LayoutKind:

  • Subgroup: sgData[innermost] % ratio == 0
  • InstData: instData[innermost] % (laneLayout[innermost] * ratio) == 0 (laneLayout falls back to subgroupSize if absent)
  • Lane: laneData[innermost] % ratio == 0

Definition at line 2783 of file XeGPULayoutImpl.cpp.

References mlir::xegpu::uArch::uArch::getSubgroupSize(), mlir::xegpu::InstData, mlir::xegpu::Lane, and mlir::xegpu::Subgroup.

Referenced by mlir::xegpu::setupBitCastResultLayout(), and mlir::xegpu::setupInterleaveResultLayout().

◆ buildInstDataLayoutWithLane()

xegpu::LayoutAttr buildInstDataLayoutWithLane ( mlir::MLIRContext * context,
ArrayRef< int64_t > instData,
ArrayRef< int64_t > laneLayout,
ArrayRef< int64_t > laneData,
DenseI32ArrayAttr orderAttr = nullptr )
static

◆ buildLaneLayout()

◆ buildLayout()

xegpu::LayoutAttr buildLayout ( mlir::MLIRContext * context,
ArrayRef< int64_t > sgLayout,
ArrayRef< int64_t > sgData,
ArrayRef< int64_t > instData,
ArrayRef< int64_t > laneLayout,
ArrayRef< int64_t > laneData,
DenseI32ArrayAttr orderAttr = nullptr )
static

◆ buildSgLayout()

xegpu::LayoutAttr buildSgLayout ( mlir::MLIRContext * context,
ArrayRef< int64_t > wgTileShape,
ArrayRef< int64_t > sgLayout,
int dimK = -1,
DenseI32ArrayAttr orderAttr = nullptr )
static

◆ collectRematerializableChain()

bool collectRematerializableChain ( Operation * root,
SmallVectorImpl< Operation * > & chain )
static

Collect each eligible producer once, producers first, for cloning with an IRMapping.

Reject chains exceeding the duplication limit or reaching an unsupported producer or vector block argument.

Definition at line 229 of file XeGPULayoutImpl.cpp.

References isLayoutPreservingVectorProducer(), and kMaxRematerializableChainOps.

Referenced by mlir::xegpu::isTriviallyRematerializable(), and mlir::xegpu::rematerialize().

◆ compute2DBlockIOLaneLayout()

std::tuple< SmallVector< int64_t >, SmallVector< int64_t >, SmallVector< int64_t > > compute2DBlockIOLaneLayout ( ArrayRef< int64_t > instShape,
int64_t subgroupSize,
int64_t bitwidth,
int64_t packingSize,
bool transform = false,
bool transpose = false )
static

Definition at line 1335 of file XeGPULayoutImpl.cpp.

Referenced by setupDefault2DBlockIOLayout().

◆ computeReductionLaneLayoutAndData()

std::tuple< SmallVector< int64_t >, SmallVector< int64_t >, SmallVector< int64_t > > computeReductionLaneLayoutAndData ( ArrayRef< int64_t > srcShape,
ArrayRef< int64_t > reductionDims,
int subgroupSize,
int64_t maxReduceVectorSize,
xegpu::DistributeLayoutAttr consumerLayout = nullptr )
static

Derives (lane_layout, lane_data, inst_data) for a vector.multi_reduction source from the layout requested by its result's consumer.

Each returned vector has one entry per source dimension.

Reuse the consumer's slice parent when the slice dimensions exactly match reductionDims, the parent's effective lane_layout and lane_data each have one entry per source dimension, and the lane layout uses all subgroupSize lanes. Clamp reused lane counts to srcShape[i] / lane_data[i], since the sliced dimensions may have different extents in the reduction source.

If the consumer's slice parent cannot be reused, initialize lane_layout and lane_data to 1, then copy available consumer entries onto non-reduced source dimensions in order, with the same clamp: a consumer that broadcasts along a unit dimension may place lanes on it.

For a derived (not reused) layout, assign any unused lanes to the innermost dimension if it is reduced, up to the same bound. If that dimension still has only one lane, then the lane can reduce a vector limited by maxReduceVectorSize and the source dimension's size. The vector budget (maxReduceVectorSize) applies to the product of lane_data across all dimensions. If that product already meets or exceeds the budget, leave lane_data unchanged.

Set inst_data[i] to lane_layout[i] * lane_data[i]. On non-reduced dimensions among the last two, preserve a reused parent's larger inst_data[i]; leading dimensions are not widened because lane-level distribution only supports unit leading dimensions.

Source layout examples with subgroupSize = maxReduceVectorSize = 16:

// Reuse a matching slice parent's lane layout and data.
srcShape=[32, 64], reductionDims=[1], consumer=slice(parent, dims=[1])
parent: lane_layout=[1, 16], lane_data=[1, 1]
source: lane_layout=[1, 16], lane_data=[1, 1], inst_data=[1, 16]
// Preserve dim 0 blocking and limit dim 1 lanes to the source size.
srcShape=[16, 4], reductionDims=[1], consumer=slice(parent, dims=[1])
parent: lane_layout=[1, 16], lane_data=[1, 1], inst_data=[8, 16]
source: lane_layout=[1, 4], lane_data=[1, 1], inst_data=[8, 4]
// Assign spare lanes to the innermost dimension when it is reduced.
srcShape=[16, 32, 32], reductionDims=[2]
consumer: lane_layout=[1, 2], lane_data=[1, 1]
source: lane_layout=[1, 2, 8], lane_data=[1, 1, 1], inst_data=[1, 2, 8]
// Keep the consumer's lanes on the non-reduced dimension.
srcShape=[32, 64], reductionDims=[0]
consumer: lane_layout=[16], lane_data=[1]
source: lane_layout=[1, 16], lane_data=[1, 1], inst_data=[1, 16]
// For a scalar reduction, put lanes on the innermost dimension.
srcShape=[32, 64], reductionDims=[0, 1]
consumer: none
source: lane_layout=[1, 16], lane_data=[1, 1], inst_data=[1, 16]
static SmallVector< Value > slice(OpBuilder &b, Location loc, Value value, VectorType nativeType)

Definition at line 1422 of file XeGPULayoutImpl.cpp.

References mlir::computeProduct().

Referenced by mlir::xegpu::setupMultiReductionResultLayout().

◆ computeScatterIOLaneLayoutAndData()

std::pair< SmallVector< int64_t >, SmallVector< int64_t > > computeScatterIOLaneLayoutAndData ( ArrayRef< int64_t > instShape,
int64_t subgroupSize,
int64_t maxChunkSize )
static

Computes lane_layout and lane_data for scatter-style store anchor layouts (store scatter, store matrix).

Lanes and the per-lane vector both live on the innermost dim:

  • laneLayout[innermost] = min(subgroupSize, srcShape[innermost])
  • laneData[innermost] = min(srcShape[innermost] / laneLayout[innermost], maxChunkSize) All other entries are 1.

Definition at line 1314 of file XeGPULayoutImpl.cpp.

Referenced by setupDefaultScatterIOLayout().

◆ createScaleLayout()

xegpu::DistributeLayoutAttr createScaleLayout ( mlir::MLIRContext * context,
VectorType matrixTy,
VectorType scaleTy,
xegpu::DistributeLayoutAttr matrixLayout,
bool isBScale,
const xegpu::uArch::uArch * uArch )
static

Helper to create a scale layout derived from a matrix operand layout.

The scale layout is computed by mapping each dimension of the matrix layout to the corresponding scale tensor dimension using the ratio between the matrix and scale shapes.

Definition at line 1725 of file XeGPULayoutImpl.cpp.

References buildLayout(), mlir::xegpu::uArch::uArch::getInstruction(), and mlir::xegpu::uArch::SubgroupScaledMatrixMultiplyAcc.

◆ enumerateFactorizations()

SmallVector< LayoutRepresentation > enumerateFactorizations ( int64_t total,
int64_t rank )
static

Enumerates all ways to split total into rank factors whose product equals total.

Returns the list of all such factorizations.

Definition at line 1081 of file XeGPULayoutImpl.cpp.

Referenced by getSgLayoutCandidates().

◆ get2DBlockIOInstDataLayout()

std::optional< SmallVector< int64_t > > get2DBlockIOInstDataLayout ( ArrayRef< int64_t > dataShape,
Type elemTy,
const xegpu::uArch::BlockIOInstructionInterface * uArchInstruction,
bool transform = false,
bool transpose = false )
static

Helper function to compute inst_data vectors for DPAS operands A, B, and C/D.

Definition at line 1183 of file XeGPULayoutImpl.cpp.

References mlir::xegpu::uArch::BlockIOInstructionInterface::getBlockWidthHeightCount(), and mlir::xegpu::getLargestDivisor().

Referenced by setupDefault2DBlockIOLayout().

◆ get2DBlockIOSubgroupLayout()

xegpu::DistributeLayoutAttr get2DBlockIOSubgroupLayout ( MLIRContext * context,
ArrayRef< int64_t > dataShape,
Type elemTy,
const xegpu::uArch::BlockIOInstructionInterface * uArchInstruction,
int numSg )
static

Picks the subgroup layout for a 2D block IO op (store_nd / prefetch_nd).

Every supported block (height, width) dividing the shape is tried, largest area first and the more square block first among equal areas, until one admits a subgroup layout.

Definition at line 1217 of file XeGPULayoutImpl.cpp.

References buildSgLayout(), mlir::xegpu::uArch::BlockIOInstructionInterface::getBlockWidthHeightCount(), and getSgLayoutCandidates().

Referenced by setupDefault2DBlockIOLayout().

◆ getBackwardRegionOrder()

SmallVector< Region * > getBackwardRegionOrder ( Operation * op)
static

Order regions for walkBackward, preferring successors before predecessors and breaking ties by reverse region order.

Definition at line 100 of file XeGPULayoutImpl.cpp.

References mlir::Operation::getRegions(), and isReady().

Referenced by walkRegionBackward().

◆ getDefaultScatterIOSubgroupLayout()

xegpu::DistributeLayoutAttr getDefaultScatterIOSubgroupLayout ( mlir::MLIRContext * context,
ArrayRef< int64_t > wgShape,
ArrayRef< int64_t > instData,
int numSg )
static

Select the most balanced numSg factorization of wgShape whose sg_data is a multiple of instData.

Definition at line 2117 of file XeGPULayoutImpl.cpp.

References buildSgLayout(), and getSgLayoutCandidates().

Referenced by setupDefaultScatterIOLayout().

◆ getDpasInstDataLayouts()

std::optional< std::tuple< SmallVector< int64_t >, SmallVector< int64_t >, SmallVector< int64_t > > > getDpasInstDataLayouts ( VectorType aTy,
VectorType bTy,
VectorType cdTy,
const xegpu::uArch::MMAInstructionInterface * uArchInstruction )
static

Helper function to compute inst_data vectors for DPAS operands A, B, and C/D.

Look up the uArch table and search for the largest supported block size that divides the data shape

Definition at line 1267 of file XeGPULayoutImpl.cpp.

References mlir::xegpu::getLargestDivisor(), mlir::xegpu::uArch::MMAInstructionInterface::getSupportedK(), mlir::xegpu::uArch::MMAInstructionInterface::getSupportedM(), and mlir::xegpu::uArch::MMAInstructionInterface::getSupportedN().

◆ getDpasSubgroupLayouts()

std::optional< std::tuple< xegpu::DistributeLayoutAttr, xegpu::DistributeLayoutAttr, xegpu::DistributeLayoutAttr > > getDpasSubgroupLayouts ( mlir::MLIRContext * context,
VectorType aTy,
VectorType bTy,
VectorType cdTy,
xegpu::DistributeLayoutAttr consumerLayout,
int numSg,
std::tuple< SmallVector< int64_t >, SmallVector< int64_t >, SmallVector< int64_t > > instDataVecs,
const xegpu::uArch::MMAInstructionInterface * uArchInstruction )
static

Helper function to set up subgroup layouts for DPAS operands A, B, and C/D.

Compute subgroup layout candidates based on wgtile and instData, and then pick the best one that satisfies all operands and the consumer (if specified).

Definition at line 1591 of file XeGPULayoutImpl.cpp.

References buildSgLayout(), getSgLayoutCandidates(), and mlir::xegpu::uArch::MMAInstructionInterface::getSupportedM().

◆ getLayoutFromUsePoints()

xegpu::DistributeLayoutAttr getLayoutFromUsePoints ( Value result)
static

◆ getLoopCarriedLayoutForYieldOperand()

xegpu::DistributeLayoutAttr getLoopCarriedLayoutForYieldOperand ( RegionBranchTerminatorOpInterface terminator,
OpOperand & operand )
static

◆ getParentResultLayoutForYieldOperand()

xegpu::DistributeLayoutAttr getParentResultLayoutForYieldOperand ( RegionBranchTerminatorOpInterface terminator,
OpOperand & operand )
static

◆ getSgLayoutCandidates()

SmallVector< LayoutRepresentation > getSgLayoutCandidates ( ArrayRef< int64_t > wgShape,
ArrayRef< int64_t > instData,
int64_t sgCount,
int64_t broadcastDim = -1 )
static

◆ isCollapsibleSgGroup()

bool isCollapsibleSgGroup ( ArrayRef< int64_t > dimGroup,
ArrayRef< int64_t > shape,
ArrayRef< int64_t > sgLayout,
ArrayRef< int64_t > sgData,
ArrayRef< int64_t > order )
static

Checks that collapsing dimGroup of a subgroup layout, which multiplies sg_layout and sg_data across the group, distributes the collapsed dim exactly like the group does.

That holds in two cases:

  • Replicas: every dim of the group is held whole, so all subgroups are copies of each other.
  • Tiling: no subgroup repeats another's tile, each sg tile is contiguous in the collapsed dim, the next subgroup's tile follows it, and the group's distributed dims are walked row-major. A dim may repeat its tiles round-robin only when every outer dim of the group has sg_layout = sg_data = 1, which the contiguity checks imply. For example, sg_layout = [1, 2], sg_data = [32, 16] over 32x32 is rejected: the sg tile 32x16 is not contiguous in the collapsed dim 1024.

Definition at line 2944 of file XeGPULayoutImpl.cpp.

References isContiguousTiling().

Referenced by setupShapeCastSgResultLayout().

◆ isContiguousTiling()

bool isContiguousTiling ( ArrayRef< int64_t > dimGroup,
ArrayRef< int64_t > shape,
ArrayRef< int64_t > counts,
ArrayRef< int64_t > tileShape,
int64_t expectedStride )
static

Checks that the tiles a split group is cut into walk the collapsed source dim with one constant stride, which is what collapseDims assumes when it multiplies a layout field across the group.

Along each dim the group is cut into counts[dim] tiles of tileShape[dim] elements (empty for single-element tiles) taken from shape[dim], which gives the row-major strides. Walking from the innermost dim out, a dim cut into several tiles steps by tileShape[dim] * stride(dim) and has to pick up where the inner dims left off, expectedStride; a dim cut into one tile does not step at all, so it only contributes its size.

Definition at line 2914 of file XeGPULayoutImpl.cpp.

Referenced by isCollapsibleSgGroup(), and mlir::xegpu::setupShapeCastResultLayout().

◆ isLayoutPreservingVectorProducer()

bool isLayoutPreservingVectorProducer ( Operation * op)
static

Accept pure vector generators and elementwise ops that preserve vector shape.

Generators have no vector operands; elementwise ops share their result layout with their vector operands, so the chain needs no layout inference.

Definition at line 211 of file XeGPULayoutImpl.cpp.

References broadcast(), mlir::Operation::getNumRegions(), mlir::Operation::getNumResults(), mlir::Operation::getResult(), mlir::Value::getType(), mlir::OpTrait::hasElementwiseMappableTraits(), and mlir::isMemoryEffectFree().

Referenced by collectRematerializableChain().

◆ isReady()

bool isReady ( Region * region,
const DenseMap< Region *, SmallPtrSet< Region *, 2 > > & targets,
const SetVector< Region * > & visitedRegions )
static

Return whether every target recorded for region has been visited.

Definition at line 86 of file XeGPULayoutImpl.cpp.

References target.

Referenced by getBackwardRegionOrder(), and isOpReady().

◆ isValidLaneLayout()

bool isValidLaneLayout ( ArrayRef< int64_t > dataShape,
ArrayRef< int64_t > laneLayout,
ArrayRef< int64_t > laneData )
static

Definition at line 505 of file XeGPULayoutImpl.cpp.

Referenced by setupDefault2DBlockIOLayout().

◆ propagateResultsToRegularOperands()

◆ setupDefault2DBlockIOLayout()

◆ setupDefaultScatterIOLayout()

xegpu::DistributeLayoutAttr setupDefaultScatterIOLayout ( xegpu::LayoutKind layoutKind,
mlir::MLIRContext * context,
int maxChunkSize,
ArrayRef< int64_t > srcShape,
int subgroupSize,
int numSg )
static

◆ setupGenericLoadAnchorLayout()

xegpu::DistributeLayoutAttr setupGenericLoadAnchorLayout ( xegpu::LayoutKind layoutKind,
mlir::MLIRContext * context,
xegpu::DistributeLayoutAttr consumerLayout,
int maxChunkSize,
ArrayRef< int64_t > resShape,
int subgroupSize,
int numSg )
static

Select a layout for load_gather or load_matrix.

Reuse requested subgroup layouts; otherwise keep the consumer's lane_layout, restrict lane_data to a bounded innermost chunk, and in InstData mode set inst_data to lane_layout * lane_data. Without a requested layout, use the default scatter IO layout.

Definition at line 2160 of file XeGPULayoutImpl.cpp.

References buildInstDataLayoutWithLane(), buildLaneLayout(), mlir::xegpu::InstData, mlir::xegpu::Lane, setupDefaultScatterIOLayout(), and mlir::xegpu::Subgroup.

◆ setupShapeCastSgResultLayout()

xegpu::DistributeLayoutAttr setupShapeCastSgResultLayout ( ArrayRef< int64_t > resShape,
ArrayRef< SmallVector< int64_t > > splitDimGroups,
xegpu::DistributeLayoutAttr consumerLayout )
static

Subgroup level of setupShapeCastResultLayout.

Keeps consumerLayout when every split group collapses exactly (see isCollapsibleSgGroup). Otherwise, the subgroups of each failing group move to its outermost dims, filling a dim before moving inward. The result is a new layout, so it uses the default order, under which the moved subgroups collapse exactly; a convert_layout gives the consumer its own layout. Returns nullptr when the subgroups do not fit the group's dims.

Definition at line 2989 of file XeGPULayoutImpl.cpp.

References buildLayout(), and isCollapsibleSgGroup().

Referenced by mlir::xegpu::setupShapeCastResultLayout().

◆ walkRegionBackward()

◆ xegpu::removeLayoutAttr< mlir::OpOperand >()

template void xegpu::removeLayoutAttr< mlir::OpOperand > ( const mlir::OpOperand & operand)

◆ xegpu::removeLayoutAttr< mlir::OpResult >()

template void xegpu::removeLayoutAttr< mlir::OpResult > ( const mlir::OpResult & result)

Variable Documentation

◆ kMaxRematerializableChainOps

unsigned kMaxRematerializableChainOps = 16
staticconstexpr

Definition at line 205 of file XeGPULayoutImpl.cpp.

Referenced by collectRematerializableChain().