MLIR 23.0.0git
XeGPULayoutImpl.h
Go to the documentation of this file.
1//===- XeGPULayoutImpl.h - Layout utility functions ------------*- C++ -*-===//
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#ifndef MLIR_DIALECT_XEGPU_UTILS_XeGPULayoutImpl_H_
10#define MLIR_DIALECT_XEGPU_UTILS_XeGPULayoutImpl_H_
11
18#include "llvm/ADT/STLFunctionalExtras.h"
19
20namespace mlir {
21
22class VectorType;
23class OpOperand;
24class OpResult;
25class OpBuilder;
26class ValueRange;
27class TypeConverter;
28class OpFoldResult;
29
30namespace xegpu {
31class DistributeLayoutAttr;
32class LayoutAttr;
33class TensorDescType;
34} // namespace xegpu
35
36namespace xegpu {
37
38LogicalResult propagateLayouts(OpBuilder &builder, Operation *target,
39 LayoutKind layoutKind, unsigned indexBitWidth,
40 bool printOnly = false);
41
42LogicalResult resolveLayoutConflicts(Operation *target);
43
44/// Callable returning the propagated layout for a given Value, used by the
45/// layout-propagation helpers below.
46using GetLayoutFnTy = llvm::function_ref<DistributeLayoutAttr(Value)>;
47
48/// Propagate layouts from a region branch op's region entry block arguments
49/// back to its init operands. The block argument's layout is obtained via
50/// `getLayoutOfValue`; the matching layout is then recorded on each init
51/// operand that flows into that block argument (e.g. scf.for's iter_args
52/// inits), and on tensor descriptor block argument types.
53LogicalResult propagateRegionArgsToInits(RegionBranchOpInterface regionOp,
54 GetLayoutFnTy getLayoutOfValue);
55
56/// Attach layout attributes to all vector-type operands of operations within
57/// the given operation's nested region. Reports an error if any vector operand
58/// lacks a layout attribute.
60
61/// Removes the LayoutAttr for a given OpOperand or OpResult if it exists.
62template <typename T,
63 typename = std::enable_if_t<std::is_same_v<T, OpOperand> ||
64 std::is_same_v<T, OpResult>>>
65void removeLayoutAttr(const T &operandOrResult);
66
67/// Removes the DistributeLayoutAttr for each OpOperand and OpResult of the
68/// given operation if they exist. If the operation contains regions, it is also
69/// applied recursively to the contained operations
71
72/// Removes the temporary layout attributes for each OpOperand and OpResult of
73/// the given operation. Recursive for contained operations if the given
74/// operation contains regions.
76
77/// Updates the NamedAttribute sequence by dropping sg-layout and
78/// sg-data information from any DistributeLayoutAttr found.
81
82/// Updates the NamedAttribute sequence by dropping inst-data information from
83/// any DistributeLayoutAttr found.
85
86/// Infers the source layout attribute for a broadcast operation given the
87/// result layout attribute, result shape, and source shape.
88DistributeLayoutAttr inferBroadcastSourceLayout(DistributeLayoutAttr resLayout,
89 ArrayRef<int64_t> resShape,
90 ArrayRef<int64_t> srcShape);
91
92/// Infers the source layout attribute for a reduction operation given the
93/// result layout attribute and reduced dims.
94DistributeLayoutAttr
95inferMultiReductionSourceLayout(DistributeLayoutAttr resLayout,
96 SmallVector<int64_t> reduceDims);
97
98/// Infers the source layout attribute for a reduction operation given the
99/// result layout attribute and reduced dims.
100DistributeLayoutAttr inferReductionSourceLayout(DistributeLayoutAttr resLayout);
101
102/// Infers the source layout attribute for a transpose operation given the
103/// result layout attribute and permutation.
104DistributeLayoutAttr inferTransposeSourceLayout(DistributeLayoutAttr resLayout,
105 ArrayRef<int64_t> permutation);
106
107/// Infers the source layout attribute for a bitcast operation given the
108/// result layout attribute, result element type bitwidth, and source element
109/// type bitwidth.
110DistributeLayoutAttr inferBitCastSourceLayout(DistributeLayoutAttr resLayout,
111 int resElemTyBitWidth,
112 int srcElemTyBitWidth);
113
114/// Infers the source layout attribute for an interleave operation given the
115/// result layout attribute. Interleave doubles the innermost dimension size.
116DistributeLayoutAttr
117inferInterleaveSourceLayout(DistributeLayoutAttr resLayout);
118
119/// Infers the source layout attribute for a deinterleave operation given the
120/// result layout attribute. Deinterleave halves the innermost dimension size.
121DistributeLayoutAttr
122inferDeinterleaveSourceLayout(DistributeLayoutAttr resLayout);
123
124/// Infers the source layout attribute for a shape cast operation given the
125/// result layout attribute, result shape, and source shape.
126DistributeLayoutAttr inferShapeCastSourceLayout(DistributeLayoutAttr resLayout,
127 ArrayRef<int64_t> resShape,
128 ArrayRef<int64_t> srcShape);
129
130/// Infers the source layout attribute for an insert strided slice operation
131/// given the result layout attribute, result shape, and source shape. Removes
132/// leading dimensions from the result layout to match the source shape size.
133DistributeLayoutAttr
134inferInsertStridedSliceSourceLayout(DistributeLayoutAttr resLayout,
135 ArrayRef<int64_t> resShape,
136 ArrayRef<int64_t> srcShape);
137
138/// Infers the source layout attribute for an insert operation.
139/// using same logic as inferInsertStridedSliceSourceLayout
140DistributeLayoutAttr inferInsertSourceLayout(DistributeLayoutAttr resLayout,
141 ArrayRef<int64_t> resShape,
142 ArrayRef<int64_t> srcShape);
143
144/// Infers the source layout attribute for an extract operation. Adds
145/// leading dimensions to the source layout to match the source shape size.
146DistributeLayoutAttr inferExtractSourceLayout(DistributeLayoutAttr resLayout,
147 ArrayRef<int64_t> resShape,
148 ArrayRef<int64_t> srcShape);
149
150/// Infers the layout attribute for mask and offset operand for Chunked load
151/// and store, given the anchor layout attribute for the value being load/store.
152DistributeLayoutAttr
153inferMaskOffsetLayoutForScatterIO(DistributeLayoutAttr payloadLayout,
154 int chunkSize);
155
156/// Infers the source layout attribute for an operand using result layout
157/// attribute
158DistributeLayoutAttr
160 DistributeLayoutAttr resLayout);
161
162/// Note on the `consumerLayout` argument used by the consumer-driven setup* /
163/// complete* helpers below:
164///
165/// Layout propagation is a backward dataflow analysis, so a producer learns its
166/// consumers' demands one at a time. The `consumerLayout` passed to these
167/// helpers is the *single* layout that the first consumer to reach the producer
168/// has requested (see `getConsumerLayoutAt`); these helpers do not pick among,
169/// or merge, multiple consumers, and they do not reason about cost (e.g. a
170/// consumer inside a loop vs. one outside). If a producer has several consumers
171/// with conflicting layout demands, only the first-arriving one shapes the
172/// producer's anchor layout here; any later, inconsistent consumer is left
173/// as-is and reconciled afterwards by the layout conflict resolution process
174/// (`ResolveLayoutConflicts`), which inserts a `convert_layout` op on that
175/// edge. So these helpers can always assume exactly one (possibly null)
176/// consumer layout to honor.
177
178/// Sets up layout for Multi-Reduction operations by creating a SliceAttr for
179/// the result.
180///
181/// This function first attempts to construct a source layout that, when
182/// sliced along reduction dimensions, produces a result layout compatible
183/// with the consumer's preferred layout. This minimizes data redistribution
184/// overhead. The SliceAttr for the result is then created based on the
185/// derived source layout and the specified reduction dimensions.
187 VectorType srcVectorTy,
188 DistributeLayoutAttr consumerLayout,
189 SmallVector<int64_t> reductionDims,
190 int numSg, const uArch::uArch *uArch);
191
192/// Sets up layout for Reduction operations by creating a SliceAttr for the
193/// result.
194SliceAttr setupReductionResultLayout(LayoutKind layoutKind,
195 VectorType srcVectorTy,
196 const uArch::uArch *uArch);
197
198/// Setup the result layout attribute for a bitcast operation based on element
199/// type bitwidths. This ensures the source layout can always be derived from
200/// the result layout.
201///
202/// When casting from a narrower to a wider element type (srcElemTyBitWidth <
203/// resElemTyBitWidth), the result layout's innermost dimension data sizes
204/// (inst_data, lane_data) are scaled up by the bitwidth ratio. This maintains
205/// the invariant that the source layout can be recovered by adjusting the
206/// result layout based on bitwidth ratio of input vs output.
207DistributeLayoutAttr setupBitCastResultLayout(
208 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
209 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
210
211/// Sets up the result layout for an interleave operation to ensure the source
212/// layout can be safely derived. Interleave doubles the innermost dimension,
213/// so the result layout must ensure that laneData is at least 2 (or a multiple
214/// of 2), and instData must be divisible by innermostDimLaneLayout * 2.
215DistributeLayoutAttr setupInterleaveResultLayout(
216 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
217 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
218
219/// Sets up the result layout for an insert strided slice operation.
220/// Creates a result layout based on the specified layout kind (InstData or
221/// Lane).
223 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
224 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
225
226/// Sets up the anchor layout for a load gather operation.
227DistributeLayoutAttr setupLoadGatherAnchorLayout(
228 LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize,
229 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
230
231/// Sets up the anchor layout for load matrix operation.
232DistributeLayoutAttr setupLoadMatrixAnchorLayout(
233 LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize,
234 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
235
236/// Sets up the anchor layout for a store scatter operation.
237/// `numSg` is only used for Subgroup-kind layouts.
238DistributeLayoutAttr setupStoreScatterAnchorLayout(LayoutKind layoutKind,
239 VectorType vectorTy,
240 int contigChunkSize,
241 int numSg,
242 const uArch::uArch *uArch);
243
244/// Sets up the anchor layout for a store matrix operation.
245/// `numSg` is only used for Subgroup-kind layouts.
246DistributeLayoutAttr setupStoreMatrixAnchorLayout(LayoutKind layoutKind,
247 VectorType vectorTy,
248 int contigChunkSize,
249 int numSg,
250 const uArch::uArch *uArch);
251
252/// If the consumer layout has only inst_data (no lane_layout/lane_data),
253/// completes it by running the corresponding scatter-style Lane-kind setup
254/// rule with inst_data as the destination shape. The resulting lane info is
255/// merged with the consumer's inst_data so downstream setup* paths see a
256/// fully-populated layout.
257/// Returns the layout unchanged when it is null, has no inst_data, or already
258/// carries lane info; returns nullopt when the derived lane factorization does
259/// not divide the user's inst_data (an invalid inst_data).
260std::optional<DistributeLayoutAttr> completeScatterLoadLaneLayoutFromInstData(
261 DistributeLayoutAttr userSpecifiedLayout,
262 DistributeLayoutAttr consumerLayout, Type elemTy,
263 const xegpu::uArch::LoadGatherInstruction *uArchInstruction,
264 const int subgroupSize);
265
266/// Like completeScatterLoadLaneLayoutFromInstData, but for scatter stores
267/// (store_scatter / store_matrix). A store is a data sink: lane info is derived
268/// purely from inst_data using the uArch's StoreScatter per-lane store width,
269/// with no consumer layout to reuse.
270std::optional<DistributeLayoutAttr> completeScatterStoreLaneLayoutFromInstData(
271 DistributeLayoutAttr specifiedLayout, Type elemTy,
272 const xegpu::uArch::StoreScatterInstruction *uArchInstruction,
273 const int subgroupSize);
274
275/// Completes a user-provided 2D-block store_nd / prefetch_nd anchor that has
276/// only inst_data. These ops are data sinks, so lane info is derived purely
277/// from inst_data using the shared BlockIOInstructionInterface; one helper
278/// serves both store_nd and prefetch_nd.
279std::optional<DistributeLayoutAttr> completeBlockStoreLaneLayoutFromInstData(
280 DistributeLayoutAttr specifiedLayout, Type elemTy,
281 const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction,
282 const int subgroupSize);
283
284/// Like completeBlockStoreLaneLayoutFromInstData, but for load_nd. The consumer
285/// layout supplies the transform / transpose / packing properties; the lane
286/// factorization is recomputed from inst_data (load-side lane counts differ
287/// from the consumer's).
288std::optional<DistributeLayoutAttr> completeBlockLoadLaneLayoutFromInstData(
289 DistributeLayoutAttr specifiedLayout, DistributeLayoutAttr consumerLayout,
290 Type elemTy,
291 const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction,
292 const int subgroupSize);
293
294/// Sets up the anchor layout for a store_nd operation. StoreNd does not
295/// consider a consumer layout (it is a data sink), and picks its layout from
296/// uArch block parameters. `numSg` is only used for Subgroup-kind layouts.
297DistributeLayoutAttr setupStoreNdAnchorLayout(LayoutKind layoutKind,
298 VectorType vectorTy, int numSg,
299 const uArch::uArch *uArch);
300
301/// Sets up the anchor layout for a prefetch_nd operation. PrefetchNd has no
302/// value result and thus no consumer; it picks its layout from uArch block
303/// parameters. `numSg` is only used for Subgroup-kind layouts.
304DistributeLayoutAttr setupPrefetchNdAnchorLayout(LayoutKind layoutKind,
305 TensorDescType tdescTy,
306 int numSg,
307 const uArch::uArch *uArch);
308
309/// Sets up the anchor layout for a load_nd operation. LoadNd takes a
310/// (downstream) consumer layout and validates it against uArch constraints;
311/// when valid, the consumer's `inst_data` / `sg_layout` are honored.
312/// Otherwise defaults derived from uArch block parameters are used.
313/// `consumerLayout` must be presented. `numSg` is only used for Subgroup-kind
314/// layouts when the consumer does not already provide an sg_layout.
315DistributeLayoutAttr
316setupLoadNdAnchorLayout(LayoutKind layoutKind, VectorType vectorTy,
317 DistributeLayoutAttr consumerLayout, int numSg,
318 const uArch::uArch *uArch);
319
320/// Sets up the anchor layouts for a dpas operands (A, B, and C/D).
321/// The numSg and consumerLayout (optional) are only used by sg layout creation.
322std::optional<std::tuple<DistributeLayoutAttr, DistributeLayoutAttr,
323 DistributeLayoutAttr>>
324setupDpasLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy,
325 VectorType cdTy, DistributeLayoutAttr consumerLayout, int numSg,
326 const uArch::uArch *uArch);
327
328/// Sets up the anchor layouts for dpas_mx operands (A, B, C/D, A_scale, and
329/// B_scale). The numSg and consumerLayout (optional) are only used by sg layout
330/// creation. A_scale and B_scale are optional.
331std::optional<
332 std::tuple<DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr,
333 DistributeLayoutAttr, DistributeLayoutAttr>>
334setupDpasMxLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy,
335 VectorType cdTy, VectorType aScaleTy, VectorType bScaleTy,
336 DistributeLayoutAttr consumerLayout, int numSg,
337 const uArch::uArch *uArch);
338
339/// Completes user-provided DPAS A/B/C-D anchors that carry only inst_data by
340/// filling in lane_layout / lane_data derived from the operand shapes (mirrors
341/// the InstData branch of setupDpasLayout). Returns nullopt if the uArch lacks
342/// the matmul instruction.
343std::optional<std::tuple<DistributeLayoutAttr, DistributeLayoutAttr,
344 DistributeLayoutAttr>>
345completeDpasLaneLayoutFromInstData(DistributeLayoutAttr aLayout,
346 DistributeLayoutAttr bLayout,
347 DistributeLayoutAttr cdLayout,
348 VectorType aTy, VectorType bTy,
349 VectorType cdTy, const uArch::uArch *uArch);
350
351/// Like completeDpasLaneLayoutFromInstData, but for dpas_mx: additionally
352/// re-derives the A_scale / B_scale layouts from the completed A / B layouts.
353std::optional<
354 std::tuple<DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr,
355 DistributeLayoutAttr, DistributeLayoutAttr>>
356completeDpasMxLaneLayoutFromInstData(DistributeLayoutAttr aLayout,
357 DistributeLayoutAttr bLayout,
358 DistributeLayoutAttr cdLayout,
359 VectorType aTy, VectorType bTy,
360 VectorType cdTy, VectorType aScaleTy,
361 VectorType bScaleTy,
362 const uArch::uArch *uArch);
363
364/// Gets the expected layout for a given consumer operand. This will check if
365/// the owning operation of the consumer operand is one of the special layout
366/// users and determine the expected layout accordingly.
367DistributeLayoutAttr getConsumerLayoutAt(OpOperand &operand);
368
369/// Returns true if `op` is safe and cheap to clone: it has no side effects,
370/// no regions, and all of its operands are themselves trivially
371/// rematerializable (e.g. `vector.step`, splat `arith.constant`, or
372/// `vector.create_mask` whose operands are constants).
374
375} // namespace xegpu
376
377} // namespace mlir
378
379#endif // MLIR_DIALECT_XEGPU_UTILS_XEGPUUTILS_H_
This class helps build Operations.
Definition Builders.h:209
This class represents a single result from folding an operation.
This class represents an operand of an operation.
Definition Value.h:254
This is a value defined by a result of an operation.
Definition Value.h:454
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:389
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
DistributeLayoutAttr inferShapeCastSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > resShape, ArrayRef< int64_t > srcShape)
Infers the source layout attribute for a shape cast operation given the result layout attribute,...
DistributeLayoutAttr setupLoadNdAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, DistributeLayoutAttr consumerLayout, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a load_nd operation.
DistributeLayoutAttr setupLoadMatrixAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize, DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch)
Sets up the anchor layout for load matrix operation.
DistributeLayoutAttr setupInterleaveResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy, DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch)
Sets up the result layout for an interleave operation to ensure the source layout can be safely deriv...
DistributeLayoutAttr inferTransposeSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > permutation)
Infers the source layout attribute for a transpose operation given the result layout attribute and pe...
DistributeLayoutAttr inferInsertSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > resShape, ArrayRef< int64_t > srcShape)
Infers the source layout attribute for an insert operation.
std::optional< std::tuple< DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr > > completeDpasMxLaneLayoutFromInstData(DistributeLayoutAttr aLayout, DistributeLayoutAttr bLayout, DistributeLayoutAttr cdLayout, VectorType aTy, VectorType bTy, VectorType cdTy, VectorType aScaleTy, VectorType bScaleTy, const uArch::uArch *uArch)
Like completeDpasLaneLayoutFromInstData, but for dpas_mx: additionally re-derives the A_scale / B_sca...
DistributeLayoutAttr inferInsertStridedSliceSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > resShape, ArrayRef< int64_t > srcShape)
Infers the source layout attribute for an insert strided slice operation given the result layout attr...
DistributeLayoutAttr setupStoreMatrixAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a store matrix operation.
void removeTemporaryLayoutAttrs(Operation *op)
Removes the temporary layout attributes for each OpOperand and OpResult of the given operation.
std::optional< std::tuple< DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr > > completeDpasLaneLayoutFromInstData(DistributeLayoutAttr aLayout, DistributeLayoutAttr bLayout, DistributeLayoutAttr cdLayout, VectorType aTy, VectorType bTy, VectorType cdTy, const uArch::uArch *uArch)
Completes user-provided DPAS A/B/C-D anchors that carry only inst_data by filling in lane_layout / la...
LayoutKind
Specifies the level of a layout hierarchy for comparison or propagation.
Definition XeGPU.h:32
SmallVector< NamedAttribute > dropInstDataOnAttrs(ArrayRef< NamedAttribute > attrs)
Updates the NamedAttribute sequence by dropping inst-data information from any DistributeLayoutAttr f...
DistributeLayoutAttr inferSourceLayoutFromResultForNonAnchorOp(OpOperand &operand, DistributeLayoutAttr resLayout)
Infers the source layout attribute for an operand using result layout attribute.
DistributeLayoutAttr inferInterleaveSourceLayout(DistributeLayoutAttr resLayout)
Infers the source layout attribute for an interleave operation given the result layout attribute.
bool recoverTemporaryLayouts(Operation *rootOp)
Attach layout attributes to all vector-type operands of operations within the given operation's neste...
DistributeLayoutAttr inferBroadcastSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > resShape, ArrayRef< int64_t > srcShape)
Infers the source layout attribute for a broadcast operation given the result layout attribute,...
std::optional< std::tuple< DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr > > setupDpasMxLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy, VectorType cdTy, VectorType aScaleTy, VectorType bScaleTy, DistributeLayoutAttr consumerLayout, int numSg, const uArch::uArch *uArch)
Sets up the anchor layouts for dpas_mx operands (A, B, C/D, A_scale, and B_scale).
SliceAttr setupMultiReductionResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, DistributeLayoutAttr consumerLayout, SmallVector< int64_t > reductionDims, int numSg, const uArch::uArch *uArch)
Note on the consumerLayout argument used by the consumer-driven setup* / complete* helpers below:
DistributeLayoutAttr setupLoadGatherAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize, DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch)
Sets up the anchor layout for a load gather operation.
llvm::function_ref< DistributeLayoutAttr(Value)> GetLayoutFnTy
Callable returning the propagated layout for a given Value, used by the layout-propagation helpers be...
std::optional< DistributeLayoutAttr > completeScatterLoadLaneLayoutFromInstData(DistributeLayoutAttr userSpecifiedLayout, DistributeLayoutAttr consumerLayout, Type elemTy, const xegpu::uArch::LoadGatherInstruction *uArchInstruction, const int subgroupSize)
If the consumer layout has only inst_data (no lane_layout/lane_data), completes it by running the cor...
DistributeLayoutAttr setupStoreScatterAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a store scatter operation.
DistributeLayoutAttr setupBitCastResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy, DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch)
Setup the result layout attribute for a bitcast operation based on element type bitwidths.
void removeLayoutAttr(const T &operandOrResult)
Removes the LayoutAttr for a given OpOperand or OpResult if it exists.
DistributeLayoutAttr inferMaskOffsetLayoutForScatterIO(DistributeLayoutAttr payloadLayout, int chunkSize)
Infers the layout attribute for mask and offset operand for Chunked load and store,...
SmallVector< NamedAttribute > dropSgLayoutAndDataOnAttrs(ArrayRef< NamedAttribute > attrs)
Updates the NamedAttribute sequence by dropping sg-layout and sg-data information from any Distribute...
DistributeLayoutAttr setupPrefetchNdAnchorLayout(LayoutKind layoutKind, TensorDescType tdescTy, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a prefetch_nd operation.
DistributeLayoutAttr inferExtractSourceLayout(DistributeLayoutAttr resLayout, ArrayRef< int64_t > resShape, ArrayRef< int64_t > srcShape)
Infers the source layout attribute for an extract operation.
LogicalResult resolveLayoutConflicts(Operation *target)
DistributeLayoutAttr inferBitCastSourceLayout(DistributeLayoutAttr resLayout, int resElemTyBitWidth, int srcElemTyBitWidth)
Infers the source layout attribute for a bitcast operation given the result layout attribute,...
DistributeLayoutAttr setupInsertStridedSliceResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy, DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch)
Sets up the result layout for an insert strided slice operation.
DistributeLayoutAttr inferReductionSourceLayout(DistributeLayoutAttr resLayout)
Infers the source layout attribute for a reduction operation given the result layout attribute and re...
std::optional< DistributeLayoutAttr > completeScatterStoreLaneLayoutFromInstData(DistributeLayoutAttr specifiedLayout, Type elemTy, const xegpu::uArch::StoreScatterInstruction *uArchInstruction, const int subgroupSize)
Like completeScatterLoadLaneLayoutFromInstData, but for scatter stores (store_scatter / store_matrix)...
std::optional< DistributeLayoutAttr > completeBlockStoreLaneLayoutFromInstData(DistributeLayoutAttr specifiedLayout, Type elemTy, const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction, const int subgroupSize)
Completes a user-provided 2D-block store_nd / prefetch_nd anchor that has only inst_data.
DistributeLayoutAttr inferDeinterleaveSourceLayout(DistributeLayoutAttr resLayout)
Infers the source layout attribute for a deinterleave operation given the result layout attribute.
DistributeLayoutAttr getConsumerLayoutAt(OpOperand &operand)
Gets the expected layout for a given consumer operand.
void removeLayoutAttrs(Operation *op)
Removes the DistributeLayoutAttr for each OpOperand and OpResult of the given operation if they exist...
DistributeLayoutAttr inferMultiReductionSourceLayout(DistributeLayoutAttr resLayout, SmallVector< int64_t > reduceDims)
Infers the source layout attribute for a reduction operation given the result layout attribute and re...
bool isTriviallyRematerializable(Operation *op)
Returns true if op is safe and cheap to clone: it has no side effects, no regions,...
LogicalResult propagateLayouts(OpBuilder &builder, Operation *target, LayoutKind layoutKind, unsigned indexBitWidth, bool printOnly=false)
DistributeLayoutAttr setupStoreNdAnchorLayout(LayoutKind layoutKind, VectorType vectorTy, int numSg, const uArch::uArch *uArch)
Sets up the anchor layout for a store_nd operation.
std::optional< DistributeLayoutAttr > completeBlockLoadLaneLayoutFromInstData(DistributeLayoutAttr specifiedLayout, DistributeLayoutAttr consumerLayout, Type elemTy, const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction, const int subgroupSize)
Like completeBlockStoreLaneLayoutFromInstData, but for load_nd.
LogicalResult propagateRegionArgsToInits(RegionBranchOpInterface regionOp, GetLayoutFnTy getLayoutOfValue)
Propagate layouts from a region branch op's region entry block arguments back to its init operands.
std::optional< std::tuple< DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr > > setupDpasLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy, VectorType cdTy, DistributeLayoutAttr consumerLayout, int numSg, const uArch::uArch *uArch)
Sets up the anchor layouts for a dpas operands (A, B, and C/D).
SliceAttr setupReductionResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, const uArch::uArch *uArch)
Sets up layout for Reduction operations by creating a SliceAttr for the result.
Include the generated interface declarations.