Custom OpenCL Kernel in OpenCV 3.x

asked 2016-03-25 03:49:11 -0600

milLII3yway gravatar image

updated 2016-03-25 04:11:10 -0600

I am trying to build my own ocl kernel in opencv 3.x. I was looking into both opencv source code and found out that the host source code calls ocl module (in *.cl file) using ocl::Kernel and ocl::ProgramSource (as mentioned in LINK and DOC).

It seems that in opencv module there is auto-generated *.hpp and *.cpp file (e.g. for modules/imgproc -> opencl_kernels_imgproc.hpp and opencl_kernels_imgproc.cpp) These files seemed to be generated based on *.cl file.

My question is, how to auto-generate these files for your custom kernel? I am guessing that it might be a CMAKE trick, but I cannot really found it. Would very much appreciated, if anyone could point me to the code/configure that do that.

Thank you.

** UPDATE ***

Seems to have something to do with

  • cmake/cl2cpp.cmake
  • cmake/OpenCVModule.cmake

Any idea to make use of it easily in your own application that will not be compiled with OpenCV?

edit retag flag offensive close merge delete

Comments

Maybe I'm wrong, but I think you don't have to generate cpp/hpp files from the cl code. You just create a ocl::Kernel using the ocl::ProgramSource (which is a string containing the OpenCL source code) and execute it on the device.

Maybe this answer will help: http://answers.opencv.org/question/26...

kbarni gravatar imagekbarni ( 2016-03-25 04:40:42 -0600 )edit

Thank you very much for your reply.

It seems that you are correct. I think this has something to do with OpenCL where you defined the kernel using text string. I am very new to these GPGPU. I guess this is quite common for people who using shading language.

milLII3yway gravatar imagemilLII3yway ( 2016-03-27 06:40:03 -0600 )edit