我正在尝试将大约 8650752 字节从设备复制到主机,但出现堆栈溢出错误,令人惊讶的是,我可以将相同的数据从主机复制到设备,但在对其进行计算后,无法返回。代码很简单,所以不知道出了什么问题
代码:
__global__
void kernel(....)
{
int x=threadIDX.x;
for (int j=0; j<256; j++)
{
for (int i=0; i<256; i++)
{
int index = 256*256*x + 256*j + i;
dVOL_in[(x*65536)+(256*j)+i]=index;
}
}
}
int main(void)
{
const int VOL_SIZE = 8650752;
const int VOL_BYTES = VOL_SIZE * sizeof(float);
float hVOL[VOL_SIZE];
float * dVOL_in;
gpuErrchk(cudaMalloc((void**) &dVOL_in, VOL_BYTES));
// volume data read from some file
gpuErrchk(cudaMemset(dVOL_in,0,VOL_BYTES));
gpuErrchk(cudaMemcpy(dVOL_in,Vol,VOL_BYTES, cudaMemcpyHostToDevice)); //works fine
kernel<<<1,132>>>(....);
cudaMemcpy(hVOL, dVOL_in, VOL_BYTES, cudaMemcpyDeviceToHost); //stack overflow error
}