[深度学习] CentOS7编译dlib GPU版

1.安装CUDA和CudNN

略..

2.更新cmake

1)下载cmake源码

wget https://cmake.org/files/v3.13/cmake-3.13.3-Linux-x86_64.tar.gz

2)解压

tar zxvf cmake-3.13.3-Linux-x86_64.tar.gz

3)删除旧的cmake

sudo yum remove cmake

4)添加cmake环境变量

sudo nano /etc/profile

# 在最后添加如下内容
export CMAKE_HOME=/home/leo/soft/cmake-3.13.3-Linux-x86_64
export PATH=$PATH:$CMAKE_HOME/bin

# 生效
source /etc/profile
# 检查版本
cmake -version

3.更新GCC

CentOS7默认的gcc版本是4.8.x,需要更新到5.5.0版本(6.4.0测试时DLIB编译报错)

1)下载gcc 5.5.0

wget ftp://ftp.gnu.org/gnu/gcc/gcc-5.5.0/gcc-5.5.0.tar.gz

2)解压

tar zxvf gcc-5.5.0.tar.gz

3)安装依赖

安装gmp包:

wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz
tar xvf gmp-6.1.2.tar.xz
cd gmp-6.1.2
./configure --prefix=/usr/local/gmp
make && make install

安装mpfr包:

wget https://www.mpfr.org/mpfr-current/mpfr-4.0.2.tar.gz
tar -zxvf mpfr-4.0.2.tar.gz
cd mpfr-4.0.2         
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
make && make install

安装mpc包:

wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
tar xvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr
make && make install

如果遇到报错:mul.c:175:1: error: conflicting types for ‘mpfr_fmma’

则将 mpc/src/mul.c中的 mpfr_fmma函数改名为mpfr_fmma_mul,一共三处

将库文件加入如下文件:

vi /etc/ld.so.conf

# 增加以下三行
/usr/local/gmp/lib
/usr/local/mpfr/lib
/usr/local/mpc/lib

# 保存退出
# 加完后使用如下命令更新
ldconfig -v

4)编译

cd gcc-5.5.0
./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc
make -j16
sudo make install

如遇报错:

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.

解决:

yum install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel

然后再重新安装.

5)删除旧的gcc

sudo yum remove gcc

6)创建软连接

ln -s /usr/local/bin/gcc /bin/cc
ln -s /usr/local/bin/c++ /bin/c++

4.编译DLIB

1)下载源码

git clone https://github.com/davisking/dlib.git

2)解压

unzip dlib-master.zip 

3)安装python版dlib

cd dlib-master/
# 进入虚拟环境
conda activate leo_env2
# 安装python版 dlib
python setup.py install --set USE_AVX_INSTRUCTIONS=1 --set DLIB_USE_CUDA=1

4)安装dlib(可选)

cd dlib-master/
mkdir build
cd build
cmake ..
cmake --build .

 5)验证dlib

import dlib
print(dlib.DLIB_USE_CUDA)  # 打印 True表示安装成功

 5.在Ubuntu20上安装gcc-6

sudo nano /etc/apt/sources.list
# 在最后添加
deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe

sudo apt-get update
sudo apt install gcc-6 g++-6 -y
# 设置gcc-6为默认编译器
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6
# 检查gcc版本为6.4
gcc -v

6.Ubuntu20.04上编译dlib

python setup.py install --set USE_AVX_INSTRUCTIONS=1 --set DLIB_USE_CUDA=1 --compiler-flags "-DCUDA_HOST_COMPILER=usr/bin/gcc-6"

 

= =

 

posted @ 2023-05-06 17:03  风间悠香  阅读(277)  评论(0编辑  收藏  举报