Skip to content

scan lowering changes #133149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

scan lowering changes #133149

wants to merge 1 commit into from

Conversation

anchuraj
Copy link
Contributor

@anchuraj anchuraj commented Mar 26, 2025

Scan reductions are supported in OpenMP with the the help of scan directive. Reduction clause of the for loop/simd directive takes an inscan modifier if scan reduction is specified. With an inscan modifier, the body of the directive should specify a scan directive. This PR implements the lowering logic for scan reductions in workshare loops of OpenMP.
The body of the for loop is splitted into two loops and a scan reduction loop is added in the middle.

size num_iters = <num_iters>;
<type> buffer[num_iters];
for (i: 0..<num_iters>) {
  <input phase>;
  buffer[i] = red;
}
for (int k = 0; k != ceil(log2(num_iters)); ++k) {
  i=pow(2,k)
  for (size cnt = last_iter; cnt >= i; --cnt)
    buffer[cnt] op= buffer[cnt-i];
}
for (0..<num_iters>) {
  red = buffer[i] ;
  <scan phase>;
}

@anchuraj anchuraj force-pushed the scan-irb branch 3 times, most recently from d2f4f97 to 92b7444 Compare March 31, 2025 18:47
Copy link

github-actions bot commented Mar 31, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
View the diff from clang-format here.
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index e18ef5233..2ef6520ba 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -2817,7 +2817,7 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
           wsloopOp.getReductionMod() && (wsloopOp.getReductionMod().value() ==
                                          mlir::omp::ReductionModifier::inscan);
       if (isInScanRegion) {
-        //TODO: Handle nesting if Scan loop is nested in a loop
+        // TODO: Handle nesting if Scan loop is nested in a loop
         assert(loopOp.getNumLoops() == 1);
         llvm::Expected<SmallVector<llvm::CanonicalLoopInfo *>> loopResults =
             ompBuilder->createCanonicalScanLoops(

@anchuraj anchuraj force-pushed the scan-irb branch 16 times, most recently from af2d143 to 0bdf144 Compare April 6, 2025 17:03
@anchuraj anchuraj requested a review from skatrak April 10, 2025 06:21
@anchuraj anchuraj force-pushed the scan-irb branch 5 times, most recently from 0d343a6 to 0f63f96 Compare April 16, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant