昨天安装caffe,因为用的是cuda10.2,遇到各种问题,最终也没有安装成功。使用cmake配置成功、生成成功、编译的时候报错。

 1 /usr/local/cuda/include/cuda_runtime_api.h:9580:60: error: ‘cudaGraphExec_t’ was not declared in this scope
 2  extern __host__ cudaError_t CUDARTAPI cudaGraphExecDestroy(cudaGraphExec_t graphExec);
 3                                                             ^~~~~~~~~~~~~~~
 4 /usr/local/cuda/include/cuda_runtime_api.h:9580:60: note: suggested alternative: ‘cudaGraphExecUpdate’
 5  extern __host__ cudaError_t CUDARTAPI cudaGraphExecDestroy(cudaGraphExec_t graphExec);
 6                                                             ^~~~~~~~~~~~~~~
 7                                                             cudaGraphExecUpdate
 8 /usr/local/cuda/include/cuda_runtime_api.h:9600:56: error: ‘cudaGraph_t’ was not declared in this scope
 9  extern __host__ cudaError_t CUDARTAPI cudaGraphDestroy(cudaGraph_t graph);
10                                                         ^~~~~~~~~~~
11 /usr/local/cuda/include/cuda_runtime_api.h:9600:56: note: suggested alternative: ‘cudaError_t’
12  extern __host__ cudaError_t CUDARTAPI cudaGraphDestroy(cudaGraph_t graph);
13                                                         ^~~~~~~~~~~
14                                                         cudaError_t
15 src/caffe/CMakeFiles/caffe.dir/build.make:503: recipe for target 'src/caffe/CMakeFiles/caffe.dir/blob.cpp.o' failed
16 make[2]: *** [src/caffe/CMakeFiles/caffe.dir/blob.cpp.o] Error 1
17 CMakeFiles/Makefile2:426: recipe for target 'src/caffe/CMakeFiles/caffe.dir/all' failed
18 make[1]: *** [src/caffe/CMakeFiles/caffe.dir/all] Error 2
19 Makefile:129: recipe for target 'all' failed
20 make: *** [all] Error 2

在网上还没有找到解决办法,原因可能是caffe很久没有更新,有很多与cuda不兼容的地方。

使用一条命令安装依赖库,安装caffe时会自动下载cuda9.1,如果cmake配置了cuda9.1也会遇到编译问题。因为cuda和显卡驱动、cuda和gcc版本都有关系。

sudo apt build-dep caffe-cpu        # dependencies for CPU-only version
sudo apt build-dep caffe-cuda       # dependencies for CUDA version

要安装cuda版本只需要执行:

sudo apt build-dep caffe-cuda       # dependencies for CUDA version

cuda版本与显卡驱动版本关系:

来源:https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

ubuntu18+caffe+cuda

 

 cuda版本与gcc版本关系:

 

ubuntu18+caffe+cuda

 

来源:https://docs.nvidia.com/cuda/archive/8.0/cuda-installation-guide-linux/index.html

从这个表可以看出cuda8.0不支持Ubuntu18.04.

 

ubuntu18+caffe+cuda

 

来源:https://docs.nvidia.com/cuda/archive/9.0/cuda-installation-guide-linux/index.html

从这个表可以看出cuda9.0还是不支持ubuntu18.04.

既然官方没有说明cuda9.0支持ubuntu18.04那么成功在ubuntu18.04上面安装cuda9.0原因是什么呢,是基于这个理论:

cuda只能支持17.04,16.04的ubuntu 下载安装,但,实际上,有点类似于word一样(高版本word能打开低版本的word文件 .)18.04版本的系统,能够安装16.04版本对应的CUDA。

ubuntu18+caffe+cuda

 

 来源:https://docs.nvidia.com/cuda/archive/9.1/cuda-installation-guide-linux/index.html

从这个表可以看出cuda9.0还是不支持ubuntu18.04.

ubuntu18+caffe+cuda

 

 来源:https://docs.nvidia.com/cuda/archive/10.0/cuda-installation-guide-linux/index.html

从这个表可以看出cuda10.0依赖gcc版本7.3.0.

 ubuntu18+caffe+cuda

 

来源:https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

从这里可以看出,Ubuntu18.04下,CUDA10.2依赖的GCC版本是7.3.0.