【发布时间】:2017-03-02 15:15:34
【问题描述】:
我这里讲教程http://deeplearning.net/software/theano/tutorial/using_gpu.html
我使用的代码
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 %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')
Testing Theano with GPU 部分: 有一些命令行将 Theano 标志设置为在 cpu 或 gpu 上运行。问题是我不知道把这些命令放进去。
我已经尝试过 windows cmd
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python theanogpu_example.py
然后我得到
'THEANO_FLAGS' is not recognized as an internal or external command,
operable program or batch file.
但是,我可以使用命令在 cpu 上运行代码
python theanogpu_example.py
我想在 GPU 上运行代码,我应该怎么做(使用tutorial 中的这些命令)?
解决方案
感谢@Blauelf 关于 windows 环境变量的想法。
但是,参数必须分开
set THEANO_FLAGS="mode=FAST_RUN" & set THEANO_FLAGS="device=gpu" & set THEANO_FLAGS="floatX=float32" & python theanogpu_example.py
【问题讨论】:
-
多个
set THEANO_FLAGS=行将替换以前的内容(这就是为什么脚本有时包含像set PATH=%PATH%;C:\myDir这样的代码,其中%PATH%会自动替换为以前的值),所以在那个命令行中,只有最后一个set实际上会有效果。
标签: python windows python-2.7 cmd theano