diff options
author | Kwok Cheung Yeung <kcyeung@baylibre.com> | 2024-02-15 20:59:39 +0000 |
---|---|---|
committer | Kwok Cheung Yeung <kcyeung@baylibre.com> | 2024-02-15 21:04:53 +0000 |
commit | 451bb5866021cc854cd972396c6bc4923eb14d39 (patch) | |
tree | 25eed3b7bd77d7ce4eb6d9d71468ca95d1c14887 /libgomp/testsuite | |
parent | 617bd59c659dcf6e5391409a2e9f64f75e905a96 (diff) | |
download | gcc-451bb5866021cc854cd972396c6bc4923eb14d39.zip gcc-451bb5866021cc854cd972396c6bc4923eb14d39.tar.gz gcc-451bb5866021cc854cd972396c6bc4923eb14d39.tar.bz2 |
openmp, fortran: Add Fortran support for indirect clause on the declare target directive
2024-02-15 Kwok Cheung Yeung <kcyeung@baylibre.com>
gcc/fortran/
* dump-parse-tree.cc (show_attr): Handle omp_declare_target_indirect
attribute.
* f95-lang.cc (gfc_gnu_attributes): Add entry for 'omp declare
target indirect'.
* gfortran.h (symbol_attribute): Add omp_declare_target_indirect
field.
(struct gfc_omp_clauses): Add indirect field.
* openmp.cc (omp_mask2): Add OMP_CLAUSE_INDIRECT.
(gfc_match_omp_clauses): Match indirect clause.
(OMP_DECLARE_TARGET_CLAUSES): Add OMP_CLAUSE_INDIRECT.
(gfc_match_omp_declare_target): Check omp_device_type and apply
omp_declare_target_indirect attribute to symbol if indirect clause
active. Show warning if there are only device_type and/or indirect
clauses on the directive.
* trans-decl.cc (add_attributes_to_decl): Add 'omp declare target
indirect' attribute if symbol has indirect attribute set.
gcc/testsuite/
* gfortran.dg/gomp/declare-target-4.f90 (f1): Update expected warning.
* gfortran.dg/gomp/declare-target-indirect-1.f90: New.
* gfortran.dg/gomp/declare-target-indirect-2.f90: New.
libgomp/
* testsuite/libgomp.fortran/declare-target-indirect-1.f90: New.
* testsuite/libgomp.fortran/declare-target-indirect-2.f90: New.
* testsuite/libgomp.fortran/declare-target-indirect-3.f90: New.
Diffstat (limited to 'libgomp/testsuite')
3 files changed, 128 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-indirect-1.f90 b/libgomp/testsuite/libgomp.fortran/declare-target-indirect-1.f90 new file mode 100644 index 0000000..39a91df --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/declare-target-indirect-1.f90 @@ -0,0 +1,39 @@ +! { dg-do run } + +module m +contains + integer function foo () + !$omp declare target to (foo) indirect + foo = 5 + end function + + integer function bar () + !$omp declare target to (bar) indirect + bar = 8 + end function + + integer function baz () + !$omp declare target to (baz) indirect + baz = 11 + end function +end module + +program main + use m + implicit none + + integer :: x, expected + procedure (foo), pointer :: foo_ptr, bar_ptr, baz_ptr + + foo_ptr => foo + bar_ptr => bar + baz_ptr => baz + + expected = foo () + bar () + baz () + + !$omp target map (to: foo_ptr, bar_ptr, baz_ptr) map (from: x) + x = foo_ptr () + bar_ptr () + baz_ptr () + !$omp end target + + stop x - expected +end program diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-indirect-2.f90 b/libgomp/testsuite/libgomp.fortran/declare-target-indirect-2.f90 new file mode 100644 index 0000000..34dd277 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/declare-target-indirect-2.f90 @@ -0,0 +1,54 @@ +! { dg-do run } +! { dg-xfail-run-if "Requires libgomp bug fix pending review" { offload_device } } + +module m +contains + integer function foo () + !$omp declare target to (foo) indirect + foo = 5 + end function + + integer function bar () + !$omp declare target to (bar) indirect + bar = 8 + end function + + integer function baz () + !$omp declare target to (baz) indirect + baz = 11 + end function +end module + +program main + use m + implicit none + + type fp + procedure (foo), pointer, nopass :: f => null () + end type + + integer, parameter :: N = 256 + integer :: i, x = 0, expected = 0; + type (fp) :: fn_ptr (N) + + do i = 1, N + select case (mod (i, 3)) + case (0) + fn_ptr (i)%f => foo + case (1) + fn_ptr (i)%f => bar + case (2) + fn_ptr (i)%f => baz + end select + expected = expected + fn_ptr (i)%f () + end do + + !$omp target teams distribute parallel do & + !$omp & reduction(+: x) map (to: fn_ptr) map (tofrom: x) + do i = 1, N + x = x + fn_ptr (i)%f () + end do + !$omp end target teams distribute parallel do + + stop x - expected +end program diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-indirect-3.f90 b/libgomp/testsuite/libgomp.fortran/declare-target-indirect-3.f90 new file mode 100644 index 0000000..00f33bd --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/declare-target-indirect-3.f90 @@ -0,0 +1,35 @@ +! { dg-do run } + +! Check that indirect calls work on procedures passed in via a dummy argument + +module m + integer, parameter :: offset = 123 +contains + function bar(x) + !$omp declare target enter (bar) indirect + integer :: bar + integer, intent(in) :: x + bar = x + offset + end function + + function foo(f, x) + integer :: foo + procedure(bar) :: f + integer, intent(in) :: x + + !$omp target map (to: x) map (from: foo) + foo = f(x) + !$omp end target + end function +end module + +program main + use m + implicit none + + integer :: a = 321 + integer :: b + + b = foo(bar, a) + stop b - (a + offset) +end program |