Ubuntu Gnome16.04下安装cuda、theano和opencv

 

1. 安装显卡驱动

~$ lspci | grep controller
00:02.0 VGA compatible controller: Intel Corporation Sky Lake Integrated Graphics (rev 07)
03:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 940MX] (rev a2)

双显卡下安装NVIDIA驱动,首先选择合适的源。

 

sudo apt-get update
sudo apt-get install nvidia-361 nvidia-prime nvidia-settings

 2.安装cuda

安装依赖包。

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

 

下载相应的安装包,安装时显卡驱动选‘N'。

 

sudo sh cuda_8.0.44_linux.run

添加动态链接库。

sudo ldconfig /usr/local/cuda/lib64

环境变量。sudo vim /etc/profile在文件末尾添加:

PATH=/usr/local/cuda/bin:$PATH
export PATH

 

官网下载和配置CUDNN。

 

 

tar zxvf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda
sudo cp ./include/cudnn.h /usr/local/cuda/include/ 
sudo cp ./lib64/lib* /usr/local/cuda/lib64/ 
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5 
sudo ln -s libcudnn.so.5.1.5 libcudnn.so.5 
sudo ln -s libcudnn.so.5 libcudnn.so 
sudo ldconfig /usr/local/cuda/lib64

 

3.安装theaoo

安装依赖包。

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git nose_parameterized

安装theano。

sudo pip install Theano

配置theano。

vi ~/.theanorc
[global]
floatX=float32
device=gpu
base_compiledir=~/external/.theano/
allow_gc=False
warn_float64=warn
[mode]=FAST_RUN
[nvcc]
fastmath=True

[cuda]
root=/usr/local/cuda

测试theano。

~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
Using gpu device 0: GeForce 940MX (CNMeM is disabled, cuDNN not available)

3.安装opencv

下载opencv 3.1.0,https://github.com/Itseez/opencv/archive/3.1.0.zip。

安装依赖包。

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

针对cuda8.0的修改。

sudo gedit opencv-3.1.0/modules/cudalegacy/src/graphcuts.cpp
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) 

改为

#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

下载ippicv_linux_20151201.tgz并替换opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e中的同名文件。

编译。

cd opencv-3.1.0  
mkdir build           
cd build  
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. 
make -j4 

 

posted on 2016-12-19 21:10  1357  阅读(430)  评论(0编辑  收藏  举报

导航