| 1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
| 2 | |* *| |
| 3 | |* Interface Definitions *| |
| 4 | |* *| |
| 5 | |* Automatically generated file, do not edit! *| |
| 6 | |* *| |
| 7 | \*===----------------------------------------------------------------------===*/ |
| 8 | |
| 9 | |
| 10 | /// Method to generate a tensor initalized with the identity value of the |
| 11 | /// reduction operator. The tensor shape is equal to operation result |
| 12 | /// shape with new dimension for each non zero tile size. |
| 13 | ::mlir::FailureOr<SmallVector<Value>> mlir::PartialReductionOpInterface::generateInitialTensorForPartialReduction(::mlir::OpBuilder & b, Location loc, ::mlir::ArrayRef<::mlir::OpFoldResult> tileSizes, const ::mlir::SetVector<unsigned> & reductionDims) { |
| 14 | return getImpl()->generateInitialTensorForPartialReduction(getImpl(), getOperation(), b, loc, tileSizes, reductionDims); |
| 15 | } |
| 16 | |
| 17 | /// Method to generate a tiled version of the operation where the tiled |
| 18 | /// reduction dimension are converted to parallel dimensions with a size |
| 19 | /// less or equal to the tile size. This is meant to be used with |
| 20 | /// `mergeReductions` method which will combine the partial reductions. |
| 21 | /// The method receives the `offset` and `sizes` for all iteration space |
| 22 | /// dimensions, as well as the iteration number of the tiled reduction |
| 23 | /// dimensions (which is the induction variable of the inter-tile loop |
| 24 | /// for the reduction dimension divided by the step of the loop) in |
| 25 | /// `splitReductionIvs`. |
| 26 | ::mlir::FailureOr<TilingResult> mlir::PartialReductionOpInterface::tileToPartialReduction(::mlir::OpBuilder & b, Location loc, ::mlir::ReductionTilingStrategy tilingStrategy, ValueRange init, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, const ::llvm::SetVector<unsigned> & reductionDims, ::mlir::ArrayRef<::mlir::OpFoldResult> splitReductionIvs) { |
| 27 | return getImpl()->tileToPartialReduction(getImpl(), getOperation(), b, loc, tilingStrategy, init, offsets, sizes, reductionDims, splitReductionIvs); |
| 28 | } |
| 29 | |
| 30 | /// Method to merge partial reductions for an operation that has been |
| 31 | /// tiled along the reduction dimensions. This will only apply the |
| 32 | /// reduction the operation. |
| 33 | ::mlir::FailureOr<MergeResult> mlir::PartialReductionOpInterface::mergeReductions(::mlir::OpBuilder & b, Location loc, ValueRange partialReduce, const ::mlir::SetVector<unsigned> & reductionDims) { |
| 34 | return getImpl()->mergeReductions(getImpl(), getOperation(), b, loc, partialReduce, reductionDims); |
| 35 | } |
| 36 | |
| 37 | /// Method to return the position of the partial result tile computed by |
| 38 | /// the tiled operation. This is same as |
| 39 | /// TilingInterface:::getResultTilePosition, but determines the result |
| 40 | /// tile position for partial reduction. |
| 41 | /// The method receives the `offset` and `sizes` for all iteration space |
| 42 | /// dimensions, as well as the iteration number of the tiled reduction |
| 43 | /// dimensions (which is the induction variable of the inter-tile loop |
| 44 | /// for the reduction dimension divided by the tile size specified) in |
| 45 | /// `splitReductionIvs`. |
| 46 | ::llvm::LogicalResult mlir::PartialReductionOpInterface::getPartialResultTilePosition(::mlir::OpBuilder & b, unsigned resultNumber, ReductionTilingStrategy tilingStrategy, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, const ::mlir::SetVector<unsigned> & reductionDims, ::mlir::ArrayRef<::mlir::OpFoldResult> splitReductionIvs, ::mlir::SmallVector<::mlir::OpFoldResult> & resultOffsets, ::mlir::SmallVector<::mlir::OpFoldResult> & resultSizes) { |
| 47 | return getImpl()->getPartialResultTilePosition(getImpl(), getOperation(), b, resultNumber, tilingStrategy, offsets, sizes, reductionDims, splitReductionIvs, resultOffsets, resultSizes); |
| 48 | } |
| 49 | |
| 50 | /// Returns a list of iterator types that describe the number of loops. |
| 51 | ::mlir::SmallVector<::mlir::utils::IteratorType> mlir::PartialReductionOpInterface::getLoopIteratorTypes() { |
| 52 | return getImpl()->implTilingInterface->getLoopIteratorTypes(getImpl()->implTilingInterface, getOperation()); |
| 53 | } |
| 54 | |
| 55 | /// Returns a list of ranges that describe the loop bounds and |
| 56 | /// step for the loops of the operation. |
| 57 | ::mlir::SmallVector<::mlir::Range> mlir::PartialReductionOpInterface::getIterationDomain(::mlir::OpBuilder & b) { |
| 58 | return getImpl()->implTilingInterface->getIterationDomain(getImpl()->implTilingInterface, getOperation(), b); |
| 59 | } |
| 60 | |
| 61 | /// Method to generate the tiled implementation of an operation. |
| 62 | /// |
| 63 | /// Given a tile of the iteration space (as returned by |
| 64 | /// `getIterationDomain`), generate in-place the code that represents |
| 65 | /// the computation corresponding to that tile of the iteration space. |
| 66 | /// It is the responsibility of the implementation of this method in |
| 67 | /// the operation to generate the slices of the operands needed for the |
| 68 | /// tiled implementation. |
| 69 | /// - `offsets` provides the offset of the tile in the coordinate system |
| 70 | /// of the original iteration space, i.e., if an iteration space |
| 71 | /// dimension had non-zero offset, it will be included in the offset |
| 72 | /// provided here (as opposed to zero-based offset "relative" to the |
| 73 | /// iteration space). |
| 74 | /// - `sizes` provides the size of the tile. |
| 75 | /// |
| 76 | /// The returned `TilingResult` must return for each result of the |
| 77 | /// untiled operation, a `Value` that is the result of the tiled |
| 78 | /// operation. |
| 79 | ::mlir::FailureOr<::mlir::TilingResult> mlir::PartialReductionOpInterface::getTiledImplementation(::mlir::OpBuilder & b, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes) { |
| 80 | return getImpl()->implTilingInterface->getTiledImplementation(getImpl()->implTilingInterface, getOperation(), b, offsets, sizes); |
| 81 | } |
| 82 | |
| 83 | /// Variant of `getTiledImplementation` that additionally takes a |
| 84 | /// per-iteration-domain `InnerTileAlignment` hint (see |
| 85 | /// `InnerTileAlignment`) asserting how each loop tile size relates to a |
| 86 | /// pack/unpack inner tile. The hint is consulted only by pack/unpack |
| 87 | /// implementations and may be empty (all `Unknown`). The default |
| 88 | /// implementation ignores it and forwards to the hint-less overload. |
| 89 | ::mlir::FailureOr<::mlir::TilingResult> mlir::PartialReductionOpInterface::getTiledImplementation(::mlir::OpBuilder & b, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, ::mlir::ArrayRef<::mlir::InnerTileAlignment> innerTileAlignments) { |
| 90 | return getImpl()->implTilingInterface->getTiledImplementation_3(getImpl()->implTilingInterface, getOperation(), b, offsets, sizes, innerTileAlignments); |
| 91 | } |
| 92 | |
| 93 | /// Method to return the position of the result tile computed by the |
| 94 | /// tiled operation. |
| 95 | /// |
| 96 | /// For operations that return a value (typically a value of type |
| 97 | /// `RankedTensorType`), the generated tiled computation has to also |
| 98 | /// recompute a replacement for the results of the original operation. |
| 99 | /// The tiled implementation of the operation returns a tile of the |
| 100 | /// result(s). This methods returns information about what part of the |
| 101 | /// result tensor is computed by the tiled implementation. The manner in |
| 102 | /// which these tiles get put together to get the final result is upto |
| 103 | /// the surrounding loop construct. If an operation has no results, (for |
| 104 | /// example an operation that operates only on memrefs), then this method |
| 105 | /// need not be implemented by the operation. |
| 106 | /// - `resultNumber` is the result number of the original operation |
| 107 | /// being processed. |
| 108 | /// - `offsets` provides the offset of the tile in the coordinate system |
| 109 | /// of the original iteration space, i.e., if an iteration space |
| 110 | /// dimension had non-zero offset, it will be included in the offset |
| 111 | /// provided here (as opposed to zero-based offset "relative" to the |
| 112 | /// iteration space). |
| 113 | /// - `sizes` provides the size of the tile. |
| 114 | /// - `resultOffsets` is the offsets of the tile of the result generated |
| 115 | /// by the tiled implementation (returned by value). |
| 116 | /// - `resultSizes` is the size of the tile of the result generated |
| 117 | /// by the tiled implementation (returned by value). |
| 118 | /// |
| 119 | /// Note: It is undefined behaviour if there is overlap between the |
| 120 | /// tiles of the result generated by the tiled implementation. |
| 121 | ::llvm::LogicalResult mlir::PartialReductionOpInterface::getResultTilePosition(::mlir::OpBuilder & b, unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, ::mlir::SmallVector<::mlir::OpFoldResult> & resultOffsets, ::mlir::SmallVector<::mlir::OpFoldResult> & resultSizes) { |
| 122 | return getImpl()->implTilingInterface->getResultTilePosition(getImpl()->implTilingInterface, getOperation(), b, resultNumber, offsets, sizes, resultOffsets, resultSizes); |
| 123 | } |
| 124 | |
| 125 | /// Method to generate the code that produces a tile of the result. |
| 126 | /// |
| 127 | /// This method is required to allow operations to be "tiled and fused" |
| 128 | /// with an (already tiled) consumer. Typically, for two operations with |
| 129 | /// producer -> consumer relation ship, to compute a tile of the |
| 130 | /// consumer a `slice` of the producer is needed. This method allows |
| 131 | /// computing that slice of the producer in-place, thereby "fusing" |
| 132 | /// the operations at tile-granularity. This method is different from |
| 133 | /// `getTiledImplementation`, which produces a tiled implementation |
| 134 | /// for a tile of the iteration space. This method produces a tiled |
| 135 | /// implementation based on the tile of producer required. |
| 136 | /// - `resultNumber` is the result of the producer used by the consumer. |
| 137 | /// - `offsets` is the offset of the slice of the producer result used by |
| 138 | /// the tiled implementation of the consumer. |
| 139 | /// - `sizes` is the size of the slice of the producer result used by the |
| 140 | /// consumer. |
| 141 | /// If fusion of the producer with the consumer is not legal for the |
| 142 | /// operation/result, this method should return failure. |
| 143 | /// |
| 144 | /// Note: This method only deals with the mechanism of implementing the |
| 145 | /// fusion. In general the fusion might result in recomputation (based on |
| 146 | /// the way the result is produced by the producer and the access pattern |
| 147 | /// used in the consumer to access). This is upto the caller to handle |
| 148 | /// appropriately. |
| 149 | ::mlir::FailureOr<::mlir::TilingResult> mlir::PartialReductionOpInterface::generateResultTileValue(::mlir::OpBuilder & b, unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes) { |
| 150 | return getImpl()->implTilingInterface->generateResultTileValue(getImpl()->implTilingInterface, getOperation(), b, resultNumber, offsets, sizes); |
| 151 | } |
| 152 | |
| 153 | /// Variant of `generateResultTileValue` that additionally takes a |
| 154 | /// per-iteration-domain `InnerTileAlignment` hint (see |
| 155 | /// `InnerTileAlignment`). The hint is consulted only by pack/unpack |
| 156 | /// implementations and may be empty (all `Unknown`). The default |
| 157 | /// implementation ignores it and forwards to the hint-less overload. |
| 158 | ::mlir::FailureOr<::mlir::TilingResult> mlir::PartialReductionOpInterface::generateResultTileValue(::mlir::OpBuilder & b, unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, ::mlir::ArrayRef<::mlir::InnerTileAlignment> innerTileAlignments) { |
| 159 | return getImpl()->implTilingInterface->generateResultTileValue_6(getImpl()->implTilingInterface, getOperation(), b, resultNumber, offsets, sizes, innerTileAlignments); |
| 160 | } |
| 161 | |
| 162 | /// Method to generate the tiled implementation of an operation that uses |
| 163 | /// the exact tiles of the given operands. |
| 164 | /// |
| 165 | /// This method is required to allow operations to be "tiled and fused" |
| 166 | /// with an (already tiled) producer. Given tiles of the producer, this |
| 167 | /// method generates the tile of the consumer that uses exactly these |
| 168 | /// produced tiles. In some sense it is the "reverse" of |
| 169 | /// `generateResultTileValue`. |
| 170 | /// - `operandNumbers` is the list of operands whose tiles are "producers". |
| 171 | /// - `allOffsets` is the offset of the slice of the producer used by the |
| 172 | /// tiled implementation of the consumer. |
| 173 | /// - `allSizes` is the size of the slice of the producer used by the |
| 174 | /// consumer. |
| 175 | /// If it is illegal to fuse with a producer along the given operand tiles for |
| 176 | /// an operation, the implementation should return a failure. |
| 177 | ::mlir::FailureOr<::mlir::TilingResult> mlir::PartialReductionOpInterface::getTiledImplementationFromOperandTiles(::mlir::OpBuilder & b, ::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes) { |
| 178 | return getImpl()->implTilingInterface->getTiledImplementationFromOperandTiles(getImpl()->implTilingInterface, getOperation(), b, operandNumbers, allOffsets, allSizes); |
| 179 | } |
| 180 | |
| 181 | /// Variant of `getTiledImplementationFromOperandTiles` that additionally |
| 182 | /// takes a per-iteration-domain `InnerTileAlignment` hint (see |
| 183 | /// `InnerTileAlignment`). The hint is consulted only by pack/unpack |
| 184 | /// implementations and may be empty (all `Unknown`). The default |
| 185 | /// implementation ignores it and forwards to the hint-less overload. |
| 186 | ::mlir::FailureOr<::mlir::TilingResult> mlir::PartialReductionOpInterface::getTiledImplementationFromOperandTiles(::mlir::OpBuilder & b, ::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes, ::mlir::ArrayRef<::mlir::InnerTileAlignment> innerTileAlignments) { |
| 187 | return getImpl()->implTilingInterface->getTiledImplementationFromOperandTiles_8(getImpl()->implTilingInterface, getOperation(), b, operandNumbers, allOffsets, allSizes, innerTileAlignments); |
| 188 | } |
| 189 | |
| 190 | /// Method to return the tile of the iteration domain that uses a given |
| 191 | /// tile of the operand. |
| 192 | /// |
| 193 | /// This method is required to allow operations to be "tiled and fused" |
| 194 | /// with an (already tiled) producer. Given tiles of operands, |
| 195 | /// returns the tile of the iteration space that uses these tiles. |
| 196 | /// - `operandNumbers` is the list of operands whose tiles are "produced" |
| 197 | /// by the producer(s). |
| 198 | /// - `allOffsets` is the offset of the slice of the producers used by |
| 199 | /// the tiled implementation of the consumer. |
| 200 | /// - `allSizes` is the size of the slice of the producers used by the |
| 201 | /// consumer. |
| 202 | /// If it is illegal to fuse with the producer slices for an operation, |
| 203 | /// or if this mapping cannot be computed, the implementation should |
| 204 | /// return a failure. |
| 205 | /// |
| 206 | /// Note that unlike the "tile consumer and fuse producer" case, the |
| 207 | /// "tile producer and fuse consumer" requires an additional method to get |
| 208 | /// the iteration tile space that encompasses all uses of the given operand |
| 209 | /// tile. The reason for this is, consider |
| 210 | /// ```mlir |
| 211 | /// %1 = scf.for... { |
| 212 | /// %2 = <tiled_producer_op> |
| 213 | /// %3 = tensor.insert_slice %2 into ... |
| 214 | /// scf.yield %3 |
| 215 | /// } |
| 216 | /// %4 = <consumer_op>)(... %1... ) |
| 217 | /// ... <some_op>(... %4 ...) |
| 218 | /// ``` |
| 219 | /// |
| 220 | /// when fused this becomes |
| 221 | /// ``` |
| 222 | /// %1 = scf.for... { |
| 223 | /// %2 = <tiled_producer_op> |
| 224 | /// %3 = <tiled_consumer_op>(... %2...) |
| 225 | /// %4 = tensor.insert_slice %3 into ... |
| 226 | /// scf.yield %4 |
| 227 | /// } |
| 228 | /// ... <some_op>(... %1 ...) |
| 229 | /// ``` |
| 230 | /// |
| 231 | /// i.e, when fusing the consumer, the replacement for the result of the |
| 232 | /// consumer needs to be returned to replace the uses of the consumer. |
| 233 | /// For the tile+fuse algorithm to do this it needs information about |
| 234 | /// which tile of the iteration space encompasses all uses of the tile |
| 235 | /// produced and use that to compute what are the results produced. Note |
| 236 | /// that this iteration space might be the entire iteration space of the |
| 237 | /// operation, or multiple operand tiles might map to intersecting |
| 238 | /// iteration spaces. It is upto the caller to make sure that it is still |
| 239 | /// fusable with producer in this scenario, or it must return a failure. |
| 240 | /// |
| 241 | /// Note that this method is only used as a way to implement the |
| 242 | /// transformation. It does not provide guarantees on whether such a |
| 243 | /// transformation is profitable. |
| 244 | /// |
| 245 | /// For most cases `getTiledImplementationFromOperandTiles` could be a |
| 246 | /// implemented using `getIterationDomainTileFromOperandTiles` + |
| 247 | /// `getTiledImplementation` methods. |
| 248 | ::llvm::LogicalResult mlir::PartialReductionOpInterface::getIterationDomainTileFromOperandTiles(::mlir::OpBuilder & b, ::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainOffsets, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainSizes) { |
| 249 | return getImpl()->implTilingInterface->getIterationDomainTileFromOperandTiles(getImpl()->implTilingInterface, getOperation(), b, operandNumbers, allOffsets, allSizes, iterDomainOffsets, iterDomainSizes); |
| 250 | } |
| 251 | |
| 252 | /// Variant of `getIterationDomainTileFromOperandTiles` that additionally |
| 253 | /// takes a per-iteration-domain `InnerTileAlignment` hint (see |
| 254 | /// `InnerTileAlignment`). The hint is consulted only by pack/unpack |
| 255 | /// implementations and may be empty (all `Unknown`). The default |
| 256 | /// implementation ignores it and forwards to the hint-less overload. |
| 257 | ::llvm::LogicalResult mlir::PartialReductionOpInterface::getIterationDomainTileFromOperandTiles(::mlir::OpBuilder & b, ::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainOffsets, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainSizes, ::mlir::ArrayRef<::mlir::InnerTileAlignment> innerTileAlignments) { |
| 258 | return getImpl()->implTilingInterface->getIterationDomainTileFromOperandTiles_10(getImpl()->implTilingInterface, getOperation(), b, operandNumbers, allOffsets, allSizes, iterDomainOffsets, iterDomainSizes, innerTileAlignments); |
| 259 | } |
| 260 | |
| 261 | /// Method to return the tile of the iteration domain based |
| 262 | /// on the given tile of the certain result. |
| 263 | /// |
| 264 | /// This method is required to allow operations to be "tiled and fused" |
| 265 | /// with an (already tiled) consumer. Given a tile of an result, |
| 266 | /// returns the tile of the iteration space that uses this tile. |
| 267 | /// - `resultNumber` is the result of the producer used by the consumer. |
| 268 | /// - `offsets` is the offset of the slice of the producer result used by |
| 269 | /// the tiled implementation of the consumer. |
| 270 | /// - `sizes` is the size of the slice of the producer result used by the |
| 271 | /// consumer. |
| 272 | /// If fusion of the producer with the consumer is not legal for the |
| 273 | /// result, or if this mapping cannot be computed, the implementation |
| 274 | /// should return a failure. |
| 275 | /// |
| 276 | /// For most cases `generateResultTileValue` could be a implemented using |
| 277 | /// `getIterationDomainTileFromResultTile` + `getTiledImplementation` |
| 278 | /// methods. |
| 279 | ::llvm::LogicalResult mlir::PartialReductionOpInterface::getIterationDomainTileFromResultTile(::mlir::OpBuilder & b, unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainOffsets, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainSizes) { |
| 280 | return getImpl()->implTilingInterface->getIterationDomainTileFromResultTile(getImpl()->implTilingInterface, getOperation(), b, resultNumber, offsets, sizes, iterDomainOffsets, iterDomainSizes); |
| 281 | } |
| 282 | |
| 283 | /// Generates the scalar implementation of the operation. |
| 284 | /// |
| 285 | /// Given the list `ivs` that represent points in the iteration space |
| 286 | /// (as specified by `getIterationDomain()`) returns the scalar operations |
| 287 | /// that represent the computation at that point in the iteration space. |
| 288 | /// This method is typically used as the "exit path", i.e. once all |
| 289 | /// transformations are done, this method can be used to lower to scalar |
| 290 | /// code that can then be lowered to LLVM or SPIR-V dialects. |
| 291 | ::llvm::LogicalResult mlir::PartialReductionOpInterface::generateScalarImplementation(::mlir::OpBuilder & b, ::mlir::Location loc, ::mlir::ValueRange ivs) { |
| 292 | return getImpl()->implTilingInterface->generateScalarImplementation(getImpl()->implTilingInterface, getOperation(), b, loc, ivs); |
| 293 | } |
| 294 | |
| 295 | /// Indicates whether it is possible to fuse this operation with the given |
| 296 | /// result slice. This method is not allowed to generate any IR. |
| 297 | bool mlir::PartialReductionOpInterface::isOpFusableWithConsumerSlice(unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes) { |
| 298 | return getImpl()->implTilingInterface->isOpFusableWithConsumerSlice(getImpl()->implTilingInterface, getOperation(), resultNumber, offsets, sizes); |
| 299 | } |
| 300 | |
| 301 | /// Indicates whether it is possible to fuse this operation with the given |
| 302 | /// list of operand slices. This method is not allowed to generate any IR. |
| 303 | bool mlir::PartialReductionOpInterface::isOpFusableWithProducerSlices(::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes) { |
| 304 | return getImpl()->implTilingInterface->isOpFusableWithProducerSlices(getImpl()->implTilingInterface, getOperation(), operandNumbers, allOffsets, allSizes); |
| 305 | } |
| 306 | |
| 307 | /// Returns a list of iterator types that describe the number of loops. |
| 308 | ::mlir::SmallVector<::mlir::utils::IteratorType> mlir::TilingInterface::getLoopIteratorTypes() { |
| 309 | return getImpl()->getLoopIteratorTypes(getImpl(), getOperation()); |
| 310 | } |
| 311 | |
| 312 | /// Returns a list of ranges that describe the loop bounds and |
| 313 | /// step for the loops of the operation. |
| 314 | ::mlir::SmallVector<::mlir::Range> mlir::TilingInterface::getIterationDomain(::mlir::OpBuilder & b) { |
| 315 | return getImpl()->getIterationDomain(getImpl(), getOperation(), b); |
| 316 | } |
| 317 | |
| 318 | /// Method to generate the tiled implementation of an operation. |
| 319 | /// |
| 320 | /// Given a tile of the iteration space (as returned by |
| 321 | /// `getIterationDomain`), generate in-place the code that represents |
| 322 | /// the computation corresponding to that tile of the iteration space. |
| 323 | /// It is the responsibility of the implementation of this method in |
| 324 | /// the operation to generate the slices of the operands needed for the |
| 325 | /// tiled implementation. |
| 326 | /// - `offsets` provides the offset of the tile in the coordinate system |
| 327 | /// of the original iteration space, i.e., if an iteration space |
| 328 | /// dimension had non-zero offset, it will be included in the offset |
| 329 | /// provided here (as opposed to zero-based offset "relative" to the |
| 330 | /// iteration space). |
| 331 | /// - `sizes` provides the size of the tile. |
| 332 | /// |
| 333 | /// The returned `TilingResult` must return for each result of the |
| 334 | /// untiled operation, a `Value` that is the result of the tiled |
| 335 | /// operation. |
| 336 | ::mlir::FailureOr<::mlir::TilingResult> mlir::TilingInterface::getTiledImplementation(::mlir::OpBuilder & b, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes) { |
| 337 | return getImpl()->getTiledImplementation(getImpl(), getOperation(), b, offsets, sizes); |
| 338 | } |
| 339 | |
| 340 | /// Variant of `getTiledImplementation` that additionally takes a |
| 341 | /// per-iteration-domain `InnerTileAlignment` hint (see |
| 342 | /// `InnerTileAlignment`) asserting how each loop tile size relates to a |
| 343 | /// pack/unpack inner tile. The hint is consulted only by pack/unpack |
| 344 | /// implementations and may be empty (all `Unknown`). The default |
| 345 | /// implementation ignores it and forwards to the hint-less overload. |
| 346 | ::mlir::FailureOr<::mlir::TilingResult> mlir::TilingInterface::getTiledImplementation(::mlir::OpBuilder & b, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, ::mlir::ArrayRef<::mlir::InnerTileAlignment> innerTileAlignments) { |
| 347 | return getImpl()->getTiledImplementation_3(getImpl(), getOperation(), b, offsets, sizes, innerTileAlignments); |
| 348 | } |
| 349 | |
| 350 | /// Method to return the position of the result tile computed by the |
| 351 | /// tiled operation. |
| 352 | /// |
| 353 | /// For operations that return a value (typically a value of type |
| 354 | /// `RankedTensorType`), the generated tiled computation has to also |
| 355 | /// recompute a replacement for the results of the original operation. |
| 356 | /// The tiled implementation of the operation returns a tile of the |
| 357 | /// result(s). This methods returns information about what part of the |
| 358 | /// result tensor is computed by the tiled implementation. The manner in |
| 359 | /// which these tiles get put together to get the final result is upto |
| 360 | /// the surrounding loop construct. If an operation has no results, (for |
| 361 | /// example an operation that operates only on memrefs), then this method |
| 362 | /// need not be implemented by the operation. |
| 363 | /// - `resultNumber` is the result number of the original operation |
| 364 | /// being processed. |
| 365 | /// - `offsets` provides the offset of the tile in the coordinate system |
| 366 | /// of the original iteration space, i.e., if an iteration space |
| 367 | /// dimension had non-zero offset, it will be included in the offset |
| 368 | /// provided here (as opposed to zero-based offset "relative" to the |
| 369 | /// iteration space). |
| 370 | /// - `sizes` provides the size of the tile. |
| 371 | /// - `resultOffsets` is the offsets of the tile of the result generated |
| 372 | /// by the tiled implementation (returned by value). |
| 373 | /// - `resultSizes` is the size of the tile of the result generated |
| 374 | /// by the tiled implementation (returned by value). |
| 375 | /// |
| 376 | /// Note: It is undefined behaviour if there is overlap between the |
| 377 | /// tiles of the result generated by the tiled implementation. |
| 378 | ::llvm::LogicalResult mlir::TilingInterface::getResultTilePosition(::mlir::OpBuilder & b, unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, ::mlir::SmallVector<::mlir::OpFoldResult> & resultOffsets, ::mlir::SmallVector<::mlir::OpFoldResult> & resultSizes) { |
| 379 | return getImpl()->getResultTilePosition(getImpl(), getOperation(), b, resultNumber, offsets, sizes, resultOffsets, resultSizes); |
| 380 | } |
| 381 | |
| 382 | /// Method to generate the code that produces a tile of the result. |
| 383 | /// |
| 384 | /// This method is required to allow operations to be "tiled and fused" |
| 385 | /// with an (already tiled) consumer. Typically, for two operations with |
| 386 | /// producer -> consumer relation ship, to compute a tile of the |
| 387 | /// consumer a `slice` of the producer is needed. This method allows |
| 388 | /// computing that slice of the producer in-place, thereby "fusing" |
| 389 | /// the operations at tile-granularity. This method is different from |
| 390 | /// `getTiledImplementation`, which produces a tiled implementation |
| 391 | /// for a tile of the iteration space. This method produces a tiled |
| 392 | /// implementation based on the tile of producer required. |
| 393 | /// - `resultNumber` is the result of the producer used by the consumer. |
| 394 | /// - `offsets` is the offset of the slice of the producer result used by |
| 395 | /// the tiled implementation of the consumer. |
| 396 | /// - `sizes` is the size of the slice of the producer result used by the |
| 397 | /// consumer. |
| 398 | /// If fusion of the producer with the consumer is not legal for the |
| 399 | /// operation/result, this method should return failure. |
| 400 | /// |
| 401 | /// Note: This method only deals with the mechanism of implementing the |
| 402 | /// fusion. In general the fusion might result in recomputation (based on |
| 403 | /// the way the result is produced by the producer and the access pattern |
| 404 | /// used in the consumer to access). This is upto the caller to handle |
| 405 | /// appropriately. |
| 406 | ::mlir::FailureOr<::mlir::TilingResult> mlir::TilingInterface::generateResultTileValue(::mlir::OpBuilder & b, unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes) { |
| 407 | return getImpl()->generateResultTileValue(getImpl(), getOperation(), b, resultNumber, offsets, sizes); |
| 408 | } |
| 409 | |
| 410 | /// Variant of `generateResultTileValue` that additionally takes a |
| 411 | /// per-iteration-domain `InnerTileAlignment` hint (see |
| 412 | /// `InnerTileAlignment`). The hint is consulted only by pack/unpack |
| 413 | /// implementations and may be empty (all `Unknown`). The default |
| 414 | /// implementation ignores it and forwards to the hint-less overload. |
| 415 | ::mlir::FailureOr<::mlir::TilingResult> mlir::TilingInterface::generateResultTileValue(::mlir::OpBuilder & b, unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, ::mlir::ArrayRef<::mlir::InnerTileAlignment> innerTileAlignments) { |
| 416 | return getImpl()->generateResultTileValue_6(getImpl(), getOperation(), b, resultNumber, offsets, sizes, innerTileAlignments); |
| 417 | } |
| 418 | |
| 419 | /// Method to generate the tiled implementation of an operation that uses |
| 420 | /// the exact tiles of the given operands. |
| 421 | /// |
| 422 | /// This method is required to allow operations to be "tiled and fused" |
| 423 | /// with an (already tiled) producer. Given tiles of the producer, this |
| 424 | /// method generates the tile of the consumer that uses exactly these |
| 425 | /// produced tiles. In some sense it is the "reverse" of |
| 426 | /// `generateResultTileValue`. |
| 427 | /// - `operandNumbers` is the list of operands whose tiles are "producers". |
| 428 | /// - `allOffsets` is the offset of the slice of the producer used by the |
| 429 | /// tiled implementation of the consumer. |
| 430 | /// - `allSizes` is the size of the slice of the producer used by the |
| 431 | /// consumer. |
| 432 | /// If it is illegal to fuse with a producer along the given operand tiles for |
| 433 | /// an operation, the implementation should return a failure. |
| 434 | ::mlir::FailureOr<::mlir::TilingResult> mlir::TilingInterface::getTiledImplementationFromOperandTiles(::mlir::OpBuilder & b, ::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes) { |
| 435 | return getImpl()->getTiledImplementationFromOperandTiles(getImpl(), getOperation(), b, operandNumbers, allOffsets, allSizes); |
| 436 | } |
| 437 | |
| 438 | /// Variant of `getTiledImplementationFromOperandTiles` that additionally |
| 439 | /// takes a per-iteration-domain `InnerTileAlignment` hint (see |
| 440 | /// `InnerTileAlignment`). The hint is consulted only by pack/unpack |
| 441 | /// implementations and may be empty (all `Unknown`). The default |
| 442 | /// implementation ignores it and forwards to the hint-less overload. |
| 443 | ::mlir::FailureOr<::mlir::TilingResult> mlir::TilingInterface::getTiledImplementationFromOperandTiles(::mlir::OpBuilder & b, ::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes, ::mlir::ArrayRef<::mlir::InnerTileAlignment> innerTileAlignments) { |
| 444 | return getImpl()->getTiledImplementationFromOperandTiles_8(getImpl(), getOperation(), b, operandNumbers, allOffsets, allSizes, innerTileAlignments); |
| 445 | } |
| 446 | |
| 447 | /// Method to return the tile of the iteration domain that uses a given |
| 448 | /// tile of the operand. |
| 449 | /// |
| 450 | /// This method is required to allow operations to be "tiled and fused" |
| 451 | /// with an (already tiled) producer. Given tiles of operands, |
| 452 | /// returns the tile of the iteration space that uses these tiles. |
| 453 | /// - `operandNumbers` is the list of operands whose tiles are "produced" |
| 454 | /// by the producer(s). |
| 455 | /// - `allOffsets` is the offset of the slice of the producers used by |
| 456 | /// the tiled implementation of the consumer. |
| 457 | /// - `allSizes` is the size of the slice of the producers used by the |
| 458 | /// consumer. |
| 459 | /// If it is illegal to fuse with the producer slices for an operation, |
| 460 | /// or if this mapping cannot be computed, the implementation should |
| 461 | /// return a failure. |
| 462 | /// |
| 463 | /// Note that unlike the "tile consumer and fuse producer" case, the |
| 464 | /// "tile producer and fuse consumer" requires an additional method to get |
| 465 | /// the iteration tile space that encompasses all uses of the given operand |
| 466 | /// tile. The reason for this is, consider |
| 467 | /// ```mlir |
| 468 | /// %1 = scf.for... { |
| 469 | /// %2 = <tiled_producer_op> |
| 470 | /// %3 = tensor.insert_slice %2 into ... |
| 471 | /// scf.yield %3 |
| 472 | /// } |
| 473 | /// %4 = <consumer_op>)(... %1... ) |
| 474 | /// ... <some_op>(... %4 ...) |
| 475 | /// ``` |
| 476 | /// |
| 477 | /// when fused this becomes |
| 478 | /// ``` |
| 479 | /// %1 = scf.for... { |
| 480 | /// %2 = <tiled_producer_op> |
| 481 | /// %3 = <tiled_consumer_op>(... %2...) |
| 482 | /// %4 = tensor.insert_slice %3 into ... |
| 483 | /// scf.yield %4 |
| 484 | /// } |
| 485 | /// ... <some_op>(... %1 ...) |
| 486 | /// ``` |
| 487 | /// |
| 488 | /// i.e, when fusing the consumer, the replacement for the result of the |
| 489 | /// consumer needs to be returned to replace the uses of the consumer. |
| 490 | /// For the tile+fuse algorithm to do this it needs information about |
| 491 | /// which tile of the iteration space encompasses all uses of the tile |
| 492 | /// produced and use that to compute what are the results produced. Note |
| 493 | /// that this iteration space might be the entire iteration space of the |
| 494 | /// operation, or multiple operand tiles might map to intersecting |
| 495 | /// iteration spaces. It is upto the caller to make sure that it is still |
| 496 | /// fusable with producer in this scenario, or it must return a failure. |
| 497 | /// |
| 498 | /// Note that this method is only used as a way to implement the |
| 499 | /// transformation. It does not provide guarantees on whether such a |
| 500 | /// transformation is profitable. |
| 501 | /// |
| 502 | /// For most cases `getTiledImplementationFromOperandTiles` could be a |
| 503 | /// implemented using `getIterationDomainTileFromOperandTiles` + |
| 504 | /// `getTiledImplementation` methods. |
| 505 | ::llvm::LogicalResult mlir::TilingInterface::getIterationDomainTileFromOperandTiles(::mlir::OpBuilder & b, ::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainOffsets, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainSizes) { |
| 506 | return getImpl()->getIterationDomainTileFromOperandTiles(getImpl(), getOperation(), b, operandNumbers, allOffsets, allSizes, iterDomainOffsets, iterDomainSizes); |
| 507 | } |
| 508 | |
| 509 | /// Variant of `getIterationDomainTileFromOperandTiles` that additionally |
| 510 | /// takes a per-iteration-domain `InnerTileAlignment` hint (see |
| 511 | /// `InnerTileAlignment`). The hint is consulted only by pack/unpack |
| 512 | /// implementations and may be empty (all `Unknown`). The default |
| 513 | /// implementation ignores it and forwards to the hint-less overload. |
| 514 | ::llvm::LogicalResult mlir::TilingInterface::getIterationDomainTileFromOperandTiles(::mlir::OpBuilder & b, ::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainOffsets, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainSizes, ::mlir::ArrayRef<::mlir::InnerTileAlignment> innerTileAlignments) { |
| 515 | return getImpl()->getIterationDomainTileFromOperandTiles_10(getImpl(), getOperation(), b, operandNumbers, allOffsets, allSizes, iterDomainOffsets, iterDomainSizes, innerTileAlignments); |
| 516 | } |
| 517 | |
| 518 | /// Method to return the tile of the iteration domain based |
| 519 | /// on the given tile of the certain result. |
| 520 | /// |
| 521 | /// This method is required to allow operations to be "tiled and fused" |
| 522 | /// with an (already tiled) consumer. Given a tile of an result, |
| 523 | /// returns the tile of the iteration space that uses this tile. |
| 524 | /// - `resultNumber` is the result of the producer used by the consumer. |
| 525 | /// - `offsets` is the offset of the slice of the producer result used by |
| 526 | /// the tiled implementation of the consumer. |
| 527 | /// - `sizes` is the size of the slice of the producer result used by the |
| 528 | /// consumer. |
| 529 | /// If fusion of the producer with the consumer is not legal for the |
| 530 | /// result, or if this mapping cannot be computed, the implementation |
| 531 | /// should return a failure. |
| 532 | /// |
| 533 | /// For most cases `generateResultTileValue` could be a implemented using |
| 534 | /// `getIterationDomainTileFromResultTile` + `getTiledImplementation` |
| 535 | /// methods. |
| 536 | ::llvm::LogicalResult mlir::TilingInterface::getIterationDomainTileFromResultTile(::mlir::OpBuilder & b, unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainOffsets, ::mlir::SmallVectorImpl<::mlir::OpFoldResult> & iterDomainSizes) { |
| 537 | return getImpl()->getIterationDomainTileFromResultTile(getImpl(), getOperation(), b, resultNumber, offsets, sizes, iterDomainOffsets, iterDomainSizes); |
| 538 | } |
| 539 | |
| 540 | /// Generates the scalar implementation of the operation. |
| 541 | /// |
| 542 | /// Given the list `ivs` that represent points in the iteration space |
| 543 | /// (as specified by `getIterationDomain()`) returns the scalar operations |
| 544 | /// that represent the computation at that point in the iteration space. |
| 545 | /// This method is typically used as the "exit path", i.e. once all |
| 546 | /// transformations are done, this method can be used to lower to scalar |
| 547 | /// code that can then be lowered to LLVM or SPIR-V dialects. |
| 548 | ::llvm::LogicalResult mlir::TilingInterface::generateScalarImplementation(::mlir::OpBuilder & b, ::mlir::Location loc, ::mlir::ValueRange ivs) { |
| 549 | return getImpl()->generateScalarImplementation(getImpl(), getOperation(), b, loc, ivs); |
| 550 | } |
| 551 | |
| 552 | /// Indicates whether it is possible to fuse this operation with the given |
| 553 | /// result slice. This method is not allowed to generate any IR. |
| 554 | bool mlir::TilingInterface::isOpFusableWithConsumerSlice(unsigned resultNumber, ::mlir::ArrayRef<::mlir::OpFoldResult> offsets, ::mlir::ArrayRef<::mlir::OpFoldResult> sizes) { |
| 555 | return getImpl()->isOpFusableWithConsumerSlice(getImpl(), getOperation(), resultNumber, offsets, sizes); |
| 556 | } |
| 557 | |
| 558 | /// Indicates whether it is possible to fuse this operation with the given |
| 559 | /// list of operand slices. This method is not allowed to generate any IR. |
| 560 | bool mlir::TilingInterface::isOpFusableWithProducerSlices(::mlir::ArrayRef<unsigned> operandNumbers, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allOffsets, ::mlir::ArrayRef<::mlir::SmallVector<::mlir::OpFoldResult>> allSizes) { |
| 561 | return getImpl()->isOpFusableWithProducerSlices(getImpl(), getOperation(), operandNumbers, allOffsets, allSizes); |
| 562 | } |
| 563 | |