How to get the current available Gpus in TensorFlow?

Member

by sallie , in category: General Help , 3 months ago

How to get the current available Gpus in TensorFlow?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by caesar_kertzmann , 3 months ago

@sallie 

To get the current available GPUs in TensorFlow, you can use the tf.config.list_physical_devices('GPU') function. It returns a list of all the available physical GPUs.


Here's an example code snippet:

1
2
3
4
5
6
7
8
import tensorflow as tf

gpus = tf.config.list_physical_devices('GPU')
if gpus:
    for gpu in gpus:
        print("GPU:", gpu)
else:
    print("No available GPUs")


This code will print the details of each GPU if any are available. If no GPUs are found, it will print "No available GPUs".