4

I struggle with Caffe compilation. Unfortunately I failed to compile it.

Steps I followed:

git clone https://github.com/BVLC/caffe.git
cd caffe
mkdir build
cd build
cmake ..
make all

Running make all fails with the following error message:

[  2%] Building NVCC (Device) object src/caffe/CMakeFiles/cuda_compile.dir/util/cuda_compile_generated_im2col.cu.o
In file included from /usr/include/cuda_runtime.h:59:0,
                 from <command-line>:0:
/usr/include/host_config.h:82:2: error: #error -- unsupported GNU version! gcc 4.9 and up are not supported!
 #error -- unsupported GNU version! gcc 4.9 and up are not supported!
  ^
CMake Error at cuda_compile_generated_im2col.cu.o.cmake:207 (message):
  Error generating /mydir/caffe/build/src/caffe/CMakeFiles/cuda_compile.dir/util/./cuda_compile_generated_im2col.cu.o

Software version:

  • OS: Debian.
  • gcc version: 5.3.1.
  • nvcc version: 6.5.12.
  • cat /proc/driver/nvidia/version result:
NVRM version: NVIDIA UNIX x86_64 Kernel Module  352.63  Sat Nov  7 21:25:42 PST 2015
GCC version:  gcc version 4.8.5 (Debian 4.8.5-3) 

Attempts to solve the problem

1st try

Simple solutions are often best ones, so (as suggested here) I tried to comment out macro checking gcc version from /usr/include/host_config.h (line 82). Unfortunately it doesn't work and compilation fails badly:

1 catastrophic error detected in the compilation of "/tmp/tmpxft_000069c2_00000000-4_im2col.cpp4.ii".

2nd try

I tried to run:

cmake -D CMAKE_CXX_COMPILER=g++-4.8 ..
make

but it fails with exactly the same error message (even though g++-4.8 should be accepted).

3rd try

I've found similar problem (though not related to Caffe) and I tried to solve it as suggested in the accepted answer.

What I did:

  1. I've ran grep -iR "find_package(CUDA" caffe command and found Cuda.cmake file which has find_package(CUDA 5.5 QUIET) in line 225.
  2. I added set(CUDA_HOST_COMPILER /usr/bin/gcc-4.8) to Cuda.cmake, line before line: find_package(CUDA 5.5 QUIET).
  3. I removed everything from build directory and ran cmake and make again - with and without -D CMAKE_CXX_COMPILER=g++-4.8.

Unfortunately result is exactly the same. Caffe probably overwrites it somehow - I didn't figure it out how.

make VERBOSE=1 2>&1 | grep -i compiler-bindir returns nothing.

What's interesting, make VERBOSE=1 prints command that fails, which is:

/usr/bin/nvcc -M -D__CUDACC__ /mydir/caffe/src/caffe/util/im2col.cu -o /mydir/caffe/build/src/caffe/CMakeFiles/cuda_compile.dir/util/cuda_compile_generated_im2col.cu.o.NVCC-depend -ccbin /usr/bin/cc -m64 -DUSE_LMDB -DUSE_LEVELDB -DUSE_OPENCV -DWITH_PYTHON_LAYER -DGTEST_USE_OWN_TR1_TUPLE -Xcompiler ,\"-fPIC\",\"-Wall\",\"-Wno-sign-compare\",\"-Wno-uninitialized\",\"-O3\",\"-DNDEBUG\" -gencode arch=compute_20,code=sm_21 -Xcudafe --diag_suppress=cc_clobber_ignored -Xcudafe --diag_suppress=integer_sign_change -Xcudafe --diag_suppress=useless_using_declaration -Xcudafe --diag_suppress=set_but_not_used -Xcompiler -fPIC -DNVCC -I/usr/include -I/mydir/caffe/src -I/usr/include -I/mydir/caffe/build/include -I/usr/include/hdf5/serial -I/usr/include/opencv -I/usr/include/atlas -I/usr/include/python2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/mydir/caffe/include -I/mydir/caffe/build

when I add --compiler-bindir /usr/bin/gcc-4.8 flag manually, it prints error:

nvcc fatal   : redefinition of argument 'compiler-bindir'

which may be related to this bug report.

Edit: I didn't notice that --compiler-bindir and -ccbin are the same options, and the latter is already set in above command that failed. When I changed -ccbin /usr/bin/cc to -ccbin /usr/bin/gcc-4.8 in above command that failed, it completes successfully. Now I need to find option in Caffe's CMake file that overwrite -ccbin in all subsequent Caffe's CMakes. Looking at cmake/Cuda.cmake:252:list(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA} seems to be good way to go.


How can I successfully complete my compilation? Any help is appreciated.

Related SO questions:

Community
  • 1
  • 1
patryk.beza
  • 4,876
  • 5
  • 37
  • 56
  • 1
    you seem to mix gcc compiler and nvcc compiler (GPU code compiler). Please try and pinpoint the issue: is it with compiling CPU code or GPU? what happens if you define in Makefile.config `CPU_ONLY := 1`? are you able to build CPU only version of caffe? – Shai Dec 21 '15 at 21:46
  • 1
    If you want to use CUDA 6.5, start with [a OS/Distro that is officially supported by CUDA 6.5](http://developer.download.nvidia.com/compute/cuda/6_5/rel/docs/CUDA_Getting_Started_Linux.pdf) (<-click and read the documentation, especially section 1.1 and table 1) and don't make any updates to gnu/gcc/g++. – Robert Crovella Dec 21 '15 at 22:45
  • @Shai In the above post I pasted `/usr/bin/nvcc -M -D__CUDACC__ (...)` command which causes error message. This line clearly states that the problem concerns GPU compilation ran by *Caffe*'s compilation process. AFAIK `nvcc` internally uses `gcc` on Linux. See `nvcc --help` to see `--compiler-bindir` (`-ccbin`) parameter description. – patryk.beza Dec 21 '15 at 22:47
  • @RobertCrovella No Debian in [here](http://developer.download.nvidia.com/compute/cuda/6_5/rel/docs/CUDA_Getting_Started_Linux.pdf). Shame. ;( – patryk.beza Dec 22 '15 at 01:39

2 Answers2

7

cmake -D CUDA_NVCC_FLAGS="-ccbin gcc-4.8" .. && make causes successful compilation.


Now another problem showed up: linking Google's libgflags or libprotobuf fails probably due to fact that it was compiled with newer gcc version but it's not related to asked question.

patryk.beza
  • 4,876
  • 5
  • 37
  • 56
1

My machine runs Ubuntu 15.10, and my default compiler version is gcc 5.2.1 .

Commenting out the #error directive in line 115 of file

/usr/local/cuda-7.5/include/host_config.h 

(or whatever the path on your system is) did the trick for me. Caffe compiled fine, all tests ran smoothly.

On the other hand, if one chooses to ignore this and proceed to compile part of the project with one compiler version, part of the project with another (for me it was gcc-4.8 and gcc-5.2.1), linking problems will arise. The linking problems of protobuf and libgflags another answer mentions are not unrelated to this.

Giorgos Sfikas
  • 707
  • 1
  • 8
  • 19