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

Move reduction lowering from DistributeOp to TeamsOp and use teams reduction clauses to generate info. #159

Merged
merged 5 commits into from
Sep 30, 2024

Conversation

jsjodin
Copy link

@jsjodin jsjodin commented Sep 17, 2024

This patch moves the reduction lowering from the DistributeOp to the TeamsOp by enabling the reduction clauses on the TeamsOp and generate the reductions from those clauses. This makes the composite code generation obsolete since the reduction information can be recomputed. This change should also allow having separate teams and wsloop reductions in the same block.
Co-author: @skatrak

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 Jan, this indeed looks a lot better. I have a couple of nits, but generally LGTM. If it's already passing Lit and smoke-fort tests I think we should merge it.

@@ -0,0 +1,15 @@
! RUN: %flang_fc1 -emit-fir -fopenmp -o - %s | FileCheck %s
Copy link

Choose a reason for hiding this comment

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

Nit: Maybe we can name this test "reduction-target-spmd.f90" and keep another simpler "reduction-teams.f90" with the same example that was removed from the "Todo" subdirectory.

RI.ReductionGen(Builder.saveIP(), RHSValue, LHSValue, Reduced);
Builder.CreateStore(Reduced, LHS, false);
}
Value *LHSValue = Builder.CreateLoad(RI.ElementType, LHS, "final.lhs");
Copy link

Choose a reason for hiding this comment

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

Nit: Remove HasDistribute function argument, since it's no longer necessary.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's a good point.

Comment on lines 928 to 929
bool isNowait = false, bool isTeamsReduction = false,
bool hasDistribute = false) {
Copy link

Choose a reason for hiding this comment

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

Suggested change
bool isNowait = false, bool isTeamsReduction = false,
bool hasDistribute = false) {
bool isNowait = false, bool isTeamsReduction = false) {

Comment on lines 3833 to 3834
// FIXME: This treats 'DO SIMD' as if it was a 'DO' construct. Reductions
// on other constructs apart from 'DO' aren't considered either.
Copy link

Choose a reason for hiding this comment

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

Nit: We can remove this comment now, since we're no longer looking for the wrappers of an omp.loop_nest.

}

template <typename OpTy>
static uint64_t getReductionDataSize(OpTy &op) {
Copy link

Choose a reason for hiding this comment

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

Don't we currently need this for other reductions? If not, do we expect to use it elsewhere or is this actually only needed to be calculated for teams reductions within a target region?

Copy link
Author

Choose a reason for hiding this comment

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

I think it is only needed for the team reduction, but I figured if we ever want to know the data size for parallel/workshare it doesn't hurt to parameterize the code.

return convertTargetDeviceOp(op, builder, moduleTranslation,
dispatchList);
return convertTargetOpsInNest(op, builder, moduleTranslation);
if (isTargetDeviceOp(op)) {
Copy link

Choose a reason for hiding this comment

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

Nit: I think the previous formatting is the preferred one (no unnecessary braces and no 'else' after 'return').

@jsjodin jsjodin merged commit 66ee96f into amd-trunk-dev Sep 30, 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.

2 participants