Committed asr16-445-g9565076f9b8105. This test supports mapping + accessing the vtab of the polymorphic variable on the host. Obviously, this only works if the host pointer is device accessible ("unified-shared memory"). In principle, we want to check for this - and enable some subtests. The enabling/disabling works, but there is no simple USM check. Currently, only the host gets the extra tests, the new test also checks it with devices, but unfortunately the USM requirement unconditionally switches to self maps. Thus, while it is useful to test this (hence, this commit), it does not check what we actually want ... Tobias PS: My plans for the future is to permit more fine tuning and some default changes. In particular, if a device is an APU, it should by default use self mapping. Additionally, the user should have the possibility to switch between mapping and self mapping for devices. Depending on the access pattern, way how USM is implemented and location of host vs. device process, copying (mapping) or direct access (self map) is faster. Additionally, copying might run into storage-size issues.
commit 9565076f9b810541aeb63cb621d694326aa12216
Author: Tobias Burnus <tbur...@baylibre.com>
Date:   Wed May 7 13:46:51 2025 +0200

    libgomp.fortran/map-alloc-comp-9{,-usm}.f90: Add unified_shared_memory variant
    
    When host memory is device accessible - independent whether mapping is done or
    not (i.e. self map), the 'vtab' pointer becomes accessible, which stores the
    dynamic type's type and size information.
    
    In principle, we want to test: USM available but mapping is still done, but
    as there is no simple + reliable not-crashing way to test for this, those
    checks are skipped in the (pre)existing test file map-alloc-comp-9.f90.
    
    Or rather: those are only active with self-maps, which is currently only true
    for the host.
    
    This commit adds map-alloc-comp-9-usm.f90 which runs the same test with
    'omp requires unified_shared_memory'.  While OpenMP permits both actual
    mapping and self maps with this flag, it in theory covers the missing cases.
    However, currently, GCC always uses self maps with USM. Still, having a
    device-run self-maps check is better than nothing, even if it misses the
    most interesting case.
    
    libgomp/ChangeLog:
    
            * testsuite/libgomp.fortran/map-alloc-comp-9.f90: Process differently
            when USE_USM_REQUIREMENT is set.
            * testsuite/libgomp.fortran/map-alloc-comp-9-usm.f90: New test.
---
 .../libgomp.fortran/map-alloc-comp-9-usm.f90          | 11 +++++++++++
 .../testsuite/libgomp.fortran/map-alloc-comp-9.f90    | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/libgomp/testsuite/libgomp.fortran/map-alloc-comp-9-usm.f90 b/libgomp/testsuite/libgomp.fortran/map-alloc-comp-9-usm.f90
new file mode 100644
index 00000000000..90378c0e42a
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/map-alloc-comp-9-usm.f90
@@ -0,0 +1,11 @@
+! { dg-additional-options "-cpp -DUSE_USM_REQUIREMENT=1 -Wno-openmp" }
+!
+! We silence the warning:
+!  Mapping of polymorphic list item '...' is unspecified behavior [-Wopenmp]
+!
+! Ensure that polymorphic mapping is diagnosed as undefined behavior
+! Ensure that static access to polymorphic variables works
+
+! Run map-alloc-comp-9.f90 in unified-shared-memory mode
+
+#include "map-alloc-comp-9.f90"
diff --git a/libgomp/testsuite/libgomp.fortran/map-alloc-comp-9.f90 b/libgomp/testsuite/libgomp.fortran/map-alloc-comp-9.f90
index 3cec39218f5..26c73d75c09 100644
--- a/libgomp/testsuite/libgomp.fortran/map-alloc-comp-9.f90
+++ b/libgomp/testsuite/libgomp.fortran/map-alloc-comp-9.f90
@@ -1,8 +1,19 @@
+! { dg-additional-options "-cpp" }
+!
 ! Ensure that polymorphic mapping is diagnosed as undefined behavior
 ! Ensure that static access to polymorphic variables works
 
+! Some extended tests are only run with shared memory
+! To enforce this (where possible) on the device side:
+!   #define USE_USM_REQUIREMENT
+! which is done in map-alloc-comp-9-usm.f90
+
 subroutine test(case)
 implicit none(type, external)
+#ifdef USE_USM_REQUIREMENT
+  !$omp requires unified_shared_memory
+#endif
+
 type t
   integer :: x(4)
 end type t
@@ -73,10 +84,14 @@ var4%y2(2)%y%x%x = -7 * [1111,2222,3333,4444]
 var4%y2(2)%y%x2(1)%x = -8 * [1111,2222,3333,4444]
 var4%y2(2)%y%x2(2)%x = -9 * [1111,2222,3333,4444]
 
+#ifdef USE_USM_REQUIREMENT
+is_shared_mem = .true.
+#else
 is_shared_mem = .false.
 !$omp target map(to: is_shared_mem)
   is_shared_mem = .true.
 !$omp end target
+#endif
 
 if (case == 1) then
   ! implicit mapping
@@ -532,6 +547,10 @@ end subroutine test
 program main
   use omp_lib
   implicit none(type, external)
+#ifdef USE_USM_REQUIREMENT
+  !$omp requires unified_shared_memory
+#endif
+
   interface
     subroutine test(case)
       integer, value :: case

Reply via email to