Ask Your Question
6

Opencl support (bm,sgbm etc)

asked 2012-08-07 09:10:03 -0500

AgentCain gravatar image

I recently found out that opencv can support opencl function for parallel GPU computing. Thats a huge PLUS for me, as Im using stereo vision algorithms for my project and I dont own a CUDA enabled GPU. I tried to build opencv with opencl support using the latest version from the repository, with little success. The built is completed successfully, libraries, include files, everything's there. But it doesnt work. Tried in both mingw and vs2010.

When will opencv will be available with opencl support as a prebuilt package for windows? Is there a guide available?

edit retag flag offensive close merge delete

Comments

@fliker09 The Answer form is for answers - no forum-like discussion, please.

sammy gravatar imagesammy ( 2013-03-24 12:42:13 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
7

answered 2012-08-18 00:48:50 -0500

pengx gravatar image

Using ocl module is pretty much alike using gpu module. To use OCL module, you must call getDevice() once before call any of the ocl module functions. It is like this:

vector<ocl::Info> info;
ocl::getDevice(info);

This function will detect if there is any valid GPU devices in all OpenCL enabled platforms on your machine; particularly, the ocl module should have best compatibility with an AMD graphic card.


Most ocl module functions require input matrices of type oclMat. oclMat is similar with Mat, but it encapsulates some OpenCL device's buffer object (cl_mem) and controls buffer release, transferring, etc. To convert a Mat to an oclMat object, simply call

oclMat myOclMat(mat); // mat is a Mat object

Alternatively, you could explicitly call

oclMat myOclMat;
myOclMat.upload(mat);

oclMat then can be fed into ocl module functions once the memory data is uploaded to opencl device's memory. To access the oclMat's data, you need to download the gpu buffer data into host memory. Similar with upload operations, you could either call

mat = Mat(myOclMat);

or

myOclMat.download(mat);

Normally you do not need to worry about memory releasing. oclMat will deconstruct its encapsulated cl_mem buffer once they are not referenced any more.


To sum up,

, the usage of the OCL module is simply:

  1. globally register an OpenCL device // call ocl::getDevice()

  2. transfer from host memory to gpu memory // convert Mat to oclMat

  3. Do the calculations on OpenCL device // call ocl module functions,

  4. transfer back from gpu memory to host memory // convert oclMat to Mat

  5. Do rest calculations with Mat

There is some sample ocl module programs provided in the trunk repository. You could refer to them as a start.

BTW, if you are not familiar with OpenCL, I recommend you to read some basics about OpenCL's basics before include OpenCL into your project.

edit flag offensive delete link more

Comments

Im familiar with cuda coding and I guess that the basics are the same (create a device, transfer data back and forth etc). I managed to build a version with openCL using a repository version. But the execution of my program ends with a crash from amdocl.dll. Does this mean that the build is not done properly or it has something to do with my openCL support?

I can reach as far as step 1, calling getDevice() I guess it initializes properly as the function returns 1

Before that i use .create(height,width,CV_8UC1) to allocate momory for some oclMat, just as I would do for a regular opencv Mat

It always crashes when trying to upload a Mat to an oclMat. Initialization and allocation is complete, then it crashes, reporting a fault in module amdocl.dll

AgentCain gravatar imageAgentCain ( 2012-08-18 03:37:34 -0500 )edit

What's your AMD APP SDK version ? And make sure link correct OpenCL.lib file.

pengx gravatar imagepengx ( 2012-08-18 04:23:47 -0500 )edit

Its version 2.7 As Im using CMake in win7 to get the makefiles, CMake reports linking with C:/Program Files (x86)/AMD APP/lib/x86/libOpenCL.a as default.

AgentCain gravatar imageAgentCain ( 2012-08-18 04:36:29 -0500 )edit

Oh I never tried to use MinGW compiler on Windows. I did not know if there are OpenCV OCL module developers tried to compile it with MinGW, but I found a thread regarding a similar crashing problem with you on AMD support forum. http://devgurus.amd.com/message/1164914#1164914 I will ask the QA team to compile OCL module with MinGW on Windows later. Hopefully I will get the feedback sometime next week.

pengx gravatar imagepengx ( 2012-08-18 11:05:25 -0500 )edit

Interesting Thanks mate! And yes, Im using 64bit OS too :(

AgentCain gravatar imageAgentCain ( 2012-08-18 14:29:41 -0500 )edit

I am using 64 bit Win 7 as well but developing with Visual Studio 2010 at 32 bit. Can you try visual studio compiler instead of MinGW to see if it works?

pengx gravatar imagepengx ( 2012-08-19 03:05:30 -0500 )edit

I just pulled the latest trunk repository and built with mingw-32. I tried to run the ocl test cases, but there were no problem at all.

pengx gravatar imagepengx ( 2012-08-20 00:28:49 -0500 )edit

I run them myself, no problem there. Many of them passed, some of them failed (I dont know why but anyway) but it run. Im able to compile opencv using VS10 but since it produces .lib files, the build is only compatible with VS10. And my code refuses to compile using VS10 (its like, only the basics, 1+1=2, run on VS10). Plus I HATE VS10. And the only reason that Im compiling in windows is the camera im using (it has a better API in windows than in linux, go figure). I prefer eclipse IDE and mingw

And the only reason Id like to use OpenCL is the blockmatching stereo algorithm and a few image filters in a near realtime manner.

AgentCain gravatar imageAgentCain ( 2012-08-20 13:58:24 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2012-08-07 09:10:03 -0500

Seen: 2,668 times

Last updated: Mar 24 '13