我已閱讀以下thread,但無法讓我的代碼正常工作。
我想在GPU上分配一個二維數組,並用值填充它,然後將其複製回CPU。我的代碼如下:CUDA:在GPU上分配2D陣列
__global__ void Kernel(char **result,int N)
{
//do something like result[0][0]='a';
}
int N=20;
int Count=5;
char **result_h=(char**)malloc(sizeof(char*)*Count);
char **result_d;
cudaMalloc(&result_d, sizeof(char*)*Count);
for(int i=0;i<Count;i++)
{
result_h[i] = (char*)malloc(sizeof(char)*N);
cudaMalloc(&result_d[i], sizeof(char)*N); //get exception here
}
//call kernel
//copy values from result_d to result_h
printf("%c",result_h[0][0])//should print a
我該如何做到這一點?