Files
TheRock/compiler/amd-llvm/mlir/test/lib/Dialect/Affine/TestAffineLoopParametricTiling.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

110 lines
3.9 KiB
C++

//= TestAffineLoopParametricTiling.cpp -- Parametric Affine loop tiling pass =//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements a test pass to test parametric tiling of perfectly
// nested affine for loops.
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/LoopUtils.h"
#include "mlir/Dialect/Affine/Transforms/Passes.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
using namespace mlir;
using namespace mlir::affine;
#define DEBUG_TYPE "test-affine-parametric-tile"
namespace {
struct TestAffineLoopParametricTiling
: public PassWrapper<TestAffineLoopParametricTiling,
OperationPass<func::FuncOp>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAffineLoopParametricTiling)
StringRef getArgument() const final { return "test-affine-parametric-tile"; }
StringRef getDescription() const final {
return "Tile affine loops using SSA values as tile sizes";
}
void runOnOperation() override;
};
} // namespace
/// Checks if the function enclosing the loop nest has any arguments passed to
/// it, which can be used as tiling parameters. Assumes that atleast 'n'
/// arguments are passed, where 'n' is the number of loops in the loop nest.
static LogicalResult checkIfTilingParametersExist(ArrayRef<AffineForOp> band) {
assert(!band.empty() && "no loops in input band");
AffineForOp topLoop = band[0];
if (func::FuncOp funcOp = dyn_cast<func::FuncOp>(topLoop->getParentOp()))
if (funcOp.getNumArguments() < band.size())
return topLoop->emitError(
"too few tile sizes provided in the argument list of the function "
"which contains the current band");
return success();
}
/// Captures tiling parameters, which are expected to be passed as arguments
/// to the function enclosing the loop nest. Also checks if the required
/// parameters are of index type. This approach is temporary for testing
/// purposes.
static LogicalResult
getTilingParameters(ArrayRef<AffineForOp> band,
SmallVectorImpl<Value> &tilingParameters) {
AffineForOp topLoop = band[0];
Region *funcOpRegion = topLoop->getParentRegion();
unsigned nestDepth = band.size();
for (BlockArgument blockArgument :
funcOpRegion->getArguments().take_front(nestDepth)) {
if (blockArgument.getArgNumber() < nestDepth) {
if (!blockArgument.getType().isIndex())
return topLoop->emitError(
"expected tiling parameters to be of index type");
tilingParameters.push_back(blockArgument);
}
}
return success();
}
void TestAffineLoopParametricTiling::runOnOperation() {
// Get maximal perfect nest of 'affine.for' ops at the top-level.
std::vector<SmallVector<AffineForOp, 6>> bands;
for (AffineForOp forOp : getOperation().getOps<AffineForOp>()) {
SmallVector<AffineForOp, 6> band;
getPerfectlyNestedLoops(band, forOp);
bands.push_back(band);
}
// Tile each band.
for (MutableArrayRef<AffineForOp> band : bands) {
// Capture the tiling parameters from the arguments to the function
// enclosing this loop nest.
SmallVector<AffineForOp, 6> tiledNest;
SmallVector<Value, 6> tilingParameters;
// Check if tiling parameters are present.
if (checkIfTilingParametersExist(band).failed())
return;
// Get function arguments as tiling parameters.
if (getTilingParameters(band, tilingParameters).failed())
return;
(void)tilePerfectlyNestedParametric(band, tilingParameters, &tiledNest);
}
}
namespace mlir {
namespace test {
void registerTestAffineLoopParametricTilingPass() {
PassRegistration<TestAffineLoopParametricTiling>();
}
} // namespace test
} // namespace mlir