Code: Alles auswählen
import tensorflow as tf
c = []
for d in ['/device:GPU:0', '/device:GPU:1']:
with tf.device(d):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3])
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2])
c.append(tf.matmul(a, b))
with tf.device('/cpu:0'):
sum = tf.add_n(c)
sess = tf.Session(config=tf.ConfigProto(
allow_soft_placement=True, log_device_placement=True)) # Creates a session with log_device_placement set to True.
print(sess.run(sum)) # Runs the opStandardmässig ist CPU 0, die eingebaute CPU und GPU 0 ist die eingebaute GPU der Grafikkarte. Wenn die angesprochene GPU 1 wenn vorhanden ist,
wird dies durch das assign der GPU durch allow:soft_placement ersetzt (auf GPU 0).