# 指定CPU/GPU计算
import tensorflow as tf
with tf.device('/cpu:0'): # 第1个CPU
a = tf.constant([4.0, 5.0, 2.0], shape=[3], name='a')
b = tf.constant([6.0, 3.0, 1.0], shape=[3], name='b')
c = a - b
print('c(CPU1):', c)
with tf.device('/cpu:1'): # 第2个CPU
d = a + b
print('d(CPU2):', d)
with tf.device('/gpu:0'): # 第1个GPU
e = a * b
print('d(GPU1):', e)