OpenCV Error: Gpu API call (-1001) in initializeOpenCLDevices

1k views Asked by At

a few weeks ago, I build up a computer vision program using C++ with Opencv 2.4.9 and OpenCL under Ubuntu 14.04 LTS. It works well, then last week I tried to update some functions using the newly released OpenCV 3.0 but failed since some APIs has changed, so I uninstalled Opencv 3.0 and reinstalled Opencv 2.4.9. Since that, whenever a function from Opencv's ocl module is called, an error that says "OpenCV Error: Gpu API call (-1001) in initializeOpenCLDevices" appears.

The whole error that shows is:

OpenCV Error: Gpu API call (-1001) in initializeOpenCLDevices, file /home/mmcom/opencv-2.4.9/modules/ocl/src/cl_context.cpp, line 455 OpenCV Error: Unknown error code -221 (OpenCL not available) in getContext, file /home/mmcom/opencv-2.4.9/modules/ocl/src/cl_context.cpp, line 677 terminate called after throwing an instance of 'cv::Exception' what(): /home/mmcom/opencv-2.4.9/modules/ocl/src/cl_context.cpp:677: error: (-221) OpenCL not available in function getContext

Then I reinstalled the whole Ubuntu 14.04 OS and drivers, same error occurs.

Below lists all things that I did after reinstall Ubuntu 14.04 OS:

  1. Install timeshift (first time backup)
  2. Install Synaptic (second time backup)
  3. Install OpenCV 2.4.9 following the guide from: http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/
  4. For OpenCL, since I am using nVidia GPU, I installed OpenCL using the command:
    sudo apt-get install nvidia-opencl-dev

The Computer that I am using is Dell Precision M6800 mobile workstation with Intel Core i7 vPro and nVIDIA Quadro K4100M GPU.

Some more information and concerns:

1.I think the core problem is that the OpenCV's ocl module can not recognize the nVIDIA GPU for some reason. But I am not sure it is the ocl module's issue or the nVIDIA GPU and its driver's issue. Is there a easy way to tell?

1.My project contains both functions using OpenCV's ocl acceleration module and my own OpenCL function. They have been proved to run successfully on the desktop with AMD GPU in the lab, as stated earlier, they also run successfully on the current mobile workstation last week.

2.Before I tried to optimize the code using newly released OpenCV 3, an error from Ubuntu software updater occurs, the error is about nvidia 331 update issue, which has been reported as a bug for many times. Since I ignored the error and install OpenCV 3 directly, I can not tell if the OpenCV error that is indicated before is caused by installing OpenCV 3 or nvidia 331 update issue. Is is caused by driver conflicts or something? I can not recall if the driver's version is 331 or 340 or something else before the project works well.

3.I use CmakeList to build the project, by typing cmake . command, it clearly says Found OpenCL: /usr/lib/x86_64-linux-gnu/libOpenCL.so Also there are nVIDIA icd in etc/OpenCL/vendors/nvidia.icd with libnvidia-opencl.so.1 in it.

4.All I did about the nVIDIA GPU is to use the command above to install OpenCL for it, I think that command also includes installing other packages related to nVIDIA GPU. From synaptic, it shows that following packages are installed:

nvidia-331-uvm NVIDIA Unified Memory kernel module

nvidia-settings Tool for configuring the NVIDIA graphics driver

nvidia-opencl-icd-331 NVIDIA OpenCL ICD

libcuda1-331 NVIDIA CUDA runtime library

nvidia-opencl-dev NVIDIA OpenCL development files

nvidia-libopencl1-331 NVIDIA OpenCL Driver and ICD Loader library

nvidia-331 NVIDIA binary driver - version 331.113

Does it mean that all related packages including GPU driver, CUDA and OpenCL are installed? Should I install other module or tools from nVIDIA?

In conclusion, I am so confused that the Opencv's ocl module works well before I update Opencv 3, and now even though I tried to reinstall everything and try to bring back the old environment, it does not work.

Any suggestions?

Thank you all.

EDIT: some suggest I should uninstall the openCL lib by nVIDIA, I did so and the error becomes: OpenCV Error: Unknown error code -6 (OpenCL function is not available: [clGetPlatformIDs]) in opencl_check_fn, file /home/mmcom/opencv-2.4.9/modules/ocl/src/cl_runtime/cl_runtime.cpp, line 83 OpenCV Error: Unknown error code -221 (OpenCL not available) in getContext, file /home/mmcom/opencv-2.4.9/modules/ocl/src/cl_context.cpp, line 677 terminate called after throwing an instance of 'cv::Exception' what(): /home/mmcom/opencv-2.4.9/modules/ocl/src/cl_context.cpp:677: error: (-221) OpenCL not available in function getContext

1

There are 1 answers

0
Frik On

I ran into the exact same issue today after a format. Any OpenCV-OpenCL code I tried to run failed with the error you gave in the question. What fixed it for me - believe it or not - was simply running such an executable once-off as root. Thereafter OpenCL functionality in all other projects resumed to normal.

I got the idea from the last sentence of this answer. Not sure how related the problems are though.