测试theano是提示使用CPU而不是gpu问题
2016-10-05 21:28
423 查看
测试theano是提示使用CPU而不是gpu问题:
cuda 和theano配置完成后,进行theano测试
为了检查你的GPU是否启用了,可以剪切下面的代码然后保存成一个Python文件(我命名为test_gpu1.py),运行看看。
[python] view
plain copy
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' % 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'
直接在终端命令行敲:python test_gpu1.py
运行结束后提示显示的是Used the cpu!!(后来经过查找资料这种情况其实是由于theano的默认配置中不是使用GPU而是CPU)
反复在根目录下添加环境变量也没能解决。最后解决方法是在命令行上指定模式 并运行test_gpu1.py:
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python test_gpu1.py
同理如果指定用CPU的话就在终端上敲:
THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python test_gpu1.py
在theano 的官网教程中,配置环境变量有两种方法:
第一种方法是THEANO_FLAGS方法(即上面使用的)
第二种方法是在根目录(home/hf(用户名为hf))下建立.theanorc文件并添加例如类似下面:
[global]
floatX=float32
device=gpu0
[lib]
cnmem=1
但我用第二种方法没能成功,第一种方法确实可行!
****第二种方法没能成功 的原因是:当时我在控制台用的是root身份,而.theanorc 所创建的根目录为home/hf(这是hf用户的根目录!!)所以我在root的根目录(cd $HOME)下创建.theano 就好了!!!
cuda 和theano配置完成后,进行theano测试
为了检查你的GPU是否启用了,可以剪切下面的代码然后保存成一个Python文件(我命名为test_gpu1.py),运行看看。
[python] view
plain copy
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' % 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'
直接在终端命令行敲:python test_gpu1.py
运行结束后提示显示的是Used the cpu!!(后来经过查找资料这种情况其实是由于theano的默认配置中不是使用GPU而是CPU)
反复在根目录下添加环境变量也没能解决。最后解决方法是在命令行上指定模式 并运行test_gpu1.py:
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python test_gpu1.py
同理如果指定用CPU的话就在终端上敲:
THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python test_gpu1.py
在theano 的官网教程中,配置环境变量有两种方法:
第一种方法是THEANO_FLAGS方法(即上面使用的)
第二种方法是在根目录(home/hf(用户名为hf))下建立.theanorc文件并添加例如类似下面:
[global]
floatX=float32
device=gpu0
[lib]
cnmem=1
但我用第二种方法没能成功,第一种方法确实可行!
****第二种方法没能成功 的原因是:当时我在控制台用的是root身份,而.theanorc 所创建的根目录为home/hf(这是hf用户的根目录!!)所以我在root的根目录(cd $HOME)下创建.theano 就好了!!!
相关文章推荐
- 关于form使用form.submit()提交的一个问题,提示form.submit不是对象的方法属性
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 使用visio 提示此UML形状所在的绘图页不是UML模型图的一部分 请问这个问题怎么解决?
- Theano和Tensorflow多GPU使用问题
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 为什么使用googletest,而不是其他C++测试框架(译自google faq的该问题)
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- Selenium使用Firefox测试SSL页面反复提示不信任问题
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- CPU使用时间问题测试
- 在使用win 7 无线承载网络时,启动该服务时,有时会提示:组或资源的状态不是执行请求操作的正确状态。 网上有文章指出,解决这个问题的方法是在设备管理器中启动“Microsoft托管网络虚拟适配
- 问题分享:最近测试VDI-in-a-Box使用AD做身份验证出现以下错误提示:
- Xbox摇身变NAS:BT的使用问题与性能测试