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