MLIR 24.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
17#include "mlir/IR/Builders.h"
20#include "mlir/IR/Operation.h"
22#include "mlir/Support/LLVM.h"
23
24#include <cstdint>
25
26namespace mlir {
27
28namespace utils {
29enum class IteratorType : uint32_t;
30} // namespace utils
31
32/// Container for result values of tiling.
33/// - `tiledOps` contains operations created by the tiling implementation that
34/// are returned to the caller for further transformations.
35/// - `tiledValues` contains the tiled value corresponding to the result of the
36/// untiled operation.
37/// - `generatedSlices` contains the list of slices that are generated during
38/// tiling. These slices can be used for fusing producers.
44
45/// Tiling can be thought of as splitting a dimension into 2 and
46/// materializing the outer dimension as a loop:
47///
48/// op[original] -> op[original / x, x] -> loop[original] { op[x] }
49///
50/// For parallel dimensions, the split can only happen in one way, with both
51/// dimensions being parallel. For reduction dimensions however, there is a
52/// choice in how we split the reduction dimension. This enum exposes this
53/// choice.
55 // [reduction] -> [reduction1, reduction2]
56 // -> loop[reduction1] { [reduction2] }
58 // [reduction] -> [reduction1, parallel2]
59 // -> loop[reduction1] { [parallel2] }; merge[reduction1]
61 // [reduction] -> [parallel1, reduction2]
62 // -> loop[parallel1] { [reduction2] }; merge[parallel1]
64};
65
66/// Container for the result of merge operation of tiling.
67/// - `mergeOps` contains operations created during the merge.
68/// - `replacements` contains the values that represents the result of the
69/// merge. These are used as replacements for the original tiled operation.
74
75/// Per-dimension alignment of a loop tile size to a `linalg.pack` /
76/// `linalg.unpack` inner tile size, supplied by the caller (which performed the
77/// tiling and knows both the tile sizes and the inner tiles) so that
78/// pack/unpack TilingInterface implementations need not re-derive it from the
79/// materialized IR. An absent entry (or `Unknown`) means "no information": the
80/// implementation must fall back to its prior behavior for that dimension.
81/// - `Multiple`: the loop tile size is an integer multiple of the pack/unpack
82/// inner tile.
83/// - `Equal`: the loop tile size equals the pack/unpack inner tile size.
85
86/// Returns true iff `value` is a valid `InnerTileAlignment` enumerator.
88 switch (static_cast<InnerTileAlignment>(value)) {
92 return true;
93 }
94 return false;
95}
96
97/// Verifies that every entry of a raw `inner_tile_alignments` integer array is
98/// a valid `InnerTileAlignment`, emitting the standard op error on `op`
99/// otherwise.
100LogicalResult verifyInnerTileAlignments(Operation *op,
101 ArrayRef<int64_t> alignments);
102
103/// Maps a validated `inner_tile_alignments` integer array onto the
104/// per-dimension `InnerTileAlignment` hints consumed by the tiling driver.
105SmallVector<InnerTileAlignment>
106convertInnerTileAlignments(ArrayRef<int64_t> alignments);
107
108/// Returns the keyword spelling of an `InnerTileAlignment` (`Unknown`,
109/// `Multiple` or `Equal`) used by the `inner_tile_alignments` assembly syntax.
111
112/// Returns the `InnerTileAlignment` for a keyword spelling, or `std::nullopt`
113/// if `keyword` is not one of `Unknown`, `Multiple` or `Equal`.
114std::optional<InnerTileAlignment>
115symbolizeInnerTileAlignment(StringRef keyword);
116
117/// Custom directive parser/printer for an `inner_tile_alignments` attribute,
118/// rendering the `DenseI64ArrayAttr` as a keyword list, e.g.
119/// `[Equal, Multiple, Unknown]` (see `InnerTileAlignment`). Shared by the
120/// transform ops that carry the hint.
121ParseResult parseInnerTileAlignmentArray(OpAsmParser &parser,
122 DenseI64ArrayAttr &alignments);
123void printInnerTileAlignmentArray(OpAsmPrinter &printer, Operation *op,
124 DenseI64ArrayAttr alignments);
125
126} // namespace mlir
127
128/// Include the ODS generated interface header files.
129#include "mlir/Interfaces/TilingInterface.h.inc"
130
131#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