nVidia CUDA, nVidia Optimus, Linux & their complex relationship

After months of brainstorming on whether to get a Macbook or a Win7 laptop, how and where to buy it, what configuration to choose etc, I finally got my new Alienware M14x (Win 7) last week. Unfortunately I got my hands on it last Monday, which in my opinion left me no choice but to reduce my sleeping hours to 3-4hrs a day. With all those extra ‘sleepless’ hours I managed to find, I could accomplish quite a lot of things I had in my rather long TODO list by the end of the week, or so I thought. But I still haven’t completely set up my system, the way I wanted – lots of games, a Linux development environment etc.

The culprit is none other than the most important component in the laptop (for me) - the GPU. Since gaming, photo editing and GPU programming (nVidia CUDA) are the three things I am looking forward to focus on for most of my time, I wanted to make sure I made the right choice in selecting the GPU. The M14x comes with an nVidia GeForce GT 555M and it boasts the nVidia Optimus technology which uses switchable graphics (with Sandy Bridge integrated GPU) for power saving. All the reviews explained a lot about how this laptop takes full advantage of Optimus. But what none of the posts (I read) mentioned was, just like any other new technology, there is no support for Optimus in Linux till date, not by nVidia, not by Linux or not even by the manufacturer (in my case, Dell/Alienware).

What this means is, even though I will be able to use the nVidia GPU in Linux for CUDA programming, I won’t be able to use the nVidia GPU for any graphics applications in Linux. For example, I will be able to do computations on the GPU as a coprocessor, but it cannot be used for display in Linux environment. It doesn’t affect me a lot as I am not looking forward for any graphics programming in Linux in the short term, I already have my hands full with the TODO list I mentioned earlier. But it sure is a bummer considering I wanted to try out some graphics/game programming in the long term in the Linux environment. Hopefully there will be support for the Optimus technology in Linux soon.

I learned this fact the hard way, after spending long hours trying to setup my system to use the nVidia GPU. This post may/may not offer any solutions to any particular problem, but just a few observations and links to some of the sites/forums that helped me in the process.

To begin with, my requirement was to be able to do CUDA programming on a Linux environment in my M14x (GT 555M). On a side note, I have done CUDA setup & programming in the past and was familiar with it. My first step was to choose one of the Linux distributions supported by CUDA. I chose Ubuntu 10.10 and installed it. During my first boot, it asked me to upgrade to 11.04, which I did not accept because I knew that gcc 4.5 or above is not supported by CUDA at the moment. Ubuntu also asked me to activate the nVidia driver which I did it. Then I downloaded the CUDA dev driver, toolkit 4.0 and the code samples. I rebooted the machine and the Xserver failed to start. So, from the command prompt, I removed the ubuntu supplied driver.

sudo apt-get --purge remove nvidia*

Then I installed the dev driver downloaded from nVidia site.
Chmod +x "filename"

I also installed the toolkit (also set the path), samples and the required libraries for building them as specified in the CUDA Getting Started Guide (Linux). I rebooted the machine and again the Xserver failed to start. I poured through support forums & blog entries, tried the black listing method, reinstalled various drivers etc. None of them worked. Ubuntu was unable to load Xserver. So I decided to reinstall Ubuntu and start from step 1.

This time I was more cautious, I did one step at a time. But the moment I installed the dev driver and reboot, Xserver stopped working. What perplexed me more was, I was still able to run the CUDA binaries, which means the driver is installed properly. For a moment, I considered giving Fedora 13 a try.

That’s when I realized that I am using Optimus technology and the thought crossed my mind that what if Linux is trying to use the integrated GPU and nvidia driver is conflicting. My heart sank when I found out that there is no support for Optimus in Linux. There is third party software called bumblebee, which didn’t work for me. Some of the posts talks about a BIOS setting which can force either of the GPUs rather than switching them dynamically. But M14x BIOS doesn’t have that option, yet. So, I was out of options and that when this post helped me. It helped me deactivate the nVidia driver and use the integrated GPU for Xserver. Also the GPU is detected as a coprocessor so that I can do my CUDA programming as long as I am not playing with graphics. Remember to update the Intel graphics driver.
sudo apt-get install xserver-xorg-video-intel

In a nutshell, if your laptop is equipped with Optimus, better use the integrated graphics as of now for Linux. It’s a shame that so much GPU power is simply wasted.