diff options
author | Tobias Burnus <tburnus@baylibre.com> | 2024-09-23 15:58:39 +0200 |
---|---|---|
committer | Tobias Burnus <tburnus@baylibre.com> | 2024-09-23 15:58:39 +0200 |
commit | cdb9aa0f623ec7899da445a47f4a502b2987dc7b (patch) | |
tree | a228cf5ab250fea524958ea258dcfd038531ecdb /libgomp/fortran.c | |
parent | ffd861c808f307c865659b556dd5a8c922bd6a51 (diff) | |
download | gcc-cdb9aa0f623ec7899da445a47f4a502b2987dc7b.zip gcc-cdb9aa0f623ec7899da445a47f4a502b2987dc7b.tar.gz gcc-cdb9aa0f623ec7899da445a47f4a502b2987dc7b.tar.bz2 |
OpenMP: Fix omp_get_device_from_uid, minor cleanup
In Fortran, omp_get_device_from_uid can also accept substrings, which are
then not NUL terminated. Fixed by introducing a fortran.c wrapper function.
Additionally, in case of a fail the plugin functions now return NULL instead
of failing fatally such that a fall-back UID is generated.
gcc/ChangeLog:
* omp-general.cc (omp_runtime_api_procname): Strip "omp_" from
string; move get_device_from_uid as now a '_' suffix exists.
libgomp/ChangeLog:
* fortran.c (omp_get_device_from_uid_): New function.
* libgomp.map (GOMP_6.0): Add it.
* oacc-host.c (host_dispatch): Init '.uid' and '.get_uid_func'.
* omp_lib.f90.in: Make it used by removing bind(C).
* omp_lib.h.in: Likewise.
* target.c (omp_get_device_from_uid): Ensure the device is initialized.
* plugin/plugin-gcn.c (GOMP_OFFLOAD_get_uid): Add function comment;
return NULL in case of an error.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_uid): Likewise.
* testsuite/libgomp.fortran/device_uid.f90: Update to test substrings.
Diffstat (limited to 'libgomp/fortran.c')
-rw-r--r-- | libgomp/fortran.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libgomp/fortran.c b/libgomp/fortran.c index 9b7f093..7976e5b 100644 --- a/libgomp/fortran.c +++ b/libgomp/fortran.c @@ -834,6 +834,24 @@ omp_get_interop_rc_desc_ (const char **res, size_t *res_len, *res_len = *res ? strlen (*res) : 0; } +int +omp_get_device_from_uid_ (const char *uid, size_t uid_len) +{ +#ifndef LIBGOMP_OFFLOADED_ONLY + char *str = __builtin_alloca ((uid_len + 1) * sizeof (char)); + memcpy (str, uid, uid_len * sizeof (char)); + str[uid_len] = '\0'; + return omp_get_device_from_uid (str); +#else + /* Inside the target region, invoking this routine is undefined + behavior; thus, resolve it already here - instead of inside + libgomp/config/.../target.c. + Note that on nvptx __builtin_alloca is defined, but fails with a sorry + during compilation, as it is unsupported until isa 7.3 / sm_52. */ + return omp_invalid_device; +#endif +} + void omp_get_uid_from_device_ (const char **res, size_t *res_len, int32_t device_num) |