|
| 1 | +//===- OpenACCUtilsTiling.h - OpenACC Loop Tiling Utilities -----*- 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 utility functions for tiling OpenACC loops. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef MLIR_DIALECT_OPENACC_OPENACCUTILSTILING_H_ |
| 14 | +#define MLIR_DIALECT_OPENACC_OPENACCUTILSTILING_H_ |
| 15 | + |
| 16 | +#include "mlir/Dialect/OpenACC/OpenACC.h" |
| 17 | +#include "mlir/IR/PatternMatch.h" |
| 18 | +#include "llvm/ADT/SmallVector.h" |
| 19 | + |
| 20 | +namespace mlir { |
| 21 | +namespace acc { |
| 22 | + |
| 23 | +/// Uncollapse tile loops with multiple IVs and collapseCount < tileCount. |
| 24 | +/// This is used to prepare loops for tiling when the collapse count is less |
| 25 | +/// than the tile count. |
| 26 | +/// |
| 27 | +/// \param origLoop The original loop operation to uncollapse. |
| 28 | +/// \param tileCount The number of tile dimensions. |
| 29 | +/// \param collapseCount The collapse count from the original loop. |
| 30 | +/// \param rewriter The rewriter to use for modifications. |
| 31 | +/// \return A vector of uncollapsed loop operations. |
| 32 | +llvm::SmallVector<mlir::acc::LoopOp> |
| 33 | +uncollapseLoops(mlir::acc::LoopOp origLoop, unsigned tileCount, |
| 34 | + unsigned collapseCount, mlir::RewriterBase &rewriter); |
| 35 | + |
| 36 | +/// Tile ACC loops according to the given tile sizes. |
| 37 | +/// |
| 38 | +/// Tiling a 2-level nested loop will create two 'tile' loops containing two |
| 39 | +/// 'element' loops. The transformation looks like: |
| 40 | +/// |
| 41 | +/// Before Tiling: |
| 42 | +/// \code |
| 43 | +/// #pragma acc loop tile(tile_size1, tile_size2) |
| 44 | +/// for (i = lb1; i < ub1; i += step1) { // original loop |
| 45 | +/// for (j = lb2; j < ub2; j += step2) { |
| 46 | +/// a[i,j] = i + j; |
| 47 | +/// } |
| 48 | +/// } |
| 49 | +/// \endcode |
| 50 | +/// |
| 51 | +/// After Tiling: |
| 52 | +/// \code |
| 53 | +/// for (i = lb1; i < ub1; i += (step1 * tile_size1)) { // tile loop 1 |
| 54 | +/// for (j = lb2; j < ub2; j += (step2 * tile_size2)) { // tile loop 2 |
| 55 | +/// for (ii = i; ii < min(ub1, (step1 * tile_size1) + i); ii += step1) { |
| 56 | +/// // element loop 1 |
| 57 | +/// for (jj = j; jj < min(ub2, (step2 * tile_size2) + j); jj += step2) |
| 58 | +/// { // element loop 2 |
| 59 | +/// a[ii,jj] = i + j; |
| 60 | +/// } |
| 61 | +/// } |
| 62 | +/// } |
| 63 | +/// } |
| 64 | +/// \endcode |
| 65 | +/// |
| 66 | +/// Unknown tile sizes (represented as -1 in acc dialect for `tile(*)`) are |
| 67 | +/// resolved to the provided default tile size. |
| 68 | +/// |
| 69 | +/// \param tileLoops The loops to tile (outermost first). |
| 70 | +/// \param tileSizes The tile sizes for each dimension. Values of -1 are |
| 71 | +/// treated as unknown and resolved to defaultTileSize. |
| 72 | +/// \param defaultTileSize The default tile size to use for unknown (*) tiles. |
| 73 | +/// \param rewriter The rewriter to use for modifications. |
| 74 | +/// \return The outermost loop after tiling. |
| 75 | +mlir::acc::LoopOp tileACCLoops(llvm::SmallVector<mlir::acc::LoopOp> &tileLoops, |
| 76 | + const llvm::SmallVector<mlir::Value> &tileSizes, |
| 77 | + int32_t defaultTileSize, |
| 78 | + mlir::RewriterBase &rewriter); |
| 79 | + |
| 80 | +} // namespace acc |
| 81 | +} // namespace mlir |
| 82 | + |
| 83 | +#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSTILING_H_ |
0 commit comments