ubuntu下让theano使用GPU
来源:互联网 发布:数据完整性保护 编辑:程序博客网 时间:2024/06/05 15:30
ubuntu下让theano使用GPU
在ubuntu下安装完theano以及cuda后,可以使用如下程序来测试你当前是否使用了GPU:
from theano import function, config, shared, sandboximport theano.tensor as Timport numpyimport timevlen = 10 * 30 * 768 # 10 x #cores x # threads per coreiters = 1000rng = 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 %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')
假设将上述代码存放在test_gpu.py中,运行test_gpu.py,如果输出如下结果:
[Elemwise{exp,no_inplace}(<TensorType(float32, vector)>)]Looping 1000 times took 3.06635117531 secondsResult is [ 1.23178029 1.61879337 1.52278066 ..., 2.20771813 2.29967761 1.62323284]Used the cpu
则说明当前使用的是CPU,并没有使用GPU。
若出现类似如下结果:
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 secondsResult is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761 1.62323296]Used the gpu
这说明当前使用了GPU,并且告诉了我们当前使用的是哪个GPU。
如果你电脑上有GPU,并且你成功安装了CUDA,但是你的程序却没有使用GPU,那说明你当前的theano配置中默认是不使用GPU的,可以通过以下两个方式来使你的theano使用GPU。
1、在运行test_gpu.py时,在python test_gpu.py前加下语句:
# THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python test_gpu.py
2、配置你的.theanorc文件
在你home下面会有一个.theanorc文件,在这个文件中添加如下语句:
[global]floatX = float32device = gpu0[lib]cnmem = 1
注意:如果在你的home下没有发现.theanorc文件,按ctrl+h(显示隐藏文件)就可以看到了。
另外,方法一其实是一种覆盖型方式,即在运行当前的.py文件时,用当前的THEANO_FLAGS来覆盖.theanorc中默认的配置。
参考资料:
http://deeplearning.net/software/theano/tutorial/using_gpu.html
http://stackoverflow.com/questions/33519182/testing-theano-code-how-is-using-gpu
1 0
- ubuntu下让theano使用GPU
- ubuntu 16.04 theano gpu
- Step by Step Ubuntu下GPU测试Theano
- win8+ubuntu双系统下配置theano的GPU模块
- 使用gpu加速theano
- Ubuntu Theano+GPU环境搭建
- win7 pycharm下 安装使用GPU 的theano
- Ubuntu 16.04 LTS 安装Theano配置GPU
- Ubuntu下安装Theano
- ubuntu下安装theano
- windows10下theano启用gpu:CUDA + Anaconda
- theano GPU
- 使用GPU和Theano加速深度学习
- 使用GPU和Theano加速深度学习
- Theano和Tensorflow多GPU使用问题
- 配置使用GPU加速的Theano环境
- 配置ubuntu16.04下Theano使用GPU运行程序的环境
- Windows 7(10) 下安装 tensorflow,theano,keras并使用GPU加速。
- 笔记
- 支付SDK
- 使物体按照指定路径移动
- swift中如何写π
- 基于KNN的手写数字识别
- ubuntu下让theano使用GPU
- strcpy拷贝越界问题
- swift自定义按钮文本和图片的位置
- [leetcode] 19. Remove Nth Node From End of List python实现【easy】
- 21下拉列表
- LeetCode:Binary Tree Maximum Path Sum
- JHTP小结_第三章_类、对象、方法及字符串简介
- 铠甲和长矛
- 运动分析和对象跟踪