Hailiang Zhang
Hailiang Zhang

Reputation: 18860

Can I access device global memory from a host?

CUDA C programming Guide states that on compute capacity above 2.0, host and device share the memory space on a 64-bit linux. I have a piece of global memory allocated via the standard run time API "cudaMalloc", but it seems the host cannot directly access it. Should I do something special to make it accessible to host?

Upvotes: 1

Views: 1304

Answers (1)

Robert Crovella
Robert Crovella

Reputation: 151799

Device memory allocated statically or dynamically is not directly accessible (e.g. by dereferencing a pointer) from the host. It is necessary to access it via a cuda runtime API call like cudaMemset, or cudaMemcpy. The fact that they share the same address space (UVA) does not mean they can be accessed the same way. It simply means that if I have a device pointer that has been allocated at a particular location such as 0x00F0000 in logical address space, I should not expect to find a host pointer at the same location. Therefore, given suitable record-keeping, I can inspect the numerical value of the pointer and immediately determine whether it is a host or device pointer.

In the programming guide, it states:

Therefore, a program manages the global, constant, and texture memory spaces visible to kernels through calls to the CUDA runtime (described in Programming Interface). This includes device memory allocation and deallocation as well as data transfer between host and device memory.

Upvotes: 2

Related Questions