I have been playing around with OpenCL recently on my Ubuntu 12.04 machine. When I call cl::Platform::get, I get an error code of -1001. After some research, I have found that this happens when the c call getPlatformIDs fails to find a valid platform, and that this can happen when there are no .icd files in your /etc/OpenCL/vendors/ directory, or when the implementation(s) referenced by the file(s) cannot be opened with a call to dlopen.
I, however have tested all of these possibilities. In /etc/OpenCL/vendors/, I found nvidia.icd, which contains the line ‘libcuda.so’. I then tried to call dlopen on this filename, and succeeded. Yet, my program still returns an error code of -1001! My nvidia drivers work well in all other respects, and I am able to compile the program. What could possibly be wrong?
Zistack
EDIT: Extra info: I am using the nvidia-current-dev drivers. I am running an nvidia GeForce GT 540M.
EDIT: I found something interesting just recently: Here is the spec from Khronos on the icd loader. It says:
Upon successfully loading a Vendor ICD’s library, the
ICD Loader queries the following functions from the library:
clIcdGetPlatformIDsKHR, clGetPlatformInfo, and
clGetExtensionFunctionAddress. If any of these functions
are not present then the ICD Loader will close and ignore
the library.
And here is a post from someone implementing an icd loader trying to load the nvidia platform. It says:
I can get clGetExtensionFunctionAddress and clGetPlatformInfo
from libcuda.so using dlsym(), and I can then use
clGetExtensionFunctionAddress to retrieve clIcdGetPlatformIDsKHR.
In my experementation, I was able to query only 2 out of 3 functions successfully – clGetPlatformInfo, and clGetExtensionFunctionAddress. The other one failed, as the forum post suggests it should: the author goes on to say that they use clGetExtensionFunctionAddress to retrieve clIcdGetPlatformIDsKHR. If the ICD loader implemented by Khronos follows the spec word for word, then it would make sense that it would fail, as the query for clIcdGetPlatformIDsKHR would fail, and the library would be ignored. Given that, it seems that the nvidia implementation does not seem to fully implement the spec, unless there is another, newer version that I am unaware of. Yet other people manage to get OpenCL working just fine on their nvidia platforms. Am I missing something?
I figured it out, the output of this command says it all:
I have optimus technology, and therefore my system uses the Intel VGA controller by default. As such, the nvidia platform is invalid because there is no hardware attached to the software from my program’s point of view. Unfortunately there is no easy way to just tell the operating system to ignore the Intel chip and just use the nvidia one, and nvidia doesn’t feel like supporting optimus under linux, so there are no drivers for this setup. However, installing bumblebee and running my program with
optirunworks like a charm.