0

代码:

from theano import function, config, shared, tensor
import numpy
import time
#import lasagne

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([], tensor.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, tensor.Elemwise) and
              ('Gpu' not in type(x.op).__name__)
              for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')

结果:

C:\Users\spk7522\AppData\Local\Continuum\Anaconda3\python.exe C:/Users/spk7522/Desktop/python/test.py 警告(theano.sandbox.cuda):cuda 后端已弃用,将被删除在下一个版本 (v0.10) 中。请切换到 gpuarray 后端。您可以在此 URL 获取有关如何切换的更多信息: https ://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29

使用 gpu 设备 0:Quadro K4000(启用 CNMeM,初始大小:95.0% 的内存,cuDNN 5110)[GpuElemwise{exp,no_inplace}(), HostFromGpu(GpuElemwise{exp,no_inplace}.0)] 循环 1000 次耗时 0.471953秒结果是 [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761 1.62323296] 使用了 gpu

进程以退出代码 0 结束

QRS: 1) 我的 theano 测试程序在 GPU 上工作正常吗 2) 如何删除警告 (theano.sandbox.cuda): 窗口 cmd 上的消息

4

0 回答 0