Skip to content

[OpenMPOpt] Make parallel regions reachable from new DeviceRTL loop functions #150927

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

Open
wants to merge 1 commit into
base: users/skatrak/flang-generic-05-parallel-wrapper
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5020,6 +5020,28 @@ struct AAKernelInfoCallSite : AAKernelInfo {
case OMPRTL___kmpc_free_shared:
// Return without setting a fixpoint, to be resolved in updateImpl.
return;
case OMPRTL___kmpc_distribute_static_loop_4:
case OMPRTL___kmpc_distribute_static_loop_4u:
case OMPRTL___kmpc_distribute_static_loop_8:
case OMPRTL___kmpc_distribute_static_loop_8u:
case OMPRTL___kmpc_distribute_for_static_loop_4:
case OMPRTL___kmpc_distribute_for_static_loop_4u:
case OMPRTL___kmpc_distribute_for_static_loop_8:
case OMPRTL___kmpc_distribute_for_static_loop_8u:
case OMPRTL___kmpc_for_static_loop_4:
case OMPRTL___kmpc_for_static_loop_4u:
case OMPRTL___kmpc_for_static_loop_8:
case OMPRTL___kmpc_for_static_loop_8u:
// Parallel regions might be reached by these calls, as they take a
// callback argument potentially arbitrary user-provided code.
ReachedUnknownParallelRegions.insert(&CB);
// TODO: The presence of these calls on their own does not prevent a
// kernel from being SPMD-izable. We mark it as such because we need
// further changes in order to also consider the contents of the
// callbacks passed to them.
SPMDCompatibilityTracker.indicatePessimisticFixpoint();
SPMDCompatibilityTracker.insert(&CB);
break;
default:
// Unknown OpenMP runtime calls cannot be executed in SPMD-mode,
// generally. However, they do not hide parallel regions.
Expand Down
130 changes: 130 additions & 0 deletions offload/test/offloading/fortran/target-generic-loops.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
! Offloading test for generic target regions containing different kinds of
! loop constructs inside.
! REQUIRES: flang, amdgpu

! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
integer :: i1, i2, n1, n2, counter

n1 = 100
n2 = 50

counter = 0
!$omp target map(tofrom:counter)
!$omp teams distribute reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do
!$omp end target

! CHECK: 1 100
print '(I2" "I0)', 1, counter

counter = 0
!$omp target map(tofrom:counter)
!$omp parallel do reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do
!$omp parallel do reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do
!$omp end target

! CHECK: 2 200
print '(I2" "I0)', 2, counter

counter = 0
!$omp target map(tofrom:counter)
counter = counter + 1
!$omp parallel do reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do
counter = counter + 1
!$omp parallel do reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do
counter = counter + 1
!$omp end target

! CHECK: 3 203
print '(I2" "I0)', 3, counter

counter = 0
!$omp target map(tofrom: counter)
counter = counter + 1
!$omp parallel do reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do
counter = counter + 1
!$omp end target

! CHECK: 4 102
print '(I2" "I0)', 4, counter


counter = 0
!$omp target teams distribute reduction(+:counter)
do i1=1, n1
!$omp parallel do reduction(+:counter)
do i2=1, n2
counter = counter + 1
end do
end do

! CHECK: 5 5000
print '(I2" "I0)', 5, counter

counter = 0
!$omp target teams distribute reduction(+:counter)
do i1=1, n1
counter = counter + 1
!$omp parallel do reduction(+:counter)
do i2=1, n2
counter = counter + 1
end do
counter = counter + 1
end do

! CHECK: 6 5200
print '(I2" "I0)', 6, counter

counter = 0
!$omp target teams distribute reduction(+:counter)
do i1=1, n1
!$omp parallel do reduction(+:counter)
do i2=1, n2
counter = counter + 1
end do
!$omp parallel do reduction(+:counter)
do i2=1, n2
counter = counter + 1
end do
end do

! CHECK: 7 10000
print '(I2" "I0)', 7, counter

counter = 0
!$omp target teams distribute reduction(+:counter)
do i1=1, n1
counter = counter + 1
!$omp parallel do reduction(+:counter)
do i2=1, n2
counter = counter + 1
end do
counter = counter + 1
!$omp parallel do reduction(+:counter)
do i2=1, n2
counter = counter + 1
end do
counter = counter + 1
end do

! CHECK: 8 10300
print '(I2" "I0)', 8, counter
end program
39 changes: 39 additions & 0 deletions offload/test/offloading/fortran/target-spmd-loops.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
! Offloading test for generic target regions containing different kinds of
! loop constructs inside.
! REQUIRES: flang, amdgpu

! RUN: %libomptarget-compile-fortran-run-and-check-generic
program main
integer :: i1, n1, counter

n1 = 100

counter = 0
!$omp target parallel do reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do

! CHECK: 1 100
print '(I2" "I0)', 1, counter

counter = 0
!$omp target map(tofrom:counter)
!$omp parallel do reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do
!$omp end target

! CHECK: 2 100
print '(I2" "I0)', 2, counter

counter = 0
!$omp target teams distribute parallel do reduction(+:counter)
do i1=1, n1
counter = counter + 1
end do

! CHECK: 3 100
print '(I2" "I0)', 3, counter
end program