https://gcc.gnu.org/g:0be5b0c519837e3238b8cf2559befe79622e1fc4
commit r17-6617-g0be5b0c519837e3238b8cf2559befe79622e1fc4 Author: Tobias Burnus <[email protected]> Date: Tue Nov 24 03:41:37 2026 +0100 libgomp: Fix nvptx GOMP_RUNTIME_USM=auto handling It turned out that the is-integrated check for nvptx GPUs was not enabled; however, at least DGX Spark report 'integrated == 1' such that 'auto' should work for GOMP_RUNTIME_USM. For nvptx's {omp,GOMP_OFFLOAD}_is_accessible_ptr, move the check of USM to that function as this is a per-device feature and not a global feature, valid for all devices. libgomp/ChangeLog: * libgomp.texi (GOMP_RUNTIME_USM): Minor wording tweaks, @ref to nvptx. * plugin/plugin-nvptx.c (using_usm): Remove global var. (is_integrated_apu): Remove (was commented out). (GOMP_OFFLOAD_get_dev_caps): Update comment and check for 'integrated' attribute to return GOMP_OFFLOAD_CAP_APU_SHARED_MEM. (GOMP_OFFLOAD_is_accessible_ptr): Check at call time whether the GPU supports unified-shared memory. Diff: --- libgomp/libgomp.texi | 16 +++++------ libgomp/plugin/plugin-nvptx.c | 66 ++++++++++++------------------------------- 2 files changed, 26 insertions(+), 56 deletions(-) diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index f4d6ab71e0ba..315f723432e9 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -5550,26 +5550,26 @@ to make use of Unified Shared Memory if the device claims to support it. For general caveats around Unified Shared Memory, please consult the relevant sections in @ref{Offload-Target Specifics}. -When Unified Shared Memory is enabled by this environment variable, the -following is currently @emph{unsupported}: using a global static variable, -specified in an @code{enter} clause on a @code{declare target}, in a -@code{map} clause with @code{always} modifier on either a @code{target} or -a @code{target data} directive. When the unsupported case is encountered, -the program aborts with an error message. +When Unified Shared Memory is enabled by this environment variable, it is +unsupported to specify a global static variable (that appeared in an +@code{enter} clause on a @code{declare target}) in a @code{map} clause with +@code{always} modifier on either a @code{target} or a @code{target data} +directive. When the unsupported case is encountered, the program aborts +with an error message. @c FIXME: This is tracked in PR libgomp/127186 When specifying the @code{unified_shared_memory} or @code{self_maps} clauses with the @code{requires} directive causes that behavior to take precedence over the behavior set by this environment variable. -OpenACC is unaffected by the value of this environment variable, however, +OpenACC is unaffected by the value of this environment variable; however, hybrid usage of OpenMP and OpenACC offloading results in the first used framework taking precedent. As an example, if one uses OpenMP offloading and then later OpenACC offloading, the capabilities the device possesses reflect the original OpenMP model. @item @emph{See also}: -@ref{Offload-Target Specifics}, @ref{AMD Radeon} +@ref{Offload-Target Specifics}, @ref{AMD Radeon}, @ref{nvptx} @end table diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index bdbcfddc98e5..de4f8943e4c4 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -342,8 +342,6 @@ struct ptx_device static struct ptx_device **ptx_devices; -static int using_usm = -1; - /* "Native" GPU thread stack size. */ static unsigned native_gpu_thread_stack_size = 0; @@ -1238,24 +1236,6 @@ nvptx_get_current_cuda_context (void) return nvthd->ptx_dev->ctx; } -#if 0 /* TODO: Use to enable self-mapping/USM automatically. */ -/* FIXME: The auto-self-map feature depends on still mapping 'declare target' - variables, even if ignoring all other mappings. Cf. PR 115279. */ - -/* Return TRUE if the GPU is integrated with host memory, i.e. GPU and - host share the same memory controller. As of Oct 2025, no such - Nvidia GPU seems to exist. */ -static bool -is_integrated_apu (struct ptx_device *ptx_dev) -{ - int pi; - CUresult r; - r = CUDA_CALL_NOCHECK (cuDeviceGetAttribute, &pi, - CU_DEVICE_ATTRIBUTE_INTEGRATED, ptx_dev->dev); - return (r == CUDA_SUCCESS && pi == 1); -} -#endif - /* Plugin entry points. */ const char * @@ -1412,44 +1392,29 @@ GOMP_OFFLOAD_get_caps (void) when USM is supported * GOMP_OFFLOAD_CAP_APU_SHARED_MEM when USM is supported and CPU and GPU are integrated using the - same memory controller. As of July 2026 no such Nvidia GPU seems - to exist. */ + same memory controller. This for instance the case for DGX Spark or + Tegra/Jetson systems. It seems as one can have pagableMemoryAccess 0 + for some older sytems of this kind, which mostly affects cache handling; + assume and report no USM in that case. */ unsigned int GOMP_OFFLOAD_get_dev_caps (int n) { - unsigned int caps = 0; - - /* Check for USM. */ - int pi; CUresult r; - r = CUDA_CALL_NOCHECK (cuDeviceGetAttribute, &pi, - CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS, - n); - if (r != CUDA_SUCCESS) - return 0; - - if (pi) - { - caps |= GOMP_OFFLOAD_CAP_SHARED_MEM; - if (using_usm == -1) - using_usm = true; - } - else - using_usm = false; + unsigned int caps = 0; -#if 0 - int pi; - CUresult r; + /* Check for USM. */ r = CUDA_CALL_NOCHECK (cuDeviceGetAttribute, &pi, - CU_DEVICE_ATTRIBUTE_INTEGRATED, n); - if (r == CUDA_SUCCESS && pi != 0) + CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS, n); + if (r == CUDA_SUCCESS && pi) { caps |= GOMP_OFFLOAD_CAP_SHARED_MEM; - caps |= GOMP_OFFLOAD_CAP_APU_SHARED_MEM; + r = CUDA_CALL_NOCHECK (cuDeviceGetAttribute, &pi, + CU_DEVICE_ATTRIBUTE_INTEGRATED, n); + if (r == CUDA_SUCCESS && pi != 0) + caps |= GOMP_OFFLOAD_CAP_APU_SHARED_MEM; } -#endif return caps; } @@ -2020,7 +1985,12 @@ GOMP_OFFLOAD_is_accessible_ptr (int ord, struct ptx_device *ptx_dev = ptx_devices[ord]; /* USM implies access. */ - if (using_usm > 0) + int pi; + CUresult r; + r = CUDA_CALL_NOCHECK (cuDeviceGetAttribute, &pi, + CU_DEVICE_ATTRIBUTE_PAGEABLE_MEMORY_ACCESS, + ord); + if (r == CUDA_SUCCESS && pi != 0) return 1; CUcontext old_ctx;
