ERROR: clGetPlatformIDs -1001 when running OpenCL code (Linux)

百般思念 提交于 2019-11-29 02:28:26
Michael Aquilina

(Mods: I am not sure if this post should be moved to AskUbuntu seeing as it was an issue related to Linux bumblebee rather than OpenCL itself?)

Ok so I managed to solve the issue after loads of effort.

There are two things that I needed to do:

Getting ICD to work

create a symbolic link from /usr/share/nvidia-331/nvidia.icd to /etc/OpenCL/vendors

sudo ln -s /usr/share/nvidia-331/nvidia.icd /etc/OpenCL/vendors

NOTE: In most cases you would need to replace nvidia-331 with whatever driver you are using - most commonly nvidia-current

I am really curious as to why this isn't done automatically when installing the cuda toolkit - but I have noticed that OpenCL programs will not work without this step!

Nvidia Optimus with Bumblebee

The reason why this was so complicated to get working was that I have an nvidia optimus laptop with poor driver support on linux. To fix this I have bumblebee installed to allow switching between my nvidia card and intel card.

However, because I am using bumblebee - the nvidia graphics card (and nvidia driver) will be unloaded unless explicitly told so. In order to use OpenCL, we need to turn on the nvidia graphics card.

To do this we need to explicitly tell bumblebee to turn the nvidia card on by using the commands optirun or primusrun:

optirun myopenclprogram

Note however, because all that matters is that the nvidia card is turned on and the drivers are loaded, you do not need to keep using optirun myprogram to get this to work (as this always involves the initial delay of waiting for the graphics card to be initialised).

You can run optirun kate for example and this would turn on the nvidia graphics card. You can then, in a separate terminal just run you opencl program without optirun and it will work just fine since the graphics card has already been turned on (and will remain on as long as you leave e.g. kate running).

You will notice that there is no delay in starting your program this time! This saves you alot of waiting - especially if you are developing the opencl program in question.

Once again, as long as you keep the nvidia graphics card turned on, your opencl program will work.

I will probably contact the bumblebee devs to see if there is an easier way to get this to work and report what they say here. Hopefully there is some way to turn the nvidia card on and off without requiring to keep a program (like kate in my example) running.

I hope this helps anyone trying to use OpenCL on linux laptops with bumblebee in the future (I could not find any clear cut solutions myself)

EDIT2: Turning you graphics card on and off can be done as follows for bumlebee users:

Turn graphics card on and load nvidia module

sudo tee /proc/acpi/bbswitch <<< ON
sudo modprobe nvidia

Turn graphics card off (nvidia module is automatically unloaded)

sudo tee /proc/acpi/bbswitch <<< OFF

To share some add info. I have installed intel opencl version on Ubuntu 13.10 saucy. Problem has been the same: -1001 error. I solved it by link analogicly to previous post:

sudo ln -sf /opt/intel/opencl-1.2-3.2.1.16712/etc/intel64.icd /etc/OpenCL/vendors/nvidia.icd
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!