[Mlir-commits] [mlir] [openacc] Attach Parallelism Levels to Auto Loops (PR #200884)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Jun 1 10:49:02 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-openacc
@llvm/pr-subscribers-openacc
Author: Delaram Talaashrafi (delaram-talaashrafi)
<details>
<summary>Changes</summary>
Auto loops are analyzed by the compiler in later compilation stages to determine whether they can be parallelized. These loops may carry parallelism levels (this does not guarantee that they are parallelizable, compiler should still analyze them). However, if the loop is parallelized, the parallelism levels specified in the source should be respected. This change attaches the parallelism level to auto loops, which enables their propagation through next compilation steps.
---
Full diff: https://github.com/llvm/llvm-project/pull/200884.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/OpenACC/Transforms/ACCComputeLowering.cpp (+7)
- (modified) mlir/test/Dialect/OpenACC/acc-compute-lowering-loop.mlir (+29)
``````````diff
diff --git a/mlir/lib/Dialect/OpenACC/Transforms/ACCComputeLowering.cpp b/mlir/lib/Dialect/OpenACC/Transforms/ACCComputeLowering.cpp
index 9868584a4b699..80b4570587a17 100644
--- a/mlir/lib/Dialect/OpenACC/Transforms/ACCComputeLowering.cpp
+++ b/mlir/lib/Dialect/OpenACC/Transforms/ACCComputeLowering.cpp
@@ -314,6 +314,13 @@ class ACCLoopConversion : public OpRewritePattern<LoopOp> {
convertACCLoopToSCFFor(loopOp, rewriter, /*enableCollapse=*/true);
if (!forOp)
return failure();
+ SmallVector<GPUParallelDimAttr> parDims =
+ getParallelDimensions(loopOp, policy, deviceType);
+ if (!parDims.empty()) {
+ auto parDimsAttr =
+ GPUParallelDimsAttr::get(loopOp->getContext(), parDims);
+ setParDimsAttr(forOp, parDimsAttr);
+ }
rewriter.replaceOp(loopOp, forOp);
} else if (!isOpInComputeRegion(loopOp) &&
!isSpecializedAccRoutine(
diff --git a/mlir/test/Dialect/OpenACC/acc-compute-lowering-loop.mlir b/mlir/test/Dialect/OpenACC/acc-compute-lowering-loop.mlir
index 4032fed217b62..358d1328fa028 100644
--- a/mlir/test/Dialect/OpenACC/acc-compute-lowering-loop.mlir
+++ b/mlir/test/Dialect/OpenACC/acc-compute-lowering-loop.mlir
@@ -174,3 +174,32 @@ func.func @device_routine_vector_with_loop(%buf: memref<8xi32>) attributes {acc.
} attributes {independent = [#acc.device_type<none>], vector = [#acc.device_type<none>]}
return
}
+
+// -----
+
+// Auto loop with gang: lowered to scf.for with predetermined par_dims.
+// CHECK-LABEL: func.func @parallel_loop_auto_gang
+func.func @parallel_loop_auto_gang(%buf: memref<1xi32>) {
+ %c0 = arith.constant 0 : index
+ %c1_i32 = arith.constant 1 : i32
+ %c10_i32 = arith.constant 10 : i32
+ %c100_i32 = arith.constant 100 : i32
+
+ %dev = acc.copyin varPtr(%buf : memref<1xi32>) -> memref<1xi32>
+ // CHECK-NOT: acc.parallel
+ // CHECK: acc.kernel_environment
+ // CHECK: acc.par_width {{.*}} {par_dim = #acc.par_dim<block_x>}
+ // CHECK: acc.compute_region launch(
+ // CHECK: scf.for
+ // CHECK-NOT: scf.parallel
+ // CHECK: acc.par_dims = #acc<par_dims[block_x]>
+ acc.parallel num_gangs({%c10_i32 : i32}) dataOperands(%dev : memref<1xi32>) {
+ acc.loop gang control(%arg0 : i32) = (%c1_i32 : i32) to (%c100_i32 : i32) step (%c1_i32 : i32) {
+ memref.store %arg0, %dev[%c0] : memref<1xi32>
+ acc.yield
+ } attributes {auto_ = [#acc.device_type<none>]}
+ acc.yield
+ }
+ acc.copyout accPtr(%dev : memref<1xi32>) to varPtr(%buf : memref<1xi32>)
+ return
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/200884
More information about the Mlir-commits
mailing list