CUDA + Nvidia Optimus in Ubuntu 11.04
Some days ago I bought a new laptop, a Samsung Q330 with an NVIDIA Optimus Card. After installing Ubuntu 11.04, I realized that 3D acceleration and CUDA was not available despite of installing the closed-source NVIDIA kernel driver. Then I realized that NVIDIA Optimus is not fully supported in Linux (my fault for not checking it first!), so I started googling to see if there was some info available. It turns out that an open source project called bumblebee enables the usage of both NVIDIA and Intel IGP card with the proprietary drivers.
Installing bumblebee in Ubuntu 11.04 is easy: just add the ppa
sudo add-apt-repository ppa:bumblebee/stable
and then install the bumblebee package
sudo apt-get update sudo apt-get install bumblebee
How it works
In addition to the main X screen associated to the first available PTY of your system, bumblebee will create a secondary one, this one with the nvidia driver. Whenever system requires to use this device, the program will be run on the secondary X and the output will be transferred to the main X screen. Bumblebee allows to configure different X transfer methods, being Xv the default (and the one I am using).
Using CUDA
As usual, to be able to use CUDA in your system, you need to install the correspondent NVIDIA CUDA driver. Traditionally, I used to install it by hand. However, manual install does not seems to work well with bumblebee. There is a PPA for CUDA available for Ubuntu that worked well for me. Installation instructions are available in this other blog, although I will put an abstract here for reference pourposes:
sudo add-apt-repository ppa:aaron-haviland/cuda-4.0sudo apt-get update sudo apt-get upgradesudo apt-get install nvidia-cuda-gdb nvidia-cuda-toolkit nvidia-compute-profiler libnpp4 nvidia-cuda-doc libcudart4 libcublas4 libcufft4 libcusparse4 libcurand4 nvidia-current nvidia-opencl-dev nvidia-current-dev nvidia-cuda-dev opencl-headers
Notice how OpenCL packages are also installed. As stated in the original post blog, additional packages might be required to compile the NVIDIA GPU Computing SDK.
After restarting your gdm, if everything was OK, you will be able to run your CUDA programs. If at first didn’t work, try using optirun:
optirun ./cudaProgram
This will tell bumblebee to force execution of the program in the GPU Device (by using the secondary X server).
I have not tested the OpenGl / CUDA interoperability with this system, although it should work properly. Performance however might be degraded due to the framebuffer transfer.

