Тест Theano GPU продолжает говорить «процессор используется» - PullRequest
0 голосов
/ 02 марта 2019

Я хочу провести этот простой тест, чтобы увидеть, использую ли я версию GPU theano или CPU, код:

# Code to test if theano is using GPU or CPU                                    
# Reference: https://stackoverflow.com/questions/34328467/how-can-i-use-my-gpu-on-ipython-notebook
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()                                                                
# if you're using Python3, rename `xrange` to `range` in the following line     
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') 

И вот что я вижу, когда выполняю его:

Matt @ limbo> THEANO_FLAGS = device = cuda0 python check_theano.py

 Using
 cuDNN version 5105 on context None 
 Mapped name None to device cuda0:
 Tesla M40 24GB (0000:04:00.0)
 [GpuElemwise{exp,no_inplace}(<GpuArrayType<None>(float64, (False,))>),
 HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)] Looping 1000
 times took 0.391111 seconds Result is [1.23178032 1.61879341
 1.52278065 ... 2.20771815 2.29967753 1.62323285] Used the cpu

Похоже, все в порядке, никаких ошибок относительно pygpu, cudnn, найденомоя карта gpu, так почему последнее сообщение «использовал процессор» ???

Я использую Theano 0.9.0, pygpu 0.6.2, python 3.5.6, cudnn / 5.1-cuda-8.0.44.

Пожалуйста, не говорите мне проверить Theano 1. *, потому что код, который мне нужен для выполнения работ на Theano 0.9

...