Caffe (0) Ubuntu 17.10 install CUDA, cnDNN, OpenCV
1. Download CUDA9.0 from the official site:
The address of the official site is https://developer.nvidia.com/cuda-90-download-archive
Select and download the runfile:
2. Blacklist nouveau:
Modify blacklist.conf:
$ sudo vim /etc/modprobe.d/blacklist.conf
Add these to the blacklist:
# this one might not be required for x86 32 bit users. blacklist amd76x_edac blacklist vga16fb blacklist nouveau blacklist rivafb blacklist nvidiafb blacklist rivatv
Update initramfs disk:
$ sudo update-initramfs -u
3. Stop gdm3 and install the graphic driver:
$ sudo /etc/init.d/gdm3 stop $ sudo init 3
Install nvidia-384 before installing CUDA. Don't use other version !!
$ runlevel # check runlevel is 3 $ sudo add-apt-repository ppa:graphics-drivers/ppa $ sudo apt update $ sudo apt install nvidia-384 nvidia-384-dev $ sudo apt-get install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev g++-6 gcc-6 $ sync $ sudo init 6 # reboot the system
Make sure that the driver has been installed correctly.
$ nvidia-smi
4. Install CUDA:
Use g++-6 and gcc-6 as default compiler:
$ cd /usr/bin $ sudo rm g++ gcc $ sudo ln -s g++-6 g++ $ sudo ln -s gcc-6 gcc
Install CUDA:
$ cd ~/Downloads $ sudo chmod +x cuda_9.0.176_384.81_linux.run $ sudo ./cuda_9.0.176_384.81_linux.run
DON'T install the driver !!
Edit the enviroment variables:
$ vim ~/.bashrc
#[start-20180602-ben(cuda)-add]# export PATH=$PATH:/usr/local/cuda/bin export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH #[end-20180602-ben(cuda)-add]#
Build CUDA examples
$ cd ~/NVIDIA_CUDA-9.0_Samples/ $ make -j4
Run the example:
$ cd ~/NVIDIA_CUDA-9.0_Samples/bin/x86_64/linux/release $ ./smokeParticles
5. Install cuDNN:
Go to the official web site. Login account and download cuDNN. Select "Download cuDNNv7.1.4 (May 16, 2018), for CUDA 9.0"
Don't select the deb file.
Unzip the file and install it:
$ tar -zxvf *.tgz $ cd cuda $ sudo cp -P include/cudnn.h /usr/include $ sudo cp -P lib64/libcudnn* /usr/lib/x86_64-linux-gnu/ $ sudo chmod a+r /usr/lib/x86_64-linux-gnu/libcudnn*
6. Download the OpenCV and OpenCV contrib:
https://opencv.org/releases.html
https://github.com/opencv/opencv_contrib/releases
Make a folder and unzip the files:
Install cmake-gui:
$ sudo apt-get update $ sudo install cmake-gui
Run cmake-gui and set the path:
Push the Configure button and select Unix Makefiles:
Make sure that cuda is selected:
Make sure that python3 is selected:
Push the Generate button.
Install OpenCV:
$ cd ~/OpenCV/opencv-3.4.1/build $ make -j4 $ sudo make install
7. Install Caffe:
Clone Caffe project https://github.com/BVLC/caffe
Go to Caffe dir and modify Makefile.config.example:
$ cp Makefile.config.example Makefile.config $ vim Makefile.config
Follow the comment and modify the options in Makefile.config.
Build Caffe
$ make -j 4
Issue: hdf5.h not found. Solution https://github.com/NVIDIA/DIGITS/issues/156
cd /usr/lib/x86_64-linux-gnu sudo ln -s libhdf5_serial.so.8.0.2 libhdf5.so sudo ln -s libhdf5_serial_hl.so.8.0.2 libhdf5_hl.so
Modify INCLUDE_DIRS and LIBRARY_DIRS in Makefile.config.
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/hdf5/serial/
Issue: error: token ""__CUDACC_VER__ is no longer supported. Solution: https://github.com/BVLC/caffe/issues/5994.
For me, I just comments /usr/local/cuda/include/crt/common_functions.h line 64: #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported. Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
Test Caffe:
$ make runtest
8. Install PyCaffe:
Build PyCaffe:
$ make pycaffe
To import the caffe Python module after completing the installation, add the module directory to your $PYTHONPATH by export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
留言
張貼留言