What Is GPU Cache Coherence? Sharing Data Between CPUs and GPUs
Cache coherence is the set of rules that keeps caches from using contradictory copies of the same memory location. It does not, by itself, make every write immediately visible or make simultaneous writes safe. Correct CPU–GPU sharing also depends on the memory type, platform support, synchronization, and access order.
What Is GPU Cache Coherence? Sharing Data Between CPUs and GPUs
Cache coherence is the set of rules that keeps caches from using contradictory copies of the same memory location. It does not, by itself, make every write immediately visible or make simultaneous writes safe. Correct CPU–GPU sharing also depends on the memory type, platform support, synchronization, and access order.
What coherence keeps consistent
CPUs and GPUs may each cache a copy of data to speed up access. If both read a shared variable x, then the CPU changes it, the GPU must not keep treating its stale copy as current. A coherence mechanism tracks which copy is valid and may update or invalidate other copies, or reconcile data at a synchronization point.
Coherence mainly addresses copies of the same address or cache line. The memory consistency model describes the order in which reads and writes, including those to different addresses, can be observed. Shared CPU–GPU memory may use hardware coherence, software coordination or page migration, or more limited support. CUDA documents these as distinct Unified Memory modes. NVIDIA CUDA Programming Guide: Unified Memory
Coherence, visibility, ordering, and atomicity
These answer different questions:
| Concept | Question | Example |
|---|---|---|
| Cache coherence | How are conflicting cached copies of one location handled? | A CPU write is made available to a GPU reading a shared buffer. |
| Visibility | Which participants can observe a particular write, and when? | The CPU waits for GPU work to finish before reading its output. |
| Memory ordering | In what order can one participant's writes and signals be observed by another? | A producer stores data, then signals with release; a consumer checks with acquire before reading. |
| Atomicity | Does an operation on one memory object occur indivisibly? | Several workers increment an atomic counter without losing updates. |
Release/acquire establishes ordering and synchronization; it does not give unsupported memory a system-wide atomicity guarantee. Synchronization scope matters too: CUDA block scope covers a block, device scope a GPU, and system scope participants such as the CPU and other GPUs. The scope must include every producer and consumer that needs to coordinate. NVIDIA CUDA Programming Guide: Thread Scopes and Scoped Atomics, NVIDIA CUDA C++ Memory Model
Coherence also does not eliminate data races. Conflicting concurrent ordinary accesses without suitable atomic operations or a happens-before relationship can have undefined behavior under CUDA's memory model. Reliable code must separately satisfy coherence, visibility, ordering, and race-freedom requirements.
Handing a buffer from the CPU to the GPU
Example: The CPU fills an image or input tensor in shared memory; a GPU kernel reads it and writes a result for the CPU. Sharing a pointer is not enough. Use the handoff and completion rules required by the platform.
| Step | Action | Check |
|---|---|---|
| 1. Produce | The CPU writes the input buffer. | The allocation type permits GPU access. |
| 2. Handoff | Start GPU work through the supported stream, event, or synchronization sequence. | The required operation makes CPU writes available to the device. |
| 3. Consume | The GPU reads the input and writes the result. | The CPU does not concurrently make ordinary writes to the same location. |
| 4. Wait | The CPU waits for the event, stream, or device work to complete. | Do not read an asynchronous result before completion. |
| 5. Read | The CPU reads the result after completion and required visibility conditions hold. | If it looks stale, check allocation, scope, and event order. |
AMD HIP describes coarse-grained memory as becoming up to date after synchronization such as hipDeviceSynchronize(), hipStreamSynchronize(), or a supported blocking operation; cache data may be flushed at that boundary. Fine-grained memory can support sharing small synchronization variables across kernel boundaries, but many AMD GPUs restrict its caching policy, for example by leaving it uncached or read-only. Check the device's supported pools and allocation flags. AMD HIP: Coherence Control
Coherence boundaries also differ within a GPU. AMD's CDNA 3 white paper says L2 is coherent within an XCD and an Infinity Cache snoop filter handles requests across multiple XCD L2 caches. This describes that architecture only; it is not a universal GPU or CPU–GPU guarantee. AMD CDNA 3 Architecture white paper
The HIP example follows documentation labeled HIP 7.17; the CUDA examples follow the Programming Guide checked on November 23, 2026. Verify the installed runtime, driver, device, allocation type, and supported atomic scope rather than assuming they match.
A practical check order
**Identify the memory type.** Device memory, mapped host memory, CUDA managed memory, and HIP fine- or coarse-grained memory have different rules.
**Check support and scope.** Verify GPU generation, runtime and driver, allocation flags, system-atomic support, and all participants (CPU, one GPU, or multiple GPUs). CUDA system-scope atomics depend on memory type and device capability; HIP documents pool properties through `rocminfo`.
**Assign readers and writers.** For a large input, a handoff at a work boundary may be simplest. For a small signal shared concurrently, consider supported fine-grained memory and an atomic whose scope includes all participants.
**Connect synchronization to ordering.** Use the event, stream or device synchronization, barrier, or release/acquire operation required by the API and memory model. Include producer and consumer in the atomic scope.
**Remove races and verify.** Avoid simultaneous ordinary writes to the same value; compare results after completion. For intermittent stale reads, inspect allocation, supported properties, access order, and event completion before trying arbitrary cache flushes.
A unified address space or identical pointer can make an address accessible across devices, but does not prove that every cache is coherent or every concurrent access is atomic and ordered. Follow the visibility and synchronization contract for the specific device and memory type.
Sources
[AMD, HIP Coherence Control](https://rocm.docs.amd.com/projects/HIP/en/latest/how-to/hip_runtime_api/memory_management/coherence_control.html)
[NVIDIA, CUDA Programming Guide: Thread Scopes and Scoped Atomics](https://docs.nvidia.com/cuda/cuda-programming-guide/03-advanced/advanced-kernel-programming.html)
[NVIDIA, CUDA C++ Memory Model](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cuda-cpp-memory-model.html)
[NVIDIA, CUDA Programming Guide: Unified Memory](https://docs.nvidia.com/cuda/cuda-programming-guide/04-special-topics/unified-memory.html)
[AMD, CDNA 3 Architecture white paper](https://www.amd.com/content/dam/amd/en/documents/instinct-tech-docs/white-papers/amd-cdna-3-white-paper.pdf)