gpuguy
gpuguy

Reputation: 4585

Pinned memory in CUDA and cudamemcpy()

I understand that when copy operation between host and device starts using cudaMemcpy, the host pointer is pinned automatically. Then what is the meaning and necessity of having a separate API cudAHostAlloc() for allocating pinned host memory?

Upvotes: 3

Views: 3897

Answers (1)

Robert Crovella
Robert Crovella

Reputation: 151799

The two operations are not the same, and the host pointer you pass to cudaMemcpy is not "pinned automatically".

For transfers from pageable memory to the device, the host memory is copied to a staging buffer. The staging buffer is then the target of any transfers.

This makes the pageable memory transfers slower (typically) than transfers from pinned memory buffers. Using pinned memory also allows for other possibilities, such as having mapped memory that is directly accessible by the device, without an explicit (API-level) transfer.

Upvotes: 5

Related Questions