【问题标题】:Theano with opencl GPUTheano 与 opencl GPU
【发布时间】: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,我正在尝试使用theanoIntel GPUopencl

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”的消息持怀疑态度:对于带有四个 coresIntel i3 来说,1.231896 秒似乎很快。

是否需要额外的配置才能将opencltheano 一起使用?还是这个程序确实显示theano 配置为使用GPUopencl

【问题讨论】:

    标签: opencl gpu theano


    【解决方案1】:

    首先感谢您的帖子。

    我正在使用 Conda 的 Ubuntu 16.04 上运行,并且我已经手动安装了 libgpuarray - 所有这些都在网络上有很好的记录。

    我使用了与您相同的测试程序(感谢您提供)。

    这是我的设置

    export MKL_THREADING_LAYER=GNU
    

    文件 ~/.theanorc 看起来像这样

    [global]
    device = opencl0:0
    floatX = float32
    
    [lib]
    cnmem=100
    

    当我运行代码时

    python test.py
    

    我看到了输出

    DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
    Assuming 131072kB available aperture size.
    May lead to reduced performance or incorrect rendering.
    get chip id failed: -1 [2]
    param: 4, val: 0
    Mapped name None to device opencl0:0: Ellesmere 
    [GpuElemwise{exp,no_inplace}(<GpuArrayType<None>(float32, vector)>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
    Looping 1000 times took 0.282664 seconds
    Result is [1.2317803 1.6187935 1.5227805 ... 2.207718  2.2996776 1.6232328]
    Used the gpu
    

    我不知道如何使用第二个 GPU(也是 OpenCL)——但我很高兴至少有 1 个 GPU 正在运行。

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 2012-09-02
      • 1970-01-01
      • 2013-08-12
      • 2013-12-03
      • 2023-03-10
      • 2013-07-31
      • 2017-03-22
      • 2015-09-12
      相关资源
      最近更新 更多