This is an archive of the discontinued LLVM Phabricator instance.

[MLIR, OpenMP] Introduce extra helper function for clauses of `ParallelOp`
AbandonedPublic

Authored by SouraVX on Oct 13 2020, 1:36 PM.

Details

Summary

These functions can be leveraged while synthesizing attibutes. A typical use case for this is lowering to OpenMPDialect in Flang.

Diff Detail

Event Timeline

SouraVX created this revision.Oct 13 2020, 1:36 PM
Herald added a project: Restricted Project. · View Herald Transcript
SouraVX requested review of this revision.Oct 13 2020, 1:36 PM
SouraVX added a comment.EditedOct 13 2020, 1:39 PM

If we agreed upon this, the next step would be to remodel default clause as UnitAttr also.

rriddle requested changes to this revision.EditedOct 13 2020, 1:40 PM

What kind of issues? This seems like a regression in terms of usability. Can you describe in detail the problems that you were having?

This revision now requires changes to proceed.Oct 13 2020, 1:40 PM
SouraVX added a comment.EditedOct 13 2020, 1:53 PM

What kind of issues? This seems like a regression in terms of usability. Can you describe in detail the problems that you were having?

Thanks for review!
Agreed with your perspective.
The problem I was faced was that, ParseTree models these clauses as enum. Can we synthesize an Attribute using enum value ?
Furthermore, this clause though initially modelled as OptionalAttr, fits well as a UnitAttr. Does changing them now has deeper implications that I'm unaware of ?

@SouraVX You can check functions for creating enum/string values for proc_bind in the following files in the build directory.
./tools/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc
./tools/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc

Once you have the string I guess you can create the StringAttr easily.

SouraVX updated this revision to Diff 298031.Oct 13 2020, 10:20 PM

Ah, potential oversight of details(Sorry for that!). Anyway I've rolled back to initial version and introduced some extra declaration that can be used by Flang(once this patch is in) while lowering.
Aside from this, Should we promote/remodel these attributes as UnitAttr? What do you guys think?

SouraVX retitled this revision from [MLIR, OpenMP] Remodel `proc_bind_kind` clause as a unit attribute to [MLIR, OpenMP] Introduce extra helper function for clauses of `ParallelOp`.Oct 13 2020, 10:21 PM
SouraVX edited the summary of this revision. (Show Details)

I guess @clementval or @rriddle can approve the new extra functions added based on its need in Flang parse-tree lowering or on similar usage for StrEnumAttributes in rest of MLIR.

Aside from this, Should we promote/remodel these attributes as UnitAttr? What do you guys think?

I feel the current modelling as an Optional StrEnumAttribute is fine here. proc_bind and default takes a set of values which are best captured by this modelling. If we have these as unit attributes then all the values can occur at the same time unless disabled using the verifier.

I guess @clementval or @rriddle can approve the new extra functions added based on its need in Flang parse-tree lowering or on similar usage for StrEnumAttributes in rest of MLIR.

Snippet of usability from an upcoming/in-progress patch.

 switch (procBindClause->v) {
+                     case Fortran::parser::OmpProcBindClause::Type::Master:
+                     parallelOp.proc_bind_valAttr(firOpBuilder.getStringAttr(parallelOp.getProcBindValueMasterAttrName()));
+                             break;
+                     case Fortran::parser::OmpProcBindClause::Type::Close:
+                     parallelOp.proc_bind_valAttr(firOpBuilder.getStringAttr(parallelOp.getProcBindValueCloseAttrName()));
+                             break;
+                     case Fortran::parser::OmpProcBindClause::Type::Spread:
+                     parallelOp.proc_bind_valAttr(firOpBuilder.getStringAttr(parallelOp.getProcBindValueSpreadAttrName()));
+                             break;

Aside from this, Should we promote/remodel these attributes as UnitAttr? What do you guys think?

I feel the current modelling as an Optional StrEnumAttribute is fine here. proc_bind and default takes a set of values which are best captured by this modelling. If we have these as unit attributes then all the values can occur at the same time unless disabled using the verifier.

+1

Ping! @ all reviewers.

File ./tools/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc has the following function. Isn't it possible to use this function?
For e.g: If you pass it mlir::omp::ClauseProcBindKind::master it will return the string "master".

::llvm::StringRef stringifyClauseProcBindKind(ClauseProcBindKind val) {

switch (val) {
  case ClauseProcBindKind::master: return "master";
  case ClauseProcBindKind::close: return "close";
  case ClauseProcBindKind::spread: return "spread";
}
return "";

}

Thanks @kiranchandramohan for suggestion. I already tried this thing(didn't worked out).
Unless I'm missing something: There's a type mismatch while interfacing this function. Here's the snippet of usability

case Fortran::parser::OmpProcBindClause::Type::Master:
          parallelOp.proc_bind_valAttr(firOpBuilder.getStringAttr(
           omp::stringifyClauseProcBindKind(procBindClause->v)));
          break;

Error:

error: cannot convert ‘const Fortran::parser::OmpProcBindClause::Type’ to ‘mlir::omp::ClauseProcBindKind’ for argument ‘1’ to ‘llvm::StringRef mlir::omp::stringifyClauseProcBindKind(mlir::omp::ClauseProcBindKind)’
              omp::stringifyClauseProcBindKind(procBindClause->v)));

An alternative solution would be: (but it's hard coding) ? (do you vote for this?)

case Fortran::parser::OmpProcBindClause::Type::Master:
          parallelOp.proc_bind_valAttr(firOpBuilder.getStringAttr(
           StringRef("master")));
          break;
  1. Does the EnumToString function in the parser work for this enum value?
  1. Otherwise, hardcoding is necessary. The solution you are proposing (below) also has hardcoding isn't it?

switch (procBindClause->v) {
+ case Fortran::parser::OmpProcBindClause::Type::Master:
+ parallelOp.proc_bind_valAttr(firOpBuilder.getStringAttr(parallelOp.getProcBindValueMasterAttrName()));

I was suggesting to use the following

switch (procBindClause->v) {
                     case Fortran::parser::OmpProcBindClause::Type::Master:
                     parallelOp.proc_bind_valAttr(firOpBuilder.getStringAttr(omp::stringifyClauseProcBindKind(omp::ClauseProcBindKind::master)));
  1. Does the EnumToString function in the parser work for this enum value?

EnumToString should work on any enum class declared using ENUM_CLASS. That's the best way to avoid repeating the name in a string.

SouraVX abandoned this revision.Oct 16 2020, 9:08 AM

Thanks @kiranchandramohan for helping out in this :). I'm abandoning this in favor of your approach. (Updating the PR also)
Thanks @tskeith for suggestion, I'll take a note of this.