Home > pyopencl, python, ubuntu > Install Pyopencl and CUDA 5.0 on Ubuntu 13.04 64 bits using nvidia optimus with Bumblebee and Primus

Install Pyopencl and CUDA 5.0 on Ubuntu 13.04 64 bits using nvidia optimus with Bumblebee and Primus

The main motivation for this post is how difficult was for me run pyopencl on my fresh ubuntu 13.04 installation. First of all nvidia drivers don’t work well on ubuntu; I am still unable to run nvidia-settings in order to change xorg.conf to run ubuntu-desktop with nvidia card.

Let’s start sharing what I did to achieve running pyopencl programs on ubuntu.

Since my graphics card is an optimus enabled, I followed this wonderful post in which this guy explains how to use your discrete nvidia card to run steam for linux. He states that you should NOT install nvidia-drivers directly so you should have a clean installation.

Basicly to make optimus work Bumblebee should be installed in our system. These are the summarized steps from cjenkins blog:

Bumblebee and Primus installation with nVidia propietary driver

sudo add-apt-repository ppa:bumblebee/stable
sudo add-apt-repository ppa:ubuntu-x-swat/x-updates
sudo apt-get update
sudo apt-get install bumblebee bumblebee-nvidia
sudo shutdown -r now

To run programs with the nvidia card you require to type in a terminal optirun followed by the name of the program you would like to run, such as:

optirun glxspheres
optirun glxgears

You can check how increase the performance by just running them without optirun with your low power graphic card.

If you want to get even better performance install Primus:

sudo add-apt-repository ppa:zhurikhin/primus
sudo apt-get update
sudo apt-get install primus

Test Primus

vblank_mode=0 optirun -b primus glxspheres

(Optional and recommended: use latest nvidia-drivers)

Just in case this does not work for you or you want to run bumblebee with the latest nvidia drivers, you can try this post. Summarizing they installed the latest nvidia-drivers in that time (nvidia-experimental-310) and then he changed configuration files for bumblebee and for primus as well:

I have to say that I followed the steps in the same way but I hope someone else tries with the latest nvidia-drivers.

sudo apt-get install nvidia-310-updates nvidia-experimental-310 nvidia-settings-310-updates

Modify bumblebee configuration file:

sudo vim /etc/bumblebee/bumblebee.conf

– on line 22, make sure “Driver=” is set to “nvidia”, like this:
Driver=nvidia

– change the “KernelDriver=” (on line 55) to “nvidia-experimental-310”, like this:
KernelDriver=nvidia-experimental-310

– change “LibraryPath=” (on line 58) to “/usr/lib/nvidia-experimental-310:/usr/lib32/nvidia-experimental-310”, so it looks like this:
LibraryPath=/usr/lib/nvidia-experimental-310:/usr/lib32/nvidia-experimental-310

– change the “XorgModulePath=” (line 61) to “XorgModulePath=/usr/lib/nvidia-experimental-310/xorg,/usr/lib/xorg/modules” so it looks like this:
XorgModulePath=/usr/lib/nvidia-experimental-310/xorg,/usr/lib/xorg/modules

Restart Bumblebee

sudo service bumblebeed restart

Logout and Login and try

optirun glxspheres

If you are using primus modify script /usr/bin/primusrun in line 16 changing nvidia-current with the nvidia-driver you installed. Same in line 27.

After this you should be able to run bumblebee and primus together and get the best from your graphic card.

Installing CUDA toolkit

Now that our nvidia drivers are working next step will be install CUDA toolkit to work with it. I will summarize this excellent post in the following steps:

Downloads =>
=> CUDA pack from developer.nvidia.com
=> pyopencl from https://pypi.python.org/pypi/pyopencl

I was just interested in pyopencl so I will focus in that part. Then in a terminal:

sudo vim /etc/environment

==> and add to PATH line the following ‘:/usr/local/cuda-5.0/bin’

sudo vim /etc/ld.so.conf 

==> and add lines: /usr/local/cuda-5.0/lib and /lib

sudo vim /etc/bash.bashrc 

==> add lines to the end

export PATH=/usr/local/cuda-5.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/lib/:$LD_LIBRARY_PATH

Then run the following commands:

sudo ldconfig
sudo apt-get install freeglut3-dev python-opengl python-pytools python-setuptools python-numpy libboost1.48-all-dev
sudo apt-get install build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libglut.so /usr/lib/libglut.so
sudo sh cuda_5.0.35_linux_64_ubuntu11.10-1.run

Once the installer is running there are some issues I had the first one don’t install the nvidia-drivers from the pack just type no at the moment of installation.
Type y for CUDA toolkit and SAMPLES (optional).

The reason why you should not install the nvidia-drivers from the pack, you will probably get this error:

ERROR: The kernel header file
       ‘/lib/modules/3.8.0-22-generic/build/include/linux/version.h’ does
       not exist.  The most likely reason for this is that the kernel
       source files in ‘/lib/modules/3.8.0-22-generic/build’ have not been
       configured.

Next Possible error with the toolkit is the following one:

Unsupported compiler: 4.7.3

SOLUTION:

sudo apt-get install gcc gcc-4.4
sudo update-alternatives --remove-all gcc
sudo update-alternatives --config gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20
gcc --version

Error:
Missing required library libglut.so

SOLUTION:

sudo ln -s /usr/lib/x86_64-linux-gnu/libglut.so.3 /usr/lib/libglut.so

Installing PyOpenCL

Once you have CUDA installed you should proceed to install pyopencl:

python configure.py   --boost-inc-dir=/usr/include/boost   --boost-lib-dir=/usr/lib   --no-use-shipped-boost   --cl-inc-dir=/usr/local/cuda-5.0/include/   --cl-lib-dir=/usr/lib/nvidia-310-updates/  --cl-libname=OpenCL
make
sudo make install

After I got to install pyopencl successfully a last error showed up:

clGetPlatformIDs failed: platform not found khr

SOLUTION:

If you just have this one

/usr/lib/nvidia-310-updates/libnvidia-opencl.so.310.44

Create a link and write in nvidia.icd the link

ln -s libnvidia-opencl.so.310.44 libnvidia-opencl.so.1
echo libnvidia-opencl.so.1 | sudo tee /etc/OpenCL/vendors/nvidia.icd
cd examples
optirun python benchmark.py

After this you should be able to run pyopencl scripts with optirun

Advertisements
  1. June 1, 2013 at 6:09 am
  2. December 30, 2013 at 7:52 pm

    OMG !
    I love you !

    Thanks so much for this it works !
    on Linux Mint 15, with Nividia-331, Primus and Optirun, Nvidia Geforce 540M

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: