我使用一个函数来计算三个向量的向量点,并使用一个 reduce 来使其更快。但是,我总是遇到这样的错误:
CUDA error at kernel.cu:120 code=30(cudaErrorUnknown) "cudaMemcpy(partia
l_c, dev_partial_c,sizeofblock,cudaMemcpyDeviceToHost )"
我不知道为什么,因为代码看起来很正常。分配函数没有返回错误。有什么可能的解决方案吗?十分感谢。
double vector_dot(double* d_A,double* d_B,double *d_C,int numElements)
{
int size = sizeof(double) * numElements;
int c_size = sizeof(char) * numElements;
double *d_D=NULL;
checkCudaErrors(cudaMalloc((void**)&d_D,size));
// Launch the Vector Add CUDA Kernel
int threadsPerBlock = 256;
int blocksPerGrid =(numElements + threadsPerBlock - 1) / threadsPerBlock;
vectorMPL<<<blocksPerGrid, threadsPerBlock>>>(d_A, d_B, d_D, numElements);
double *partial_c;
double*dev_partial_c;
int sizeofblock=blocksPerGrid*sizeof(double);
partial_c = (double*)malloc(sizeofblock);
checkCudaErrors( cudaMalloc( (void**)&dev_partial_c,sizeofblock )) ;
vector_dot_h<<<blocksPerGrid, threadsPerBlock>>>(d_D, d_C, dev_partial_c, numElements);
double sum = 0;
checkCudaErrors(cudaMemcpy(partial_c,dev_partial_c,sizeofblock,cudaMemcpyDeviceToHost));
for (int i=0; i<blocksPerGrid; i++) {
sum += partial_c[i];
}
checkCudaErrors(cudaFree(d_D));
checkCudaErrors(cudaFree(dev_partial_c));
free(partial_c);
// Reset the device and exit
checkCudaErrors(cudaDeviceReset());
return sum;
}
如果我删除它,我会在 cudafree 调用中收到未知错误。似乎所有的 cuda API 调用都无法完成。我想知道为什么?什么是未知的cuda错误?原因是什么?