Ask Your Question
0

How to run OpenCL file (example fast.cl) in OpenCV library?

asked 2017-03-19 22:20:02 -0500

minhntu gravatar image

Hi guys, Anyone knows how to run OpenCL source code in OpenCV library? I see that there are many kernels in a file. I am confused how to set up arguments to run it. Thank you very much for your help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-19 22:48:54 -0500

Tetragramm gravatar image

Take a look HERE for an explanation of the Transparent API.

edit flag offensive delete link more

Comments

I want to run OpenCL file (example fast.cl at opencv310\sources\modules\features2d\src\opencl\fast.cl) in OpenCV library. But I see in this file have many kernels. And each kernel has a different number of arguments. How can I set up arguments to run this file?

minhntu gravatar imageminhntu ( 2017-03-20 05:06:10 -0500 )edit

You don't need to. You just run normal fast with UMat as the arguments.

Tetragramm gravatar imageTetragramm ( 2017-03-20 17:52:11 -0500 )edit

it's mean when I change Mat by UMat. FAST function will be run on GPU. Do you know what fast.cl in OpenCV library use for?

minhntu gravatar imageminhntu ( 2017-03-21 01:31:35 -0500 )edit

I'm not entirely sure what you're asking. Here is where the fast.cl kernels are called from.

Again, you don't need to do anything but use UMat matrices and have compiled OpenCV with OpenCL support.

Tetragramm gravatar imageTetragramm ( 2017-03-21 17:40:50 -0500 )edit

It means I only need to change from

Mat img = imread("chessboard.jpg", IMREAD_UNCHANGED);
FAST(gray, keypointsCorners, thresholdCorner, true);

to

cv::ocl::Device(context.device(0)); 
UMat img, gray; 
imread("chessboard.jpg", 1).copyTo(img); 
FAST(gray, keypointsCorners, thresholdCorner, true);

to have OpenCL code and this code will run on GPU? And while FAST () function is implementing it will call fast.cl file inside?

minhntu gravatar imageminhntu ( 2017-03-21 20:50:56 -0500 )edit

Try to use the code tag in the editor to make it readable.

Yes, so long as your OpenCV was compiled with OpenCL support, then it will run on the gpu. Though do note that in the snippet here, you don't actually fill gray. I assume you just left that out for brevity.

Tetragramm gravatar imageTetragramm ( 2017-03-21 20:57:07 -0500 )edit

When I change Mat by UMat. My result is code ran on GPU. But it is slower than CPU. And when I change a name of "fast.cl" file in path: opencv310\sources\modules\features2d\src\opencl\fast.cl), Code still run normally. Whether fast.cl file was not called while the code is implementing. How do we know that when changing Mat by UMat, Code will run parallel on GPU?

minhntu gravatar imageminhntu ( 2017-03-22 04:39:54 -0500 )edit

Just to make sure, you are compiling the code? Not using the installer? The installer is not (I think) compiled with OpenCL, so you will see no benefit.

Tetragramm gravatar imageTetragramm ( 2017-03-22 21:10:34 -0500 )edit

When I run code below

        cout << context.ndevices() << " GPU devices are detected." << endl;
    for (int i = 0; i < context.ndevices(); i++)
    {
        cv::ocl::Device device = context.device(i);
        cout << "name                 : " << device.name() << endl;
        cout << "available            : " << device.available() << endl;
        cout << "imageSupport         : " << device.imageSupport() << endl;
        cout << "OpenCL_C_Version     : " << device.OpenCL_C_Version() << endl;
        cout << endl;
    }

It showed results: 1 GPU devices are detected name: Quadro K2000 available: 1 image surport: 1

OpenCL version: OpenCL C 1.2

And while Code is implementing. It took 11026 ms for MAT and 29340ms for UMAT in the same time. Do you know why it is?

minhntu gravatar imageminhntu ( 2017-03-23 01:56:34 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-03-19 22:20:02 -0500

Seen: 82 times

Last updated: Mar 19