配置ubuntu16.04下Theano使用GPU运行程序的环境

ubuntu16.04默认安装了python2.7和python3.5 。本教程使用python3.5

第一步:将ubuntu16.04默认的python2修改成默认使用python3 。

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

运行上述代码之后会将ubuntu16.04默认使用python2修改为默认使用python3 。

输入命令 python 可以进入python的交互界面,会显示python的版本 。

第二步:安装theano和CUDA

sudo apt-get install python3-numpy python3-scipy python3-dev python3-pip python3-nose g++ libopenblas-dev git
sudo pip3 install Theano

# cuda 7.5 don‘t support the default g++ version. Install an supported version and make it the default.
sudo apt-get install g++-4.9

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

# Work around a glibc bug
echo -e "\n[nvcc]\nflags=-D_FORCE_INLINES\n" >> ~/.theanorc

逐个运行上述命令即可安装theano和CUDA,以及numpy、scipy等常用的库。

安装完成后,可进入python交互界面,运行

import numpy;numpy.test()

import scipy;scipy.test()

import theano;theano.test()

检测是否安装成功。

作者安装后测试时numpy和scipy这两个库显示OK,theano显示Fail,但是theano可以正常导入和使用。(这点我也不明白,大神们路过时还望指点一二)

至此,theano安装完毕,可以在cpu上运行theano的程序了。

第三步:配置.theanorc文件

在linux根目录下打开.theanorc(注意前面是带点的)文件,将

[global]

device = gpu

floatX = float32

[nvcc]

fastmath = True

加入到该文件里。

第四步:安装nvcc

这个就比较简单了

sudo apt-get insatll nvcc

就可以了。

至此,所有安装程序都完成了。

可以使用下面这点代码来测试程序是使用cpu还是gpu

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 range(iters):
    r = f()
t1 = time.time()
print (‘Looping %d times took‘ % iters, t1 - t0, ‘seconds‘ )
print (‘Result is‘, 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‘)

  

以上就是本人亲身安装的全部过程,折腾了好久。如有疑问或者哪里有不对的,还请留言指出。

  

时间: 2024-07-31 16:09:18

配置ubuntu16.04下Theano使用GPU运行程序的环境的相关文章

Ubuntu16.04下编译安装及运行单目ORBSLAM2

官网有源代码和配置教程,地址是 https://github.com/raulmur/ORB_SLAM2 1 安装必要工具 首先,有两个工具是需要提前安装的.即cmake和Git. sudo apt-get install cmake sudo apt-get install git 2 安装Pangolin,用于可视化和用户接口 安装依赖项: sudo apt-get install libglew-dev sudo apt-get install libpython2.7-dev 先转到一个

ubuntu16.04下sublime text3安装和配置

ubuntu16.04下sublime text3安装和配置 2018年04月20日 10:31:08 zhengqijun_ 阅读数:1482 1.安装方法 1)使用ppa安装 sudo add-apt-repository ppa:webupd8team/sublime-text-3 sudo apt-get update sudo apt-get install sublime-text-installer 卸载 sublime text 命令: sudo apt-get remove s

Ubuntu16.04下LAMP环境的安装与配置

Ubuntu16.04下LAMP环境的安装与配置 最近做个实验需要用到Ubuntu环境的靶场,所以这里介绍下Ubuntu环境下LAMP的安装与配置,话不多说,我们gkd! 1.Apache2的安装 首先确保机器已经进行了sudo apt-get update && sudo apt-get upgrade,如果速度慢请换源,这里我使用的是清华源. sudo apt-get install apache2,安装信息省略,一般安装结束之后apache会自动开启. systemctl statu

【原创】Octovis在Ubuntu16.04下运行出现core dump的解决方案

本人SLAM研究新手,使用系统为Ubuntu16.04.本文原址:http://www.cnblogs.com/hitlrk/p/6667253.html 在学习SLAM的过程中,使用Octomap进行八叉树地图的建立,Octomap的编译安装没有出现问题,octovis模块也顺利安装.悲催的是,在我调用octovis模块打开已有的八叉树地图时,便会出现一大堆乱码,乱码最后有一个Core Dump. 这个错误和2016年时g2o_viewer在Ubuntu16.04下出现的错误一样,不过目前g2

Ubuntu16.04下写的Qt程序,调试时没问题,运行时偶现崩溃 (需要在运行时生成core dump文件,QMAKE_CC += -g)

记录一下 Ubuntu16.04下写的Qt程序,调试时没问题,运行时偶现崩溃 需要在运行时生成core dump文件 首先在pro结尾里加入 QMAKE_CC += -g QMAKE_CXX += -g QMAKE_LINK += -g 在终端输入 ulimit -c 显示为 0 然后输入 ulimit -c unlimited 继续在终端运行编写的程序 出错后,会在当前目录生成 core 文件 然后在终端执行 “gdb 你的程序名 core” 然后输入 bt 对该错误进行跟踪调试 (gdb)

深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow

深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow 最近在公司做深度学习相关的学习和实验,原来一直在自己的电脑上安装虚拟机跑,速度实在太慢,主机本身性能太弱,独显都没有,物理安装Ubuntu也没多大意义,所以考虑用公司性能最强悍的游戏主机(i7 6700+GTX 1070) 做实验,这台主机平时是用来跑HTC VIVE的,现在归我用了o(*≧▽≦)ツ. 原本以为整个一套安装下来会很顺利,一路火花

(转)深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0

深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0 发表于2016年07月15号由52nlp 接上文<深度学习主机攒机小记>,这台GTX1080主机准备好之后,就是配置深度学习环境了,这里选择了比较熟悉Ubuntu系统,不过是最新的16.04版本,另外在Nvidia GTX1080的基础上安装相关GPU驱动,外加CUDA8.0,因为都比较新,所以踩了很多坑. 1. 安装Ubuntu16.04 不考虑双系统,直接安装 Ubuntu16.04,从ubun

Ubuntu16.04 下部署 nginx+uwsgi+django1.9.7(虚拟环境pyenv+virtualenv)

由于用的新版本系统,和旧的稍有差别,在网上搜了很多相关资料,搞了三天终于搞好在Ubuntu16.04下的部署,接下来就详细写写步骤以及其中遇到的问题.前提是安装有虚拟环境pyenv+virtualenv. 一.安装uwsgi 1. 在虚拟环境下安装uwsgi 1 # 启动环境 2 pyenv activate your_env_name 3 pip install uwsgi 2. 测试uwsgi,创建test.py def application(env, start_response): s

Ubuntu16.04下安装oracle客户端

在Ubuntu16.04下安装oracle数据库客户端,使Django项目连接到Oracle数据库 1.下载oracle客户端安装包: 进入官网http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html下载如下所需的三个包. oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm oracle-instantclient11.2-devel-11.2.0.4.0-1