一:安装cuda
PS:特别推荐*.deb的方法,目前已提供离线版的deb文件,该方法比较简单,不需要切换到tty模式。这里以CUDA 7.0为例。
一、CUDA Repository
获取CUDA安装包,安装包请自行去NVidia官网下载。
https://developer.nvidia.com/cuda-downloads 选择linux-》x86-》ubuntu-》14.04-》deb(local)
下载下来后拷贝到系统user目录下
在该目录下执行下面的命令:(注意命令中的版本要改成与你下载下来的相同)
$ sudo dpkg -i cuda-repo-ubuntu1410-7-0-local_7.0-28_amd64.deb
$ sudo apt-get update
二、CUDA Toolkit
$ sudo apt-get install -y cuda
三、Environment Variables
配置环境变量:注意查看下有无该目录,目录版本编号
/etc/profile add:
export CUDA_HOME=/usr/local/cuda-7.5
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
PATH=${CUDA_HOME}/bin:${PATH}
export PATH
接下来做一些验证工作:
查看显卡的驱动版本
cat /proc/driver/nvidia/version
查看nvcc编译器的版本
nvcc -V i
编译cuda的示例代码:
然后make一下编译代码。
cd ~/NVIDIA_CUDA-6.5_Samples
进入bin路径运行devicequery
cd ~/NVIDIA_CUDA-6.5_Samples/bin
./ deviceQuery
二:安装python环境:
选择一个适合你的IDE运行环境,我是用的是Spyder,因为它内置了 iPython 环境,Caffe有不少的程序是基于 iPython 环境完成的。安装方法很简单,直接在Ubuntu软件中心搜索“spyder”即可安装。
三:安装theano
下载theano安装包
https://pypi.python.org/pypi/Theano
下载0.7版本的theano
解压
进入解压后的目录
执行 sudo python setup.py install
安装完成后,我们测试安装是否成功
编写代码 check1.py
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in xrange(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu')
执行命令:
THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python check1.py
返回:
[Elemwise{exp,no_inplace}(<TensorType(float32, vector)>)]
Looping 1000 times took 3.06635117531 seconds
Result is [ 1.23178029 1.61879337 1.52278066 ..., 2.20771813 2.29967761 1.62323284]
Used the cpu
执行:
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python check1.py
返回:
Using gpu device 0: GeForce GTX 580
[GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.638810873032 seconds
Result is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761 1.62323296]
Used the gpu
Fedora安装theano:http://www.linuxdiyf.com/linux/14998.html
Ubuntu安装Theano+CUDA:http://www.linuxdiyf.com/linux/2697.html
ubunt14.04安装cuda:http://www.linuxdiyf.com/linux/15027.html
Ubuntu安装CUDA驱动:http://www.linuxdiyf.com/linux/10093.html
Ubuntu下CUDA(含GPU卡驱动)安装过程:http://www.linuxdiyf.com/linux/13012.html