MLIR 24.0.0git
OpenACCUtilsTiling.h
Go to the documentation of this file.
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
18#include "llvm/ADT/SmallVector.h"
19
20namespace mlir {
21namespace acc {
22
23/// Tile a single fused acc.loop that carries all associated induction
24/// variables (one IV per tile dimension).
25///
26/// This produces exactly two multi-IV loops, each carrying all of the tiled
27/// induction variables:
28///
29/// - a "tile group" loop that steps over tiles: each step is the
30/// original step multiplied by the tile size. It keeps the original loop's
31/// gang attribute.
32/// - an "element group" loop that walks the iterations inside one tile: it
33/// keeps the original step, its lower bound is the current tile's starting
34/// index, and its upper bound is clamped to min(original upper bound,
35/// tile start + tile extent). It keeps the original loop's vector (or
36/// worker) attribute.
37///
38/// Before Tiling:
39/// \code
40/// #pragma acc loop tile(tile_size1, tile_size2)
41/// for (i = lb1; i < ub1; i += step1) { // original loop
42/// for (j = lb2; j < ub2; j += step2) {
43/// a[i,j] = i + j;
44/// }
45/// }
46/// \endcode
47///
48/// After Tiling (each group is one multi-IV loop over all tiled IVs):
49/// \code
50/// // tile group
51/// for (i = lb1; i < ub1; i += (step1 * tile_size1),
52/// j = lb2; j < ub2; j += (step2 * tile_size2)) {
53/// // element group
54/// for (ii = i; ii < min(ub1, (step1 * tile_size1) + i); ii += step1,
55/// jj = j; jj < min(ub2, (step2 * tile_size2) + j); jj += step2) {
56/// a[ii,jj] = i + j;
57/// }
58/// }
59/// \endcode
60///
61/// Unknown tile sizes (represented as -1 in acc dialect for `tile(*)`) are
62/// resolved to the provided default tile size.
63///
64/// \param tileLoop The fused loop to tile.
65/// \param tileSizes The tile sizes for each tiled dimension. Values of -1 are
66/// treated as unknown and resolved to defaultTileSize.
67/// \param defaultTileSize The default tile size to use for unknown (*) tiles.
68/// \param rewriter The rewriter to use for modifications.
69/// \return The tile group loop that is modified in place.
70mlir::acc::LoopOp tileACCLoops(mlir::acc::LoopOp tileLoop,
71 const llvm::SmallVector<mlir::Value> &tileSizes,
72 int32_t defaultTileSize,
73 mlir::RewriterBase &rewriter);
74
75} // namespace acc
76} // namespace mlir
77
78#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSTILING_H_
mlir::acc::LoopOp tileACCLoops(mlir::acc::LoopOp tileLoop, const llvm::SmallVector< mlir::Value > &tileSizes, int32_t defaultTileSize, mlir::RewriterBase &rewriter)
Tile a single fused acc.loop that carries all associated induction variables (one IV per tile dimensi...
Include the generated interface declarations.