MLIR 23.0.0git
TilingInterface.h
Go to the documentation of this file.
1//===- TilingInterface.h - Interface for tiling operations ------*- 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// This file contains the definitions of the TilingInterface defined in
10// `TilingInterface.td`.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_INTERFACES_TILINGINTERFACE_H_
15#define MLIR_INTERFACES_TILINGINTERFACE_H_
16
18#include "mlir/IR/Builders.h"
21#include "mlir/IR/Operation.h"
23#include "mlir/Support/LLVM.h"
24
25namespace mlir {
26
27/// Container for result values of tiling.
28/// - `tiledOps` contains operations created by the tiling implementation that
29/// are returned to the caller for further transformations.
30/// - `tiledValues` contains the tiled value corresponding to the result of the
31/// untiled operation.
32/// - `generatedSlices` contains the list of slices that are generated during
33/// tiling. These slices can be used for fusing producers.
39
40/// Tiling can be thought of as splitting a dimension into 2 and
41/// materializing the outer dimension as a loop:
42///
43/// op[original] -> op[original / x, x] -> loop[original] { op[x] }
44///
45/// For parallel dimensions, the split can only happen in one way, with both
46/// dimensions being parallel. For reduction dimensions however, there is a
47/// choice in how we split the reduction dimension. This enum exposes this
48/// choice.
50 // [reduction] -> [reduction1, reduction2]
51 // -> loop[reduction1] { [reduction2] }
53 // [reduction] -> [reduction1, parallel2]
54 // -> loop[reduction1] { [parallel2] }; merge[reduction1]
56 // [reduction] -> [parallel1, reduction2]
57 // -> loop[parallel1] { [reduction2] }; merge[parallel1]
59};
60
61/// Container for the result of merge operation of tiling.
62/// - `mergeOps` contains operations created during the merge.
63/// - `replacements` contains the values that represents the result of the
64/// merge. These are used as replacements for the original tiled operation.
69
70/// Per-dimension alignment of a loop tile size to a `linalg.pack` /
71/// `linalg.unpack` inner tile size, supplied by the caller (which performed the
72/// tiling and knows both the tile sizes and the inner tiles) so that
73/// pack/unpack TilingInterface implementations need not re-derive it from the
74/// materialized IR. An absent entry (or `Unknown`) means "no information": the
75/// implementation must fall back to its prior behavior for that dimension.
76/// - `Multiple`: the loop tile size is an integer multiple of the pack/unpack
77/// inner tile.
78/// - `Equal`: the loop tile size equals the pack/unpack inner tile size.
80
81/// Returns true iff `value` is a valid `InnerTileAlignment` enumerator.
83 switch (static_cast<InnerTileAlignment>(value)) {
87 return true;
88 }
89 return false;
90}
91
92/// Verifies that every entry of a raw `inner_tile_alignments` integer array is
93/// a valid `InnerTileAlignment`, emitting the standard op error on `op`
94/// otherwise.
95LogicalResult verifyInnerTileAlignments(Operation *op,
96 ArrayRef<int64_t> alignments);
97
98/// Maps a validated `inner_tile_alignments` integer array onto the
99/// per-dimension `InnerTileAlignment` hints consumed by the tiling driver.
100SmallVector<InnerTileAlignment>
101convertInnerTileAlignments(ArrayRef<int64_t> alignments);
102
103/// Returns the keyword spelling of an `InnerTileAlignment` (`Unknown`,
104/// `Multiple` or `Equal`) used by the `inner_tile_alignments` assembly syntax.
106
107/// Returns the `InnerTileAlignment` for a keyword spelling, or `std::nullopt`
108/// if `keyword` is not one of `Unknown`, `Multiple` or `Equal`.
109std::optional<InnerTileAlignment>
110symbolizeInnerTileAlignment(StringRef keyword);
111
112/// Custom directive parser/printer for an `inner_tile_alignments` attribute,
113/// rendering the `DenseI64ArrayAttr` as a keyword list, e.g.
114/// `[Equal, Multiple, Unknown]` (see `InnerTileAlignment`). Shared by the
115/// transform ops that carry the hint.
116ParseResult parseInnerTileAlignmentArray(OpAsmParser &parser,
117 DenseI64ArrayAttr &alignments);
118void printInnerTileAlignmentArray(OpAsmPrinter &printer, Operation *op,
119 DenseI64ArrayAttr alignments);
120
121} // namespace mlir
122
123/// Include the ODS generated interface header files.
124#include "mlir/Interfaces/TilingInterface.h.inc"
125
126#endif // MLIR_INTERFACES_TILINGINTERFACE_H_
Include the generated interface declarations.
bool isValidInnerTileAlignment(int64_t value)
Returns true iff value is a valid InnerTileAlignment enumerator.
ReductionTilingStrategy
Tiling can be thought of as splitting a dimension into 2 and materializing the outer dimension as a l...
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
void printInnerTileAlignmentArray(OpAsmPrinter &printer, Operation *op, DenseI64ArrayAttr alignments)
ParseResult parseInnerTileAlignmentArray(OpAsmParser &parser, DenseI64ArrayAttr &alignments)
Custom directive parser/printer for an inner_tile_alignments attribute, rendering the DenseI64ArrayAt...
std::optional< InnerTileAlignment > symbolizeInnerTileAlignment(StringRef keyword)
Returns the InnerTileAlignment for a keyword spelling, or std::nullopt if keyword is not one of Unkno...
StringRef stringifyInnerTileAlignment(InnerTileAlignment alignment)
Returns the keyword spelling of an InnerTileAlignment (Unknown, Multiple or Equal) used by the inner_...
SmallVector< InnerTileAlignment > convertInnerTileAlignments(ArrayRef< int64_t > alignments)
Maps a validated inner_tile_alignments integer array onto the per-dimension InnerTileAlignment hints ...
LogicalResult verifyInnerTileAlignments(Operation *op, ArrayRef< int64_t > alignments)
Verifies that every entry of a raw inner_tile_alignments integer array is a valid InnerTileAlignment,...
InnerTileAlignment
Per-dimension alignment of a loop tile size to a linalg.pack / linalg.unpack inner tile size,...
Container for the result of merge operation of tiling.
SmallVector< Value > replacements
SmallVector< Operation * > mergeOps
Container for result values of tiling.
SmallVector< Value > tiledValues
SmallVector< Operation * > tiledOps
SmallVector< Operation * > generatedSlices