Pinned host memory and transfers
Plan DMA eligibility, overlap conditions, and buffer lifetimes instead of equating an asynchronous API return with transfer completion.
On this page
The question for today
What you’ll understand
- Distinguish pageable, page-locked, and mapped host-memory contracts.
- Identify conditions for transfer/computation overlap.
- Preserve source and destination lifetimes until the appropriate completion boundary.
A training input pipeline prepares the next batch while the GPU computes on the current one. Host-to-device transfer can become part of a useful pipeline, but the host allocation and synchronization rules matter. This lesson uses CUDA 12.8.1 runtime documentation for a discrete Ampere-class GPU connected to host memory. Integrated platforms, mapped access, copy-engine capabilities, and NUMA topology can change the implementation and performance.
Pinning changes the transfer contract
Page-locked host memory can be used for DMA without relying on an ordinary pageable buffer remaining resident in a convenient physical arrangement. CUDA exposes allocation or registration APIs for this purpose. Pinning is a limited system resource: excessive page locking can reduce memory available for ordinary paging and degrade the host. Prefer a bounded pool with an explicit owner and measured reuse rather than repeatedly pinning unbounded batches as demand rises.
Pinned and mapped are related but different properties. A host allocation can support an explicit copy to device memory, while mapped access allows a kernel to access host-backed storage under the platform’s rules. That access still traverses the relevant interconnect on a discrete GPU and does not magically become local device DRAM. Check capabilities and API flags rather than inferring placement from a pointer value. For training tensors, repeated device reuse often makes one explicit transfer preferable to repeatedly reading remote host memory, but measure the actual workload.
Overlap needs resources and independent ordering
An asynchronous-named copy API does not promise identical host behavior for every allocation and direction. Pageable memory can require staging or synchronization described by the CUDA runtime’s API synchronization rules. For reliable transfer/computation overlap, establish suitable pinned buffers, device support, independent streams or operations, and enough execution resources. Legacy default-stream interactions can impose ordering that serializes a seemingly parallel schedule. Record the actual dependency graph rather than assuming two API calls automatically overlap.
The source of a host-to-device copy must remain valid and unmodified until its required completion condition, and a device-to-host destination must not be consumed early by the CPU. An API returning after enqueueing is not that completion. Use stream or event completion with the correct device and operation association, then transfer buffer ownership back to the producer. The same reasoning applies to recycling a pool slot: a later batch must not overwrite bytes still being read by an earlier transfer.
Measure the complete input stage
Separate CPU decoding, pinning or registration, transfer queueing, DMA duration, and device consumption. Increasing pinned buffers can hide short fluctuations but cannot raise a saturated link’s sustained throughput. Host NUMA placement can also affect the path to the GPU. Include a realistic batch size distribution and avoid timing only enqueue latency. Keep correctness checks for buffer reuse and transfer completion while profiling; a pipeline that skips a needed wait can look fast by consuming data before it is ready.
The queue lab isolates pending-work pressure. Reset, set arrival rate to 4 and service rate to 3, predict backlog at one second, then Step twice. Compare a fresh Reset with both arrival rate at 2 and service rate at 4, predicting before two Steps. Each starts with four abstract equal batches. This fluid model has no pinned pages, DMA engines, streams, or ownership states. Use it to explain why more queued transfers cannot fix a sustained rate imbalance, and draw a separate completion timeline for safe buffer reuse.
Work it through
Separate movement time from buffer occupancy
Assume equal batches of 24 MB in decimal units and effective transfer bandwidth 12 GB/s. The complete source-buffer holding time is fixed at 5 milliseconds, including queueing and completion handling. Batches arrive deterministically at 400 per second; ignore bursts.
The movement-only lower bound is 24,000,000 / 12,000,000,000 = 0.002 seconds, or two milliseconds. It is not the complete five-millisecond holding interval.
Concurrent source-buffer demand under the fixed-time model is ceil(400 × 0.005) = 2 buffers. Their payload is 48 MB, before reserve slots or metadata.
Check actual event completion before returning either buffer to the CPU producer. Queueing variation or bursts can require more capacity, and capacity does not remove the lifetime rule.
Two milliseconds of ideal movement and five milliseconds of ownership describe different boundaries. Safe pooling follows the latter.
The living notebook
Explore the model
Interactive lab · queue
Queued transfers still need sustained capacity
Reset, set arrival rate λ = 4 and service rate μ = 3, predict backlog after one second, then Step twice. Compare a fresh Reset with both λ = 2 and μ = 4 before two Steps. This four-item fluid model contains no pinned memory, DMA, streams, or completion evidence.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forBuffering can absorb bounded variation; it does not replace capacity or transfer-completion ownership.
Pause & reason
Check your understanding
Your turn
Try it yourself
A 16 MB batch crosses an assumed 8 GB/s path. Compute the ideal movement bound. If a buffer is held for a fixed 8 milliseconds at a deterministic 250 batches per second, calculate the minimum ideal concurrent count and explain why it is not a burst guarantee.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use decimal bytes for movement and seconds for rate times holding duration.
Compare with the solution
The movement lower bound is 16,000,000/8,000,000,000 = two milliseconds. The concurrent count is ceil(250 × 0.008) = 2. Bursty arrivals, longer completion handling, and variable queueing can exceed that fixed-time model. Retain buffers until actual completion even if a rate calculation suggested they should already be free.
Keep the idea
Take it with you
- Page locking, mapping, and local device storage are distinct properties.
- Overlap depends on capabilities, streams, resources, and independent work.
- A returned enqueue call does not release a transfer’s source or destination lifetime.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.