0

When I run this command:

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

I get this log:

2017-06-16 11:29:42.305931: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-16 11:29:42.305950: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-16 11:29:42.305963: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-06-16 11:29:42.305975: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-16 11:29:42.305986: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2017-06-16 11:29:42.406689: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:901] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2017-06-16 11:29:42.406961: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties: 
name: GeForce GTX 1070
major: 6 minor: 1 memoryClockRate (GHz) 1.7715
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 248.75MiB
2017-06-16 11:29:42.406991: I tensorflow/core/common_runtime/gpu/gpu_device.cc:908] DMA: 0 
2017-06-16 11:29:42.407010: I tensorflow/core/common_runtime/gpu/gpu_device.cc:918] 0:   Y 
2017-06-16 11:29:42.407021: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0
2017-06-16 11:29:42.408087: I tensorflow/core/common_runtime/direct_session.cc:257] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0

Does this assure me that tensorflow code will use GPU? I had a previous version of tensorflow and the message was clear that it used GPU. Now after I upgraded it, the messages are different and confusing. I can see that it discovered my GPU, but is it using it for sure or still using the CPU? How can I check this from the code to make sure the device used is GPU?

I'm concerned because I have:

import keras
Using TensorFlow backend

It shows that keras is using a CPU version!

talonmies
  • 70,661
  • 34
  • 192
  • 269
Mutaz
  • 547
  • 4
  • 12

1 Answers1

1

Use device scope as follow:

with tf.device('/gpu:0'):
    a = tf.constant(0)
sess = tf.Session()
sess.run(a)

If it doesn't complain that it can't assign a device to node, you are using the GPU.

You can go one step further to analyse where each node is being allocated to through log_device_placement.

jkschin
  • 5,776
  • 6
  • 35
  • 62
  • Thank you. It seems it works. Gave me `Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)` . It should be ok, right? – Mutaz Jun 16 '17 at 09:59
  • You can go further to add log_device_placement and see the allocation of ops. The best test would be run matrix multiplies. The difference in speed would be significant. – jkschin Jun 16 '17 at 10:01
  • Ok thanks. But still importing `keras` gives `Using TensorFlow backend` only (which means CPU). It should give more log details that it is using GPU if it was really using GPU :( – Mutaz Jun 16 '17 at 10:08
  • I'm not sure how Keras works. Try the matrix multiplies and measure the time taken. – jkschin Jun 16 '17 at 10:10
  • I'm fitting a model now on Keras with verbose logging and it is blazing fast. For sure this is a GPU performance. Thanks for the help. – Mutaz Jun 16 '17 at 10:17
  • Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as accepted. – jkschin Jun 21 '17 at 08:01