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/// Tile a single fused acc.loop that carries all associated induction
23/// variables (one IV per tile dimension).
24///
25/// This produces exactly two multi-IV loops, each carrying all of the tiled
26/// induction variables:
27///
28/// - a "tile group" loop that steps over tiles: each step is the
29/// original step multiplied by the tile size. It keeps the original loop's
30/// gang attribute.
31/// - an "element group" loop that walks the iterations inside one tile: it
32/// keeps the original step, its lower bound is the current tile's starting
33/// index, and its upper bound is clamped to min(original upper bound,
34/// tile start + tile extent). It keeps the original loop's vector (or
35/// worker) attribute.
36///
37/// Before Tiling:
38/// \code
39/// #pragma acc loop tile(tile_size1, tile_size2)
40/// for (i = lb1; i < ub1; i += step1) { // original loop
41/// for (j = lb2; j < ub2; j += step2) {
42/// a[i,j] = i + j;
43/// }
44/// }
45/// \endcode
46///
47/// After Tiling (each group is one multi-IV loop over all tiled IVs). As the
48/// OpenACC specification defines, the first tile size applies to the innermost
49/// loop:
50/// \code
51/// // tile group
52/// for (i = lb1; i < ub1; i += (step1 * tile_size2),
53/// j = lb2; j < ub2; j += (step2 * tile_size1)) {
54/// // element group
55/// for (ii = i; ii < min(ub1, (step1 * tile_size2) + i); ii += step1,
56/// jj = j; jj < min(ub2, (step2 * tile_size1) + j); jj += step2) {
57/// a[ii,jj] = i + j;
58/// }
59/// }
60/// \endcode
61///
62/// The element bounds above assume ascending steps. For a descending dimension,
63/// the tile's far edge lies below the original bound, so the clamp uses max
64/// instead of min.
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 tileLoop The fused loop to tile.
70/// \param tileSizes The tile sizes in the order of the tile clause: with `n`
71/// sizes, the first `n` induction variables are tiled and the size at
72/// position `k` applies to induction variable `n - 1 - k`. Values of -1
73/// are treated as unknown and resolved to defaultTileSize.
74/// \param defaultTileSize The default tile size to use for unknown (*) tiles.
75/// \param rewriter The rewriter to use for modifications.
76/// \return The tile group loop that is modified in place.
77mlir::acc::LoopOp tileACCLoops(mlir::acc::LoopOp tileLoop,
78 const llvm::SmallVector<mlir::Value> &tileSizes,
79 int32_t defaultTileSize,
80 mlir::RewriterBase &rewriter);
81
82} // namespace acc
83} // namespace mlir
84
85#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.