Skip to content

[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

Merged
merged 5 commits into from
Jul 23, 2021

Conversation

Leporacanthicus
Copy link
Collaborator

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.

@jeanPerier
Copy link
Collaborator

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.

Copy link

@schweitzpgi schweitzpgi left a 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.

return mlir::omp::ClauseScheduleModifier::Monotonic;
case Fortran::parser::OmpScheduleModifierType::ModType::Nonmonotonic:
return mlir::omp::ClauseScheduleModifier::Nonmonotonic;
default:

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.

if (modifier) {
const auto &modType1 =
std::get<Fortran::parser::OmpScheduleModifier::Modifier1>(modifier->t);
// TODO: Add support for SIMD, which means modType2 gets used.

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.

Copy link
Collaborator Author

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... :)

@Leporacanthicus Leporacanthicus force-pushed the modifiers branch 2 times, most recently from 7ccb9b8 to 60d6c24 Compare May 26, 2021 17:06
@jeanPerier
Copy link
Collaborator

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.

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.

@Leporacanthicus
Copy link
Collaborator Author

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.

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! :(

@Leporacanthicus
Copy link
Collaborator Author

Right, finally got this updated to the current version of F18.

I believe I've fixed all previous review comments.

Copy link
Collaborator

@kiranchandramohan kiranchandramohan left a 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) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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()) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
}
Copy link
Collaborator

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.

}

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) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point.

Comment on lines 641 to 646
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);
}
Copy link
Collaborator

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?

Copy link
Collaborator

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.

@Leporacanthicus Leporacanthicus force-pushed the modifiers branch 2 times, most recently from f3c5981 to 14b94be Compare July 12, 2021 11:07
Copy link
Collaborator

@kiranchandramohan kiranchandramohan left a 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) {
Copy link
Collaborator

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.
@schweitzpgi
Copy link

LGTM. I have one comment. Can be ignored if not necessary.

Can we upstream the mlir portion?

In general, feel free to upstream any portions that make sense here.

@schweitzpgi schweitzpgi merged commit 18b0621 into flang-compiler:fir-dev Jul 23, 2021
jeanPerier added a commit that referenced this pull request Oct 27, 2021
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.
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.

5 participants