NVIDIA CUDA GPU computing on a (modern) laptop

***NOTE*** I added a small update at the end of the post for the CUDA 7 finial release which is out now.

Modern high-end laptops can be treated as desktop system replacements so it's expected that people will want to try to do some serious computing on them. Doing GPU accelerated computing on a laptop is possible and performance can be surprisingly good with a high-end NVIDIA GPU. [I'm looking at GTX 980m and 970m ]. However, first you have to get it to work! Optimus technology can present serious problems to someone who wants to run a Linux based CUDA laptop computing platform.

I just spent considerable time exploring options and failing many times trying to get a laptop setup for GPU computing with Linux (including Optimus GPU switching). I finally succeeded with a straight forward install without including Optimus support. Even though I did succeed a couple of times with full optimus GPU switching support it proved to be very unstable and would break at the slightest provocation. I have to concede defeat on Optimus under Linux, it was just too fragile. However, we really didn’t care about it anyway! Our intent was to have a nice NVIDIA GPU accelerated laptop for CUDA development and modest load job runs. For that, the setup I describe here should work great. It’s essentially what I would do on a desktop machine.

I have a couple of CUDA compute performance numbers for you using the GTX970m and GTX980m at the end of the post …

The setups with Optimus that I tried suffered badly from side effects. When I made a change and then reverted the change, I didn’t recover the previous system state. It was also the case that doing something like a system shutdown while the Intel graphics were running and then rebooting and changing to NVIDA and then shutting down could leave the system in a different state and possibly a black screen or lockup. I would have a system setup that seemed stable and working properly and then some sequence of events would break it. Reinstall repeating the same process would not guarantee a system in the same state that I had done a few days ago. I’m not going to try to list the number of things I tried to get a stable setup because there were just too many and it would likely be pointless for anyone to try to repeat them since they were all effectively non-repeatable after a few days with any OS update involving the kernel, drivers, or X.

My impression was that a lot of the trouble I had was related to the gnome desktop core since both Ubuntu Unity and Gnome3 desktops were very susceptible to black-screen states and/or corrupted workspaces. KDE didn’t seem to suffer from these problems.

I have confidence that the following procedure will give you a working, NVIDIA driven, CUDA development laptop. I believe this mainly because it’s simple!

Laptops

The two laptops I’ve been working with are;

[They are similar and based around Clevo P150SM-A and P170SM-A]

Installation and Setup

The Linux version for these build was Ubuntu 14.04.1 server with kubuntu-desktop.

I start with a simple Ubuntu 14.04 server install. I do this routinely for Ubuntu installs since it’s easier to automate than using a “Live-Image” install and the added packages will come from the update repos rather than the (stale) install media.

… basic server text based install …

Then

sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo shutdown -r now

That gives you a fresh install with the latest kernel updates.

Then add the desktop and other needed packages. These will pull down LOTS of dependencies!

sudo apt-get install kubuntu-desktop build-essential emacs synaptic dkms
sudo apt-get upgrade
sudo shutdown -r now

At this point you will have a Ubuntu with a KDE desktop login screen and the systems will be using the Intel video driver. [ Yes, this is essentially Kubuntu ] I personally prefer synaptic for a graphical package manager on Ubuntu and, of course, emacs is essential! 🙂 build-essential will install the needed compilers, build tools and kernel headers and dkms (Dynamic Kernel Module Support) is useful for automatically (hopefully) rebuilding kernel driver modules on boot whenever there is a kernel version change.

That is a working laptop! And if you didn’t have the nice NVIDIA graphics card in the system that you desperately want to use for computing you could go on your merry way and be happy with your new Linux laptop.

NVIDIA graphics driver and CUDA setup.

DO NOT install NVIDIA drivers from the Ubuntu repos or any of the independent ppa’s (repos)!

We will install the NVIDIA drivers as part of the CUDA setup. This is simple and gives a stable setup ready to go with CUDA.

