Inferensys

Glossary

Unified Virtual Memory (UVM)

Unified Virtual Memory (UVM) is a hardware and software architecture that creates a single, coherent virtual address space across CPU and GPU memory, simplifying data management for AI inference techniques like KV cache offloading.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
KV CACHE MANAGEMENT

What is Unified Virtual Memory (UVM)?

Unified Virtual Memory (UVM) is a hardware and software architecture that provides a single, coherent virtual address space across CPU and GPU memory, simplifying the programming model for techniques like KV cache offloading.

Unified Virtual Memory (UVM) is a memory management architecture that creates a single, coherent virtual address space spanning both CPU and GPU physical memory. This allows the CPU and GPU to access each other's memory transparently using pointers, eliminating the need for explicit data copies. In the context of KV cache management, UVM enables techniques like KV cache offloading, where portions of the cache can be seamlessly migrated to CPU RAM or NVMe storage to overcome GPU memory limits for long contexts.

The primary implementation is CUDA UVM, which uses hardware page faulting and on-demand data migration. When a GPU kernel accesses a page residing in CPU memory, a fault occurs, and the page is automatically transferred. This simplifies programming for memory-bound inference workloads but introduces latency from data movement. Efficient use requires cache-aware scheduling to minimize these faults, making UVM a critical tool for managing large KV caches within the Inference Optimization and Latency Reduction pillar.

KV CACHE MANAGEMENT

Core Characteristics of UVM

Unified Virtual Memory (UVM) is a hardware and software architecture that provides a single, coherent virtual address space across CPU and GPU memory, simplifying the programming model for techniques like KV cache offloading.

01

Single Virtual Address Space

The foundational characteristic of UVM is the creation of a unified virtual address space that spans both CPU system memory and GPU device memory. This allows pointers to data to be valid and meaningful on both the CPU and GPU, regardless of the data's physical location. This eliminates the need for explicit, manual memory copies (cudaMemcpy) between host and device for data movement, as the hardware and driver can manage migration transparently.

  • Simplified Programming: Developers can write code that references data using a single pointer, as if working with a single, large memory pool.
  • Key Use Case: Essential for implementing KV cache offloading, where parts of the key-value tensor cache can seamlessly reside in CPU RAM while being accessed by the GPU, without complex manual buffer management.
02

On-Demand Page Migration

UVM systems implement on-demand page migration, a mechanism analogous to virtual memory paging in operating systems. When a GPU (or CPU) attempts to access a memory page that resides in the other processor's physical memory, a page fault occurs. The UVM driver then transparently migrates the requested page to the local memory of the accessing processor.

  • Efficiency: Data is moved only when needed, optimizing bandwidth usage.
  • Granularity: Migration happens at the page level (e.g., 4KB, 64KB), allowing fine-grained movement of data. For KV cache management, this means individual blocks of the cache can be swapped between GPU and CPU memory based on the attention pattern of the decoding process.
03

Memory Oversubscription

A critical capability enabled by UVM is memory oversubscription. The total size of allocated UVM memory can exceed the physical capacity of the GPU's high-bandwidth memory (HBM). The system uses the CPU's RAM and, if necessary, even NVMe storage as a slower, larger backing store.

  • Enables Longer Contexts: This directly supports long-context inference by allowing the KV cache for thousands of tokens to be allocated, even if it doesn't all fit in GPU memory at once.
  • Performance Trade-off: Accessing data in CPU RAM is significantly slower than GPU HBM, creating a latency/throughput trade-off that must be managed by scheduling and access patterns.
04

Data Coherence & Consistency

UVM provides coherence guarantees between the CPU and GPU caches. When the CPU writes to a UVM-managed region, subsequent GPU reads will see the updated data, and vice-versa. This is typically achieved through a software-managed coherence model in implementations like CUDA UVM, where explicit synchronization calls (cudaDeviceSynchronize, cudaStreamSynchronize) enforce a consistent view of memory.

  • Deterministic Behavior: Ensures correctness when both processors are manipulating shared data structures, such as metadata for managing a partitioned KV cache.
  • Developer Responsibility: Unlike fully coherent CPU multi-core systems, the programmer must insert appropriate synchronization points to avoid race conditions.
05

Unified Pointer & Allocation Semantics

