Skip to content
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

[flang][OpenMP] Lower private, firstprivate, shared, copyin clauses for Parallel construct #456

Merged
merged 1 commit into from
Oct 2, 2020

Conversation

SouraVX
Copy link
Collaborator

@SouraVX SouraVX commented Sep 28, 2020

TODO:
Handle Attribute based clauses:

  1. Default clause
  2. ProcBind clause

@@ -21,6 +23,32 @@

#define TODO() llvm_unreachable("not yet implemented")

static const Fortran::parser::Name *
getDesignatorNameIfDataRef(const Fortran::parser::Designator &designator) {
const auto *dataRef{std::get_if<Fortran::parser::DataRef>(&designator.u)};

Choose a reason for hiding this comment

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

LLVM/MLIR prefer type var = expression; style. For consistency with MLIR, we follow that style in lowering.

} else if (const auto &defaultClause =
std::get_if<Fortran::parser::OmpDefaultClause>(
&clause.u)) {
TODO();
Copy link

@schweitzpgi schweitzpgi Sep 28, 2020

Choose a reason for hiding this comment

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

We're moving to TODO("string") in lowering. The string can be anything, including "", of course. See Todo.h for more.

@@ -11,6 +11,8 @@
//===----------------------------------------------------------------------===//

#include "flang/Lower/OpenMP.h"
#include "SymbolMap.h"

Choose a reason for hiding this comment

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

Is this include required? (I probably just missed it while skimming...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Yea, not needed. Must be residual of my other work.

defaultClauseOperand.dyn_cast_or_null<StringAttr>(),
privateClauseOperands, firstprivateClauseOperands, sharedClauseOperands,
copyinClauseOperands,
procBindClauseOperand.dyn_cast_or_null<StringAttr>());
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can move the handling of proc_bind and default clause after the op create so you can directly set attribute on it. The code below should get you there. Didn't build it so might need some changes. Also I guess there should be helper functions generated by MLIR TableGen to get the name of the Attr and not hardcoding it

Suggested change
procBindClauseOperand.dyn_cast_or_null<StringAttr>());
procBindClauseOperand.dyn_cast_or_null<StringAttr>());
// Clauses mapped to attributes.
for (const auto &clause : parallelOpClauseList.v) {
if (const auto &procBindClause =
std::get_if<Fortran::parser::OmpProcBindClause>(
&clause.u)) {
switch (procBindClause.v) {
case OmpProcBindClause::Type::Close:
parallelOp.setAttr("proc_bind_val", llvm::omp::OMP_PROC_BIND_close);
break;
case OmpProcBindClause::Type::Master:
parallelOp.setAttr("proc_bind_val", llvm::omp::OMP_PROC_BIND_master);
break;
case OmpProcBindClause::Type::Spread:
parallelOp.setAttr("proc_bind_val", llvm::omp::OMP_PROC_BIND_spread);
break;
} else if (const auto &defaultClause =
std::get_if<Fortran::parser::OmpDefaultClause>(
&clause.u)) {
switch (defaultClause.v) {
case OmpDefaultClause::Type::Private:
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultPrivate);
break;
case OmpDefaultClause::Type::Firstprivate:
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultFirstprivate);
break;
case OmpDefaultClause::Type::Shared:
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultShared);
break;
case OmpDefaultClause::Type::None:
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultNone);
break;
}
}
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the suggestion!, I also looked for other solutions.
This one doesn't work since mlir::omp::ClauseDefault::ClauseDefaultNone doesn't implicitly converts to Attribute.

parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultNone);

Maybe these 2 attributes based clauses deserves a fresh look separately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As I mentioned, there is probably helper functions to translate enum to string for that purpose. This should be in the tablegen generated file for the OpenMP dialect.

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.

+1 for the progress here. See a few comments inline.

@@ -21,6 +23,32 @@

#define TODO() llvm_unreachable("not yet implemented")

