If you're starting to work with deep learning and using TensorFlow as your framework of choice, it can be useful to know of the available GPU devices on your system. It allows you to select a specific GPU for your TensorFlow operations if you have multiple GPUs on your machine. This tutorial explains how to get available GPU devices using TensorFlow.
In the following code, we retrieve a list of available GPU devices on the system. We iterate over each GPU device in the list and retrieve detailed information. Finally, within the loop, we print the name from the details dictionary for each GPU device.
import tensorflow as tf
devices = tf.config.list_physical_devices('GPU')
for device in devices:
details = tf.config.experimental.get_device_details(device)
print(details['device_name'])
Here's an example of what the output might look like when running the code snippet:
NVIDIA GeForce RTX 3070 Laptop GPU
In this example, the output shows one available GPU device.
Leave a Comment
Cancel reply