How access GpuMat in a kernel
Hello,
I'm quite new in cuda programming, and I need to write my own kernel. However, most of the things are clear to me, except one. The folloing sentence is written in the docu: The GpuMat class is convertible to gpu::DevMem2D_ and gpu::PtrStep_ so it can be passed directly to the kernel. I'm asking now myself how to access the buffers within a kernel, specially if I would like to use a struct to store my buffers. Here some PsydoCode:
struct GpuBuffer{
GpuMat InBuffer1;
GpuMat InBuffer2;
GpuMat InBuffer3;
GpuMat OutBuffer;
};
int main (void)
{
GpuBuffer d_buffer;
InitGPUBuffer (d_buffer);
callKernel(d_buffer);
return 0;
}
void InitGPUBuffer(GpuBuffer &d_buffer)
{
Mat QuadFloatArr = Mat.zeros(Size(640, 480), CV_32FC4);
d_buffer.InBuffer1.upload(QuadFloatArr);
d_buffer.InBuffer2.upload(QuadFloatArr);
d_buffer.InBuffer3.upload(QuadFloatArr);
d_buffer.OutBuffer.upload(QuadFloatArr);
}
void callKernel(GpuBuffer& d_buffer)
{
Cuda_KernelCall(d_buffer);
}
//cu-file
extern "C" bool Cuda_KernelCall(GpuBuffer& Buffer)
{
dim3 threads(16,16);
dim3 grid((Buffer.InBuffer1.cols/2)/(threads.x), (Buffer.InBuffer1.rows/2)/(threads.y));
Kernel<<<treads, grid>>>(Buffer);
return true;
}
__global__ void Kernel( GpuBuffer Buffer )
{
int x = (blockIdx.x * blockDim.x) + threadIdx.x;
int y = (blockIdx.y * blockDim.y) + threadIdx.y;
// how to access the several buffer that are stored in the struct?
}
Thank you very much in advance.
cheers greg
See this thread: http://answers.opencv.org/question/215/cant-compile-cu-file-when-including-opencvhpp/
Hi Vladislav,
tnx for the comment. I though so already, there is no direct way to pass GpuMat to a kernel, just via the light-weighted wrapper or via the the pointer directly. Ok, thanks a lot. I will have to rewrite my struct.
cheers greg