| 1 |
! { dg-additional-options "-fdump-tree-gimple" } |
| 2 |
|
| 3 |
! This mainly checks 'has_device_addr' without associated 'need_device_addr' |
| 4 |
! |
| 5 |
! Do diagnostic check / dump check only; |
| 6 |
! Note: this test should work as run-test as well. |
| 7 |
|
| 8 |
module m |
| 9 |
use iso_c_binding |
| 10 |
! use omp_lib |
| 11 |
implicit none (type, external) |
| 12 |
interface |
| 13 |
integer function omp_get_default_device (); end |
| 14 |
integer function omp_get_num_devices (); end |
| 15 |
end interface |
| 16 |
|
| 17 |
contains |
| 18 |
subroutine g (x, y) |
| 19 |
!$omp declare variant(f) adjust_args(need_device_ptr: x, y) match(construct={dispatch}) |
| 20 |
type(c_ptr), value :: x, y |
| 21 |
end |
| 22 |
|
| 23 |
subroutine f (cfrom, cto) |
| 24 |
type(c_ptr), value :: cfrom, cto |
| 25 |
integer, save :: cnt = 0 |
| 26 |
cnt = cnt + 1 |
| 27 |
if (cnt >= 3) then |
| 28 |
if (omp_get_default_device () /= -1 & |
| 29 |
.and. omp_get_default_device () < omp_get_num_devices ()) then |
| 30 |
! On offload device but not mapped |
| 31 |
if (.not. c_associated(cfrom)) & ! Not mapped |
| 32 |
stop 1 |
| 33 |
else |
| 34 |
block |
| 35 |
integer, pointer :: from(:) |
| 36 |
call c_f_pointer(cfrom, from, shape=[1]) |
| 37 |
if (from(1) /= 5) & |
| 38 |
stop 2 |
| 39 |
end block |
| 40 |
end if |
| 41 |
return |
| 42 |
end if |
| 43 |
|
| 44 |
!$omp target is_device_ptr(cfrom, cto) |
| 45 |
block |
| 46 |
integer, pointer :: from(:), to(:) |
| 47 |
call c_f_pointer(cfrom, from, shape=[2]) |
| 48 |
call c_f_pointer(cto, to, shape=[2]) |
| 49 |
to(1) = from(1) * 10 |
| 50 |
to(2) = from(2) * 10 |
| 51 |
end block |
| 52 |
end |
| 53 |
|
| 54 |
subroutine sub (a, b) |
| 55 |
integer, target :: a(:), b(:) |
| 56 |
type(c_ptr), target :: ca, cb |
| 57 |
|
| 58 |
ca = c_loc(a) |
| 59 |
cb = c_loc(b) |
| 60 |
|
| 61 |
! The has_device_addr is a bit questionable as the caller is not actually |
| 62 |
! passing a device address - but we cannot pass one because of the |
| 63 |
! following: |
| 64 |
! |
| 65 |
! As for 'b' need_device_ptr has been specified and 'b' is not |
| 66 |
! in the semantic requirement set 'is_device_ptr' (and only in 'has_device_addr') |
| 67 |
! "the argument is converted in the same manner that a use_device_ptr clause |
| 68 |
! on a target_data construct converts its pointer" |
| 69 |
|
| 70 |
!$omp dispatch is_device_ptr(ca), has_device_addr(cb) |
| 71 |
call g (ca, cb) ! { dg-warning "'has_device_addr' for 'cb' does not imply 'is_device_ptr' required for 'need_device_ptr' \\\[-Wopenmp\\\]" } |
| 72 |
end |
| 73 |
end |
| 74 |
|
| 75 |
program main |
| 76 |
use m |
| 77 |
implicit none (type, external) |
| 78 |
|
| 79 |
integer, target :: A(2), B(2) = [123, 456], C(1) = [5] |
| 80 |
integer, pointer :: p(:) |
| 81 |
|
| 82 |
p => A |
| 83 |
|
| 84 |
!$omp target enter data map(A, B) |
| 85 |
|
| 86 |
! Note: We don't add 'use_device_addr(B)' here; |
| 87 |
! if we do, it will fail with an illegal memory access (why?). |
| 88 |
!$omp target data use_device_ptr(p) |
| 89 |
call sub(p, B) |
| 90 |
call sub(C, B) ! C is not mapped -> 'from' ptr == NULL |
| 91 |
!$omp end target data |
| 92 |
|
| 93 |
!$omp target exit data map(A, B) |
| 94 |
end |
| 95 |
|
| 96 |
! { dg-final { scan-tree-dump-times "#pragma omp dispatch is_device_ptr\\(ca\\) has_device_addr\\(cb\\)" 1 "gimple" } } |
| 97 |
! { dg-final { scan-tree-dump-times "__builtin_omp_get_mapped_ptr" 1 "gimple" } } |
| 98 |
! { dg-final { scan-tree-dump-times "D\\.\[0-9\]+ = __builtin_omp_get_mapped_ptr \\(cb" 1 "gimple" } } |
| 99 |
! { dg-final { scan-tree-dump-times "f \\(ca\\.\[0-9\]+, D\\.\[0-9\]+\\);" 1 "gimple" } } |