我一直在 stackoverflow 上阅读一些关于 2D 数组和 cudaMallocPitch 的线程,并且尝试将 cudaMallocPitch 与我找到的小文档一起使用。但是我现在面临一个问题。
我需要遍历一个数组并执行类似的操作:
for(int k=0; k<100; ++k){
for(i=SID; i<SID+stride; ++i){
while(-1 < j && Driver[k][j] != Road[i]){
j = Pilot[j][k];
}
++j;
}
}
因此我想知道,我应该如何调整这段代码以使其与音调一起工作,因为我读到我必须将指针更新到行的开头。当然,我的内核收到以下信息:
__global__ void driving(char *Driver, size_t pitch_driver,
char *Road, int *Pilot, size_t pitch_pilot)
我不太确定如何让事情发挥作用,我一直在阅读和尝试,但目前似乎不起作用。
谢谢。
Edit 1:我特别读过这个帖子:如何在 CUDA 中使用 2D 数组? https://stackoverflow.com/questions/5029920/how-to-use-2d-arrays-in-cuda/9974989#9974989并遇到了以下问题:
for (int row = 0; row < rowCount; row++)
{
// update the pointer to point to the beginning of the next row
float* rowData = (float*)(((char*)d_array) + (row * pitch));
for (int column = 0; column < columnCount; column++)
{
rowData[column] = 123.0; // make every value in the array 123.0
destinationArray[(row*columnCount) + column] = rowData[column];
}
}
这是更新下一行的指针,我不知道如何使用我的 2 个 for 循环以及在工作时如前面的代码中那样。
目前我只能访问数组的一维,而不能访问另一维。
它返回值 2,但是当我尝试多次比较时,它只返回 0,甚至比较两个值也不起作用。