我已经在 Windows 机器上安装了 Theano 并按照配置进行操作指示 http://deeplearning.net/software/theano/library/config.html.
我将以下 .theanorc.txt 文件放置在 C:\Users\my_username 文件夹中:
#!sh
[global]
device = gpu
floatX = float32
[nvcc]
fastmath = True
# flags=-m32 # we have this hard coded for now
[blas]
ldflags =
# ldflags = -lopenblas # placeholder for openblas support
我尝试运行测试,但未能在 GPU 上运行。我猜想 .theanorc.txt 中的值没有被读取,因为我添加了行 print config.device 并且它输出“cpu”。
以下是基本测试脚本和输出:
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
print config.device
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'
output:
pydev debugger: starting (pid: 9564)
cpu
[Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)]
Looping 1000 times took 10.0310001373 seconds
Result is [ 1.23178032 1.61879341 1.52278065 ..., 2.20771815 2.29967753
1.62323285]
Used the cpu
我已成功安装 CUDA Toolkit,但未能安装 pyCUDA。我想 Theano 应该可以在没有安装 pyCUDA 的情况下工作。
如果有人可以帮助解决这个问题,我将非常感激。我已关注these https://stackoverflow.com/questions/25729969/installing-theano-on-windows-8-with-gpu-enabled说明,但不知道为什么程序中的配置值与 .theanorc.txt 文件中的值不匹配。