[英]there is no speed-up using multi-gpus
我尝试使用以下代码测试多GPU的性能:
test__multi.py
import time
import numpy as np
from numpy.random import random
import theano
import theano.tensor as T
from theano import shared
from theano import function
a = time.time()
v_00 = shared(
value=random((10240, 10240)).astype(theano.config.floatX, copy=False)
,target='dev0'
)
v_01 = shared(
value=random((10240, 10240)).astype(theano.config.floatX, copy=False)
,target='dev0'
)
v_10 = shared(
value=random((10240, 10240)).astype(theano.config.floatX, copy=False)
,target='dev1'
)
v_11 = shared(
value=random((10240, 10240)).astype(theano.config.floatX, copy=False)
,target='dev1'
)
b = time.time()
print b - a
f = function(inputs=[], outputs=[
theano.tensor.dot(v_00, v_01),
theano.tensor.dot(v_10, v_11)
]
)
c = time.time()
print c - b
res0, res1 = f()
d = time.time()
print d - c
如图所示,我得到了结果,当我使用两个不同的gpu设备时没有任何改进。(THEANO_FLAGS ='contexts = dev0-> cuda0; dev1-> cuda1')
终端中的日志如下:
lanlin@UbuntuGpu:~$ cd python
lanlin@UbuntuGpu:~/python$ THEANO_FLAGS='contexts=dev0->cuda0;dev1->cuda0' python test__multi.py
Mapped name dev0 to device cuda0: Tesla K80 (CuDNN not available)
Mapped name dev1 to device cuda0: Tesla K80 (CuDNN not available)
6.47632694244
0.34957909584
2.27110910416
lanlin@UbuntuGpu:~/python$ THEANO_FLAGS='contexts=dev0->cuda0;dev1->cuda1' python test__multi.py
Mapped name dev0 to device cuda0: Tesla K80 (CuDNN not available)
Mapped name dev1 to device cuda1: Tesla K80 (CuDNN not available)
6.49380016327
0.36678981781
2.40865397453
进行一些更改将显示改进:
theano.tensor.dot(v_00, v_01).transfer('dev0')
告诉函数输出留在GPU上。 np.asarray(res0)
甚至什至print(res_0)
,以及完成此操作所需的时间。 这样可以确保所有计算都已实际完成。 您必须避免观察到的加速是每次执行数学运算时都会将输出传输到CPU。 从循环开始到np.assarray
调用结束的时间将是计算和传输最后一个答案的总时间。 循环过程中经过的时间仅是将GPU中的操作排队而不是完成操作的时间。 我不确定如何单独安排GPU执行时间的时间; 您必须推断出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.