Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Background: I'm a 3D artist (as a hobby) and have recently started using Ubuntu 12.04 LTS as a dual-boot with Windows 7. It's running on my a fairly new 64-bit Toshiba laptop with an nVidia GeForce GT 540M GPU (graphics card). It also, however has Intel Integrated Graphics (which I suspect Ubuntu's been using).

So, when I render my 3D scenes to images on Windows, I am able to choose between using my CPU or my nVidia GPU (faster). From the 3D application, I can set the GPU to use either CUDA or OpenCL. In Ubuntu, there's no GPU option.

After doing (too much?) research on the issues with Linux and the nVidia Optimus technology, I am slightly more enlightened, but a lot more confused.

I don't care one bit about the Optimus technology, as battery life is not by any means an issue for me.

Here's my question: What can I do to be able to use CUDA-utilizing programs (such as Blender) on my nVidia GPU in Ubuntu? Will I need nVidia drivers? (I have heard they don't play nicely with Optimus setups on Linux.) Is there at least a way to use OpenCL on my GPU in Ubuntu?

share|improve this question
add comment

4 Answers 4

Hybrid graphics (usually Intel integrated graphics and Nvidia discrete graphics) support under Linux is currently a bit troublesome. Something is slowly moving in the X server field but don't hold your breath.

As you have guessed Bumblebee is currently a good way to go.

I recently bought an Asus N55 laptop with Intel/Nvidia graphics I was able to get the Blender Cycles renderer to use CUDA.

When I installed Ubuntu 12.04 it used the integrated graphics by default trough the intel graphics driver. The noveau graphics driver should not get installed.

Then I opened a terminal and did:

sudo add-apt-repository ppa:bumblebee/stable
sudo apt-get update
sudo apt-get install bumblebee bumblebee-nvidia

After that I did (as recommended by the installation instructions):

sudo usermod -a -G bumblebee $USER

Then I rebooted.

To choose the driver to use when launching programs use the optirun program, for example:

optirun blender

To test if all works correctly use:

optirun glxspheres

And verify the GL vendor string contains the word Nvidia. If you run instead:

glxspheres

The vendor string should contain the Intel word

share|improve this answer
    
Will I need to install nVidia drivers before installing Bumblebee? I'm guessing not, based on how you worded your answer. Also, it's good to see someone's been able to use CUDA on Ubuntu with an Optimus card! I'll vote this up just as soon as I get 15 rep. :) –  Peter Cassetta May 8 '12 at 11:49
    
Okay, I installed Bumblebee. I used optirun and I can verify that Blender was using my nVidia GPU to render the 3D viewport. However, there is no "GPU" option in the dropdown in the Blender User Preferences. It only lists "CPU". See this screenshot. Will I need to install additional drivers in order to use CUDA? –  Peter Cassetta May 8 '12 at 12:34
add comment

I've just done some experimenation and can confirm Eric Appleman's statements that Bumblebee is not necessary for CUDA. (more about Bumblebee: How well do laptops with Nvidia Optimus work?)

However, when you need to show graphical examples using OpenGL, you do need something like Bumblebee for Optimus systems, otherwise you either don't see anything on your display or get the error:

ERROR: Support for necessary OpenGL extensions missing.

When running a CUDA program, you need to install the CUDA toolkit and a nvidia driver. If you intend to compile programs, you also need the SDK. The installers can be found on http://developer.nvidia.com/cuda-downloads, please read the below instructions before borking your Optimus laptop.

Installing CUDA

Driver

I recommend to install the nvidia driver from Ubuntu's package manager. If you install Bumblebee, you don't need to worry about the driver. Otherwise, after installation, disable the nvidia libraries as described on http://askubuntu.com/a/107746/6969. If you do not do so, you'll loose 3D acceleraration and possibly get stuck on a low resolution.

Toolkit

Basically you have to download the installer, make it executable and run it. - Download the installer. As of this writing, 4.2.9 is the most recent driver. As I've a 64-bit OS, I use the 64-bit 11.04 Ubuntu package (though I'm running 12.04) - Make it executable and allow installation to /usr/local/cuda:

chmod +x cudatoolkit_4.2.9_linux_64_ubuntu11.04.run
sudo ./cudatoolkit_4.2.9_linux_64_ubuntu11.04.run

When the installation message occurs which asks you where to install CUDA, just press Enter to accept the default /usr/local/cuda:

......................................
Enter install path (default /usr/local/cuda, '/cuda' will be appended):

After installation, it'll print some messages that suggest to put the cuda library directory to your library search path:

========================================

