-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Changes to map variables in link clause of declare target #83643
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d1fe42b
[flang] Changes to correctly map variables in link clause of declare …
anchuraj 1721b2b
Revision 2: adding runtime test, fixing comment
anchuraj e776601
R3: Reformatting test cases, adding a scalar test
anchuraj 43e31c3
R4: Fixing minor formating issues in the test
anchuraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,55 @@ | ||
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s | ||
!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s | ||
!RUN: bbc -emit-hlfir -fopenmp %s -o - | FileCheck %s | ||
!RUN: bbc -emit-hlfir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s | ||
|
||
program test_link | ||
|
||
integer :: test_int = 1 | ||
!$omp declare target link(test_int) | ||
|
||
integer :: test_array_1d(3) = (/1,2,3/) | ||
!$omp declare target link(test_array_1d) | ||
|
||
integer, pointer :: test_ptr1 | ||
!$omp declare target link(test_ptr1) | ||
|
||
integer, target :: test_target = 1 | ||
!$omp declare target link(test_target) | ||
|
||
integer, pointer :: test_ptr2 | ||
!$omp declare target link(test_ptr2) | ||
|
||
!CHECK-DAG: {{%.*}} = omp.map_info var_ptr({{%.*}} : !fir.ref<i32>, i32) map_clauses(implicit, tofrom) capture(ByRef) -> !fir.ref<i32> {name = "test_int"} | ||
!$omp target | ||
test_int = test_int + 1 | ||
!$omp end target | ||
|
||
|
||
!CHECK-DAG: {{%.*}} = omp.map_info var_ptr({{%.*}} : !fir.ref<!fir.array<3xi32>>, !fir.array<3xi32>) map_clauses(implicit, tofrom) capture(ByRef) bounds({{%.*}}) -> !fir.ref<!fir.array<3xi32>> {name = "test_array_1d"} | ||
!$omp target | ||
do i = 1,3 | ||
test_array_1d(i) = i * 2 | ||
end do | ||
!$omp end target | ||
|
||
allocate(test_ptr1) | ||
test_ptr1 = 1 | ||
!CHECK-DAG: {{%.*}} = omp.map_info var_ptr({{%.*}} : !fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.box<!fir.ptr<i32>>) map_clauses(implicit, tofrom) capture(ByRef) members({{%.*}} : !fir.llvm_ptr<!fir.ref<i32>>) -> !fir.ref<!fir.box<!fir.ptr<i32>>> {name = "test_ptr1"} | ||
!$omp target | ||
test_ptr1 = test_ptr1 + 1 | ||
!$omp end target | ||
|
||
!CHECK-DAG: {{%.*}} = omp.map_info var_ptr({{%.*}} : !fir.ref<i32>, i32) map_clauses(implicit, tofrom) capture(ByRef) -> !fir.ref<i32> {name = "test_target"} | ||
!$omp target | ||
test_target = test_target + 1 | ||
!$omp end target | ||
|
||
|
||
!CHECK-DAG: {{%.*}} = omp.map_info var_ptr({{%.*}} : !fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.box<!fir.ptr<i32>>) map_clauses(implicit, tofrom) capture(ByRef) members({{%.*}} : !fir.llvm_ptr<!fir.ref<i32>>) -> !fir.ref<!fir.box<!fir.ptr<i32>>> {name = "test_ptr2"} | ||
test_ptr2 => test_target | ||
!$omp target | ||
test_ptr2 = test_ptr2 + 1 | ||
!$omp end target | ||
|
||
end |
33 changes: 0 additions & 33 deletions
33
openmp/libomptarget/test/offloading/fortran/declare-target-array-in-target-region.f90
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
openmp/libomptarget/test/offloading/fortran/declare-target-vars-in-target-region.f90
This file contains hidden or 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,81 @@ | ||
! Offloading test with a target region mapping a declare target | ||
! Fortran array writing some values to it and checking the host | ||
! correctly receives the updates made on the device. | ||
! REQUIRES: flang | ||
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO | ||
! UNSUPPORTED: aarch64-unknown-linux-gnu | ||
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO | ||
! UNSUPPORTED: x86_64-pc-linux-gnu | ||
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO | ||
|
||
! RUN: %libomptarget-compile-fortran-run-and-check-generic | ||
module test_0 | ||
implicit none | ||
INTEGER :: arr1(10) = (/0,0,0,0,0,0,0,0,0,0/) | ||
INTEGER :: arr2(10) = (/0,0,0,0,0,0,0,0,0,0/) | ||
!$omp declare target link(arr1) enter(arr2) | ||
INTEGER :: scalar = 1 | ||
!$omp declare target link(scalar) | ||
end module test_0 | ||
|
||
subroutine test_with_array_link_and_tofrom() | ||
use test_0 | ||
integer :: i = 1 | ||
integer :: j = 11 | ||
!$omp target map(tofrom:arr1, i, j) | ||
do while (i <= j) | ||
arr1(i) = i; | ||
i = i + 1 | ||
end do | ||
!$omp end target | ||
|
||
! CHECK: 1 2 3 4 5 6 7 8 9 10 | ||
PRINT *, arr1(:) | ||
end subroutine test_with_array_link_and_tofrom | ||
|
||
subroutine test_with_array_link_only() | ||
use test_0 | ||
integer :: i = 1 | ||
integer :: j = 11 | ||
!$omp target map(i, j) | ||
do while (i <= j) | ||
arr1(i) = i + 1; | ||
i = i + 1 | ||
end do | ||
!$omp end target | ||
|
||
! CHECK: 2 3 4 5 6 7 8 9 10 11 | ||
PRINT *, arr1(:) | ||
end subroutine test_with_array_link_only | ||
|
||
subroutine test_with_array_enter_only() | ||
use test_0 | ||
integer :: i = 1 | ||
integer :: j = 11 | ||
!$omp target map(i, j) | ||
do while (i <= j) | ||
arr2(i) = i + 1; | ||
i = i + 1 | ||
end do | ||
!$omp end target | ||
|
||
! CHECK: 0 0 0 0 0 0 0 0 0 0 | ||
PRINT *, arr2(:) | ||
end subroutine test_with_array_enter_only | ||
|
||
subroutine test_with_scalar_link_only() | ||
use test_0 | ||
!$omp target | ||
scalar = 10 | ||
!$omp end target | ||
|
||
! CHECK: 10 | ||
PRINT *, scalar | ||
end subroutine test_with_scalar_link_only | ||
|
||
program main | ||
call test_with_array_link_and_tofrom() | ||
call test_with_array_link_only() | ||
call test_with_array_enter_only() | ||
call test_with_scalar_link_only() | ||
end program |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! However, should this be an
==
rather than a!=
or is the comment at line 1123~ misworded (there's also a chance I am misreading something as it's very late on a Friday, so I appologies if that's the case!). Going off of the PR description I'd wager the comment might need a little rewording from "and if device type is nohost" to "and if device type is not nohost"Otherwise, this PR looks good to me, I'll give it a little test on Monday on the local map tests I have just to be sure (will almost certainly be fine, but I am a little OCD with the tests I suppose!) and await your reply to the above comment before signing off on it fully!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And as an aside, if it wouldn't be too much of a bother could you add a runtime test to: https://github.com/llvm/llvm-project/tree/main/openmp/libomptarget/test/offloading/fortran not necessary for me signing off, but it would be excellent to track this behavior with a runtime test as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @agozillon ,
Thank you for reviewing my PR. My comment is incorrect. Thanks for noticing and for the suggestion of adding a runtime test. I do agree with it. I will raise a second revision with the changes.