Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUDA version X complains about not supporting gcc version Y - what to do?

The question is about a specific combination of versions but is relevant more generally.

I've just dist-upgraded from Kubuntu 12.04 to 14.04. Now, when I want to compile CUDA code (with CUDA 6.5), I get:

#error -- unsupported GNU version! gcc 4.9 and up are not supported!

I installed gcc-4.8 (and 4.7), and tried to use the symlinks-in-/usr/local/cuda/bin solution suggested here:

CUDA incompatible with my gcc version

but this doesn't work. What should I do?

like image 639
einpoklum Avatar asked Jan 18 '15 12:01

einpoklum


People also ask

Does GCC support CUDA?

According to the CUDA 10.2 System Requirements, Table 1, the nvcc compiler in CUDA 10 doesn't support the latest versions of GCC and Clang.

How do I find my GCC version?

So if you ever need to check the version of the GCC C++ compiler that you have installed on your PC, you can do it through the command prompt by typing in the single line, g++ --version, and this will return the result.


1 Answers

This solution is relevant to multiple combinations of CUDA and GCC versions.


You can tell CUDA's nvcc to use a specific version of gcc. So, suppose you want gcc 4.7 for use with CUDA 6. You run:

sudo apt-get install gcc-4.7 g++-4.7

and then add the following switch to your nvcc command-line:

nvcc --compiler-bindir /usr/bin/gcc-4.7  # rest of the command line here

If you're building with CMake, add an appropriate setting before looking for CUDA to your CMakeLists.txt, e.g.:

set(CUDA_HOST_COMPILER /usr/bin/gcc-4.7)  # -> ADD THIS LINE <-
find_package(CUDA)

Also, it seems clang can compile CUDA as well, maybe that's worth experimenting with (although you would have to build it appropriately).

Note: Some Linux (or other OS) distributions don't have packages for multiple versions of gcc (in the same release of the OS distribution). I would advise against trying to install a package from another release of the distribution on an older release, and consider building gcc instead. That's not entirely trivial but it is quite doable - and of course, it's your only option if you don't have root access to your machine.

like image 145
einpoklum Avatar answered Oct 06 '22 18:10

einpoklum