diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-10-22 09:31:01 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-10-22 09:31:01 +0200 |
commit | 74c9882b80bda50b37c9555498de7123c6bdb9e4 (patch) | |
tree | a076a134ac5adf7de55c2eb0cf7776d79edfb542 /libgomp/target.c | |
parent | d3acf7a02631997c5505e109660457fdca3ed2d1 (diff) | |
download | gcc-74c9882b80bda50b37c9555498de7123c6bdb9e4.zip gcc-74c9882b80bda50b37c9555498de7123c6bdb9e4.tar.gz gcc-74c9882b80bda50b37c9555498de7123c6bdb9e4.tar.bz2 |
openmp: Change omp_get_initial_device () to match OpenMP 5.1 requirements
> Therefore, I think until omp_get_initial_device () value is changed, we
The following so far untested patch implements that change.
OpenMP 4.5 said for omp_get_initial_device:
The value of the device number is implementation defined. If it is between 0 and one less than
omp_get_num_devices() then it is valid for use with all device constructs and routines; if it is
outside that range, then it is only valid for use with the device memory routines and not in the
device clause.
and OpenMP 5.0 similarly, but OpenMP 5.1 says:
The value of the device number is the value returned by the omp_get_num_devices routine.
As the new value is compatible with what has been required earlier, I think
we can change it already now.
2020-10-22 Jakub Jelinek <jakub@redhat.com>
* icv.c (omp_get_initial_device): Remove including corresponding
ialias.
* icv-device.c (omp_get_initial_device): New function. Return
gomp_get_num_devices (). Add ialias.
* target.c (resolve_device): Don't fail with
OMP_TARGET_OFFLOAD=mandatory if device_id is equal to
gomp_get_num_devices ().
(omp_target_alloc, omp_target_free, omp_target_is_present,
omp_target_memcpy, omp_target_memcpy_rect, omp_target_associate_ptr,
omp_target_disassociate_ptr, omp_pause_resource): Use
gomp_get_num_devices () instead of GOMP_DEVICE_HOST_FALLBACK on the
first use in the functions, in uses dominated by the
gomp_get_num_devices call use num_devices_openmp instead.
* libgomp.texi (omp_get_initial_device): Document.
* config/gcn/icv-device.c (omp_get_initial_device): New function.
Add ialias.
* config/nvptx/icv-device.c (omp_get_initial_device): Likewise.
* testsuite/libgomp.c/target-40.c: New test.
Diffstat (limited to 'libgomp/target.c')
-rw-r--r-- | libgomp/target.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/libgomp/target.c b/libgomp/target.c index 97f0cdd..1a8c67c 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -118,7 +118,8 @@ resolve_device (int device_id) if (device_id < 0 || device_id >= gomp_get_num_devices ()) { if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY - && device_id != GOMP_DEVICE_HOST_FALLBACK) + && device_id != GOMP_DEVICE_HOST_FALLBACK + && device_id != num_devices_openmp) gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, " "but device not found"); @@ -132,8 +133,7 @@ resolve_device (int device_id) { gomp_mutex_unlock (&devices[device_id].lock); - if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY - && device_id != GOMP_DEVICE_HOST_FALLBACK) + if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY) gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, " "but device is finalized"); @@ -2716,7 +2716,7 @@ GOMP_teams (unsigned int num_teams, unsigned int thread_limit) void * omp_target_alloc (size_t size, int device_num) { - if (device_num == GOMP_DEVICE_HOST_FALLBACK) + if (device_num == gomp_get_num_devices ()) return malloc (size); if (device_num < 0) @@ -2742,7 +2742,7 @@ omp_target_free (void *device_ptr, int device_num) if (device_ptr == NULL) return; - if (device_num == GOMP_DEVICE_HOST_FALLBACK) + if (device_num == gomp_get_num_devices ()) { free (device_ptr); return; @@ -2773,7 +2773,7 @@ omp_target_is_present (const void *ptr, int device_num) if (ptr == NULL) return 1; - if (device_num == GOMP_DEVICE_HOST_FALLBACK) + if (device_num == gomp_get_num_devices ()) return 1; if (device_num < 0) @@ -2807,7 +2807,7 @@ omp_target_memcpy (void *dst, const void *src, size_t length, struct gomp_device_descr *dst_devicep = NULL, *src_devicep = NULL; bool ret; - if (dst_device_num != GOMP_DEVICE_HOST_FALLBACK) + if (dst_device_num != gomp_get_num_devices ()) { if (dst_device_num < 0) return EINVAL; @@ -2820,7 +2820,7 @@ omp_target_memcpy (void *dst, const void *src, size_t length, || dst_devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) dst_devicep = NULL; } - if (src_device_num != GOMP_DEVICE_HOST_FALLBACK) + if (src_device_num != num_devices_openmp) { if (src_device_num < 0) return EINVAL; @@ -2958,7 +2958,7 @@ omp_target_memcpy_rect (void *dst, const void *src, size_t element_size, if (!dst && !src) return INT_MAX; - if (dst_device_num != GOMP_DEVICE_HOST_FALLBACK) + if (dst_device_num != gomp_get_num_devices ()) { if (dst_device_num < 0) return EINVAL; @@ -2971,7 +2971,7 @@ omp_target_memcpy_rect (void *dst, const void *src, size_t element_size, || dst_devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) dst_devicep = NULL; } - if (src_device_num != GOMP_DEVICE_HOST_FALLBACK) + if (src_device_num != num_devices_openmp) { if (src_device_num < 0) return EINVAL; @@ -3007,7 +3007,7 @@ int omp_target_associate_ptr (const void *host_ptr, const void *device_ptr, size_t size, size_t device_offset, int device_num) { - if (device_num == GOMP_DEVICE_HOST_FALLBACK) + if (device_num == gomp_get_num_devices ()) return EINVAL; if (device_num < 0) @@ -3070,7 +3070,7 @@ omp_target_associate_ptr (const void *host_ptr, const void *device_ptr, int omp_target_disassociate_ptr (const void *ptr, int device_num) { - if (device_num == GOMP_DEVICE_HOST_FALLBACK) + if (device_num == gomp_get_num_devices ()) return EINVAL; if (device_num < 0) @@ -3113,9 +3113,9 @@ int omp_pause_resource (omp_pause_resource_t kind, int device_num) { (void) kind; - if (device_num == GOMP_DEVICE_HOST_FALLBACK) + if (device_num == gomp_get_num_devices ()) return gomp_pause_host (); - if (device_num < 0 || device_num >= gomp_get_num_devices ()) + if (device_num < 0 || device_num >= num_devices_openmp) return -1; /* Do nothing for target devices for now. */ return 0; |