【发布时间】:2018-05-08 21:25:49
【问题描述】:
我已经配置theano如下:
[idf@localhost python]$ more ~idf/.theanorc
[global]
device = opencl0:0
floatX = float32
[lib]
cnmem=100
[idf@localhost python]$
我也需要
[idf@localhost python]$ export MKL_THREADING_LAYER=GNU
虽然很有趣,但如果我安装 openblas 并添加
[blas]
ldflags = -lopenblas
到.theanorc file,我不再需要:
export MKL_THREADING_LAYER=GNU
使用我在互联网上找到的一个程序,我稍作修改以使用gpuarray,我正在尝试使用theano 和Intel GPU 到opencl:
import os
import shutil
from theano import function, config, shared, gpuarray
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 %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')
当我运行该程序时,它似乎可以识别GPU,但最后会打印出消息“used the cpu”。
[idf@localhost python]$ python theanoexam1.py
Mapped name None to device opencl0:0: Intel(R) HD Graphics 5500 BroadWell U-Processor GT2
[GpuElemwise{exp,no_inplace}(<GpuArrayType<None>(float32, vector)>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 1.231896 seconds
Result is [ 1.23178029 1.61879337 1.52278054 ..., 2.20771813 2.29967737
1.62323284]
Used the cpu
[idf@localhost python]$
我对“使用 cpu”的消息持怀疑态度:对于带有四个 cores 的 Intel i3 来说,1.231896 秒似乎很快。
是否需要额外的配置才能将opencl 与theano 一起使用?还是这个程序确实显示theano 配置为使用GPU 到opencl?
【问题讨论】: