一.安装好系统后【最好安装ubuntu 14.04.×,否则还得升级。。】:
1.设置root 用户:sudo passwd root
设置密码
登陆 su root
2.更新一下:sudo apt-get update【可选】
3.安装各种python库(gfortran, numpy, scipy, sklearn, blas, atlas等)详见:http://www.th7.cn/system/lin/201508/123570.shtml
su
do apt-get install gfortran
sudo apt-get install libopenblas-dev
sudo apt-get install liblapack-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install python-pip
sudo apt-get install python-dev
sudo apt-get install python-nose
#安装numpy和scipy sudo apt-get install python-numpy sudo apt-get install python-scipy sudo apt-get install python-sklearn #卸载numpy和scipy sudo apt-get remove python-numpy sudo apt-get remove python-scipy #再次安装numpy scipy
sudo pip install numpy
sudo pip install scipy
#测试numpy scipy
python -c "import numpy;numpy.test()"
python -c
"import scipy;scipy.test()"
sudo pip install Theano
#测试Theano python -c "import theano;theano.test()" 【若测试有问题很可能numpy scipy 这两库没装好
】 5.安装CUDA [详见:http://www.myexception.cn/cuda/2017261.html] #下载对应ubuntu版本的CUDA:https://developer.nvidia.com/cuda-toolkit-55-archive 【注意:CUDA5.5只支持GCC4.6版本】 #安装一些依赖库:
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libGLU.so.1.3.1 /usr/lib/libGLU.so
#
设置环境变量
echo 'export PATH=/usr/local/cuda-7.5/bin:$PATH' >> ~/.bashrc echo 'export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc #验证:
终端输入 nvcc -V #新建配置文件sudo vi ~/.theanorc
添加:(注意不要写在一行,要么不识别)
[global] device = gpu floatX = float32 [nvcc] fastmath = True [cuda] root=/usr/local/cuda/bin/
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')
tar xvzf cudnn-7.5-linux-x64-v5.0-ga.tgz sudo cp cuda/include/cudnn.h /usr/local/cuda/include sudo cp -a cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/lib64/libcudnn*#测试运行 python test_cpu_gpu.py 提示 CNMEM is disabled, cuDNN 5005 成功
8.安装CNMeM(占用更多的显存提升速度)
# 下载:git clone https://github.com/NVIDIA/cnmem.git cnmem
# 编译:
cd cnmem
mkdir build
cd build
cmake ..
make
#安装:sudo cp ../include/cnmem.h /usr/local/cuda/include
sudo cp *.so /usr/local/cuda/lib64/
#使用:THEANO_FLAGS="mode=FAST_RUN,device=gpu,lib.cnmem=0.8,optimizer_including=cudnn" pyhton test_cpu_gpu.py
[note:lib.cnmem=0.8 指使用80%的显存跑这个数据]
9.附加
#系统还原: tar -xvpzf /media/00021448000D62F3/ubuntu/system/backup.tgz -C /
【其中黑色为备份目录】
#系统修复:不能正常启动时:ctrl+alt+F1-6 启动tty命令行 F7为桌面模式 测试桌面:sudo apt-get install unity or 更新:sudo apt-get update