Ask Your Question
0

Strange error when trying to use OCL library

asked 2013-01-18 01:22:01 -0600

joelb92 gravatar image

updated 2013-01-18 09:55:23 -0600

I recently compiled the latest version of OpenCV 2.4.3 using cmake to build on macOSX with this line of code:

cmake -G "Unix Makefiles" -D WITH_OPENCL=ON ..

All libraries work just fine in xcode, but when I try and call any function other than oclMat.upload(Mat) or getDevices(vector<info>), I get the following error message:

            BUILD LOG
Error getting function data from server
OpenCV Error: Gpu API call (CL_BUILD_PROGRAM_FAILURE) in openCLGetKernelFromSource,
file /OpenCV-2.4.3/modules/ocl/src/initialization.cpp, line 630
libc++abi.dylib: terminate called throwing an exception

Does anyone know what could be going on here? I'm running Mac OSX mountain lion with an AMD Radeon HD 6750M with 1024mb of memory, and I have OpenCL installed (comes integrated with OSX natively). Does anyone have any idea what this error means?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-05-15 04:01:36 -0600

yid gravatar image

updated 2013-05-15 23:37:16 -0600

Hi,

The error means that your opencl compiler could not compile some code and quit compiling.

I also had a problem trying to get run the face detection on Mac OS X. But I solved it! Here's how:

  1. finding out the erroneous opencl kernel file:

modules/ocl/src/initialization.cpp tries to compile opencl kernels. unfortunately the ATI/AMD compiler on the mac does not compile opencl kernel. This is what causes the error. To find out which kernel it it I inserted at the beginning of the method

      cl_kernel openCLGetKernelFromSource(const Context *clCxt, const char **source, string kernelName,
                                        const char *build_options)

the following line:

      fprintf(stderr, "Loading %s %s\n", clCxt->impl->binpath.c_str(), kernelName.c_str());

now I can see all kernels that are compiled. The last one before the error causes the crash. I my case it was "integral_cols". A short "grep" command later I knew it was in "modules/ocl/src/opencl/imgproc_integral.cl"

  1. finding and fixing the erroneous line:

This was a bit of trial and error. I took a program which only compiles opencl kernels. (In my case it was my Qt based test program for openCL), but you may use opencv itself. In that case you always have to patch - make opencl - make install for each iteration which is not nice after all...

By commenting out all code with "#if 0" ... "#endif" blocks and slowly de-commenting I deduced which lines did not work. In my case it was some combination of the conditional-operator ("?: operator") and double braces "[][]" in one statement which could not be compiled. I refactored this code. You can see the result here: (the #if 0 block is what not compiled, and the #else branch is my version)

#if 0
        sum_t[0] = (i == 0 ? 0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]);
        sqsum_t[0] = (i == 0 ? 0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]);
        sum_t[1] =  (i == 0 ? 0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]);
    sqsum_t[1] =  (i == 0 ? 0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]);
 #else
        if (i==0) {
            sum_t[0] = 0;
            sqsum_t[0] = 0;
            sum_t[1] =  0;
            sqsum_t[1] =  0;
        } else {
            sum_t[0] = lm_sum[0][LSIZE_2 + LOG_LSIZE];
            sqsum_t[0] = lm_sqsum[0][LSIZE_2 + LOG_LSIZE];
            sum_t[1] =  lm_sum[1][LSIZE_2 + LOG_LSIZE];
            sqsum_t[1] =  lm_sqsum[1][LSIZE_2 + LOG_LSIZE];
        }
 #endif

the integral_rows kernel had a similar problem and was to be fixed also:

#if 0
        src_t[0] = i + lid < rows ? srcsum[(lid+i) * src_step + gid * 2] : 0;
        sqsrc_t[0] = i + lid < rows ? srcsqsum[(lid+i) * src_step + gid * 2] : 0;
        src_t[1] = i + lid < rows ? srcsum[(lid+i) * src_step + gid * 2 + 1] : 0;
        sqsrc_t[1] = i + lid < rows ? srcsqsum[(lid+i) * src_step + gid * 2 + 1] : 0;

        sum_t[0] =  (i == 0 ? 0 : lm_sum[0][LSIZE_2 + LOG_LSIZE]);
        sqsum_t[0] =  (i == 0 ? 0 : lm_sqsum[0][LSIZE_2 + LOG_LSIZE]);
        sum_t[1] =  (i == 0 ? 0 : lm_sum[1][LSIZE_2 + LOG_LSIZE]);
        sqsum_t[1] =  (i == 0 ? 0 : lm_sqsum[1][LSIZE_2 + LOG_LSIZE]);
#else
        if (i + lid < rows) {
            src_t[0] =  srcsum[(lid+i) * src_step + gid * 2];
            sqsrc_t[0] = srcsqsum[(lid+i) * src_step + gid * 2];
            src_t[1] = srcsum[(lid+i) * src_step + gid * 2 + 1] ;
            sqsrc_t[1 ...
(more)
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-01-18 01:22:01 -0600

Seen: 1,657 times

Last updated: May 15 '13