【发布时间】:2016-03-27 23:39:48
【问题描述】:
我为Caffe 编译而苦恼。可惜我编译失败了。
Steps我关注了:
git clone https://github.com/BVLC/caffe.git
cd caffe
mkdir build
cd build
cmake ..
make all
运行 make all 失败并显示以下错误消息:
[ 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
软件版本:
- 操作系统:
Debian。 -
gcc版本:5.3.1。 -
nvcc版本:6.5.12。 -
cat /proc/driver/nvidia/version结果:
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)
尝试解决问题
第一次尝试
简单的解决方案通常是最好的解决方案,所以(如建议的here)我试图从/usr/include/host_config.h(第82行)注释掉宏检查gcc版本。不幸的是它不起作用并且编译失败:
1 catastrophic error detected in the compilation of "/tmp/tmpxft_000069c2_00000000-4_im2col.cpp4.ii".
第二次尝试
我试着跑了:
cmake -D CMAKE_CXX_COMPILER=g++-4.8 ..
make
但它失败了 exactly 相同的错误消息(即使 g++-4.8 应该被接受)。
第三次尝试
我找到了similar problem(尽管与 Caffe 无关),我尝试按照接受的答案中的建议解决它。
我做了什么:
- 我运行了
grep -iR "find_package(CUDA" caffe命令,发现Cuda.cmake文件在225 行中有find_package(CUDA 5.5 QUIET)。 - 我在
Cuda.cmake中添加了set(CUDA_HOST_COMPILER /usr/bin/gcc-4.8),行前一行:find_package(CUDA 5.5 QUIET)。 - 我从
build目录中删除了所有内容,然后再次运行cmake和make- 有和没有-D CMAKE_CXX_COMPILER=g++-4.8。
不幸的是结果完全一样。 Caffe 可能会以某种方式覆盖它 - 我没有弄清楚如何。
make VERBOSE=1 2>&1 | grep -i compiler-bindir 不返回任何内容。
有趣的是,make VERBOSE=1 打印失败的命令,即:
/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
当我手动添加--compiler-bindir /usr/bin/gcc-4.8 标志时,它会打印错误:
nvcc fatal : redefinition of argument 'compiler-bindir'
可能与this 错误报告有关。
编辑:我没有注意到--compiler-bindir 和-ccbin 是相同的选项,而后者已经在上面失败的命令中设置了。当我在上面失败的命令中将-ccbin /usr/bin/cc 更改为-ccbin /usr/bin/gcc-4.8 时,它成功完成。现在我需要在 Caffe 的 CMake 文件中找到覆盖所有后续 Caffe 的 CMake 中的 -ccbin 的选项。看看cmake/Cuda.cmake:252:list(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_EXTRA} 似乎是个好方法。
我怎样才能成功地完成我的编译?任何帮助表示赞赏。
相关的 SO 问题:
【问题讨论】:
-
你似乎混合了 gcc 编译器和 nvcc 编译器(GPU 代码编译器)。请尝试找出问题所在:是编译 CPU 代码还是 GPU?如果你在 Makefile.config
CPU_ONLY := 1中定义会发生什么?你能构建仅 CPU 版本的 caffe 吗? -
如果您想使用 CUDA 6.5,请从 a OS/Distro that is officially supported by CUDA 6.5 开始(
-
@Shai 在上面的帖子中我粘贴了
/usr/bin/nvcc -M -D__CUDACC__ (...)命令,这会导致错误消息。该行清楚地表明问题涉及由 Caffe 的编译过程运行的 GPU 编译。 AFAIKnvcc在 Linux 内部使用gcc。看nvcc --help看--compiler-bindir(-ccbin)参数说明。 -
@RobertCrovella here 中没有 Debian。耻辱。 ;(