Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

We see this quite often in many of the TensorFlow tutorials:

sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, 
                                        log_device_placement=True))

What does allow_soft_placement and log_device_placement mean?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
555 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you look at the API of ConfigProto, on line 278, you will see this:

  // Whether soft placement is allowed. If allow_soft_placement is true,
  // an op will be placed on CPU if
  //   1. there's no GPU implementation for the OP
  // or
  //   2. no GPU devices are known or registered
  // or
  //   3. need to co-locate with reftype input(s) which are from CPU.
  bool allow_soft_placement = 7;

What this really means is that if you do something like this without allow_soft_placement=True, TensorFlow will throw an error.

with tf.device('/gpu:0'):
    # some op that doesn't have a GPU implementation

Right below it, you will see on line 281:

  // Whether device placements should be logged.
  bool log_device_placement = 8;

When log_device_placement=True, you will get a verbose output of something like this:

2017-07-03 01:13:59.466748: I tensorflow/core/common_runtime/simple_placer.cc:841] Placeholder_1: (Placeholder)/job:localhost/replica:0/task:0/cpu:0
Placeholder: (Placeholder): /job:localhost/replica:0/task:0/cpu:0
2017-07-03 01:13:59.466765: I tensorflow/core/common_runtime/simple_placer.cc:841] Placeholder: (Placeholder)/job:localhost/replica:0/task:0/cpu:0
Variable/initial_value: (Const): /job:localhost/replica:0/task:0/cpu:0
2017-07-03 01:13:59.466783: I tensorflow/core/common_runtime/simple_placer.cc:841] Variable/initial_value: (Const)/job:localhost/replica:0/task:0/cpu:0

You can see where each operation is mapped to. For this case, they are all mapped to /cpu:0, but if you're in a distributed setting, there would be many more devices.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...