tf.config.list_physical_devices
allows querying the physical hardware resources prior to runtime initialization.
import tensorflow as tf
physical_devices = tf.config.list_physical_devices('CPU')
for dev in physical_devices:
print(dev)
#### Output ####
PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')
import tensorflow as tf
physical_devices = tf.config.list_physical_devices('GPU')
for dev in physical_devices:
print(dev)
#### Output ####
PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')
import tensorflow as tf
physical_devices = tf.config.list_physical_devices()
for dev in physical_devices:
print(dev)
### Output ####
PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')
PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')
Similar Articles