Cuda 9.2 Samples 'make' failure - cannot compile example code

I seem to have successfully installed cuda-9.2 (Please see output of nvcc -V and nvidia-smi below). I am using Nvidia driver version 396.37, which satisfies the requirement for cuda-9.2 (version >=390). I am using a Titan Xp with Ubuntu 16.04.4 LTS.

I have followed the Cuda Toolkit Documentation instructions for installation to the letter, but I am unable to successfully execute the make command at step 7.2.3.2 Compiling the Examples. The (rather lengthy) error message is provided below. I have no idea what is going wrong, I have ensured all permissions for the directory containing the sample code with sudo chmod 777 NVIDIA_CUDA-9.2_Samples. I have been trying for days to properly install cuda, and had a similar issue while installing cuDNN. If anyone can provide any insights I would be eternally grateful!

------------------------------------
Checking cuda and driver installations:
------------------------------------

marlena@millenium-falcon:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Tue_Jun_12_23:07:04_CDT_2018
Cuda compilation tools, release 9.2, V9.2.148
marlena@millenium-falcon:~$ nvidia-smi
Thu Jul 12 16:45:39 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.37                 Driver Version: 396.37                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  TITAN Xp            Off  | 00000000:26:00.0  On |                  N/A |
| 23%   34C    P8    11W / 250W |    205MiB / 12194MiB |      1%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1122      G   /usr/lib/xorg/Xorg                           160MiB |
|    0      1919      G   compiz                                        42MiB |
+-----------------------------------------------------------------------------+
marlena@millenium-falcon:~$ cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module  396.37  Tue Jun 12 13:47:27 PDT 2018
GCC version:  gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)

------------------------------------
Errors upon running make:
------------------------------------

marlena@millenium-falcon:~/cuda_sample_code/NVIDIA_CUDA-9.2_Samples$ make
make[1]: Entering directory '/home/marlena/cuda_sample_code/NVIDIA_CUDA-9.2_Samples/0_Simple/vectorAddDrv'
/usr/local/cuda-9.2/bin/nvcc -ccbin g++ -I../../common/inc  -m64    -gencode arch=compute_30,code=compute_30 -o vectorAddDrv.o -c vectorAddDrv.cpp
vectorAddDrv.cpp: In function ‘int getMaxGflopsDeviceId()’:
vectorAddDrv.cpp:144:25: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
         checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_devic
                         ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
vectorAddDrv.cpp:144:25: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
         checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_devic
                         ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
vectorAddDrv.cpp:144:81: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
     checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_device));
                                                                             ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
vectorAddDrv.cpp:165:25: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
         checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_devic
                         ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
vectorAddDrv.cpp:165:25: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
         checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_devic
                         ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
vectorAddDrv.cpp:165:81: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
     checkCudaErrors(cuDeviceComputeCapability(&major, &minor, current_device));
                                                                             ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
vectorAddDrv.cpp: In function ‘int main(int, char**)’:
vectorAddDrv.cpp:323:25: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
         checkCudaErrors(cuDeviceComputeCapability(&major, &minor, devID));
                         ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
vectorAddDrv.cpp:323:25: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
         checkCudaErrors(cuDeviceComputeCapability(&major, &minor, devID));
                         ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
vectorAddDrv.cpp:323:72: warning: ‘CUresult cuDeviceComputeCapability(int*, int*, CUdevice)’ is deprecated [-Wdeprecated-declarations]
         checkCudaErrors(cuDeviceComputeCapability(&major, &minor, devID));
                                                                        ^
vectorAddDrv.cpp:71:50: note: in definition of macro ‘checkCudaErrors’
 #define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
                                                  ^
In file included from vectorAddDrv.cpp:31:0:
/usr/local/cuda-9.2/bin/../targets/x86_64-linux/include/cuda.h:2531:36: note: declared here
 __CUDA_DEPRECATED CUresult CUDAAPI cuDeviceComputeCapability(int *major, int *m
                                    ^
Assembler messages:
Fatal error: can't create vectorAddDrv.o: Permission denied
Makefile:345: recipe for target 'vectorAddDrv.o' failed
make[1]: *** [vectorAddDrv.o] Error 1
make[1]: Leaving directory '/home/marlena/cuda_sample_code/NVIDIA_CUDA-9.2_Samples/0_Simple/vectorAddDrv'
Makefile:52: recipe for target '0_Simple/vectorAddDrv/Makefile.ph_build' failed
make: *** [0_Simple/vectorAddDrv/Makefile.ph_build] Error 2

You’re running make in a directory structure where you don’t have write access permissions.

To work around this you could do

sudo make

or even better

sudo make -k

alternatively, when installing CUDA, use the runfile installer and have it install the sample codes to a directory structure where you have write access permissions.

Doing

sudo chmod 777 NVIDIA_CUDA-9.2_Samples.

does not fix this issue. It only fixes it for that one particular directory, but the make process will move around in various directories.

This solved it - thank you so much! I am fairly new to Linux and this is my first time building my own system from scratch so I didn’t realize I had that issue. Thanks again!