How to use CUDA with NVIDIA Prime
In my case I found that the NVidia card was not actually turned off, and the only thing I actually needed to do to run CUDA code was:
export LD_LIBRARY_PATH=/usr/lib/nvidia-352
in the shell where I want to run it (I am assuming that globally changing the alternatives setting would break compiz, etc, etc...)
To get to this point (on a Dell Optiplex 7010, with Ubuntu 14.04, CUDA 7.5, and a GTX 980) I believe the steps were:
- Use the PRIME Profiles tab to select Intel
- Reboot, and select Intel as the default in the BIOS
- Shut down the computer
- Plug the monitors into the onboard video :)
Everything seems to be working fine so far (nvidia-smi sees the card, cuda samples run, theano uses the card, etc...)
I believe I've found at least a cursory solution to this, as described in the update to my original post. Really there's two solutions I found, though I'm sure there are others.
1 - With Prime in Intel mode, re-enable the NVIDIA card via bbswitch, then run modprobe nvidia
to load the module and create the device nodes.
2 - Use Bumblebee optirun to launch a bash session from where you can do all your CUDA stuff.
Both these solutions allow you to use the onboard graphics for your display, while using the NVIDIA card for compute loads. The optirun solution seems more versatile, but I prefer the first one for its minimalism.
I'm hoping someone with more understanding will improve on this answer.
I use NVIDIA card only for CUDA executions and find out this approach:
All the time I use intel card and it is confirmed by command lspci | grep -E "VGA|3D"
:
00:02.0 VGA compatible controller: Intel Corporation Skylake Integrated Graphics (rev 06)
01:00.0 3D controller: NVIDIA Corporation GM107M [GeForce GTX 960M] (rev ff)
In the corresponding row for NVIDIA card you should see (rev ff)
means it turned off.
To turn the card on and use it for CUDA computations I use two following commands:
sudo prime-select nvidia
sudo prime-switch
After that command lspci | grep -E "VGA|3D"
report:
00:02.0 VGA compatible controller: Intel Corporation Skylake Integrated Graphics (rev 06)
01:00.0 3D controller: NVIDIA Corporation GM107M [GeForce GTX 960M] (rev a2)
Notice about (rev a2)
, not (rev ff)
in the corresponding row.
Now card ready to computation.
After computations I use backward actions:
sudo prime-select intel
sudo prime-switch
And lspci | grep -E "VGA|3D"
reports:
00:02.0 VGA compatible controller: Intel Corporation Skylake Integrated Graphics (rev 06)
01:00.0 3D controller: NVIDIA Corporation GM107M [GeForce GTX 960M] (rev ff)