2014年12月15日 星期一

Install caffe on ubuntu 14.04 with cuda-6.5.14

My device:

  1. OS: ubuntu 14.04
  2. linux kernel: 3.13.0-39
  3. graphic card: nvidia gtx 660
(I can't promise that this way can do well on laptop which graphic card include nvidia Optimus mechanisum)

  1. Install CUDA (include nvidia driver)
    • Install build essential
    sudo apt-get update && sudo apt-get install build-essential
    
    • Download CUDA and Extract
    wget http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.14_linux_64.run
    
      chmod a+x cuda_6.5.14_linux_64.run
        mkdir nvidia_installer
          ./cuda_6.5.14_linux_64.run -extract=`pwd`/nvidia_installer
          • Press Ctrl-Alt-F1 and login
          Stop the lightdm and remove current nvidia driver
          sudo service lightdm stop
          sudo apt-get remove --purge nvidia-*
          # If it returns there are some process cause it can't be remove, i just kill them all and remove again.

        • Install
        • cd nvidia_installer
          sudo ./NVIDIA-Linux-x86_64-340.29.run
          sudo ./cuda-linux64-rel-6.5.14-18749181.run
          sudo ./cuda-samples-linux-6.5.14-18745345.run
          # restart lightdm and disable nouveaus
          sudo service lightdm start
          
          (I set every settings by default!)
          • Disable nouveau
          • gedit /etc/modprobe.d/blacklist-nouveau.conf
            and add
            blacklist nouveau
            blacklist lbm-nouveau
            options nouveau modeset=0
            alias nouveau off
            alias lbm-nouveau off
            Reboot
            update-initramfs -u
            sudo reboot
          • Other necessary libs.
          • cudnn api download (Login and answer some questions to get the download permission.)
            tar -xzvf cudnn-6.5-linux-R1.tgz
            cd cudnn-6.5-linux-R1
            sudo cp lib* /usr/local/cuda/lib64/
            sudo cp cudnn.h /usr/local/cuda/include/
            
            sudo cp lib* /usr/local/lib
            sudo cp cudnn.h /usr/local/include
            sudo ln -sf /usr/local/lib/libcudnn.so.6.5.18 /usr/local/lib/libcudnn.so.6.5
            
            OpenBLAS
            git clone https://github.com/xianyi/OpenBLAS
            cd OpenBLAS
            make
            mkdir build
            make install PREFIX=build
            leveldb
            git clone https://github.com/google/leveldb
            cd leveldb
            make
            sudo cp --preserve=links libleveldb.* /usr/local/lib
            sudo cp -r include/leveldb /usr/local/include/
            sudo ldconfig
            others
            sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
          • Install caffe and testing
          • git clone https://github.com/BVLC/caffe
            cd caffe
            cp Makefile.config.example Makefile.config
            gedit Makefile.config
            edit:
            • USE_CUDNN := 1
            • BLAS := open
            • BLAS_INCLUDE := your-path-to-blas/OpenBLAS/build/include
            • BLAS_LIB := your-path-to-blas/OpenBLAS/build/lib
            install
            #compile
            make all
            # test
            make testexport LD_LIBRARY_PATH=~/Library/OpenBLAS/build/lib/
            make runtest