I've just done some experimenation and can confirm Eric Appleman's statements that Bumblebee is not necessary for CUDA. (more about Bumblebee: Is a NVIDIA GeForce with Optimus Technology supported by Ubuntu?)
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 https://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
I have exactely the same issue. I am trying to test my working setup with Ubuntu 16.04 and GTX1080 with CUDA 7.5 for parallel computing, and was hoping to easily get this done by using the packages provided in the repos. Unfortunately as noted above they are missing. It is possible to use the runfile install for installing only the samples. See e.g. for an older version:
https://stackoverflow.com/questions/27306724/ubuntu-14-04-how-to-install-cuda-6-5-without-installing-nvidia-driver
This works also for 7.5.
Simply say "no" when prompted for driver and toolkit installation. You will also need to set the right toolkit libraries. This installs cuda samples into your home by default. However there seem to be an issue with libraries not being found as the package from the repo also puts them into a different location.
However some simple samples like matrixMul compile and run fine.
There might be a simple workaround by adding the right path, but probably installing at least cuda-toolkit together with samples from the runfile should make it work 'out-of-the-box' - have not tried it yet...
Best Answer
It looks as though the
CUDA 9.1
is actually in the official 18.04 repositories now. Run the following from a terminal window:After it is installed run
nvcc -V
to confirm. You should see something similar to this:The toolkit also installs the necessary drivers and support for
OpenCL
. Just installclinfo
and run it to see:Then you should get something similar to the following:
To install the NVIDIA graphics drivers in 18.04LTS, follow the steps below:
In a terminal window, type in:
Then run the update:
Then install the graphics driver:
After a reboot, you can run
nvidia-smi
to see if it is installed:Hope this helps!