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

[OpenMP][flang][do-conc] Map values depending on values defined outside target region. #148

Merged

Conversation

ergawy
Copy link

@ergawy ergawy commented Aug 20, 2024

Adds support for do concurrent mapping when mapped value(s) depend on values defined outside the target region; e.g. the size of the array is dynamic. This needs to be handled by localizing these region outsiders by either cloning them in the region or in case we cannot do that, map them and use the mapped values.

@ergawy ergawy force-pushed the do_concurrent_runtime_sized_arrays branch from dde321c to f434fdc Compare August 20, 2024 08:43
@ergawy ergawy changed the title [OpenMP][flang][do-conc] Map values depending on values defined outsi… [OpenMP][flang][do-conc] Map values depending on values defined outside target region. Aug 20, 2024
Copy link

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@skatrak skatrak 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 Kareem, I have a couple comments.

while (!valuesDefinedAbove.empty()) {
for (mlir::Value val : valuesDefinedAbove) {
mlir::Operation *valOp = val.getDefiningOp();
if (mlir::isMemoryEffectFree(valOp)) {
Copy link

Choose a reason for hiding this comment

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

The case where the value defined above is a block argument (valOp == nullptr) will cause the compiler to crash during this check. If there is a reason why that's never supposed to happen, I'd suggest adding a specific assert for it. Otherwise, I think that case should be handled.

Copy link
Author

Choose a reason for hiding this comment

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

This is copied from OpenMP.cpp and will extracted to a shared util later (see TODO above the function). So I assume we did not hit problems with this yet. But I agree with you, I added an assert here and OpenMP.cpp to be on the safe side.

mlir::Operation *clonedOp = valOp->clone();
regionBlock->push_front(clonedOp);
val.replaceUsesWithIf(
clonedOp->getResult(0), [regionBlock](mlir::OpOperand &use) {
Copy link

Choose a reason for hiding this comment

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

If valOp defines multiple values and val is not the first, clonedOp->getResult(0) won't be the right value to use here. This probably needs a bit of refinement to find the right index. Another issue is that, if multiple values defined by the same operation above are used inside the target region, it will result in the same operation being cloned multiple times.

Copy link
Author

Choose a reason for hiding this comment

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

Added an assert as well.

flang/lib/Optimizer/Transforms/DoConcurrentConversion.cpp Outdated Show resolved Hide resolved
llvm::SmallVector<mlir::Value> bounds;
std::stringstream name;
builder.setInsertionPoint(targetOp);
mlir::Value mapOp = createMapInfoOp(
Copy link

Choose a reason for hiding this comment

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

Nit: Would it be possible to use genMapInfoOpForLiveIn, perhaps adapting it if needed? I'm just wondering this code seems duplicated and we'd eventually need to support all sorts of types in both cases.

Copy link
Author

Choose a reason for hiding this comment

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

I want to keep both this and the corresponding Lower/OpenMP.cpp code as close as possible to extract into a shared util (hopefully soon once I am done with getting LBL's codebase to work for the device).

flang/lib/Optimizer/Transforms/DoConcurrentConversion.cpp Outdated Show resolved Hide resolved
…de target region.

Adds support for `do concurrent` mapping when mapped value(s) depend on
values defined outside the target region; e.g. the size of the array is
dynamic. This needs to be handled by localizing these region outsiders
by either cloning them in the region or in case we cannot do that, map
them and use the mapped values.
@ergawy ergawy force-pushed the do_concurrent_runtime_sized_arrays branch from f434fdc to 93c1ec3 Compare August 22, 2024 04:45
Copy link

@skatrak skatrak 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 Kareem, I didn't realize this was duplicated code from OpenMP.cpp. Hopefully we can start extracting shared features soon, since this pass is getting quite large with duplicated logic.

@ergawy ergawy merged commit f8b719f into ROCm:amd-trunk-dev Aug 27, 2024
2 of 4 checks passed
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.

3 participants