lceans
lceans

Reputation: 191

Tensorflow with GPU, how to see tensorflow is using the GPU?

Trying to install tensorflow to work with the GPU. Some documentation I see says tensorflow comes out of box with gpu support when detected. If so, what command can I use to see tensorflow is using my GPU? I have seen other documentation saying you need tensorflow-gpu installed. I have tried both but do not see how my GPU is being used?

Upvotes: 6

Views: 18223

Answers (3)

Laurie King
Laurie King

Reputation: 1

print(tf.config.list_physical_devices('GPU'))

[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

Upvotes: 0

sekomer
sekomer

Reputation: 742

Go to command line and run Python

The following example lists the number of visible GPUs on the host. Docs

import tensorflow as tf
devices = tf.config.list_physical_devices('GPU')
print(len(devices)) 

For CUDA Docs

import tensorflow as tf
tf.test.is_built_with_cuda()

Returns whether TensorFlow was built with CUDA (GPU) support. Docs

You can check with following function too but it's deprecated**

import tensorflow as tf

tf.test.is_gpu_available()

Both returns True if your GPU is available

Upvotes: 8

B200011011
B200011011

Reputation: 4268

Tensorflow 2 GPU checking can be found here,

Deprecated, https://www.tensorflow.org/api_docs/python/tf/test/is_gpu_available

https://www.tensorflow.org/api_docs/python/tf/config/list_physical_devices

Check if Tensorflow was built with CUDA (GPU) support,

https://www.tensorflow.org/api_docs/python/tf/test/is_built_with_cuda

Tensorflow GPU guide,

https://www.tensorflow.org/guide/gpu

Code

import tensorflow as tf

print(tf.config.list_physical_devices('GPU'))
# [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

print(tf.test.is_built_with_cuda)
# <function is_built_with_cuda at 0x7f4f5730fbf8>

print(tf.test.gpu_device_name())
# /device:GPU:0

print(tf.config.get_visible_devices())
# [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

Upvotes: 4

Related Questions