How to do it...

  1. In order to find out which devices TensorFlow is using for which operations, we need to set a config in the session parameters that sets log_device_placement to True. When we run the script from the command line, we will see specific device placements, as shown in the following output:
import tensorflow as tf 
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') 
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') 
c = tf.matmul(a, b) 
# Runs the op. 
print(sess.run(c)) 
  1. From the terminal, run the following command:
$python3 using_multiple_devices.py Device mapping: no known devices. I tensorflow/core/common_runtime/direct_session.cc:175] ...

Get TensorFlow Machine Learning Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.