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/// Drops inst-data information from DistributeLayoutAttrs stored as inherent
97/// attributes on the operation.
99
100//===----------------------------------------------------------------------===//
101// Backward layout inference (result layout -> source layout)
102//===----------------------------------------------------------------------===//
103//
104// The infer*SourceLayout helpers below derive the layout of an operation's
105// source operand from the layout of its result. They implement the per-op
106// transfer functions used by the backward layout propagation analysis, which
107// flows layouts from anchor ops (dpas, store_nd, ...) back to their producers.
108
109/// Infers the source layout attribute for a broadcast operation given the
110/// result layout attribute, result shape, and source shape.
111DistributeLayoutAttr inferBroadcastSourceLayout(DistributeLayoutAttr resLayout,
112 ArrayRef<int64_t> resShape,
113 ArrayRef<int64_t> srcShape);
114
115/// Infers the source layout attribute for a reduction operation given the
116/// result layout attribute and reduced dims.
117DistributeLayoutAttr
118inferMultiReductionSourceLayout(DistributeLayoutAttr resLayout,
119 SmallVector<int64_t> reduceDims);
120
121/// Infers the source layout attribute for a reduction operation given the
122/// result layout attribute and reduced dims.
123DistributeLayoutAttr inferReductionSourceLayout(DistributeLayoutAttr resLayout);
124
125/// Infers the source layout attribute for a transpose operation given the
126/// result layout attribute and permutation.
127DistributeLayoutAttr inferTransposeSourceLayout(DistributeLayoutAttr resLayout,
128 ArrayRef<int64_t> permutation);
129
130/// Infers the source layout attribute for a bitcast operation given the
131/// result layout attribute, result element type bitwidth, and source element
132/// type bitwidth.
133DistributeLayoutAttr inferBitCastSourceLayout(DistributeLayoutAttr resLayout,
134 int resElemTyBitWidth,
135 int srcElemTyBitWidth);
136
137/// Infers the source layout attribute for an interleave operation given the
138/// result layout attribute. Interleave doubles the innermost dimension size.
139DistributeLayoutAttr
140inferInterleaveSourceLayout(DistributeLayoutAttr resLayout);
141
142/// Infers the source layout attribute for a deinterleave operation given the
143/// result layout attribute. Deinterleave halves the innermost dimension size.
144DistributeLayoutAttr
145inferDeinterleaveSourceLayout(DistributeLayoutAttr resLayout);
146
147/// Infers the source layout attribute for a shape cast operation given the
148/// result layout attribute, result shape, and source shape.
149DistributeLayoutAttr inferShapeCastSourceLayout(DistributeLayoutAttr resLayout,
150 ArrayRef<int64_t> resShape,
151 ArrayRef<int64_t> srcShape);
152
153/// Infers the source layout attribute for an insert strided slice operation
154/// given the result layout attribute, result shape, and source shape. Removes
155/// leading dimensions from the result layout to match the source shape size.
156DistributeLayoutAttr
157inferInsertStridedSliceSourceLayout(DistributeLayoutAttr resLayout,
158 ArrayRef<int64_t> resShape,
159 ArrayRef<int64_t> srcShape);
160
161/// Infers the source layout attribute for an insert operation.
162/// using same logic as inferInsertStridedSliceSourceLayout
163DistributeLayoutAttr inferInsertSourceLayout(DistributeLayoutAttr resLayout,
164 ArrayRef<int64_t> resShape,
165 ArrayRef<int64_t> srcShape);
166
167/// Infers the source layout attribute for an extract operation. Adds
168/// leading dimensions to the source layout to match the source shape size.
169DistributeLayoutAttr inferExtractSourceLayout(DistributeLayoutAttr resLayout,
170 ArrayRef<int64_t> resShape,
171 ArrayRef<int64_t> srcShape);
172
173/// Infers the source layout attribute for an operand using result layout
174/// attribute
175DistributeLayoutAttr
177 DistributeLayoutAttr resLayout);
178
179//===----------------------------------------------------------------------===//
180// Forward layout inference (source layout -> result layout)
181//===----------------------------------------------------------------------===//
182//
183// The infer*ResultLayout helpers below are the forward counterparts of the
184// infer*SourceLayout helpers above: given the layout of an operation's source
185// operand they derive the layout of its result. They are used by the local
186// forward-fill step in XeGPUPropagateLayout that assigns layouts to values not
187// reached by the backward propagation analysis (e.g. loop-carried values whose
188// only consumer is the next iteration).
189
190/// Infers the result layout attribute for a transpose operation given the
191/// source layout attribute and permutation. Inverse of
192/// inferTransposeSourceLayout.
193DistributeLayoutAttr inferTransposeResultLayout(DistributeLayoutAttr srcLayout,
194 ArrayRef<int64_t> permutation);
195
196/// Infers the result layout attribute for a shape cast operation given the
197/// source layout attribute, source shape, and result shape. Inverse of
198/// inferShapeCastSourceLayout. Returns nullptr for shape-cast patterns whose
199/// forward direction is ambiguous (e.g. unit-dim expansion).
200DistributeLayoutAttr inferShapeCastResultLayout(DistributeLayoutAttr srcLayout,
201 ArrayRef<int64_t> srcShape,
202 ArrayRef<int64_t> resShape);
203
204/// Infers the result layout attribute for a non-anchor operation from the
205/// layouts of its source operands (the forward counterpart of
206/// inferSourceLayoutFromResultForNonAnchorOp). `operandLayouts` is indexed by
207/// operand number; entries may be null for operands without a known layout.
208/// Returns nullptr when no forward rule applies (the result is then left
209/// un-laid-out).
211 Operation *op, ArrayRef<DistributeLayoutAttr> operandLayouts);
212
213/// Note on the `consumerLayout` argument used by the consumer-driven setup* /
214/// complete* helpers below:
215///
216/// Layout propagation is a backward dataflow analysis, so a producer learns its
217/// consumers' demands one at a time. The `consumerLayout` passed to these
218/// helpers is the *single* layout that the first consumer to reach the producer
219/// has requested (see `getConsumerLayoutAt`); these helpers do not pick among,
220/// or merge, multiple consumers, and they do not reason about cost (e.g. a
221/// consumer inside a loop vs. one outside). If a producer has several consumers
222/// with conflicting layout demands, only the first-arriving one shapes the
223/// producer's anchor layout here; any later, inconsistent consumer is left
224/// as-is and reconciled afterwards by the layout conflict resolution process
225/// (`ResolveLayoutConflicts`), which inserts a `convert_layout` op on that
226/// edge. So these helpers can always assume exactly one (possibly null)
227/// consumer layout to honor.
228
229/// Sets up layout for Multi-Reduction operations by creating a SliceAttr for
230/// the result.
231///
232/// This function first attempts to construct a source layout that, when
233/// sliced along reduction dimensions, produces a result layout compatible
234/// with the consumer's preferred layout. This minimizes data redistribution
235/// overhead. The SliceAttr for the result is then created based on the
236/// derived source layout and the specified reduction dimensions.
238 VectorType srcVectorTy,
239 DistributeLayoutAttr consumerLayout,
240 SmallVector<int64_t> reductionDims,
241 int numSg, const uArch::uArch *uArch);
242
243/// Sets up layout for Reduction operations by creating a SliceAttr for the
244/// result.
245SliceAttr setupReductionResultLayout(LayoutKind layoutKind,
246 VectorType srcVectorTy,
247 const uArch::uArch *uArch);
248
249/// Setup the result layout attribute for a bitcast operation based on element
250/// type bitwidths. This ensures the source layout can always be derived from
251/// the result layout.
252///
253/// When casting from a narrower to a wider element type (srcElemTyBitWidth <
254/// resElemTyBitWidth), the result layout's innermost dimension data sizes
255/// (inst_data, lane_data) are scaled up by the bitwidth ratio. This maintains
256/// the invariant that the source layout can be recovered by adjusting the
257/// result layout based on bitwidth ratio of input vs output.
258DistributeLayoutAttr setupBitCastResultLayout(
259 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
260 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
261
262/// Sets up the result layout for an interleave operation to ensure the source
263/// layout can be safely derived. Interleave doubles the innermost dimension,
264/// so the result layout must ensure that laneData is at least 2 (or a multiple
265/// of 2), and instData must be divisible by innermostDimLaneLayout * 2.
266DistributeLayoutAttr setupInterleaveResultLayout(
267 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
268 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
269
270/// Sets up the result layout for a shape cast that splits one source dim into
271/// several consecutive result dims, so that the source layout can be safely
272/// derived by collapsing each split group.
273///
274/// Within a group, the leading dims the lanes do not split and the first dim
275/// they do split may stay partial. Every dim after that is stretched to full:
276/// lane_data becomes dim_size / lane_layout, and inst_data the dim size.
277///
278/// Example:
279/// shape_cast: vector<16x1024xf32> -> vector<16x32x32xf32>
280/// Consumer layout: inst_data = [1, 2, 8], lane_layout = [1, 2, 8],
281/// lane_data = [1, 1, 1]
282/// Adjusted: inst_data = [1, 2, 32], lane_layout = [1, 2, 8],
283/// lane_data = [1, 1, 4]
284/// The adjusted layout collapses to inst_data = [1, 64],
285/// lane_layout = [1, 16], lane_data = [1, 4] on the source, whereas the
286/// unadjusted one would have collapsed to a strided inst_data = [1, 16].
287///
288/// Stretching does not guarantee the result layout is collapsible: collapsing
289/// also requires each lane to own one contiguous run of the source dim, which
290/// the consumer's lane_layout can rule out. This function checks that
291/// restriction on the stretched layout and returns nullptr when it does not
292/// hold, rejecting the consumer layout.
293///
294/// Example of a rejected layout:
295/// shape_cast: vector<16x128xf32> -> vector<16x2x4x16xf32>
296/// Consumer layout: inst_data = [1, 2, 2, 4], lane_layout = [1, 2, 2, 4],
297/// lane_data = [1, 1, 1, 1]
298/// Adjusted: inst_data = [1, 2, 4, 16], lane_layout = [1, 2, 2, 4],
299/// lane_data = [1, 1, 2, 4]
300/// Each lane owns two runs of 4 elements, 16 apart, instead of the 8
301/// contiguous source elements the collapsed lane_data = [1, 8] claims.
302///
303/// Only the inst_data and lane phases are handled; a subgroup-level layout is
304/// returned unchanged.
305DistributeLayoutAttr
306setupShapeCastResultLayout(LayoutKind layoutKind, VectorType srcVectorTy,
307 VectorType resVectorTy,
308 DistributeLayoutAttr consumerLayout);
309
310/// Sets up the result layout for an insert strided slice operation.
311/// Creates a result layout based on the specified layout kind (InstData or
312/// Lane).
314 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
315 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
316
317/// Sets up the anchor layout for a load gather operation.
318/// `contigChunkSize` is the per-lane contiguous run the offsets allow, from
319/// the op's `contiguity` attribute (1 when it is absent).
320DistributeLayoutAttr setupLoadGatherAnchorLayout(
321 LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize,
322 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
323
324/// Sets up the anchor layout for load matrix operation.
325DistributeLayoutAttr setupLoadMatrixAnchorLayout(
326 LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize,
327 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
328
329/// Sets up the anchor layout for a store scatter operation.
330/// `contigChunkSize` is the per-lane contiguous run the offsets allow, from
331/// the op's `contiguity` attribute (1 when it is absent).
332/// `numSg` is only used for Subgroup-kind layouts.
333DistributeLayoutAttr setupStoreScatterAnchorLayout(LayoutKind layoutKind,
334 VectorType vectorTy,
335 int contigChunkSize,
336 int numSg,
337 const uArch::uArch *uArch);
338
339/// Sets up the anchor layout for a store matrix operation.
340/// `numSg` is only used for Subgroup-kind layouts.
341DistributeLayoutAttr setupStoreMatrixAnchorLayout(LayoutKind layoutKind,
342 VectorType vectorTy,
343 int contigChunkSize,
344 int numSg,
345 const uArch::uArch *uArch);
346
347/// If the consumer layout has only inst_data (no lane_layout/lane_data),
348/// completes it by running the corresponding scatter-style Lane-kind setup
349/// rule with inst_data as the destination shape. The resulting lane info is
350/// merged with the consumer's inst_data so downstream setup* paths see a
351/// fully-populated layout.
352/// Returns the layout unchanged when it is null, has no inst_data, or already
353/// carries lane info; returns nullopt when the derived lane factorization does
354/// not divide the user's inst_data (an invalid inst_data).
355std::optional<DistributeLayoutAttr> completeScatterLoadLaneLayoutFromInstData(
356 DistributeLayoutAttr userSpecifiedLayout,
357 DistributeLayoutAttr consumerLayout, Type elemTy,
358 const xegpu::uArch::LoadGatherInstruction *uArchInstruction,
359 const int subgroupSize);
360
361/// Like completeScatterLoadLaneLayoutFromInstData, but for scatter stores
362/// (store_scatter / store_matrix). A store is a data sink: lane info is derived
363/// purely from inst_data using the uArch's StoreScatter per-lane store width,
364/// with no consumer layout to reuse.
365std::optional<DistributeLayoutAttr> completeScatterStoreLaneLayoutFromInstData(
366 DistributeLayoutAttr specifiedLayout, Type elemTy,
367 const xegpu::uArch::StoreScatterInstruction *uArchInstruction,
368 const int subgroupSize);
369
370/// Completes a user-provided 2D-block store_nd / prefetch_nd anchor that has
371/// only inst_data. These ops are data sinks, so lane info is derived purely
372/// from inst_data using the shared BlockIOInstructionInterface; one helper
373/// serves both store_nd and prefetch_nd.
374std::optional<DistributeLayoutAttr> completeBlockStoreLaneLayoutFromInstData(
375 DistributeLayoutAttr specifiedLayout, Type elemTy,
376 const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction,
377 const int subgroupSize);
378
379/// Like completeBlockStoreLaneLayoutFromInstData, but for load_nd. The consumer
380/// layout supplies the transform / transpose / packing properties; the lane
381/// factorization is recomputed from inst_data (load-side lane counts differ
382/// from the consumer's).
383std::optional<DistributeLayoutAttr> completeBlockLoadLaneLayoutFromInstData(
384 DistributeLayoutAttr specifiedLayout, DistributeLayoutAttr consumerLayout,
385 Type elemTy,
386 const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction,
387 const int subgroupSize);
388
389/// Sets up the anchor layout for a store_nd operation. StoreNd does not
390/// consider a consumer layout (it is a data sink), and picks its layout from
391/// uArch block parameters. `numSg` is only used for Subgroup-kind layouts.
392DistributeLayoutAttr setupStoreNdAnchorLayout(LayoutKind layoutKind,
393 VectorType vectorTy, int numSg,
394 const uArch::uArch *uArch);
395
396/// Sets up the anchor layout for a prefetch_nd operation. PrefetchNd has no
397/// value result and thus no consumer; it picks its layout from uArch block
398/// parameters. `numSg` is only used for Subgroup-kind layouts.
399DistributeLayoutAttr setupPrefetchNdAnchorLayout(LayoutKind layoutKind,
400 TensorDescType tdescTy,
401 int numSg,
402 const uArch::uArch *uArch);
403
404/// Sets up the anchor layout for a load_nd operation. LoadNd takes a
405/// (downstream) consumer layout and validates it against uArch constraints;
406/// when valid, the consumer's `inst_data` / `sg_layout` are honored.
407/// Otherwise defaults derived from uArch block parameters are used.
408/// `consumerLayout` must be presented. `numSg` is only used for Subgroup-kind
409/// layouts when the consumer does not already provide an sg_layout.
410DistributeLayoutAttr
411setupLoadNdAnchorLayout(LayoutKind layoutKind, VectorType vectorTy,
412 DistributeLayoutAttr consumerLayout, int numSg,
413 const uArch::uArch *uArch);
414
415/// Sets up the anchor layouts for a dpas operands (A, B, and C/D).
416/// The numSg and consumerLayout (optional) are only used by sg layout creation.
417std::optional<std::tuple<DistributeLayoutAttr, DistributeLayoutAttr,
418 DistributeLayoutAttr>>
419setupDpasLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy,
420 VectorType cdTy, DistributeLayoutAttr consumerLayout, int numSg,
421 const uArch::uArch *uArch);
422
423/// Sets up the anchor layouts for dpas_mx operands (A, B, C/D, A_scale, and
424/// B_scale). The numSg and consumerLayout (optional) are only used by sg layout
425/// creation. A_scale and B_scale are optional.
426std::optional<
427 std::tuple<DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr,
428 DistributeLayoutAttr, DistributeLayoutAttr>>
429setupDpasMxLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy,
430 VectorType cdTy, VectorType aScaleTy, VectorType bScaleTy,
431 DistributeLayoutAttr consumerLayout, int numSg,
432 const uArch::uArch *uArch);
433
434/// Completes user-provided DPAS A/B/C-D anchors that carry only inst_data by
435/// filling in lane_layout / lane_data derived from the operand shapes (mirrors
436/// the InstData branch of setupDpasLayout). Returns nullopt if the uArch lacks
437/// the matmul instruction.
438std::optional<std::tuple<DistributeLayoutAttr, DistributeLayoutAttr,
439 DistributeLayoutAttr>>
440completeDpasLaneLayoutFromInstData(DistributeLayoutAttr aLayout,
441 DistributeLayoutAttr bLayout,
442 DistributeLayoutAttr cdLayout,
443 VectorType aTy, VectorType bTy,
444 VectorType cdTy, const uArch::uArch *uArch);
445
446/// Like completeDpasLaneLayoutFromInstData, but for dpas_mx: additionally
447/// re-derives the A_scale / B_scale layouts from the completed A / B layouts.
448std::optional<
449 std::tuple<DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr,
450 DistributeLayoutAttr, DistributeLayoutAttr>>
451completeDpasMxLaneLayoutFromInstData(DistributeLayoutAttr aLayout,
452 DistributeLayoutAttr bLayout,
453 DistributeLayoutAttr cdLayout,
454 VectorType aTy, VectorType bTy,
455 VectorType cdTy, VectorType aScaleTy,
456 VectorType bScaleTy,
457 const uArch::uArch *uArch);
458
459/// Gets the expected layout for a given consumer operand. This will check if
460/// the owning operation of the consumer operand is one of the special layout
461/// users and determine the expected layout accordingly.
462DistributeLayoutAttr getConsumerLayoutAt(OpOperand &operand);
463
464/// Returns true if `op` is safe and cheap to clone: it has no side effects,
465/// no regions, and all of its operands are themselves trivially
466/// rematerializable (e.g. `vector.step`, splat `arith.constant`, or
467/// `vector.create_mask` whose operands are constants).
469
470} // namespace xegpu
471
472} // namespace mlir
473
474#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.
void dropInstDataOnInherentAttrs(Operation *op)
Drops inst-data information from DistributeLayoutAttrs stored as inherent attributes on the operation...
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 setupShapeCastResultLayout(LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy, DistributeLayoutAttr consumerLayout)
Sets up the result layout for a shape cast that splits one source dim into several consecutive result...
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.