Guilherme Torres Castro
Guilherme Torres Castro

Reputation: 15350

Cuda copy constant from device to host

I'm trying to copy a memory from device to host, but i'm getting the following error:

CUDA Error 13: invalid device symbol

__device__ __constant__ unsigned int cuda_delta = 0;
int delta = 0;
checkCuda(cudaMemcpyToSymbol(cuda_delta, 
                             &delta,sizeof(unsigned int),
                             0,
                             cudaMemcpyHostToDevice)); // work
... // call kernel

// does not work, return  CUDA Error 13: invalid device symbol
checkCuda(cudaMemcpyToSymbol(&delta,
                             &cuda_delta,
                             sizeof(unsigned int), 
                             cudaMemcpyDeviceToHost)); 

Upvotes: 2

Views: 2495

Answers (1)

Roger Dahl
Roger Dahl

Reputation: 15744

A symbol references GPU memory, so you can't use *ToSymbol when you want to copy from device to host. For device to host, use cudaMemcpyFromSymbol.

cudaError_t cudaMemcpyFromSymbol    (   void *  dst,
  const char *  symbol,
  size_t    count,
  size_t    offset = 0,
  enum cudaMemcpyKind   kind = cudaMemcpyDeviceToHost    
)       

Upvotes: 5

Related Questions