* Please make sure your PATH includes /tmp/cuda/cuda/bin
* Please make sure your LD_LIBRARY_PATH
*   for 32-bit Linux distributions includes /tmp/cuda/cuda/lib
*   for 64-bit Linux distributions includes /tmp/cuda/cuda/lib64:/tmp/cuda/cuda/lib
* OR
*   for 32-bit Linux distributions add /tmp/cuda/cuda/lib
*   for 64-bit Linux distributions add /tmp/cuda/cuda/lib64 and /tmp/cuda/cuda/lib
* to /etc/ld.so.conf and run ldconfig as root

* Please read the release notes in /tmp/cuda/cuda/doc/

* To uninstall CUDA, remove the CUDA files in /tmp/cuda/cuda
* Installation Complete

You may skip this step if you want, but then you've to set LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH later when running a program.

SDK

If you want to be able to compile CUDA applications, you can install the SDK in a similar way as described above. Download, make it executable and run it (not as root, e.g. without sudo!). When compiling parts of it, I had to make some changes to NVIDIA_GPU_Computing_SDK/C/common/common.mk though:

  • after about line 189, OPENGLLIB := -lGL -lGLU -lX11 -lXi -lXmu, add:

    OPENGLLIB += -L/usr/lib/nvidia-current -L/usr/lib32/nvidia-current
    
  • after about line 271, swap ${RENDERCHECKGLLIB} with ${OPENGLLIB} such that it looks like:

    LIB += $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB} -ldl -rdynamic
    
  • a few (5) lines further, do the same, but remove -lcuda too.
  • a few (7) lines further, do the same as you did in line 271.

Using CUDA

CUDA does not need a nvidia-driven X server to work. In that case you can run your random test program like:

LD_LIBRARY_PATH=/usr/lib/nvidia-current:/usr/lib32/nvidia-current:$LD_LIBRARY_PATH someComputallyIntensiveProgram

If you have not added CUDA to your library path, you will need:

LD_LIBRARY_PATH=/usr/lib/nvidia-current:/usr/lib32/nvidia-current:/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH someComputallyIntensiveProgram

(you can strip the 32-bit paths from it if your program is 64-bit).

If the CUDA program does have something to display using OpenGL, you have to use optirun:

 optirun blender

Or, if you did not have CUDA added to your default path:

LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH optirun blender

share|improve this answer
    
Thanks, I'll award the bounty to you (but I'll accept my Community Wiki answer). –  Peter Cassetta May 10 '12 at 12:42
    
Also, 100 rep and an upvote don't accurately express how much I appreciate your work on the Bumblebee Project. You and your colleagues have made it the great piece of software that it is. So thank you. :) –  Peter Cassetta May 10 '12 at 18:53
2  
You're welcome, now I hope that time will award us with a final solution in form of PRIME with an updated xorg+mesa (or Wayland?) stack :) –  Lekensteyn May 10 '12 at 19:41
    
I have only the faintest idea as to what that last comment means, so +1 for making me feel confused! :) –  Peter Cassetta May 10 '12 at 19:45
1  
PRIME, Xorg is the display server responsible for showing you graphics, Mesa is for OpenGL, Wayland is a possible successor of Xorg. –  Lekensteyn May 10 '12 at 19:50
show 2 more comments
up vote 10 down vote accepted

Here is the complete answer (based off Alex Falappa and Lekensteyn's answers):

It is indeed possible to get nVidia Optimus GPUs to run CUDA on Ubuntu.

Bumblebee is not necessary for CUDA. (more about Bumblebee: How well do laptops with Nvidia Optimus work?)

However, when you need to show graphical examples using OpenGL, you do need something like Bumblebee for Optimus systems, otherwise you either don't see anything on your display or get the error:

ERROR: Support for necessary OpenGL extensions missing. 

If you need to use a graphics-intensive program such as Blender, Bumblebee is currently a good way to go.

Skip to Installing CUDA if you don't want to install Bumblebee (i.e. if you don't need OpenGL).
Otherwise, read on.

Installing Bumblebee

Follow the instructions at How well do laptops with Nvidia Optimus work?

These are currently kept up-to-date by a Bumblebee developer.

Once you've installed Bumblebee and rebooted, you will be able to choose the graphics card to use when launching programs by using the optirun program.
For example:

optirun blender

To quickly test if all works correctly, use:

optirun glxspheres

You'll see a program with colorful spinning spheres if all's working correctly.

Verify that the GL vendor string in the terminal contains the word nvidia.
If you run only glxspheres, you'll see the vendor string contains the Intel card instead.

