【问题标题】:What's the effect of CNMeM enabled but 'cuDNN not available' in Theano?在 Theano 中启用 CNMeM 但“cuDNN 不可用”有什么影响?
【发布时间】:2016-05-18 01:06:49
【问题描述】:

我有以下基于Theano example的代码:

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')

现在当我用两种模式测试代码时:

GPU 模式,我明白了:

$ THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python gpu.py
Using gpu device 0: Tesla C2075 (CNMeM is enabled with initial size: 95.0% of memory, cuDNN not available)
[GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.475526 seconds
Result is [ 1.23178029  1.61879349  1.52278066 ...,  2.20771813  2.29967761
  1.62323296]
Used the gpu

CPU 模式,我明白了:

$ THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python gpu.py
[Elemwise{exp,no_inplace}(<TensorType(float32, vector)>)]
Looping 1000 times took 5.221368 seconds
Result is [ 1.23178029  1.61879337  1.52278066 ...,  2.20771813  2.29967761
  1.62323284]
Used the cpu

请注意两件事,GPU 确实比 CPU 快(0.47 秒对 5 秒)。但同时在 GPU 上,我收到 cuDNN not available 消息。

我的问题是这样的。没有 cuDNN 有什么影响?有害吗?

【问题讨论】:

  • 自从我上次使用 theano 已经有一段时间了,但我认为您可能正在使用通用的 CUDA 库,因此获得了 GPU 加速的好处,而不是更专业的 cudNN 库。因此,如果您能够安装并运行 cudNN,您可能会获得一些额外的加速。

标签: python nvidia theano theano-cuda


【解决方案1】:

如果您没有使用 cuDNN ,您的代码就不会使用 GPU 的所有功能。 GPU先于CPU的好处是GPU有很多真正的核心(从700到4000),普通CPU从1到8。

但 GPU 内核只能进行原始计算。如果您不使用 cuDNN ,其他标准库会进行计算,或者可能(我不确切知道只使用 GPU 内存并使用简单的 CPU 进行计算)。

CuDNN 是一个 GPU 加速的原语库。 这意味着如果你开始制作深度神经网络应用程序,它不会那么快,因为它可以。

请阅读CuDNN

注意:因为我写的GPU核心只能进行原始计算,如果你选择使用GPU,但使用GPU不支持的功能,theano会临时将应用程序切换为CPU的这种功能。(制作需要时间它)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-28
    • 2017-01-08
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 2017-07-12
    • 2013-04-29
    • 2015-11-05
    相关资源
    最近更新 更多