Page MenuHomePhabricator

Adding support for target in_reduction
ClosedPublic

Authored by RitanyaB on May 16 2022, 1:16 AM.

Details

Summary

Implementing target in_reduction by wrapping target task with host task with in_reduction and if clause. This is in compliance with OpenMP 5.0 section: 2.19.5.6.
So, this

#pragma omp target in_reduction(+:res)
  for (int i=0; i<N; i++) {
    res = res+i
  }

will become

#pragma omp task in_reduction(+:res) if(0)
#pragma omp target map(res)
for (int i=0; i<N; i++) {
  res = res+i
}

Diff Detail

Event Timeline

RitanyaB created this revision.May 16 2022, 1:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 1:16 AM
RitanyaB requested review of this revision.May 16 2022, 1:16 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript

Could someone please review the changes?

Thanks.

ABataev added inline comments.Tue, Jun 14, 5:24 AM
clang/lib/CodeGen/CGStmtOpenMP.cpp
5059–5063

Why integer, not a boolean? Also, this is currently meaningless, since these 2 vars are not visible outside of the if context.

RitanyaB updated this revision to Diff 438554.Tue, Jun 21, 4:42 AM

The if condition in the method EmitOMPTargetTaskBasedDirective in CGStmtOpenMP.cpp file was removed since it was unnecessary.

What about the description? Shall we still emit if(0)?

RitanyaB marked an inline comment as done.Thu, Jun 23, 3:23 AM

What about the description? Shall we still emit if(0)?

Can you please elaborate for more clarity?

clang/lib/CodeGen/CGStmtOpenMP.cpp
5059–5063

Thank you for the suggestion. I have removed the if block.

What about the description? Shall we still emit if(0)?

Can you please elaborate for more clarity?

The description of the patch
So, this

#pragma omp target in_reduction(+:res)

for (int i=0; i<N; i++) {
  res = res+i
}

will become

#pragma omp task in_reduction(+:res) if(0)
#pragma omp target map(res)
for (int i=0; i<N; i++) {

res = res+i

}

So, the question is is this still true?

What about the description? Shall we still emit if(0)?

Can you please elaborate for more clarity?

The description of the patch
So, this

#pragma omp target in_reduction(+:res)

for (int i=0; i<N; i++) {
  res = res+i
}

will become

#pragma omp task in_reduction(+:res) if(0)
#pragma omp target map(res)
for (int i=0; i<N; i++) {

res = res+i

}

So, the question is is this still true?

The idea here is to wrap the target task with a host task and move in_reduction to that new host task with if(0) condition, making it an undeferred task. The approach here is basically using the framework that is in place for the host in_reduction.

This revision is now accepted and ready to land.Thu, Jun 23, 8:28 AM
This revision was landed with ongoing or failed builds.Mon, Jun 27, 8:37 AM
Closed by commit rG8322fe200d60: Adding support for target in_reduction (authored by RitanyaB, committed by cchen). · Explain Why
This revision was automatically updated to reflect the committed changes.