diff options
author | Marcel Vollweiler <marcel@codesourcery.com> | 2022-05-02 23:56:44 -0700 |
---|---|---|
committer | Marcel Vollweiler <marcel@codesourcery.com> | 2022-05-02 23:56:44 -0700 |
commit | 941cdc8b6d29f9fe494fdd244e96a5e5aa08ba32 (patch) | |
tree | 2fd28aefc17121aa268953dace732e22305b3ccf /libgomp/target.c | |
parent | 404edfce683cb1801b052ee7c8d45d603c392e08 (diff) | |
download | gcc-941cdc8b6d29f9fe494fdd244e96a5e5aa08ba32.zip gcc-941cdc8b6d29f9fe494fdd244e96a5e5aa08ba32.tar.gz gcc-941cdc8b6d29f9fe494fdd244e96a5e5aa08ba32.tar.bz2 |
OpenMP, libgomp: Add new runtime routine omp_get_mapped_ptr.
This patch adds the OpenMP runtime routine "omp_get_mapped_ptr" which was
introduced in OpenMP 5.1.
gcc/ChangeLog:
* omp-low.cc (omp_runtime_api_call): Added get_mapped_ptr to
omp_runtime_apis array.
libgomp/ChangeLog:
* libgomp.map: Added omp_get_mapped_ptr.
* libgomp.texi: Tagged omp_get_mapped_ptr as supported.
* omp.h.in: Added omp_get_mapped_ptr.
* omp_lib.f90.in: Added interface for omp_get_mapped_ptr.
* omp_lib.h.in: Likewise.
* target.c (omp_get_mapped_ptr): Added implementation of
omp_get_mapped_ptr.
* testsuite/libgomp.c-c++-common/get-mapped-ptr-1.c: New test.
* testsuite/libgomp.c-c++-common/get-mapped-ptr-2.c: New test.
* testsuite/libgomp.c-c++-common/get-mapped-ptr-3.c: New test.
* testsuite/libgomp.c-c++-common/get-mapped-ptr-4.c: New test.
* testsuite/libgomp.fortran/get-mapped-ptr-1.f90: New test.
* testsuite/libgomp.fortran/get-mapped-ptr-2.f90: New test.
* testsuite/libgomp.fortran/get-mapped-ptr-3.f90: New test.
* testsuite/libgomp.fortran/get-mapped-ptr-4.f90: New test.
Diffstat (limited to 'libgomp/target.c')
-rw-r--r-- | libgomp/target.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libgomp/target.c b/libgomp/target.c index 9017458..86930ea 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -3665,6 +3665,44 @@ omp_target_disassociate_ptr (const void *ptr, int device_num) return ret; } +void * +omp_get_mapped_ptr (const void *ptr, int device_num) +{ + if (device_num < 0 || device_num > gomp_get_num_devices ()) + return NULL; + + if (device_num == omp_get_initial_device ()) + return (void *) ptr; + + struct gomp_device_descr *devicep = resolve_device (device_num); + if (devicep == NULL) + return NULL; + + if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_OPENMP_400) + || devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) + return (void *) ptr; + + gomp_mutex_lock (&devicep->lock); + + struct splay_tree_s *mem_map = &devicep->mem_map; + struct splay_tree_key_s cur_node; + void *ret = NULL; + + cur_node.host_start = (uintptr_t) ptr; + cur_node.host_end = cur_node.host_start; + splay_tree_key n = gomp_map_0len_lookup (mem_map, &cur_node); + + if (n) + { + uintptr_t offset = cur_node.host_start - n->host_start; + ret = (void *) (n->tgt->tgt_start + n->tgt_offset + offset); + } + + gomp_mutex_unlock (&devicep->lock); + + return ret; +} + int omp_pause_resource (omp_pause_resource_t kind, int device_num) { |