首先cd进入caffe文件夹,然后执行命令
cp Makefile.config.example Makefile.config
gedit Makefile.config
此时将打开Makefile.config文件,根据个人情况对其内容进行修改。
a.若使用cudnn,则
-
将
-
#USE_CUDNN := 1
-
修改成:
-
USE_CUDNN := 1
b.若使用的opencv版本是3的,则
-
将
-
#OPENCV_VERSION := 3
-
修改为:
-
OPENCV_VERSION := 3
c.若要使用python来编写layer,则
-
将
-
#WITH_PYTHON_LAYER := 1
-
修改为
-
WITH_PYTHON_LAYER := 1
d. 重要的一项 :
将# Whatever else you find you need goes here.下面的
-
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
-
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
-
修改为:
-
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
-
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
这是因为ubuntu16.04的文件包含位置发生了变化,尤其是需要用到的hdf5的位置,所以需要更改这一路径.
去掉compute_20
-
找到
-
# CUDA architecture setting: going with all of them.
-
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
-
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
-
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
-
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-
-gencode arch=compute_20,code=sm_21 \
-
-gencode arch=compute_30,code=sm_30 \
-
-gencode arch=compute_35,code=sm_35 \
-
-gencode arch=compute_50,code=sm_50 \
-
-gencode arch=compute_52,code=sm_52 \
-
-gencode arch=compute_60,code=sm_60 \
-
-gencode arch=compute_61,code=sm_61 \
-
-gencode arch=compute_61,code=compute_61
-
改为:
-
# CUDA architecture setting: going with all of them.
-
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
-
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
-
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
-
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
-
-gencode arch=compute_35,code=sm_35 \
-
-gencode arch=compute_50,code=sm_50 \
-
-gencode arch=compute_52,code=sm_52 \
-
-gencode arch=compute_60,code=sm_60 \
-
#-gencode arch=compute_61,code=sm_61 \
-
#
-gencode arch=compute_61,code=compute_61
由于CUDA 9.x +并不支持compute_20,此处不修改的话编译caffe时会报错:
同时若非cuda8则注释掉compute_61
nvcc fatal : Unsupported gpu architecture 'compute_20'
e. 在Makefile文件的第173行,把 hdf5_hl 和hdf5修改为hdf5_serial_hl 和 hdf5_serial,也就是把下面第一行代码改为第二行代码。
-
将:
-
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
-
改为:
-
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
在Makefile文件中第260行左右添加boost_regex,即
LIBRARIES += boost_thread stdc++后,如下
LIBRARIES += boost_thread stdc++ boost_regex
继续在Makefile文件中查找
-
将:
-
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
-
替换为:
-
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
第三步:编辑/usr/local/cuda/include/host_config.h 将其中的第115行注释掉:
-
将
-
#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
-
改为
-
//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
第四步:将一些文件复制到/usr/local/lib文件夹下,解决"libcudart.so.8.0 cannot open shared object file: Nosuch fileor directory"
:
-
#注意自己CUDA的版本号!
-
cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig
-
cp /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/local/lib/libcublas.so.8.0 && sudo ldconfig
-
cp /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/local/lib/libcurand.so.8.0 && sudo ldconfig