Note that there are some explanatory texts on larger screens.

plurals
  1. POCUDA - Copy device data to host?
    primarykey
    data
    text
    <p>I have device variable and in this variable I alloc and fill array in device, but I have problem to get data to host. cudaMemcpy() return cudaErrorInvalidValue error. how can i do it?</p> <p>PS: The Code is just example, I know, that In this particular case I can use cudaMalloc, because I know size of array, but In my REAL code, It computes size of array in device and it needs immediately alloc memory. </p> <p>PS2: I found similar problem, but I still dont know, how can i solve it? - <a href="https://stackoverflow.com/questions/8322547/copy-data-which-is-allocated-in-device-from-device-to-host">copy data which is allocated in device from device to host</a></p> <p>PS3: I have updated code, but still doesnt works :{</p> <p>PS4: I am just trying to run this code on notebook with Nvidia GT 520MX(lastest game driver) and doesnt work too :(</p> <p>thx</p> <pre><code>#include &lt;cuda.h&gt; #include &lt;stdio.h&gt; #define N 400 __device__ int* d_array; __global__ void allocDeviceMemory() { d_array = new int[N]; for(int i=0; i &lt; N; i++) d_array[i] = 123; } int main() { allocDeviceMemory&lt;&lt;&lt;1, 1&gt;&gt;&gt;(); cudaDeviceSynchronize(); int* d_a = NULL; cudaMemcpyFromSymbol((void**)&amp;d_a, "d_array", sizeof(d_a), 0, cudaMemcpyDeviceToHost); printf("gpu adress: %lld\n", d_a); int* h_array = (int*)malloc(N*sizeof(int)); cudaError_t errr = cudaMemcpy(h_array, d_a, N*sizeof(int), cudaMemcpyDeviceToHost); printf("h_array: %d, %d\n", h_array[0], errr); getchar(); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload