close

How to tell if tensorflow is using gpu acceleration from inside python shell?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to tell if tensorflow is using gpu acceleration from inside python shell in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to tell if tensorflow is using gpu acceleration from inside python shell?

  1. How to tell if tensorflow is using gpu acceleration from inside python shell?

    No, I don't think “open CUDA library” is enough to tell, because different nodes of the graph may be on different devices.

  2. tensorflow is using gpu acceleration from inside python shell

    No, I don't think “open CUDA library” is enough to tell, because different nodes of the graph may be on different devices.

Method 1

No, I don’t think “open CUDA library” is enough to tell, because different nodes of the graph may be on different devices.

When using tensorflow2:

print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))

For tensorflow1, to find out which device is used, you can enable log device placement like this:

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

Check your console for this type of output.

Method 2

Following piece of code should give you all devices available to tensorflow.

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

Sample Output

[name: “/cpu:0” device_type: “CPU” memory_limit: 268435456 locality { } incarnation: 4402277519343584096,

name: “/gpu:0” device_type: “GPU” memory_limit: 6772842168 locality { bus_id: 1 } incarnation: 7471795903849088328 physical_device_desc: “device: 0, name: GeForce GTX 1070, pci bus id: 0000:05:00.0” ]

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read