When running a CUDA program, you need to install the CUDA toolkit and a nvidia driver. If you intend to compile programs, you also need the SDK. The installers can be found on http://developer.nvidia.com/cuda-downloads, please read the below instructions before borking your Optimus laptop.

Installing CUDA

Driver

I recommend to install the nvidia driver from Ubuntu's package manager. If you install Bumblebee, you don't need to worry about the driver. Otherwise, after installation, disable the nvidia libraries as described on http://askubuntu.com/a/107746/6969. If you don't, you'll lose 3D acceleration and possibly get stuck on a low resolution.

Toolkit

Basically you have to download the installer, make it executable and run it. - Download the installer. As of Jan 9th, 2013, 5.0.35 is the most recent driver. As I've a 64-bit OS, I use the 64-bit 11.10 Ubuntu package (though I'm running 12.10) - Make it executable and allow installation to /usr/local/cuda:

chmod +x cudatoolkit_5.0.35_linux_64_ubuntu11.10-1.run
sudo ./cudatoolkit_5.0.35_linux_64_ubuntu11.10-1.run

When the installation message occurs which asks you where to install CUDA, just press Enter to accept the default /usr/local/cuda:

......................................
Enter install path (default /usr/local/cuda, '/cuda' will be appended):

After installation, it'll print some messages that suggest to put the cuda library directory to your library search path:

========================================

* Please make sure your PATH includes /tmp/cuda/cuda/bin
* Please make sure your LD_LIBRARY_PATH
*   for 32-bit Linux distributions includes /tmp/cuda/cuda/lib
*   for 64-bit Linux distributions includes /tmp/cuda/cuda/lib64:/tmp/cuda/cuda/lib
* OR
*   for 32-bit Linux distributions add /tmp/cuda/cuda/lib
*   for 64-bit Linux distributions add /tmp/cuda/cuda/lib64 and /tmp/cuda/cuda/lib
* to /etc/ld.so.conf and run ldconfig as root

* Please read the release notes in /tmp/cuda/cuda/doc/

* To uninstall CUDA, remove the CUDA files in /tmp/cuda/cuda
* Installation Complete

You may skip this step if you want, but then you have to set LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH later when running a program.

SDK

If you want to be able to compile CUDA applications, you can install the SDK in a similar way as described above. Download, make it executable and run it (not as root, e.g. without sudo!).

Using CUDA

CUDA does not need a nvidia-driven X server to work. In that case you can run your random test program like:

LD_LIBRARY_PATH=/usr/lib/nvidia-current:/usr/lib32/nvidia-current:$LD_LIBRARY_PATH someComputallyIntensiveProgram

If you have not added CUDA to your library path, you will need:

LD_LIBRARY_PATH=/usr/lib/nvidia-current:/usr/lib32/nvidia-current:/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH someComputallyIntensiveProgram

(you can strip the 32-bit paths from it if your program is 64-bit).

If the CUDA program does have something to display using OpenGL, you have to use optirun:

 optirun blender

Or, if you did not have CUDA added to your default path:

LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH optirun blender

Installing a Blender Build

(With Pre-compiled CUDA Kernels)

When you run optirun blender, you may get a message from Blender saying that CUDA kernel compilation failed, and a message in the terminal similar to the following:

Compiling CUDA kernel ...
nvcc warning : Option '--opencc-options (-Xopencc)' is obsolete and ignored, when
targeting compute_20, sm_20, or higher
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
CUDA kernel compilation failed, see console for details.

If you want to use Blender's GPU rendering feature, you may need a Blender build with pre-compiled CUDA kernels. Builds from Blender.org all have pre-compiled CUDA kernels; the ppa:cheleb/blender-svn builds (more information at this question) do not.

To install an official Blender build, simply follow the instructions laid out in this answer.

If you've installed Blender to /usr/lib/blender, you should then be able to run Blender from the terminal and use GPU rendering with:

 optirun '/usr/lib/blender/blender'
share|improve this answer
    
Recent versions of Bumblebee (installed from the bumblebee/stable PPA) do not need the usermod command. I'll keep the installation instructions on askubuntu.com/a/36936/6969 updated, so please link to that post instead of copying those installation instructions. –  Lekensteyn May 10 '12 at 19:42
    
@Lekensteyn Okay, done! –  Peter Cassetta May 11 '12 at 0:50
add comment

I find that to run all the examples of CUDA, using Bumblebee, you have to install the drivers 295.40 from here and during installation choose not to override the config x11.

Then you have to use the same driver to compile the examples and to run the program.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.