佛山做優(yōu)化的網(wǎng)絡公司手機網(wǎng)站關鍵詞seo
眾所周知,caffe是個較老的框架,而且只支持到cudnn7,但是筆者在復現(xiàn)ds-slam過程中又必須編譯caffe,我的cuda版本是11.4,最低只支持到8.2.4,故沒辦法,只能編譯了
在此記錄過程、報錯及解決辦法如下;
首先安裝依賴:
sudo apt-get install git
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev
libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
然后git項目源碼:
git clone https://github.com/BVLC/caffe.git
然后編譯:
cd caffe
mkdir build
cd build
cmake ..
make all
sudo make install
make runtest
哈哈哈,不會那么順利噠!
在cmake ..過程中,報了第一個錯:
Found cuDNN: ver. ??? found (include: /usr/local/cuda-11.4/include, library: /usr/local/cuda-11.4/lib64/libcudnn.so) CMake Error at cmake/Cuda.cmake:227 (message): cuDNN version >3 is required. Call Stack (most recent call first): cmake/Cuda.cmake:255 (detect_cuDNN) cmake/Dependencies.cmake:85 (include) CMakeLists.txt:49 (include)
什么原因呢,是因為CMake 找不到或者無法正確檢測到 cuDNN
的版本。錯誤消息中提到 “cuDNN version >3 is required”,但它沒有成功識別你安裝的 cuDNN 版本,但是不可能啊,我們安裝了啊。
直接說解決辦法;修改cmake/Cuda.cmake , 將里面的"cudnn.h" 全部用 "cudnn_version.h"代替
然后是第二個錯:找不到cublas
說找不到cuda_cublas的一系列位置,這不可能,我安裝了呀,先find一下:
果然有,那就set一下,在caffe的編譯目錄里cmake,找到相應的cuda.cmake,然后找CUDA_cublas_LIBRARY,在前添加行
set(CUDA_CUBLAS_LIBRARIES /usr/local/cuda/targets/x86_64-linux/lib/libcublas.so
)
這回這個問題過了,然后在make all過程中開始出錯:
對了,這個方法還能解決
../lib/libcaffe.so.1.0.0:對‘cublasSetStream_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasDdot_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasDaxpy_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasDscal_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasScopy_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasSgemv_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasSdot_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasDcopy_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasDestroy_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasSgemm_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasDgemv_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasDasum_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasGetStream_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasSaxpy_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasDgemm_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasSscal_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasSasum_v2’未定義的引用 ../lib/libcaffe.so.1.0.0:對‘cublasCreate_v2’未定義的引用
等一系列關于cublas*_v2的未定義的引用錯誤。
說是cudnn_conv_layer.cpp第131行報錯
上網(wǎng)上一查,這是因為cudnn8里沒有cudnnGetConvolutionForwardAlgorithm()這個函數(shù)了,改成了cudnnGetConvolutionForwardAlgorithm_v7(),也沒了CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT這個宏定義
那么改唄:
將 src/caffe/layers/cudnn_conv_layer.cpp:中的相關位置reshape函數(shù)替換成下面的:
template <typename Dtype>
void CuDNNConvolutionLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {ConvolutionLayer<Dtype>::Reshape(bottom, top);CHECK_LE(2, this->num_spatial_axes_)<< "CuDNNConvolution input must have 2 spatial axes "<< "(e.g., height and width). "<< "Use 'engine: CAFFE' for general ND convolution.";bottom_offset_ = this->bottom_dim_ / this->group_;top_offset_ = this->top_dim_ / this->group_;const int height = bottom[0]->shape(this->channel_axis_ + 1 );const int width = bottom[0]->shape(this->channel_axis_ + 2 );const int height_out = top[0]->shape(this->channel_axis_ + 1 );const int width_out = top[0]->shape(this->channel_axis_ + 2 );const int* pad_data = this->pad_.cpu_data();const int pad_h = pad_data[0];const int pad_w = pad_data[1];const int* stride_data = this->stride_.cpu_data();const int stride_h = stride_data[0];const int stride_w = stride_data[1];#if CUDNN_VERSION_MIN(8, 0, 0)int RetCnt;bool found_conv_algorithm;size_t free_memory, total_memory;cudnnConvolutionFwdAlgoPerf_t fwd_algo_pref_[4];cudnnConvolutionBwdDataAlgoPerf_t bwd_data_algo_pref_[4];//get memory sizescudaMemGetInfo(&a