I'm new to CUDA and C and I could use some help with the following: I want to pass a C array of GpuMats to a CUDA kernel:
Here is the code of my Kernel:
__global__
void disparityFromDiffMapsKernel(cuda::PtrStepSzi* differenceMapsArray,
int arraySize,
cuda::PtrStepSzi disparityMap){
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
//check if thread is inside the image
if(x > differenceMapsArray[0].cols || y > differenceMapsArray[0].rows){
return;
}
//do stuff
}
And here is the code where I initialize the array and call the kernel:
cuda::PtrStepSzi diffMaps[diffMapsSize];
for(int i = 0; i <= offset; i++){
cuda::GpuMat diffMap(leftImageGPU.size(),CV_32SC1);
cuda::PtrStepSzi diffMapPtr = diffMap;
diffMaps[i] = diffMapPtr;
}
disparityFromDiffMapsKernel<<<numBlocks,threadsPerBlock>>>(diffMaps,diffMapsSize,disparityImageGPU); //gpu mat is initialized before
When I run this code I get the following opencv error:
OpenCV(3.4.1) Error: Gpu API call (an illegal memory access was encountered)
I would really appreciate any help!
diffMapsresides on the host, while you are passing it as a kernel argument and trying to access it on the device.