[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:30:32 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) {
+
+    // Determine the mapping to use for this loop.
+    int hwMapping = kNumHardwareIds;
----------------
fabrizio-indirli wrote:

nit: can we add a comment explaining that this will be mapped as _Sequential_ by `getHardwareIdForMapping()` ?

https://github.com/llvm/llvm-project/pull/160634


More information about the Mlir-commits mailing list