UVM introduces memory allocation functions (e.g., cudaMallocManaged) that return pointers usable by both CPU and GPU code. These unified pointers simplify code structure. The allocation also comes with hints (e.g., cudaMemAdvise) that allow developers to guide the UVM driver's migration and prefetching policies.

  • Common Allocation API: Replaces separate malloc and cudaMalloc calls.
  • Performance Optimization: Advising the system that data will be accessed mostly by the GPU (cudaMemAdviseSetPreferredLocation) or that it should be prefetched (cudaMemAdviseSetAccessedBy) can significantly reduce page fault latency, a crucial optimization for managing the streaming access patterns of a KV cache during decoding.
06

Integration with KV Cache Offloading

UVM is the enabling hardware/software layer for efficient KV cache offloading strategies. The KV cache can be allocated as a unified memory region. Hot, actively accessed cache entries (e.g., for recent tokens and attention sinks) reside in GPU HBM, while colder, older portions of the context can be transparently paged out to CPU RAM.

  • Transparent Management: The attention computation kernels access the KV cache via unified pointers; the UVM system handles the physical location.
  • Enables New Optimizations: Allows systems like vLLM to think in terms of virtual cache blocks, which can be non-contiguously mapped to physical memory pages on either CPU or GPU, similar to its PagedAttention concept but across a memory hierarchy.
KV CACHE MANAGEMENT

How Unified Virtual Memory Works

Unified Virtual Memory (UVM) is a hardware and software architecture that creates a single, coherent virtual address space spanning both CPU and GPU memory, fundamentally simplifying memory management for complex workloads like KV cache offloading.

Unified Virtual Memory (UVM) provides a single virtual address space across CPU and GPU memory, managed by the system's memory management unit (MMU) and page tables. This allows both processors to access any memory location using the same pointer, with data automatically migrated on-demand via page faults. In frameworks like CUDA UVM, this eliminates the need for explicit cudaMemcpy calls, enabling seamless oversubscription of GPU memory by spilling to host RAM or storage. For KV cache management, UVM allows the cache to transparently span device and host memory, enabling longer contexts without complex manual orchestration.

The architecture relies on demand paging and coherence protocols to maintain consistency. When a GPU accesses a page residing in CPU memory, a fault triggers a migration to GPU memory, caching it for performance. This is critical for KV cache offloading, where less frequently accessed cache pages can reside in cheaper, higher-capacity CPU RAM, while active pages stay on the GPU. The major trade-off is latency: accessing off-device memory incurs higher I/O cost, making UVM performance dependent on access locality and workload patterns versus the deterministic control of discrete memory transfers.

MEMORY MANAGEMENT

UVM in AI Frameworks and Platforms

Unified Virtual Memory (UVM) is a hardware and software architecture that creates a single, coherent virtual address space spanning CPU and GPU memory. This simplifies programming for memory-intensive AI workloads, particularly for managing large KV caches during inference.

01

Core Mechanism: Single Virtual Address Space

UVM provides a unified virtual address space across CPU and GPU memory. This allows both the CPU and GPU to access any memory location using the same pointer, managed by the system's memory management unit (MMU) and page tables. The key components enabling this are:

  • Page Fault Handling: The GPU can generate a page fault if data is not resident in its local memory, triggering a page migration from CPU RAM or system storage.
  • Coherency Protocols: Hardware and software maintain memory coherency, ensuring all processors see a consistent view of data without explicit programmer synchronization.
  • On-Demand Paging: Memory pages are moved between CPU and GPU memory only when accessed, enabling efficient use of total system memory capacity.
02

Primary Use Case: KV Cache Offloading

UVM is critical for KV cache offloading, a technique to handle long-context inference. When a model's key-value cache exceeds GPU memory, UVM allows it to spill over to CPU RAM or NVMe storage. The process involves:

  • Transparent Access: The GPU's attention kernels access the KV cache via virtual addresses. If a required block is not in GPU memory, a page fault occurs.
  • Background Migration: The UVM driver migrates the required page from CPU memory to GPU memory, allowing the computation to proceed. Less-recently-used pages may be evicted back to the CPU.
  • Performance Trade-off: This exchanges higher I/O latency for vastly increased effective cache capacity, enabling context windows of millions of tokens without model architecture changes.
03

CUDA UVM: The NVIDIA Implementation

CUDA Unified Virtual Memory is NVIDIA's implementation, a cornerstone for large model inference on their GPUs. Key features include:

  • Managed Memory: Allocated via cudaMallocManaged(), this memory is automatically migrated by the CUDA driver.
  • Access Counters: The driver uses counters to track page usage, implementing policies like prefetching and data locality optimization.
  • GPU Direct RDMA: Supports direct peer-to-peer access and Remote Direct Memory Access (RDMA) over NVLink and InfiniBand, allowing efficient memory sharing across multiple GPUs and nodes.
  • Integration with Libraries: Deeply integrated with cuBLAS, cuDNN, and frameworks like TensorRT-LLM, which use UVM for efficient KV cache management and continuous batching.
04

System Requirements & Hardware Support

UVM requires specific hardware and software support to function efficiently:

  • GPU Architecture: Requires Pascal (SM 6x) or newer NVIDIA GPUs for full hardware support. Older architectures use slower software-emulated modes.
  • CPU-GPU Interconnect: Performance depends on PCIe bandwidth (Gen3/4/5). NVLink provides significantly higher bandwidth for page migrations between CPU and GPU.
  • Operating System: Requires driver and OS support for handling GPU page faults. Linux is the primary production environment.
  • Page Size: Modern systems support large pages (e.g., 2MB, 1GB) to reduce page table overhead and TLB misses during massive KV cache access.
05

Performance Implications & Trade-offs

While UVM simplifies programming, it introduces specific performance characteristics that engineers must design for:

  • Latency vs. Capacity: The primary trade-off. Accessing CPU memory can be ~5-10x slower than GPU HBM. NVMe offload can be ~100-1000x slower.
  • Page Fault Overhead: The first access to a non-resident page incurs a high latency penalty (tens of microseconds). This makes access patterns critical.
  • Prefetching Strategies: Proactive prefetching algorithms are essential to hide migration latency. This involves predicting which KV cache blocks will be needed next based on attention patterns.
  • Coherency Overhead: Maintaining coherency across devices adds minor protocol overhead, but is negligible compared to page migration costs.
06

Integration with Inference Engines

Modern high-performance inference engines leverage UVM as a foundational layer for advanced memory management:

  • vLLM with PagedAttention: While vLLM's PagedAttention manages the KV cache in software blocks, it can use UVM at a lower level to allocate and migrate those blocks between GPU and CPU memory.
  • TensorRT-LLM: Uses CUDA UVM for dynamic KV cache allocation and to support its in-flight batching capabilities, allowing seamless handling of variable-length sequences.
  • Orchestration with Cache-Aware Scheduling: Schedulers can group requests with similar KV cache footprints to improve locality of reference, minimizing thrashing and page faults within the UVM system.
ARCHITECTURAL COMPARISON

UVM vs. Traditional GPU Memory Management

A technical comparison of memory management paradigms, highlighting how Unified Virtual Memory simplifies programming for techniques like KV cache offloading by eliminating manual data transfers.

Feature / MetricTraditional GPU Memory ManagementUnified Virtual Memory (UVM)

Address Space

Disjoint CPU and GPU virtual address spaces

Single, unified virtual address space across CPU and GPU

Data Movement

Explicit, manual (cudaMemcpy)

Implicit, on-demand via page faults

Memory Coherence

None; programmer-managed consistency

Hardware-enforced coherence at page granularity

Programming Model Complexity

High (requires explicit transfer logic)

Low (pointer-based, similar to CPU code)

KV Cache Offloading Feasibility

Complex, requires custom pinned memory pools

Simplified, enables seamless CPU RAM/SSD spillover

Pageable Memory Support

Zero-Copy Access (CPU→GPU)

Memory Oversubscription Support

Typical Latency for Un-cached Access

< 1 µs (GPU HBM)

~10-100 µs (CPU RAM), ~100-1000 µs (NVMe)

Primary Use Case in Inference

Static, predictable workloads

Dynamic workloads with large, variable context (e.g., long-context LLMs)

KV CACHE MANAGEMENT

Frequently Asked Questions

Unified Virtual Memory (UVM) is a foundational hardware-software architecture for managing memory across CPU and GPU, critical for optimizing KV cache operations in large language model inference. These questions address its core mechanisms and practical applications.

Unified Virtual Memory (UVM) is a hardware and software architecture that creates a single, coherent virtual address space spanning both CPU and GPU memory, allowing either processor to access any memory location seamlessly. In practice, this is implemented through technologies like CUDA UVM, where the system's memory management unit (MMU) and the GPU's page fault engine handle address translation and data movement transparently. When a GPU kernel accesses a page residing in CPU RAM, a page fault occurs, triggering the driver to migrate the page to GPU memory. This abstraction simplifies programming by eliminating the need for explicit cudaMemcpy calls for data movement, enabling techniques like KV cache offloading where parts of the cache can reside in cheaper, higher-capacity CPU memory and be paged in on-demand during the decode phase.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.