-
Notifications
You must be signed in to change notification settings - Fork 16
[OpenMP][Flang]Add support for modifiers monotonic and non-monotonic #791
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
[OpenMP][Flang]Add support for modifiers monotonic and non-monotonic #791
Conversation
Hi, thanks for the patch. I am working on a full rebase of fir-dev on llvm main that I would like to get in probably next Tuesday. It will include the first three commits from LLVM. If it's OK for you to wait until then, it would be easier for me to not have this PR in before the rebase (which mean you will probably have to cherry-pick your last commit into the fresh fir-dev and make a new PR/update this one afterwards). It does not prevent others from reviewing your last commit specific to fir-dev already. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR. Looks good. Just a few minor nitpick comments.
flang/lib/Lower/OpenMP.cpp
Outdated
return mlir::omp::ClauseScheduleModifier::Monotonic; | ||
case Fortran::parser::OmpScheduleModifierType::ModType::Nonmonotonic: | ||
return mlir::omp::ClauseScheduleModifier::Nonmonotonic; | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an FYI. At one time, flang was using -Wswitch
as an error to handle some unreachable cases at compile time.
flang/lib/Lower/OpenMP.cpp
Outdated
if (modifier) { | ||
const auto &modType1 = | ||
std::get<Fortran::parser::OmpScheduleModifier::Modifier1>(modifier->t); | ||
// TODO: Add support for SIMD, which means modType2 gets used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a hard TODO()
here? (See flang/lower/Todo.h..) In general, we prefer that flang exits rather than emits incorrect code silently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand it,it won't generate incorrect code [functionality-wise] by skipping the SIMD modifier. It may be less efficient than the intent from the programmer... :)
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
Outdated
Show resolved
Hide resolved
7ccb9b8
to
60d6c24
Compare
Rebase was just done, so you should just be able to cherry-pick your last commit into fir-dev head now without bringing LLVM commits. |
Thanks, I'm working on an update. Currently not compiling, probably something I broke in the rebase! :( |
60d6c24
to
c6057cc
Compare
Right, finally got this updated to the current version of F18. I believe I've fixed all previous review comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a few minor comments and one request for change.
@@ -1404,6 +1405,10 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Schedule &x) { | |||
} | |||
} | |||
|
|||
void OmpStructureChecker::Enter(const parser::OmpClause::ScheduleModifier &x) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use CHECK_SIMPLE_CLAUSE instead of writing this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's no longer a clause, not really needed.
@@ -299,6 +299,22 @@ convertOmpWsLoop(Operation &opInst, llvm::IRBuilderBase &builder, | |||
break; | |||
} | |||
|
|||
if (loop.schedule_modifiers().hasValue()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a TODO here also for multiple modifiers? Also in print and parse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO was mainly to explain why there was commented out code. SIMD will just add a bit more code here... :)
omp.wsloop (%iv) : index = (%lb) to (%ub) step (%step) ordered(2) private(%data_var : memref<i32>) | ||
firstprivate(%data_var : memref<i32>) lastprivate(%data_var : memref<i32>) linear(%data_var = %linear_var : memref<i32>) | ||
schedule(static = %chunk_var) collapse(3) { | ||
schedule(static = %chunk_var, None) collapse(3) { | ||
omp.yield | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a modifier test here as well.
And also in mlir/test/Target/LLVMIR/openmp-llvm.mlir
While it looks excessive, i think the convention in llvm projects is that things should be independently separately tested.
c6057cc
to
241ed58
Compare
} | ||
|
||
llvm.func @test_omp_wsloop_dynamic_monotonic(%lb : i64, %ub : i64, %step : i64) -> () { | ||
omp.wsloop (%iv) : i64 = (%lb) to (%ub) step (%step) schedule(dynamic, Monotonic) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have the same case for the schedule type and the modifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point.
auto mod = parser.getBuilder().getStringAttr(modifiers[0]); | ||
result.addAttribute("schedule_modifiers", mod); | ||
if (modifiers.size() > 1) { | ||
mod = parser.getBuilder().getStringAttr(modifiers[1]); | ||
result.addAttribute("simd_modifier", mod); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the formatting off here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not addressed.
f3c5981
to
14b94be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I have one comment. Can be ignored if not necessary.
Can we upstream the mlir portion?
} | ||
|
||
static mlir::omp::ScheduleModifier | ||
getSIMDModifier(const Fortran::parser::OmpScheduleClause &x) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this function be combined with getScheduleModifier?
The implementation supports static schedule for Fortran do loops. This implements the dynamic variant of the same concept. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D97393
When using parallel loop construct, the OpenMP specification allows for guided, auto and runtime as scheduling variants (as well as static and dynamic which are already supported). Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D101435
When lowering the dynamic, guided, auto and runtime types of scheduling, there is an optional monotonic or non-monotonic modifier. This patch adds support in the OMP IR Builder to pass this down to the runtime functions. Also implements tests for the variants. Differential Revision: https://reviews.llvm.org/D102008
Pass the modifiers from the Flang parser to FIR/MLIR workshare loop operation. Not yet supporting the SIMD modifier, which is a bit more work than just adding it to the list of modifiers, so will go in a separate patch. This adds a new field to the WsLoopOp. Also add test for dynamic WSLoop, checking that dynamic schedule calls the init and next functions as expected.
Add support for SIMD modifier in OpenMP worksharing loops.
14b94be
to
cba7222
Compare
In general, feel free to upstream any portions that make sense here. |
Some OpenMP local changes related to SIMD were done in #791 and touched llvm parts outside of flang. These parts were lost in the rebase/cannot be applied anymore since the files changed too much. The upstreaming of these changes is ongoing in: https://reviews.llvm.org/D111051 Try as much as possible to apply D111051 in a way that works with fir-dev environment.
This is a package of 4 patches, three of which are already in LLVM (support for modifiers at time of writing in review). The last one of these changes brings the modifiers from the source code to the LLVM translation.