CUDA从设备到主机复制常量

Gui*_*tro 2 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)); 
Run Code Online (Sandbox Code Playgroud)

Rog*_*ahl 5

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

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