Tuesday, April 26, 2022

How to check Tensorflow is working with your GPU

How to check Tensorflow is working with your GPU

If you have installed Tensorflow with GPU support in your laptop or PC you may be wondering how to check whether it is working with GPU. There are several methods to do this. 

In your Jupyter notebook you can run following commands.

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

This will output the number of available GPUs

Num GPUs Available:  1

If the Tensorflow is not installed properly with GPU support number of GPUs will be shown as 0

To view the details of the GPU you can use following command.

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

This will output details similar to below.

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 13418863311310513005
xla_global_id: -1
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 3667263488
locality {
  bus_id: 1
  links {
  }
}
incarnation: 8234622026470474717
physical_device_desc: "device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6"
xla_global_id: 416903419
]

Physical device description will show you the details of the GPU in your PC or laptop. Here it is shown as NVIDIA GeForce RTX 3060 laptop GPU which is in my laptop.

If you are using free version of Google Colab following details will be shown.

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 5996649638546807441
xla_global_id: -1
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 11320098816
locality {
  bus_id: 1
  links {
  }
}
incarnation: 8194472726421902671
physical_device_desc: "device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7"
xla_global_id: 416903419
]

Google Colaboratory free version provides you with Tesla K80 GPU.

No comments:

Post a Comment