CNMeM启用但“cuDNN不可用”的效果如何?

2024-04-23 10:40:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下基于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模式,我得到这个:

^{pr2}$

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秒vs 5秒)。但同时在GPU我收到了cuDNN not available消息。在

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


Tags: theimportnumpyconfiggputime模式function
1条回答
网友
1楼 · 发布于 2024-04-23 10:40:48

如果你不使用cuDNN,你的代码就不会使用GPU的全部功能。 GPU先于CPU的优点是GPU有很多实核(从700到4000),普通CPU从1到8。在

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

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

请阅读CuDNN

注意:因为我写的GPU内核只能进行原始计算,如果你选择使用GPU,但是使用了不支持GPU的函数,theano会为CPU临时切换该函数的应用程序。(这需要时间)

相关问题 更多 >