forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang][OpenMP] Generate implicit mapping for reduction variable. (#15)
* Generate implicit mapping for reduction variable. The result of the reduction was not being copied back to reduction variable on the host. To sidestep this problem, an explicit map(tofrom: var) has to be added in the code to get the result back. This patch tries to solve this problem by generating an implicit tofrom mapping for reduction variable. All variables used in the target region (and without an explicit mapping) gets an implcit mapping in getTargetOP. We switch on TO,FROM bits for reduction varibles on this mapping. * Move code to get the reduction variables into separate function.
- Loading branch information
Showing
2 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s | ||
|
||
! This test checks that if reduction clause is on a combined target | ||
! construct, there is an implicit map(tofrom) for each reduction variable. | ||
|
||
! construct with target | ||
subroutine omp_target_combined | ||
implicit none | ||
integer(kind = 8) :: s1 | ||
integer(kind = 8) :: s2 | ||
integer(kind = 4) :: i | ||
s1 = 1 | ||
s2 = 1 | ||
!$omp target teams distribute parallel do reduction(+:s1) reduction(+:s2) | ||
do i=1,1000 | ||
s1 = s1 + i | ||
s2 = s2 + i | ||
end do | ||
!$omp end target teams distribute parallel do | ||
return | ||
end subroutine omp_target_combined | ||
!CHECK-LABEL: func.func @_QPomp_target_combined() { | ||
!CHECK: omp.map_info var_ptr({{.*}} : !fir.ref<i64>, i64) map_clauses(implicit, tofrom) capture(ByRef) -> !fir.ref<i64> {name = "s1"} | ||
!CHECK: omp.map_info var_ptr({{.*}} : !fir.ref<i64>, i64) map_clauses(implicit, tofrom) capture(ByRef) -> !fir.ref<i64> {name = "s2"} | ||
!CHECK: omp.map_info var_ptr({{.*}} : !fir.ref<i32>, i32) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !fir.ref<i32> {name = "i"} | ||
|
||
subroutine omp_target_team_separate | ||
implicit none | ||
integer(kind = 8) :: s3 | ||
integer i | ||
s3 = 1 | ||
!$omp target | ||
s3 = 2 | ||
!$omp teams distribute parallel do reduction(+:s3) | ||
do i=1,1000 | ||
s3 = s3 + i | ||
end do | ||
!$omp end teams distribute parallel do | ||
!$omp end target | ||
return | ||
end subroutine omp_target_team_separate | ||
!CHECK-LABEL: func.func @_QPomp_target_team_separate() { | ||
!CHECK: omp.map_info var_ptr({{.*}} : !fir.ref<i64>, i64) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !fir.ref<i64> {name = "s3"} |