【发布时间】:2016-01-04 05:34:03
【问题描述】:
我刚刚开始使用 Theano 和深度学习。我正在尝试 Theano 教程 (http://deeplearning.net/software/theano/tutorial/using_gpu.html#returning-a-handle-to-device-allocated-data) 中的一个示例。示例代码如下所示:
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 xrange(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')
我正在尝试理解定义“vlen”的表达式,
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
我在文本中找不到任何地方提到此示例中指定的 GPU 内核数量以及为什么选择 30。我也找不到为什么使用 768 个线程的值。我的 GPU (GeForce 840M) 有 384 个内核。我可以假设如果我用 384 代替 30 的值,我将使用所有 384 个内核吗? 768线程的值也应该保持固定吗?
【问题讨论】:
-
我很确定评论的目的是建议要创建的问题大小 (
vlen) 是/应该大到足以在 GPU 上“有趣”。 CUDA 代码,包括使用 CUDA 的 theano 基础,通常不指定内核数或每个内核的线程数(我在这里只能假设“core”=“SM”,这不是通常的定义,而是唯一有意义的)。毕竟vlen这里最终只是一个数字,一个数组的长度。如果您按原样运行代码,它将使用您所有的 GPU 内核。 (10,30,768) 中没有任何魔法。 -
这就是为什么我很难定义“vlen”。似乎没有任何理由来表达为什么。这实际上似乎具有误导性。
-
是的,这很令人沮丧,因为它是教程的一部分。
标签: python machine-learning gpgpu theano theano-cuda