I need to hold reference of multiple 2d arrays. I am storing a single 2d array as follows: float* Filtered, and access it in this manner: Filtered[(y*WIDTH)+x]. Now I want to pass multiple 2D arrays to a cuda kernel. I was trying the following:
Allocation on device:
float d_allFiltered[2][15];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 15; j++)
cudaMalloc((void*)&d_allFiltered[i][j], energySizex * energySizey * sizeof(float));
Calling kernel (passing 15 elements):
ComputeSum<<< dimGrid, dimBlock, 0 >>>(d_allFiltered[image], d_SUM1mapAll, sizex, sizey);
Kernel:
global void ComputeSum(float* Filtered, float* SUM1mapAll, unsigned int sizex, unsigned int sizey)
{
unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;
if ((x < sizex) && (y < sizey))
{
SUM1mapAll[(y * sizex) + x] = 0;
for (int i = 0; i < 15; i++)
SUM1mapAll[(y * sizex) + x] += Filtered[i][(y * sizex) + x];
}
}
When a thread tries to access “Filtered[i][(y * sizex) + x]”, an error is triggered. Can someone either tell me what am I doing wrong, or propose me another better method to keep reference of multiple 2D arrays.
Thanks