static const Fortran::parser::Name *
getDesignatorNameIfDataRef(const Fortran::parser::Designator &designator) {
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 shared (with OpenACC, possibly elsewhere too) by putting it in a commonplace?

return dataRef ? std::get_if<Fortran::parser::Name>(&dataRef->u) : nullptr;
}

static void genObjectList(const Fortran::parser::OmpObjectList &objectList,
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 be shared too?

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, I'm observing and marking these. Some of the Directive handling code can be shared(Maybe LowerDirectives.cpp in lib/Lower dir ? or so..). But these are not on top of my priority list as of now.
Since they may break things(for short term) in Lowering of OpenACC or OpenMP of which both are developing rapidly and to some sort orthogonal to each other.

!LLVMIR: call void @_QQmain..omp_par
!LLVMIR: call void @__kmpc_end_serialized_parallel

program ifclause
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 few more variants with true, false, constant eval logical expression, logical variable on the if clause.

!LLVMIRDialect: omp.terminator
!LLVMIRDialect: }

program private_clause
Copy link
Collaborator

Choose a reason for hiding this comment

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

A few more variants,
-> subroutine arguments.
-> Array

Copy link
Collaborator Author

@SouraVX SouraVX Sep 29, 2020

Choose a reason for hiding this comment

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

Done thanks!
Just wanted clarify that array print inside a omp region doesn't work(crashes). So test cases captures array, however do not attempt to print them.
This may be related to:
#454
I think once we have the minimal set of operations lowered to fir dialect, we can start to focus on phase ordering/lower level issues. This will again help us to re-establish end-to-end functional test cases.

} else if (const auto &procBindClause =
std::get_if<Fortran::parser::OmpProcBindClause>(
&clause.u)) {
TODO("default clause for omp parallel");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I'll take care of this in subsequent revision.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you don't handle these in this PR, can you adapt the name of the PR and description to reflect it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, makes sense! Actually just now I noticed there's one more clause allocate defined in 5.0 standard, currently in review stage.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rin is handling the allocate clause. You can leave that for now.

} else if (const auto &procBindClause =
std::get_if<Fortran::parser::OmpProcBindClause>(
&clause.u)) {
TODO("default clause for omp parallel");
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you don't handle these in this PR, can you adapt the name of the PR and description to reflect it.

@SouraVX SouraVX changed the title [flang][OpenMP] Handle the remaining clauses for parallel construct [flang][OpenMP] Lower private, firstprivate, shared, copyin clauses for Parallel construct Sep 29, 2020
@SouraVX
Copy link
Collaborator Author

SouraVX commented Sep 29, 2020

@schweitzpgi plan is to merge this PR post this week scheduled merge. Some changes are still in LLVM master.
I'll straighten up this PR and keep you posted.
Thanks!

…or Parallel construct

 TODO:
    Handle Attribute based clauses:
    1. Default clause
    2. ProcBind clause
@SouraVX
Copy link
Collaborator Author

SouraVX commented Oct 2, 2020

Squashed and prepared for merging.

@schweitzpgi schweitzpgi merged commit 9550c6e into flang-compiler:fir-dev Oct 2, 2020
SouraVX added a commit to llvm/llvm-project that referenced this pull request Oct 23, 2020
Note: This patch reflects the work that can be upstreamed from PR's(merged):

1. flang-compiler#456
2. flang-compiler#485

Also replaced TODO with new TODO.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D89769
arichardson pushed a commit to arichardson/llvm-project that referenced this pull request Mar 25, 2021
Note: This patch reflects the work that can be upstreamed from PR's(merged):

1. flang-compiler/f18-llvm-project#456
2. flang-compiler/f18-llvm-project#485

Also replaced TODO with new TODO.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D89769
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this pull request Oct 7, 2022
Note: This patch reflects the work that can be upstreamed from PR's(merged):

1. flang-compiler/f18-llvm-project#456
2. flang-compiler/f18-llvm-project#485

Also replaced TODO with new TODO.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D89769
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.

4 participants