【发布时间】:2017-11-06 09:19:46
【问题描述】:
我想在 2 个 GPU 上并行化以下简单表达式:C = A^n + B^n,方法是在对结果求和之前计算 GPU 0 上的 A^n 和 GPU 1 上的 B^n。
在 TensorFlow 中,我会喜欢:
with tf.device('/gpu:0'):
An = matpow(A, n)
with tf.device('/gpu:1'):
Bn = matpow(B, n)
with tf.Session() as sess:
C = sess.run(An + Bn)
但是,由于 PyTorch 是动态的,所以我在做同样的事情时遇到了麻烦。我尝试了以下方法,但只需要更多时间。
with torch.cuda.device(0):
A = A.cuda()
with torch.cuda.device(1):
B = B.cuda()
C = matpow(A, n) + matpow(B, n).cuda(0)
我知道有一个模块可以使用 torch.nn.DataParallel 在批处理维度上并行化模型,但在这里我尝试做一些更基本的事情。
【问题讨论】: