title: Copying data from GPU to CPU - CUDA
body: <p>I have problem with copying data from GPU to CPU. At the beginning I create variable in GPU space:</p>
  
  <pre><code>__device__ float gpu_array;
  </code></pre>
  
  <p>In this GPU function, I want to copy the data from od.fS[gi] (value = 0,43...) to gpu_array:</p>
  
  <pre><code>__global__ void Collide(.....){
  ....
  
  //Streaming
      od.fS[gi] = fi_S;
      od.fN[gi] = fi_N;
      od.fE[gi] = fi_E;
      od.fW[gi] = fi_W;
  
      gpu_array = od.fC[gi];
  }
  </code></pre>
  
  <p>End here is function to copy data from GPU to CPU:</p>
  
  <pre><code>void showData(){
  
  cudaDeviceSynchronize();
  
  float* temp_array = NULL;
  cudaMemcpyFromSymbol((void**)&amp;temp_array, "gpu_array", sizeof(temp_array), 0, cudaMemcpyDeviceToHost);
  
  float* cpu_array = (float*)malloc(sizeof(float));
  cudaMemcpy(cpu_array, temp_array, sizeof(float), cudaMemcpyDeviceToHost);
  printf("h_array: %f\n", *cpu_array);
  }
  </code></pre>
  
  <p>In finally copies but wrong values (0.00000, -0.00000 etc.). What am I doing wrong? </p>