What is Unified memory?

Memory accessible from CPU and GPU through the same pointer, with data migrating automatically on access. It simplifies programs, but migration costs need attention.

Field: GPU Programming

Japanese name: ユニファイドメモリ

Automatic page-by-page migration

In CUDA, memory allocated with cudaMallocManaged is unified memory. Data is managed in pages, and on GPUs and systems that support page faulting, when the GPU touches a page that resides on the CPU side, the driver migrates it to GPU memory; when the CPU touches it, it moves back. No explicit cudaMemcpy is needed, so complex data structures containing pointers can be used as they are. On such systems you can also allocate more data than fits in GPU memory and process it while only the parts needed are moved in.

Tuning for performance

Handling page faults and transferring data in small pieces tends to be slower than a single bulk copy, and if the CPU and GPU take turns using the same pages, the pages bounce back and forth and performance drops sharply. When speed matters, cudaMemPrefetchAsync moves data before it is used, and cudaMemAdvise tells the driver things such as that the data is mostly read. A common approach is to get the program working with unified memory first, inspect the migrations with a profiler, and then add such hints.

How it differs from similar mechanisms

Unified virtual addressing (UVA) only places CPU and GPU memory in one address space; it does not move data automatically. Zero-copy access lets the GPU read pinned host memory directly over PCI Express without moving it. A SoC design in which the CPU and GPU physically share the same DRAM is also called "unified memory". CUDA unified memory differs in being a programming mechanism that also works on GPUs with their own separate memory.

Try it: questions about Unified memory

Which describes CUDA unified memory?

  1. AMemory usable from both CPU and GPU through the same pointer, with data migrating automatically as needed
  2. BThe CPU and GPU physically merged into one chip
  3. CGPU memory made entirely read-only
Show answer and explanation

Answer: A. Memory usable from both CPU and GPU through the same pointer, with data migrating automatically as needed

With unified memory, an allocation can be accessed from both CPU and GPU through the same pointer. On GPUs and systems that support page faulting, data migrates page by page to whichever side accesses it. Programs become simpler, and on such systems data larger than GPU memory is also easier to handle. Each migration involves page faults and transfers, though, so for performance, programs issue hints to prefetch data in advance.

Books on GPU Programming Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary