How to get the current available Gpus in TensorFlow?

Member

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

How to get the current available Gpus in TensorFlow?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by caesar_kertzmann , 8 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".

Member

by enrico , 3 months ago

@sallie 

Here is a simple code snippet to get the available GPUs in TensorFlow:

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")


You can run this code in a Python environment with TensorFlow installed to see the available GPUs. If no GPUs are available, it will print "No available GPUs".