Reputation: 69
I would like some help with the following. I have an array on host code, a kernel function and a device function called from the kernel. I want only the device function to use the host array. Can I make my host array "visible" from the device function directly in some way or do I have to copy it to the kernel first?
Upvotes: 1
Views: 2395
Reputation: 5554
You could have a look at this answer:
Default Pinned Memory Vs Zero-Copy Memory
or search for:
Mapped Memory and Page-Locked Host Memory
Upvotes: 1
Reputation: 4962
CUDA kernel is a code executing on GPU (device). GPU can only access the memory located on the graphics card, not the main CPU memory. CPU can copy data between main and device memory. The usual scenario is:
I recommend you to read the official documentation. If you prefer slides, you can start from the introductory presentation.
Upvotes: 0
Reputation: 6450
I don't believe there is any way for the device function to access host memory directly. Even if you could, the latency and bandwidth would be brutal and likely not worthwhile.
If you mean that you want the device function to be run by the CPU on the host side, then that is possible. You can prefix __host__ __device__
to the function definition, and that function will be compiled for both the host and device so that you can use it directly on the CPU. The only catch is that the function can't make use of any CUDA features not available on the CPU (eg., shared memory, etc.).
Upvotes: 0