In the book CUDA By Example on page no 26 it written that:
You can pass pointers allocated with cudaMalloc() to functions that execute on the host.
You cannot use pointers allocated with cudaMalloc() to read or write memory from code that executes on the host.
To demonstrate the first concept I am writing the code here:
main() { int * ad, N; cudaMalloc((void **)&ad, Sizeof(int) *N); GPUFunction<<<...>>>(ad); Hostfunction(ad); } Hostfunction(int * AD) { int c ; c=AD[N-1]; printf("%d", c); } __global__ void GPUFunction(int *AD) { AD[threadIdx.x]= threadidx.x; } Is this what the point# 1 above explains? If so it in contradiction to point# 2 above, as you can see the host function is reading memory ad. So where is my understanding going wrong?