MLIR 24.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/// Propagate layouts from a region branch terminator's forwarded operands to
57/// the matching region results / successor block arguments. For each operand
58/// that a terminator (e.g. scf.yield) forwards to a successor input, the
59/// operand's layout is obtained via `getLayoutOfValue` and recorded on the
60/// successor input when it is an op result. Returns failure if a forwarded
61/// operand has no assigned layout.
63 RegionBranchTerminatorOpInterface terminator,
64 GetLayoutFnTy getLayoutOfValue);
65
66/// Attach layout attributes to all vector-type operands of operations within
67/// the given operation's nested region. Reports an error if any vector operand
68/// lacks a layout attribute.
70
71/// Removes the LayoutAttr for a given OpOperand or OpResult if it exists.
72template <typename T,
73 typename = std::enable_if_t<std::is_same_v<T, OpOperand> ||
74 std::is_same_v<T, OpResult>>>
75void removeLayoutAttr(const T &operandOrResult);
76
77/// Removes the DistributeLayoutAttr for each OpOperand and OpResult of the
78/// given operation if they exist. If the operation contains regions, it is also
79/// applied recursively to the contained operations
81
82/// Removes the temporary layout attributes for each OpOperand and OpResult of
83/// the given operation. Recursive for contained operations if the given
84/// operation contains regions.
86
87/// Updates the NamedAttribute sequence by dropping sg-layout and
88/// sg-data information from any DistributeLayoutAttr found.
91
92/// Updates the NamedAttribute sequence by dropping inst-data information from
93/// any DistributeLayoutAttr found.
95
96//===----------------------------------------------------------------------===//
97// Backward layout inference (result layout -> source layout)
98//===----------------------------------------------------------------------===//
99//
100// The infer*SourceLayout helpers below derive the layout of an operation's
101// source operand from the layout of its result. They implement the per-op
102// transfer functions used by the backward layout propagation analysis, which
103// flows layouts from anchor ops (dpas, store_nd, ...) back to their producers.
104
105/// Infers the source layout attribute for a broadcast operation given the
106/// result layout attribute, result shape, and source shape.
107DistributeLayoutAttr inferBroadcastSourceLayout(DistributeLayoutAttr resLayout,
108 ArrayRef<int64_t> resShape,
109 ArrayRef<int64_t> srcShape);
110
111/// Infers the source layout attribute for a reduction operation given the
112/// result layout attribute and reduced dims.
113DistributeLayoutAttr
114inferMultiReductionSourceLayout(DistributeLayoutAttr resLayout,
115 SmallVector<int64_t> reduceDims);
116
117/// Infers the source layout attribute for a reduction operation given the
118/// result layout attribute and reduced dims.
119DistributeLayoutAttr inferReductionSourceLayout(DistributeLayoutAttr resLayout);
120
121/// Infers the source layout attribute for a transpose operation given the
122/// result layout attribute and permutation.
123DistributeLayoutAttr inferTransposeSourceLayout(DistributeLayoutAttr resLayout,
124 ArrayRef<int64_t> permutation);
125
126/// Infers the source layout attribute for a bitcast operation given the
127/// result layout attribute, result element type bitwidth, and source element
128/// type bitwidth.
129DistributeLayoutAttr inferBitCastSourceLayout(DistributeLayoutAttr resLayout,
130 int resElemTyBitWidth,
131 int srcElemTyBitWidth);
132
133/// Infers the source layout attribute for an interleave operation given the
134/// result layout attribute. Interleave doubles the innermost dimension size.
135DistributeLayoutAttr
136inferInterleaveSourceLayout(DistributeLayoutAttr resLayout);
137
138/// Infers the source layout attribute for a deinterleave operation given the
139/// result layout attribute. Deinterleave halves the innermost dimension size.
140DistributeLayoutAttr
141inferDeinterleaveSourceLayout(DistributeLayoutAttr resLayout);
142
143/// Infers the source layout attribute for a shape cast operation given the
144/// result layout attribute, result shape, and source shape.
145DistributeLayoutAttr inferShapeCastSourceLayout(DistributeLayoutAttr resLayout,
146 ArrayRef<int64_t> resShape,
147 ArrayRef<int64_t> srcShape);
148
149/// Infers the source layout attribute for an insert strided slice operation
150/// given the result layout attribute, result shape, and source shape. Removes
151/// leading dimensions from the result layout to match the source shape size.
152DistributeLayoutAttr
153inferInsertStridedSliceSourceLayout(DistributeLayoutAttr resLayout,
154 ArrayRef<int64_t> resShape,
155 ArrayRef<int64_t> srcShape);
156
157/// Infers the source layout attribute for an insert operation.
158/// using same logic as inferInsertStridedSliceSourceLayout
159DistributeLayoutAttr inferInsertSourceLayout(DistributeLayoutAttr resLayout,
160 ArrayRef<int64_t> resShape,
161 ArrayRef<int64_t> srcShape);
162
163/// Infers the source layout attribute for an extract operation. Adds
164/// leading dimensions to the source layout to match the source shape size.
165DistributeLayoutAttr inferExtractSourceLayout(DistributeLayoutAttr resLayout,
166 ArrayRef<int64_t> resShape,
167 ArrayRef<int64_t> srcShape);
168
169/// Infers the layout attribute for mask and offset operand for Chunked load
170/// and store, given the anchor layout attribute for the value being load/store.
171DistributeLayoutAttr
172inferMaskOffsetLayoutForScatterIO(DistributeLayoutAttr payloadLayout,
173 int chunkSize);
174
175/// Infers the source layout attribute for an operand using result layout
176/// attribute
177DistributeLayoutAttr
179 DistributeLayoutAttr resLayout);
180
181//===----------------------------------------------------------------------===//
182// Forward layout inference (source layout -> result layout)
183//===----------------------------------------------------------------------===//
184//
185// The infer*ResultLayout helpers below are the forward counterparts of the
186// infer*SourceLayout helpers above: given the layout of an operation's source
187// operand they derive the layout of its result. They are used by the local
188// forward-fill step in XeGPUPropagateLayout that assigns layouts to values not
189// reached by the backward propagation analysis (e.g. loop-carried values whose
190// only consumer is the next iteration).
191
192/// Infers the result layout attribute for a transpose operation given the
193/// source layout attribute and permutation. Inverse of
194/// inferTransposeSourceLayout.
195DistributeLayoutAttr inferTransposeResultLayout(DistributeLayoutAttr srcLayout,
196 ArrayRef<int64_t> permutation);
197
198/// Infers the result layout attribute for a shape cast operation given the
199/// source layout attribute, source shape, and result shape. Inverse of
200/// inferShapeCastSourceLayout. Returns nullptr for shape-cast patterns whose
201/// forward direction is ambiguous (e.g. unit-dim expansion).
202DistributeLayoutAttr inferShapeCastResultLayout(DistributeLayoutAttr srcLayout,
203 ArrayRef<int64_t> srcShape,
204 ArrayRef<int64_t> resShape);
205
206/// Infers the result layout attribute for a non-anchor operation from the
207/// layouts of its source operands (the forward counterpart of
208/// inferSourceLayoutFromResultForNonAnchorOp). `operandLayouts` is indexed by
209/// operand number; entries may be null for operands without a known layout.
210/// Returns nullptr when no forward rule applies (the result is then left
211/// un-laid-out).
213 Operation *op, ArrayRef<DistributeLayoutAttr> operandLayouts);
214
215/// Note on the `consumerLayout` argument used by the consumer-driven setup* /
216/// complete* helpers below:
217///
218/// Layout propagation is a backward dataflow analysis, so a producer learns its
219/// consumers' demands one at a time. The `consumerLayout` passed to these
220/// helpers is the *single* layout that the first consumer to reach the producer
221/// has requested (see `getConsumerLayoutAt`); these helpers do not pick among,
222/// or merge, multiple consumers, and they do not reason about cost (e.g. a
223/// consumer inside a loop vs. one outside). If a producer has several consumers
224/// with conflicting layout demands, only the first-arriving one shapes the
225/// producer's anchor layout here; any later, inconsistent consumer is left
226/// as-is and reconciled afterwards by the layout conflict resolution process
227/// (`ResolveLayoutConflicts`), which inserts a `convert_layout` op on that
228/// edge. So these helpers can always assume exactly one (possibly null)
229/// consumer layout to honor.
230
231/// Sets up layout for Multi-Reduction operations by creating a SliceAttr for
232/// the result.
233///
234/// This function first attempts to construct a source layout that, when
235/// sliced along reduction dimensions, produces a result layout compatible
236/// with the consumer's preferred layout. This minimizes data redistribution
237/// overhead. The SliceAttr for the result is then created based on the
238/// derived source layout and the specified reduction dimensions.
240 VectorType srcVectorTy,
241 DistributeLayoutAttr consumerLayout,
242 SmallVector<int64_t> reductionDims,
243 int numSg, const uArch::uArch *uArch);
244
245/// Sets up layout for Reduction operations by creating a SliceAttr for the
246/// result.
247SliceAttr setupReductionResultLayout(LayoutKind layoutKind,
248 VectorType srcVectorTy,
249 const uArch::uArch *uArch);
250
251/// Setup the result layout attribute for a bitcast operation based on element
252/// type bitwidths. This ensures the source layout can always be derived from
253/// the result layout.
254///
255/// When casting from a narrower to a wider element type (srcElemTyBitWidth <
256/// resElemTyBitWidth), the result layout's innermost dimension data sizes
257/// (inst_data, lane_data) are scaled up by the bitwidth ratio. This maintains
258/// the invariant that the source layout can be recovered by adjusting the
259/// result layout based on bitwidth ratio of input vs output.
260DistributeLayoutAttr setupBitCastResultLayout(
261 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
262 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
263
264/// Sets up the result layout for an interleave operation to ensure the source
265/// layout can be safely derived. Interleave doubles the innermost dimension,
266/// so the result layout must ensure that laneData is at least 2 (or a multiple
267/// of 2), and instData must be divisible by innermostDimLaneLayout * 2.
268DistributeLayoutAttr setupInterleaveResultLayout(
269 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
270 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
271
272/// Sets up the result layout for an insert strided slice operation.
273/// Creates a result layout based on the specified layout kind (InstData or
274/// Lane).
276 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
277 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
278
279/// Sets up the anchor layout for a load gather operation.
280DistributeLayoutAttr setupLoadGatherAnchorLayout(
281 LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize,
282 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
283
284/// Sets up the anchor layout for load matrix operation.
285DistributeLayoutAttr setupLoadMatrixAnchorLayout(
286 LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize,
287 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
288
289/// Sets up the anchor layout for a store scatter operation.
290/// `numSg` is only used for Subgroup-kind layouts.
291DistributeLayoutAttr setupStoreScatterAnchorLayout(LayoutKind layoutKind,
292 VectorType vectorTy,
293 int contigChunkSize,
294 int numSg,
295 const uArch::uArch *uArch);
296
297/// Sets up the anchor layout for a store matrix operation.
298/// `numSg` is only used for Subgroup-kind layouts.
299DistributeLayoutAttr setupStoreMatrixAnchorLayout(LayoutKind layoutKind,
300 VectorType vectorTy,
301 int contigChunkSize,
302 int numSg,
303 const uArch::uArch *uArch);
304
305/// If the consumer layout has only inst_data (no lane_layout/lane_data),
306/// completes it by running the corresponding scatter-style Lane-kind setup
307/// rule with inst_data as the destination shape. The resulting lane info is
308/// merged with the consumer's inst_data so downstream setup* paths see a
309/// fully-populated layout.
310/// Returns the layout unchanged when it is null, has no inst_data, or already
311/// carries lane info; returns nullopt when the derived lane factorization does
312/// not divide the user's inst_data (an invalid inst_data).
313std::optional<DistributeLayoutAttr> completeScatterLoadLaneLayoutFromInstData(
314 DistributeLayoutAttr userSpecifiedLayout,
315 DistributeLayoutAttr consumerLayout, Type elemTy,
316 const xegpu::uArch::LoadGatherInstruction *uArchInstruction,
317 const int subgroupSize);
318
319/// Like completeScatterLoadLaneLayoutFromInstData, but for scatter stores
320/// (store_scatter / store_matrix). A store is a data sink: lane info is derived
321/// purely from inst_data using the uArch's StoreScatter per-lane store width,
322/// with no consumer layout to reuse.
323std::optional<DistributeLayoutAttr> completeScatterStoreLaneLayoutFromInstData(
324 DistributeLayoutAttr specifiedLayout, Type elemTy,
325 const xegpu::uArch::StoreScatterInstruction *uArchInstruction,
326 const int subgroupSize);
327
328/// Completes a user-provided 2D-block store_nd / prefetch_nd anchor that has
329/// only inst_data. These ops are data sinks, so lane info is derived purely
330/// from inst_data using the shared BlockIOInstructionInterface; one helper
331/// serves both store_nd and prefetch_nd.
332std::optional<DistributeLayoutAttr> completeBlockStoreLaneLayoutFromInstData(
333 DistributeLayoutAttr specifiedLayout, Type elemTy,
334 const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction,
335 const int subgroupSize);
336
337/// Like completeBlockStoreLaneLayoutFromInstData, but for load_nd. The consumer
338/// layout supplies the transform / transpose / packing properties; the lane
339/// factorization is recomputed from inst_data (load-side lane counts differ
340/// from the consumer's).
341std::optional<DistributeLayoutAttr> completeBlockLoadLaneLayoutFromInstData(
342 DistributeLayoutAttr specifiedLayout, DistributeLayoutAttr consumerLayout,
343 Type elemTy,
344 const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction,
345 const int subgroupSize);
346
347/// Sets up the anchor layout for a store_nd operation. StoreNd does not
348/// consider a consumer layout (it is a data sink), and picks its layout from
349/// uArch block parameters. `numSg` is only used for Subgroup-kind layouts.
350DistributeLayoutAttr setupStoreNdAnchorLayout(LayoutKind layoutKind,
351 VectorType vectorTy, int numSg,
352 const uArch::uArch *uArch);
353
354/// Sets up the anchor layout for a prefetch_nd operation. PrefetchNd has no
355/// value result and thus no consumer; it picks its layout from uArch block
356/// parameters. `numSg` is only used for Subgroup-kind layouts.
357DistributeLayoutAttr setupPrefetchNdAnchorLayout(LayoutKind layoutKind,
358 TensorDescType tdescTy,
359 int numSg,
360 const uArch::uArch *uArch);
361
362/// Sets up the anchor layout for a load_nd operation. LoadNd takes a
363/// (downstream) consumer layout and validates it against uArch constraints;
364/// when valid, the consumer's `inst_data` / `sg_layout` are honored.
365/// Otherwise defaults derived from uArch block parameters are used.
366/// `consumerLayout` must be presented. `numSg` is only used for Subgroup-kind
367/// layouts when the consumer does not already provide an sg_layout.
368DistributeLayoutAttr
369setupLoadNdAnchorLayout(LayoutKind layoutKind, VectorType vectorTy,
370 DistributeLayoutAttr consumerLayout, int numSg,
371 const uArch::uArch *uArch);
372
373/// Sets up the anchor layouts for a dpas operands (A, B, and C/D).
374/// The numSg and consumerLayout (optional) are only used by sg layout creation.
375std::optional<std::tuple<DistributeLayoutAttr, DistributeLayoutAttr,
376 DistributeLayoutAttr>>
377setupDpasLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy,
378 VectorType cdTy, DistributeLayoutAttr consumerLayout, int numSg,
379 const uArch::uArch *uArch);
380
381/// Sets up the anchor layouts for dpas_mx operands (A, B, C/D, A_scale, and
382/// B_scale). The numSg and consumerLayout (optional) are only used by sg layout
383/// creation. A_scale and B_scale are optional.
384std::optional<
385 std::tuple<DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr,
386 DistributeLayoutAttr, DistributeLayoutAttr>>
387setupDpasMxLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy,
388 VectorType cdTy, VectorType aScaleTy, VectorType bScaleTy,
389 DistributeLayoutAttr consumerLayout, int numSg,
390 const uArch::uArch *uArch);
391
392/// Completes user-provided DPAS A/B/C-D anchors that carry only inst_data by
393/// filling in lane_layout / lane_data derived from the operand shapes (mirrors
394/// the InstData branch of setupDpasLayout). Returns nullopt if the uArch lacks
395/// the matmul instruction.
396std::optional<std::tuple<DistributeLayoutAttr, DistributeLayoutAttr,
397 DistributeLayoutAttr>>
398completeDpasLaneLayoutFromInstData(DistributeLayoutAttr aLayout,
399 DistributeLayoutAttr bLayout,
400 DistributeLayoutAttr cdLayout,
401 VectorType aTy, VectorType bTy,
402 VectorType cdTy, const uArch::uArch *uArch);
403
404/// Like completeDpasLaneLayoutFromInstData, but for dpas_mx: additionally
405/// re-derives the A_scale / B_scale layouts from the completed A / B layouts.
406std::optional<
407 std::tuple<DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr,
408 DistributeLayoutAttr, DistributeLayoutAttr>>
409completeDpasMxLaneLayoutFromInstData(DistributeLayoutAttr aLayout,
410 DistributeLayoutAttr bLayout,
411 DistributeLayoutAttr cdLayout,
412 VectorType aTy, VectorType bTy,
413 VectorType cdTy, VectorType aScaleTy,
414 VectorType bScaleTy,
415 const uArch::uArch *uArch);
416
417/// Gets the expected layout for a given consumer operand. This will check if
418/// the owning operation of the consumer operand is one of the special layout
419/// users and determine the expected layout accordingly.
420DistributeLayoutAttr getConsumerLayoutAt(OpOperand &operand);
421
422/// Returns true if `op` is safe and cheap to clone: it has no side effects,
423/// no regions, and all of its operands are themselves trivially
424/// rematerializable (e.g. `vector.step`, splat `arith.constant`, or
425/// `vector.create_mask` whose operands are constants).
427
428} // namespace xegpu
429
430} // namespace mlir
431
432#endif // MLIR_DIALECT_XEGPU_UTILS_XEGPUUTILS_H_
This class helps build Operations.
Definition Builders.h:210
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 inferResultLayoutFromSourceForNonAnchorOp(Operation *op, ArrayRef< DistributeLayoutAttr > operandLayouts)
Infers the result layout attribute for a non-anchor operation from the layouts of its source operands...
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.
LogicalResult propagateYieldOperandsToRegionResults(RegionBranchTerminatorOpInterface terminator, GetLayoutFnTy getLayoutOfValue)
Propagate layouts from a region branch terminator's forwarded operands to the matching region results...
DistributeLayoutAttr inferShapeCastResultLayout(DistributeLayoutAttr srcLayout, ArrayRef< int64_t > srcShape, ArrayRef< int64_t > resShape)
Infers the result layout attribute for a shape cast operation given the source layout attribute,...
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.
DistributeLayoutAttr inferTransposeResultLayout(DistributeLayoutAttr srcLayout, ArrayRef< int64_t > permutation)
Infers the result layout attribute for a transpose operation given the source layout attribute and pe...
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.