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 layout attribute for mask and offset operand for Chunked load
174/// and store, given the anchor layout attribute for the value being load/store.
175DistributeLayoutAttr
176inferMaskOffsetLayoutForScatterIO(DistributeLayoutAttr payloadLayout,
177 int chunkSize);
178
179/// Infers the source layout attribute for an operand using result layout
180/// attribute
181DistributeLayoutAttr
183 DistributeLayoutAttr resLayout);
184
185//===----------------------------------------------------------------------===//
186// Forward layout inference (source layout -> result layout)
187//===----------------------------------------------------------------------===//
188//
189// The infer*ResultLayout helpers below are the forward counterparts of the
190// infer*SourceLayout helpers above: given the layout of an operation's source
191// operand they derive the layout of its result. They are used by the local
192// forward-fill step in XeGPUPropagateLayout that assigns layouts to values not
193// reached by the backward propagation analysis (e.g. loop-carried values whose
194// only consumer is the next iteration).
195
196/// Infers the result layout attribute for a transpose operation given the
197/// source layout attribute and permutation. Inverse of
198/// inferTransposeSourceLayout.
199DistributeLayoutAttr inferTransposeResultLayout(DistributeLayoutAttr srcLayout,
200 ArrayRef<int64_t> permutation);
201
202/// Infers the result layout attribute for a shape cast operation given the
203/// source layout attribute, source shape, and result shape. Inverse of
204/// inferShapeCastSourceLayout. Returns nullptr for shape-cast patterns whose
205/// forward direction is ambiguous (e.g. unit-dim expansion).
206DistributeLayoutAttr inferShapeCastResultLayout(DistributeLayoutAttr srcLayout,
207 ArrayRef<int64_t> srcShape,
208 ArrayRef<int64_t> resShape);
209
210/// Infers the result layout attribute for a non-anchor operation from the
211/// layouts of its source operands (the forward counterpart of
212/// inferSourceLayoutFromResultForNonAnchorOp). `operandLayouts` is indexed by
213/// operand number; entries may be null for operands without a known layout.
214/// Returns nullptr when no forward rule applies (the result is then left
215/// un-laid-out).
217 Operation *op, ArrayRef<DistributeLayoutAttr> operandLayouts);
218
219/// Note on the `consumerLayout` argument used by the consumer-driven setup* /
220/// complete* helpers below:
221///
222/// Layout propagation is a backward dataflow analysis, so a producer learns its
223/// consumers' demands one at a time. The `consumerLayout` passed to these
224/// helpers is the *single* layout that the first consumer to reach the producer
225/// has requested (see `getConsumerLayoutAt`); these helpers do not pick among,
226/// or merge, multiple consumers, and they do not reason about cost (e.g. a
227/// consumer inside a loop vs. one outside). If a producer has several consumers
228/// with conflicting layout demands, only the first-arriving one shapes the
229/// producer's anchor layout here; any later, inconsistent consumer is left
230/// as-is and reconciled afterwards by the layout conflict resolution process
231/// (`ResolveLayoutConflicts`), which inserts a `convert_layout` op on that
232/// edge. So these helpers can always assume exactly one (possibly null)
233/// consumer layout to honor.
234
235/// Sets up layout for Multi-Reduction operations by creating a SliceAttr for
236/// the result.
237///
238/// This function first attempts to construct a source layout that, when
239/// sliced along reduction dimensions, produces a result layout compatible
240/// with the consumer's preferred layout. This minimizes data redistribution
241/// overhead. The SliceAttr for the result is then created based on the
242/// derived source layout and the specified reduction dimensions.
244 VectorType srcVectorTy,
245 DistributeLayoutAttr consumerLayout,
246 SmallVector<int64_t> reductionDims,
247 int numSg, const uArch::uArch *uArch);
248
249/// Sets up layout for Reduction operations by creating a SliceAttr for the
250/// result.
251SliceAttr setupReductionResultLayout(LayoutKind layoutKind,
252 VectorType srcVectorTy,
253 const uArch::uArch *uArch);
254
255/// Setup the result layout attribute for a bitcast operation based on element
256/// type bitwidths. This ensures the source layout can always be derived from
257/// the result layout.
258///
259/// When casting from a narrower to a wider element type (srcElemTyBitWidth <
260/// resElemTyBitWidth), the result layout's innermost dimension data sizes
261/// (inst_data, lane_data) are scaled up by the bitwidth ratio. This maintains
262/// the invariant that the source layout can be recovered by adjusting the
263/// result layout based on bitwidth ratio of input vs output.
264DistributeLayoutAttr setupBitCastResultLayout(
265 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
266 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
267
268/// Sets up the result layout for an interleave operation to ensure the source
269/// layout can be safely derived. Interleave doubles the innermost dimension,
270/// so the result layout must ensure that laneData is at least 2 (or a multiple
271/// of 2), and instData must be divisible by innermostDimLaneLayout * 2.
272DistributeLayoutAttr setupInterleaveResultLayout(
273 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
274 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
275
276/// Sets up the result layout for an insert strided slice operation.
277/// Creates a result layout based on the specified layout kind (InstData or
278/// Lane).
280 LayoutKind layoutKind, VectorType srcVectorTy, VectorType resVectorTy,
281 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
282
283/// Sets up the anchor layout for a load gather operation.
284DistributeLayoutAttr setupLoadGatherAnchorLayout(
285 LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize,
286 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
287
288/// Sets up the anchor layout for load matrix operation.
289DistributeLayoutAttr setupLoadMatrixAnchorLayout(
290 LayoutKind layoutKind, VectorType vectorTy, int contigChunkSize,
291 DistributeLayoutAttr consumerLayout, const uArch::uArch *uArch);
292
293/// Sets up the anchor layout for a store scatter operation.
294/// `numSg` is only used for Subgroup-kind layouts.
295DistributeLayoutAttr setupStoreScatterAnchorLayout(LayoutKind layoutKind,
296 VectorType vectorTy,
297 int contigChunkSize,
298 int numSg,
299 const uArch::uArch *uArch);
300
301/// Sets up the anchor layout for a store matrix operation.
302/// `numSg` is only used for Subgroup-kind layouts.
303DistributeLayoutAttr setupStoreMatrixAnchorLayout(LayoutKind layoutKind,
304 VectorType vectorTy,
305 int contigChunkSize,
306 int numSg,
307 const uArch::uArch *uArch);
308
309/// If the consumer layout has only inst_data (no lane_layout/lane_data),
310/// completes it by running the corresponding scatter-style Lane-kind setup
311/// rule with inst_data as the destination shape. The resulting lane info is
312/// merged with the consumer's inst_data so downstream setup* paths see a
313/// fully-populated layout.
314/// Returns the layout unchanged when it is null, has no inst_data, or already
315/// carries lane info; returns nullopt when the derived lane factorization does
316/// not divide the user's inst_data (an invalid inst_data).
317std::optional<DistributeLayoutAttr> completeScatterLoadLaneLayoutFromInstData(
318 DistributeLayoutAttr userSpecifiedLayout,
319 DistributeLayoutAttr consumerLayout, Type elemTy,
320 const xegpu::uArch::LoadGatherInstruction *uArchInstruction,
321 const int subgroupSize);
322
323/// Like completeScatterLoadLaneLayoutFromInstData, but for scatter stores
324/// (store_scatter / store_matrix). A store is a data sink: lane info is derived
325/// purely from inst_data using the uArch's StoreScatter per-lane store width,
326/// with no consumer layout to reuse.
327std::optional<DistributeLayoutAttr> completeScatterStoreLaneLayoutFromInstData(
328 DistributeLayoutAttr specifiedLayout, Type elemTy,
329 const xegpu::uArch::StoreScatterInstruction *uArchInstruction,
330 const int subgroupSize);
331
332/// Completes a user-provided 2D-block store_nd / prefetch_nd anchor that has
333/// only inst_data. These ops are data sinks, so lane info is derived purely
334/// from inst_data using the shared BlockIOInstructionInterface; one helper
335/// serves both store_nd and prefetch_nd.
336std::optional<DistributeLayoutAttr> completeBlockStoreLaneLayoutFromInstData(
337 DistributeLayoutAttr specifiedLayout, Type elemTy,
338 const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction,
339 const int subgroupSize);
340
341/// Like completeBlockStoreLaneLayoutFromInstData, but for load_nd. The consumer
342/// layout supplies the transform / transpose / packing properties; the lane
343/// factorization is recomputed from inst_data (load-side lane counts differ
344/// from the consumer's).
345std::optional<DistributeLayoutAttr> completeBlockLoadLaneLayoutFromInstData(
346 DistributeLayoutAttr specifiedLayout, DistributeLayoutAttr consumerLayout,
347 Type elemTy,
348 const xegpu::uArch::BlockIOInstructionInterface *uArchInstruction,
349 const int subgroupSize);
350
351/// Sets up the anchor layout for a store_nd operation. StoreNd does not
352/// consider a consumer layout (it is a data sink), and picks its layout from
353/// uArch block parameters. `numSg` is only used for Subgroup-kind layouts.
354DistributeLayoutAttr setupStoreNdAnchorLayout(LayoutKind layoutKind,
355 VectorType vectorTy, int numSg,
356 const uArch::uArch *uArch);
357
358/// Sets up the anchor layout for a prefetch_nd operation. PrefetchNd has no
359/// value result and thus no consumer; it picks its layout from uArch block
360/// parameters. `numSg` is only used for Subgroup-kind layouts.
361DistributeLayoutAttr setupPrefetchNdAnchorLayout(LayoutKind layoutKind,
362 TensorDescType tdescTy,
363 int numSg,
364 const uArch::uArch *uArch);
365
366/// Sets up the anchor layout for a load_nd operation. LoadNd takes a
367/// (downstream) consumer layout and validates it against uArch constraints;
368/// when valid, the consumer's `inst_data` / `sg_layout` are honored.
369/// Otherwise defaults derived from uArch block parameters are used.
370/// `consumerLayout` must be presented. `numSg` is only used for Subgroup-kind
371/// layouts when the consumer does not already provide an sg_layout.
372DistributeLayoutAttr
373setupLoadNdAnchorLayout(LayoutKind layoutKind, VectorType vectorTy,
374 DistributeLayoutAttr consumerLayout, int numSg,
375 const uArch::uArch *uArch);
376
377/// Sets up the anchor layouts for a dpas operands (A, B, and C/D).
378/// The numSg and consumerLayout (optional) are only used by sg layout creation.
379std::optional<std::tuple<DistributeLayoutAttr, DistributeLayoutAttr,
380 DistributeLayoutAttr>>
381setupDpasLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy,
382 VectorType cdTy, DistributeLayoutAttr consumerLayout, int numSg,
383 const uArch::uArch *uArch);
384
385/// Sets up the anchor layouts for dpas_mx operands (A, B, C/D, A_scale, and
386/// B_scale). The numSg and consumerLayout (optional) are only used by sg layout
387/// creation. A_scale and B_scale are optional.
388std::optional<
389 std::tuple<DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr,
390 DistributeLayoutAttr, DistributeLayoutAttr>>
391setupDpasMxLayout(LayoutKind layoutKind, VectorType aTy, VectorType bTy,
392 VectorType cdTy, VectorType aScaleTy, VectorType bScaleTy,
393 DistributeLayoutAttr consumerLayout, int numSg,
394 const uArch::uArch *uArch);
395
396/// Completes user-provided DPAS A/B/C-D anchors that carry only inst_data by
397/// filling in lane_layout / lane_data derived from the operand shapes (mirrors
398/// the InstData branch of setupDpasLayout). Returns nullopt if the uArch lacks
399/// the matmul instruction.
400std::optional<std::tuple<DistributeLayoutAttr, DistributeLayoutAttr,
401 DistributeLayoutAttr>>
402completeDpasLaneLayoutFromInstData(DistributeLayoutAttr aLayout,
403 DistributeLayoutAttr bLayout,
404 DistributeLayoutAttr cdLayout,
405 VectorType aTy, VectorType bTy,
406 VectorType cdTy, const uArch::uArch *uArch);
407
408/// Like completeDpasLaneLayoutFromInstData, but for dpas_mx: additionally
409/// re-derives the A_scale / B_scale layouts from the completed A / B layouts.
410std::optional<
411 std::tuple<DistributeLayoutAttr, DistributeLayoutAttr, DistributeLayoutAttr,
412 DistributeLayoutAttr, DistributeLayoutAttr>>
413completeDpasMxLaneLayoutFromInstData(DistributeLayoutAttr aLayout,
414 DistributeLayoutAttr bLayout,
415 DistributeLayoutAttr cdLayout,
416 VectorType aTy, VectorType bTy,
417 VectorType cdTy, VectorType aScaleTy,
418 VectorType bScaleTy,
419 const uArch::uArch *uArch);
420
421/// Gets the expected layout for a given consumer operand. This will check if
422/// the owning operation of the consumer operand is one of the special layout
423/// users and determine the expected layout accordingly.
424DistributeLayoutAttr getConsumerLayoutAt(OpOperand &operand);
425
426/// Returns true if `op` is safe and cheap to clone: it has no side effects,
427/// no regions, and all of its operands are themselves trivially
428/// rematerializable (e.g. `vector.step`, splat `arith.constant`, or
429/// `vector.create_mask` whose operands are constants).
431
432} // namespace xegpu
433
434} // namespace mlir
435
436#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...
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.