I used the Ubuntu 14.04 CUDA repo version 7rc. That is the “release candidate” for version 7. I’ve been using it for all of my CUDA testing for several weeks now without problems and it may be at full release by the time you read this.

You will need to be a registered developer to get the rc version! If you do any CUDA work then you should go ahead and register. NVIDIA is very good about the email that they send out to registered developers. It’s infrequent and they are not “spamy” — I always find the information interesting.

The full file I downloaded was;

cuda-repo-ubuntu1404-7-rc_7.0-18_amd64.deb

Install that with,

sudo dpkg -i   cuda-repo-ubuntu1404-7-rc_7.0-18_amd64.deb

Then do

sudo apt-get update
sudo apt-get install cuda
sudo shutdown -r now

The cuda install pulls down a lot dependencies and runs some very good configure scripts to properly setup the NVIDIA graphics kernel modules and initializes the dkms settings for you. This is, in my opinion, the easiest way to install the NVIDIA graphics drivers on Linux.

After the reboot you will be running on your nifty NVIDIA graphics card and won't be pestered by that Intel video i.e. you wont have a simple way to switch over to it. You may consider that good or bad. I consider it good!

Run nvidia-settings and see that everything is as expected. You will not have the NVIDIA “optimus prime” panel to switch drivers. Count your blessings!

To finish up the CUDA setup I like to add a couple of system files;

You will need to be root to create the files so use your favorite sudo friendly editor (sudo -s to a root shell) and create;

/etc/profile.d/cuda.sh

containing the line

export PATH=$PATH:/usr/local/cuda/bin

This will execute when you login and put the cuda tools on your path.

You can also add the cuda libraries to the system by creating

/etc/ld.so.conf.d/cuda.conf

containing the line

/usr/local/cuda/lib64

 

Then run

 

sudo ldconfig 

Now on to some testing.

Copy the CUDA samples directory to your home directory or wherever you want to put it.

 

I do (be careful with rsync if you are not used to it — you could just use cp -a if you like)

 

rsync -av /usr/local/cuda/samples  . 

Then

cd samples/
make -j4

and watch as all of the sample codes compile.

My favorite simple test code is the “nbody” sample. It has a “benchmark" mode with switches to to make it useful.

cd bin/x86_64/linux/release/
./nbody -benchmark -numbodies=256000

and marvel at the incredible single precision floating point performance of the GPU. It’s pretty impressive!

Here’s what I got;

GTX 970m    1415    single-precision GFLOP/s
GTX 980m    1835    single-precision GFLOP/s

On the order of 1.5 Tera flops of compute performance from a laptop!!

for reference the desktop card gives

GTX 980    2496    single-precision GFLOP/s
2 x 980    4561    single-precision GFLOP/s

Here’s another testing result (as a teaser for a post I’ll do about running GROMACS with GPU acceleration) “lysozyme in water” molecular dynamics simulation with GROMACS on the GTX970m powered laptop gave

58 ns/day

That may not mean that much to you if you are not familiar with gromacs and that particular test job but I’ll assure you it’s impressive (about the same as a simple desktop machine with a Core i7 4770 4-core @ 3.4 GHz CPU with a Tesla K40 for acceleration! Note: that the GPU compute part of the calculation is single-precision so the GTX GeForce card is at it’s best for this.)

ADDENDUM FOR CUDA 7 FINIAL

A few days after I wrote this (while I was at GTC) NVIDIA finalized cuda 7. I did a fresh install and it worked fine. If you are going to follow what I’ve outlined above then just use the release version. I used the network install repo, https://developer.nvidia.com/cuda-downloads

If you have already done an install using the 7rc then you can update to the release version by grabbing either the network repo or the full repo (you may as well use the network version) then,



sudo dpkg -i  cuda-repo-ubuntu1404_7.0-28_amd64.deb
sudo apt-get update
sudo apt-get upgrade  (it will see the updated repo and offer to upgrade cuda)
sudo shutdown -r now

On reboot you should have the latest CUDA and NVIDIA graphics drivers. Easy!

Happy computing! –dbk

 

Tags: , , , ,