CUDA sample code did not get installed through sudo apt-get install nvidia-cuda-toolkit; any solutions?

NVIDIA has released the samples here: https://github.com/NVIDIA/cuda-samples

Make sure to get the version corresponding to your CUDA version (starting from v9.2): https://github.com/NVIDIA/cuda-samples/releases

(I think this repo might miss some samples that were available in the installer, but I'm not sure.)


Here are the directions I followed:

  1. go to the CUDA website
  2. download the .run file
  3. install the .run file after hitting ctrl+alt+f1 to enter into terminal mode
  4. close the x-window system running in the background
  5. install an nvidia driver at least version 371
  6. install cuda by running the .run file. do not install the advanced nvidia driver when it prompts you.
  7. reboot
  8. test by building the 1_utilities/deviceQuery sample and running it. It should say Result = Pass at the end.

This was difficult because the advanced nvidia driver that the .run file tried to install was incompatible with my desktop environment, but the versions of the nvidia driver in my ppi were too old for CUDA. So, I had to find a ppa with a more recent nvidia driver.