13

I have just installed Debian Stretch (9) and Cuda 8 on a new GPU server. Stretch does not come with older versions of gcc, so I need to use clang as the host compiler (nvcc does not support gcc-6). I can do this invoking nvcc as:

nvcc -ccbin clang-3.8

Is there any way to acheive this system wide - e.g. in cuda config or an environment variable?

Chris
  • 852
  • 1
  • 8
  • 19

2 Answers2

17

Documentation of nvcc does not list any env variable to change ccbin, only the option:

http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html

--compiler-bindir directory, -ccbin Specify the directory in which the compiler executable resides. The host compiler executable name can be also specified to ensure that the correct host compiler is selected.

Linux guide have no such info too: http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

You may try creating some nvcc wrapper script and putting it earlier in the PATH env var like:

mkdir ~/supernvcc
echo '#!/bin/sh' > ~/supernvcc/nvcc
echo `which nvcc` -ccbin clang-3.8 '$@' >> ~/supernvcc/nvcc
chmod +x ~/supernvcc/nvcc
export PATH=/home/`id -un`/supernvcc:$PATH

(repeat last line with export in every new shell before using nvcc or add it to your .bashrc or other shell init script)

PS: and nvcc is bash script too, you can just copy it and edit:

cat `which nvcc`

UPDATE: People recommend to link correct gcc version to the internal dir /usr/local/cuda/bin/ of cuda:

  sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc
osgx
  • 90,338
  • 53
  • 357
  • 513
  • Thanks, although to go to that effort it might be work just modifying the makefiles - I was jus hoping there was a "clean" way to do this – Chris Jun 28 '17 at 02:14
  • @RobertCrovella, alias will not work for script shells started from makefiles. In Ubuntu nvcc (/usr/bin/nvcc) from ubuntu package is script, did not check debian and/or nvidia's variant of package (and there is gcc-5 / g++-5 in ubuntu which is supported by nvcc too). `supernvcc/nvcc` may be more convenient when there are many makefiles. – osgx Jun 28 '17 at 02:26
  • And my solution is incomplete: I have makefile (cmakefile) which calls nvcc with incorrect `-ccbin /usr/bin/cc` which points to gcc-6, not gcc-5 needed by nvcc. And nvcc fails when there are two options of `-ccbin`. So, some better supernvcc/nvcc is needed which will filter `$@` from `-ccbin` and next argument and pass other arguments to real nvcc, but I have no knowledge of this kind of bash magic. – osgx Jun 30 '17 at 03:13
  • The last update is great, works like a charm! – dreamflasher May 31 '22 at 20:17
  • if someone find compilation errors when manually adjusting the gcc version the make sure the symlink is of the same version – loran d Aug 29 '23 at 13:49
2

you can use NVCC_PREPEND_FLAGS and NVCC_APPEND_FLAGS as described in the official docs to inject -ccbin into all calls of nvcc.

For example, I have the following in my ~/.bash_profile:

export NVCC_PREPEND_FLAGS='-ccbin /home/linuxbrew/.linuxbrew/bin/g++-11'
xdavidliu
  • 2,411
  • 14
  • 33