Skip to content

How to Check if Tensorflow is Using GPU

  • by
Check if Tensorflow is Using GPU

Is your Tensorflow taking much GPU or space? Want to know how? Good to hear today’s topic, it is really interesting.

So, if you are a developer and you are a user of Tensorflow as well so, you should have an idea of how you can check if Tensorflow is using GPU.

Let’s get started!

How to Check if Tensorflow is Using GPU?

There are a few ways to check.

# For TensorFlow 2

The following code will help you in Tensorflow version 2.0 and this will help for those who already have updated their version.

import tensorflow as tf

print(tf.test.gpu_device_name())

print("Check GPU: ", len(tf.config.list_physical_devices('GPU')))
  • The above line code is just help to check physical devices.
tf.test.is_gpu_available
  • The above code is built-in you do not need to make your own function if you are using this.

# For TensorFlow 1:

Here you must have version 1.0, then you must consider the following code.

import tensorflow as tf
print(tf.test.gpu_device_name())

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

print(new_var)
  • First of all, you have to import Tensorflow library then mention a short name such as tf.
  • Okay, now just use the built-in function as well that is: tf.test.gpu_device_name().
  • Now create a new variable with any name.
  • Here you are creating a config of all log devices.
  • Just print out your made variable.

Are you getting AttributeError: module ‘tensorflow’ has no attribute ‘Session’? It is very tough to solve. Now you are to free out of it. I hope this official guide will help as well.

Leave a Reply

Your email address will not be published. Required fields are marked *