Cuda从设备复制常量到主机

时间:2013-09-16 01:07:16

标签: cuda

我试图将内存从设备复制到主机,但我收到以下错误:

  

CUDA错误13:设备符号无效

__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)); 

1 个答案:

答案 0 :(得分:4)

符号引用GPU内存,因此当您要从设备复制到主机时,不能使用* ToSymbol。要设备托管,请使用cudaMemcpyFromSymbol

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