This is an archive of the discontinued LLVM Phabricator instance.

[mlir][OpenMP] Add support for SIMD modifier
ClosedPublic

Authored by Leporacanthicus on Oct 4 2021, 5:48 AM.

Details

Summary

Add support for SIMD modifier in OpenMP worksharing loops.

Diff Detail

Event Timeline

Leporacanthicus created this revision.Oct 4 2021, 5:48 AM
Leporacanthicus requested review of this revision.Oct 4 2021, 5:48 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript

Trying to get two commits in one arcanist command - may not work

ftynse requested changes to this revision.Oct 6 2021, 1:05 AM
ftynse added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
231–232

I'm not sure I understand the modeling here. The same enum attribute is listed twice with different names, and there is no verification of what can go where. It looks like one can have OMP_SCHEUDLE_MOD_SIMD as schedule_modifiers and OMP__SCHEDULE_MOD_None as simd_modifier. Or even monotonic in one and non-monotonic in the other.

Should SIMD be just a unit attribute?

Also consider renaming schedule_modifiers to schedule_modifier (singular) because it can only contain a single instance anyway.

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
272–275

Nit: you may need to update this comment

860

This needs to error out with a message if there is more than two modifiers.

We also need a verifier that checks that modifiers are what we expect them to be, e.g., there's no conflict between monotonic and non-monotonic, no repetition, etc. See the remark above.

990

It looks preferable to have the default case here (modifier is none and missing modifier are the same, aren't they?) and just avoid extra printing in that case altogether.

This revision now requires changes to proceed.Oct 6 2021, 1:05 AM

There is an RFC for better support for unordered lists in MLIR assembly, maybe that could be used. However, as @Leporacanthicus mentioned in the OpenMP/flang conference call, D111051 and this are part of upstreaming the fir-dev branch. In the interest of not making the upstreaming process for fir-dev more difficult, we should consider to keep the delta low and defer larger changes after complete upstreaming of fir-dev.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
231–232

Since simd is also a schedule modifier, maybe rename schedule_modifiers to monotonicity_modifier? I.e. we'd have monotonicity_[schedule_]modifier and simd_[schedule_]modifier.

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
990

[serious] I think there might be a real bug here. If no monotonicity modifier is used, but the simd modifier, then according this code will print schedule(static,simd). However, the parsing code will interpret the first modifier as monotonicity modifier, and try to interpret simd as one.

Update to match changes in dependent commit (+ rebase)

Leporacanthicus marked an inline comment as done.Oct 26 2021, 4:33 AM
Leporacanthicus added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
231–232

I haven't completely fixed this, but i have added error checking code in a separate commit [to keep changes here to a minimum -> helping the rebase on fir-dev to avoid too much problems]. https://reviews.llvm.org/D112526

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
272–275

Done as a separate commit. https://reviews.llvm.org/D112526

860

Done in a separate commit:
https://reviews.llvm.org/D112526

990

Done in a separate commit, see https://reviews.llvm.org/D112526

ftynse added inline comments.Oct 28 2021, 1:52 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
231–232

Why can't that commit be folded into this change? It has not landed yet, and it would be significantly easier to review to bisect if necessary. This may require rebasing some downstream patchset, but that is the usual price to pay for developing downstream.

Leporacanthicus marked an inline comment as done.Nov 1 2021, 10:39 AM

BUMP.

BUMP.

Could you address @ftynse's question on why you create new reviews instead of updating this one?

Squashed the "fixes" commit and the original commit

Thanks for this patch. I have a few comments @Leporacanthicus.

Could you please clarify the purpose of mlir/test/Target/LLVMIR/openmp-llvm-bad-schedule-modifier.mlir? As far as I can tell, these tests can be a part of llvm-project/mlir/test/Dialect/OpenMP/invalid.mlir.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
231–232

+1 to SIMD being a unit attribute.

Would it be better to have an ArrayAttr of ScheculeModifier (similar to the spec)?

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
245

suggestion: renaming it to verifyScheduleClause and calling it from verifyWsLoopOp?

mlir/test/Target/LLVMIR/openmp-llvm.mlir
525–526

nit: indentation

537–538

nit: indentation

ftynse accepted this revision.Nov 5 2021, 4:55 AM

LGTM when all comments are addresesd.

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
258

Nit: please use braces symmterically

269

Having two terms on the LHS isn't valid BNF AFAIK.

274

Ditto, I don't understand what this wants to say.

307

I believe there is a function symbolizeScheduleModifier or something similar that is generated from ODS, which returns Optional<ScheduleModifier> equal to None if the wrong keyword is used. This avoids magic strings and is also future-proof.

307–310

Nit: I would have put this into the validation function.

This revision is now accepted and ready to land.Nov 5 2021, 4:55 AM
Leporacanthicus marked 3 inline comments as done.

Fix review comments

Leporacanthicus marked an inline comment as done.

Make simd_modifier a unit-attribute and fix formatting

Leporacanthicus marked 2 inline comments as done.Nov 17 2021, 9:46 AM
Leporacanthicus added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
231–232

I've made the simd_modifier into a unit attribute.

This will need to be updated in fir-dev to match, I will make a patch for that when I get this one into llvm/main.

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
245

Rename: I've changed the name to verifyScheduelModifiers to represent what it does.
Calling it from verifyWsLoopOp: some of the error checking done here can't be done at that point - such as checking if there's more than two modifiers, because we no longer have the array of modifiers, only the two that has been stored in the WsLoopOp.

258

Rewritten it in a simpler way to reduce the need for parenthesis.

269

Darned clang-format has messed with my comments!

I'll fix, but may need to use shorter names.

274

Ditto clang-format reflowing comments.

307

Indeed there is. I'm changing this here, and then doing a similar change for the ScheduleKind which is being tested in form of strings above.

mlir/test/Target/LLVMIR/openmp-llvm.mlir
525–526

Fixing all of the incorrectly formatted tests (all my fault!)

peixin added a subscriber: peixin.Nov 24 2021, 7:14 PM

LGTM.

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
695

The simd modifier info is not passed to applyStaticWorkshareLoop. That is, the schedule type of StaticBalancedChunked is not handled and checked. Considering this function is refactored in https://reviews.llvm.org/D114413. Maybe you can merge this patch, and let it to be handled in D114413.

This revision was automatically updated to reflect the committed changes.
Leporacanthicus marked an inline comment as done.Nov 26 2021, 6:49 AM
Leporacanthicus added inline comments.
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
695

Thanks for the LGTM. I've pushed this patch, and if you are happy to do that in D114413, then do that - or we can fix it in a different patch.

peixin added inline comments.Nov 28 2021, 4:22 AM
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
695

OK. It is better to let one patch focus on one thing. Please remember to make this fix after D114413 is accepted and merged.