[Mlir-commits] [mlir] [mlir][gpu] Add innermost-first policy when mapping loops to GPU IDs (PR #160634)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 25 02:18:36 PDT 2025
================
@@ -107,20 +121,34 @@ static Processor getHardwareIdForMapping(MappingLevel level, int dimension) {
/// Add mapping information to the given parallel loop. Do not add
/// mapping information if the loop already has it. Also, don't
/// start a mapping at a nested loop.
-static void mapParallelOp(ParallelOp parallelOp,
- MappingLevel mappingLevel = MapGrid) {
+static void
+mapParallelOp(ParallelOp parallelOp, MappingLevel mappingLevel = MapGrid,
+ MappingPolicy mappingPolicy = MappingPolicy::OutermostFirst) {
// Do not try to add a mapping to already mapped loops or nested loops.
if (parallelOp->getAttr(getMappingAttrName()) ||
((mappingLevel == MapGrid) && parallelOp->getParentOfType<ParallelOp>()))
return;
+ const int numLoops = static_cast<int>(parallelOp.getNumLoops());
+ const int loopsToMap = std::min(numLoops, kNumHardwareIds);
+
MLIRContext *ctx = parallelOp.getContext();
Builder b(ctx);
SmallVector<ParallelLoopDimMappingAttr, 4> attrs;
- attrs.reserve(parallelOp.getNumLoops());
- for (int i = 0, e = parallelOp.getNumLoops(); i < e; ++i) {
+ attrs.reserve(numLoops);
+
+ for (int i = 0, e = numLoops; i < e; ++i) {
----------------
fabrizio-indirli wrote:
I know that this is not your doing, but `e` here seems unused (and is not increased in the loop either); could it be changed to `for (int i = 0; i < numLoops; ++i)`? Or am I missing something?
https://github.com/llvm/llvm-project/pull/160634
More information about the Mlir-commits
mailing list