Python 当赋值和放置在不同的设备中时,tensorflow变量赋值真正发生在哪里

Python 当赋值和放置在不同的设备中时,tensorflow变量赋值真正发生在哪里,python,tensorflow,Python,Tensorflow,我对tensorflow中的变量赋值和放置感到困惑 如果我们在某个设备中创建变量,例如在gpu0中。虽然我们需要在不同的设备中更新此变量的值,例如在gpu2中。确切的任务将发生在哪里 def foo(): tf.reset_default_graph() with tf.device("/gpu:0"): x = tf.Variable(3, name='x') with tf.device("/gpu:1"): y = tf.Variab

我对tensorflow中的变量赋值和放置感到困惑

如果我们在某个设备中创建变量,例如在gpu0中。虽然我们需要在不同的设备中更新此变量的值,例如在gpu2中。确切的任务将发生在哪里

def foo():
    tf.reset_default_graph()
    with tf.device("/gpu:0"):
        x = tf.Variable(3, name='x')
    with tf.device("/gpu:1"):
        y = tf.Variable(6, name='y')
    return x, y

x, y = foo()

with device("/gpu:2")  
    z1 = tf.assign(x, 1)    ---(1)
    z2 = tf.assign(y, 2)    ---(2)
    z3 = tf.multipy(x, y)   ---(3)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    sess.run(z1)
    sess.run(z2)
    sess.run(z3)
对于上面的例子,我的理解是,z1/z2将发生在gpu2上,但实际上,x将在gpu0中更新,y将在gpu1中更新。在--(3)中,gpu2将再次从gpu0和gpu1获取x/y,然后在gpu2中的乘法运算中完成

如果我没听懂,请纠正我