Ask Your Question

How access GpuMat in a kernel

asked 2013-03-04 10:26:03 -0600

Ikarus79 gravatar image

updated 2013-03-04 10:29:13 -0600


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);
    return 0;

void InitGPUBuffer(GpuBuffer &d_buffer)
    Mat QuadFloatArr = Mat.zeros(Size(640, 480), CV_32FC4);

void callKernel(GpuBuffer& d_buffer)

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

edit retag flag offensive close merge delete


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

Ikarus79 gravatar imageIkarus79 ( 2013-03-05 04:34:43 -0600 )edit

1 answer

Sort by » oldest newest most voted

answered 2015-05-14 15:29:51 -0600

See this comment, maybe will help you:

edit flag offensive delete link more

Question Tools


Asked: 2013-03-04 10:26:03 -0600

Seen: 4,597 times

Last updated: Mar 04 '13