我正在调用 cudaMemcpy 并且副本成功返回,但是源值没有被复制到目标。我使用 memcpy() 写了一篇类似的文章,效果很好。我在这里想念什么?
// host externs
extern unsigned char landmask[DIMX * DIMY];
// use device constant memory for landmask
unsigned char *tempmask;
__device__ unsigned char *landmask_d;
..
void checkCUDAError(const char* msg) {
cudaError_t err = cudaGetLastError();
if (cudaSuccess != err) {
fprintf(stderr, "Cuda error: %s: %s.\n", msg, cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
}
..
// try a memcpy
size_t landMemSize_t landMemSize = DIMX * DIMY * sizeof(char);
tempmask = (unsigned char*)malloc(landMemSize);
memcpy(tempmask, landmask, DIMX * DIMY);
if (landmask[0] != *tempmask) printf("FAILURE!\n");
// allocate device memory for landmask
cudaMalloc((void **)&landmask_d, landMemSize);
printf("allocating %ld Kbytes for landmask\n", landMemSize/1024);
checkCUDAError("memory allocation");
// copy landmask from host to device
cudaMemcpy(landmask_d, landmask, landMemSize, cudaMemcpyHostToDevice);
checkCUDAError("memory copy");
if (landmask[0] != *landmask_d) printf("FAILURE!\n");
没有一个 CUDAErrors 报告任何问题,但第二个 FAILURE 被调用..?