2016-05-18 48 views
2

我已經基於Theano example下面的代碼:啓用CNMeM的效果如何,但Theano中的'cuDNN不可用'?

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是ind比CPU更快(0.47秒vs 5秒)。但同時在GPU上,我得到了cuDNN not available消息。

我的問題是這樣的。缺少cuDNN有什麼作用?它有害嗎?

+1

自從我上次使用theano以來已經有一段時間了,但我認爲你可能會使用一般的CUDA庫,因此獲得GPU加速的好處,但不是更專業化的cudNN庫。所以如果你能夠安裝並運行cudNN,你可能會獲得一些額外的加速。 – Marius

回答

1

如果您沒有使用cuDNN,您的代碼不會使用GPU的所有功能。 CPU之前GPU的好處是,GPU有很多真實核心(從700到4000),普通CPU從1到8.

但是GPU核心只能做原始計算。如果您不使用cuDNN,其他標準庫會進行計算,或者可能(我不確定只使用GPU內存,並使用簡單的CPU進行計算)。

CuDNN是一個GPU加速的基元庫。 這意味着如果您開始製作深度神經網絡應用程序,它將不會如此快,因爲它可以。

請仔細閱讀CuDNN

注:因爲我寫的GPU核心只能讓原始的計算,如果您選擇使用GPU,但不支持GPU的使用功能,theano將切換應用程序臨時爲這樣的功能CPU(需要一定的時間)

相關問題