What Is CUDA UVA? Inspecting Memory Types and Inferring Copy Direction from Pointers
CUDA Unified Virtual Addressing (UVA) places host and supported GPU allocations in one virtual address space within a process. This lets CUDA identify a pointer’s memory location and lets `cudaMemcpyDefault` infer the direction of a copy. A shared address space does not merge physical memories, make every pointer accessible to every GPU kernel, or automatically move data.
What Is CUDA UVA? Inspecting Memory Types and Inferring Copy Direction from Pointers
CUDA Unified Virtual Addressing (UVA) places host and supported GPU allocations in one virtual address space within a process. This lets CUDA identify a pointer’s memory location and lets cudaMemcpyDefault infer the direction of a copy. A shared address space does not merge physical memories, make every pointer accessible to every GPU kernel, or automatically move data.
This guide covers UVA in NVIDIA CUDA C++. Memory type, device accessibility, and managed-memory behavior still depend on the allocation, current device, and platform features, so inspect them with the documented APIs.
What does UVA unify in the address space?
Within one process, CPU memory and the global memory of each GPU occupy distinct ranges in a shared virtual address space. This includes CUDA allocations such as cudaMalloc as well as host allocations made with new, malloc, or mmap. A pointer value does not mean that the bytes reside in one physical memory. Instead, the pointer and CUDA’s allocation or mapping information can identify whether an address belongs to host memory or a particular GPU’s memory.
CUDA virtual address space in one OS process
┌────────────────────────────────────────────────────────┐
│ Host address range │ GPU 0 address range │ GPU 1 range │
│ new/malloc/mmap │ cudaMalloc │ cudaMalloc │
└────────────────────────────────────────────────────────┘
│ pointer value + cudaPointerGetAttributes()
├─ identify memory type and owning device
└─ cudaMemcpyDefault: infer copy direction from pointers
One virtual address space ≠ one physical memory or automatic page migrationThe CUDA Programming Guide explains that pointer values in the UVA space can identify memory location and that cudaMemcpyDefault can infer the copy kind. The Runtime API’s cudaPointerGetAttributes reports the memory type, allocation device, and host/device aliases available through the current device. UVA therefore reduces pointer bookkeeping and can simplify copy calls, but identifying an address is separate from access permission or memory migration. CUDA Programming Guide — Unified Virtual Address Space CUDA Runtime API — Unified Addressing
How are UVA, Unified Memory, and mapped memory different?
These features can be used together, but they solve different problems. UVA is an addressing scheme for identifying pointers and memory locations. Unified Memory manages allocations that CPU and GPU code can use; placement, access, and movement behavior depend on platform support. Mapped pinned host memory maps a host allocation so a kernel can access it directly. A unified pointer address alone does not create mapped access for arbitrary host allocations.
| Feature | Main problem it solves | Effect on pointers or data | What it does not guarantee by itself |
|---|---|---|---|
| UVA | Pointer address space and memory-location identification | Supported ranges lie in one process virtual address space; pointer queries and cudaMemcpyDefault can be used | Merged physical memory, arbitrary kernel access, or automatic page migration |
| Unified Memory | CPU/GPU use and management of managed allocations | Managed memory such as cudaMallocManaged can be used by CPU and GPU code; placement and movement behavior depend on the system | The same migration policy or performance on every system |
| Mapped pinned host memory | Direct kernel access to host memory | Page-locked host allocation is mapped into the GPU address space for kernel access | Host memory becoming as fast as local GPU memory |
On UVA-capable devices, pinned host memory allocated with cudaHostAlloc or cudaMallocHost is directly accessible from the GPU and usually uses the same pointer value on host and device. cudaHostAllocWriteCombined is an exception. Memory registered later with cudaHostRegister may have a distinct device pointer, so obtain its device alias with cudaHostGetDevicePointer. This behavior comes from UVA together with the allocation or mapping API; it is not a universal property of every host allocation. CUDA Runtime API — Unified Addressing
On some systems with HMM or ATS support, CUDA Unified Memory can treat ordinary system memory as implicitly managed. That behavior comes from managed-memory and coherency support, not from UVA automatically moving data. Check device attributes and the relevant memory feature to determine pointer usability, page movement, or concurrent access. CUDA Programming Guide — Unified Memory
How do you inspect a device and pointer before copying?
First check whether the process and target device support UVA through cudaDeviceProp::unifiedAddressing. Then inspect pointer attributes to determine which device owns a device allocation, and use cudaMemcpyDefault to let the runtime infer the copy direction from source and destination addresses. cudaMemcpyDefault is valid only on systems that support UVA.
| API or property | What it checks or does | What to keep in mind |
|---|---|---|
cudaDeviceProp::unifiedAddressing | Reports UVA support for a device returned by cudaGetDeviceProperties | Check the property on the target device instead of guessing from pointer equality |
cudaPointerGetAttributes(&attr, ptr) | Reports pointer type, allocation device, and host/device aliases available through the current device | If devicePointer is NULL, the current device has no direct-access alias for that pointer |
cudaMemcpyDefault | Infers copy direction from pointer values | Invalid on systems without UVA; does not change placement or access permissions |
cudaDeviceCanAccessPeer / cudaDeviceEnablePeerAccess | Checks and enables direct access from one GPU to another GPU’s memory | UVA is a prerequisite for P2P, not a substitute for device, driver, or topology support |
The example below copies from a pinned host allocation to a device allocation and queries the device pointer’s memory type and owning device. The important detail is that the copy uses cudaMemcpyDefault instead of an explicit direction constant. Printing pointer numbers or checking whether they match is not enough to establish kernel accessibility or physical location.
#include <cuda_runtime.h>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#define CUDA_CHECK(call) do { \
cudaError_t err = (call); \
if (err != cudaSuccess) { \
std::fprintf(stderr, "%s\n", cudaGetErrorString(err)); \
std::exit(EXIT_FAILURE); \
} \
} while (0)
int main() {
constexpr int device = 0;
constexpr std::size_t bytes = sizeof(float);
cudaDeviceProp prop{};
CUDA_CHECK(cudaGetDeviceProperties(&prop, device));
if (!prop.unifiedAddressing) {
std::fprintf(stderr, "UVA is unavailable on this device.\n");
return EXIT_FAILURE;
}
CUDA_CHECK(cudaSetDevice(device));
float* host = nullptr;
float* deviceBuffer = nullptr;
CUDA_CHECK(cudaHostAlloc(&host, bytes, cudaHostAllocDefault));
CUDA_CHECK(cudaMalloc(&deviceBuffer, bytes));
host[0] = 42.0f;
cudaPointerAttributes attr{};
CUDA_CHECK(cudaPointerGetAttributes(&attr, deviceBuffer));
if (attr.type != cudaMemoryTypeDevice || attr.device != device) {
std::fprintf(stderr, "Pointer does not describe the expected device allocation.\n");
CUDA_CHECK(cudaFree(deviceBuffer));
CUDA_CHECK(cudaFreeHost(host));
return EXIT_FAILURE;
}
CUDA_CHECK(cudaMemcpy(deviceBuffer, host, bytes, cudaMemcpyDefault));
float result = 0.0f;
CUDA_CHECK(cudaMemcpy(&result, deviceBuffer, bytes, cudaMemcpyDefault));
std::printf("result = %.1f\n", result);
CUDA_CHECK(cudaFree(deviceBuffer));
CUDA_CHECK(cudaFreeHost(host));
}This listing illustrates API order; it is not a claim that the code was compiled or run on a particular CUDA version or GPU. In production software, manage resource lifetime with RAII or an equivalent method so allocations are released on error paths too. If pointer-attribute lookup fails, check that the pointer is an allocation visible to the current CUDA context and has not already been freed. If cudaMemcpyDefault fails or UVA is unavailable, use an explicit direction constant when the actual source and destination types are known, and still verify that the selected memory is accessible through the intended path. CUDA Runtime API — Memory Management
How do you diagnose peer access and pointer failures?
UVA can provide the address-space foundation for distinguishing memory ranges across multiple GPUs. But to let one GPU directly access another GPU’s memory, first check whether the device pair supports peer access and then enable it. If cudaDeviceCanAccessPeer reports no support, the existence of a UVA pointer does not bypass that limitation. Choose a supported transfer path such as peer copy or host staging.
| Symptom | What to check | Safe action |
|---|---|---|
cudaMemcpyDefault returns an error | Target device’s unifiedAddressing, pointer validity and lifetime, and copy API’s address requirements | Check UVA support first; use an explicit direction constant to narrow the issue when appropriate |
| Pointer value looks valid but attribute lookup fails | Whether the pointer was allocated, registered, or mapped in the current CUDA context and whether it was freed | Trace the allocation API and owner; query the pointer only during its valid lifetime |
| A kernel on one GPU cannot access a pointer from another GPU | cudaDeviceCanAccessPeer, whether peer access is enabled, and the device pair/topology | Use cudaDeviceEnablePeerAccess only after support is confirmed; otherwise use a supported copy route |
| Confusion about CPU or kernel accessibility | Pointer memory type and current-device host/device aliases in cudaPointerAttributes | Validate address unification separately from direct access and managed-memory features |
**Check the execution environment.** Query `unifiedAddressing` for the 64-bit process and target device. If the program uses several GPUs, check each device.
**Record pointer origin and lifetime.** Identify whether memory came from `cudaMalloc`, `cudaHostAlloc`, `cudaHostRegister`, `cudaMallocManaged`, or a system allocator. Use it only until its owner frees or unregisters it.
**Inspect attributes when needed.** Check the pointer’s type, owning device, and aliases available through the current device. An attribute query identifies an address; it does not synchronize work.
**Verify copy direction explicitly.** When UVA is supported, use `cudaMemcpyDefault` and compare the resulting data. If useful, compare with a direction-specific call such as `cudaMemcpyHostToDevice`.
**Check device-to-device access separately.** For P2P, query support for each device pair and confirm enablement. If unsupported, recover with host staging or an explicit supported peer-copy path.
In short, UVA is an address system that helps determine which memory a pointer refers to. cudaPointerGetAttributes and cudaMemcpyDefault use that information, but they do not merge physical memories or grant arbitrary kernel access. Unified Memory page management, mapped host access, and peer-device permissions each have separate support and behavior to verify.
References
[NVIDIA CUDA Programming Guide — Unified and System Memory](https://docs.nvidia.com/cuda/cuda-programming-guide/02-basics/understanding-memory.html)
[NVIDIA CUDA Runtime API 13.5 — Unified Addressing](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__UNIFIED.html)
[NVIDIA CUDA Runtime API 13.5 — Memory Management](https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__MEMORY.html)
[NVIDIA CUDA C++ Best Practices Guide 13.5 — Unified Virtual Addressing](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/)