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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…