Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have installed tensorflow in my ubuntu 16.04 using the second answer here

with ubuntu's builtin apt Cuda installation.

Now my question is how can I test if tensorflow is really using GPU? I have a gtx 960m GPU. When I import tensorflow this is the output

I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally 

I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally 

I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally 

I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcuda.so.1 locally 

I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally

2 Answers

0 votes
by (106k points)

You can use the below-mentioned code to tell if tensorflow is using gpu acceleration from inside python shell there is an easier way to achieve this.

import tensorflow as tf 

if tf.test.gpu_device_name(): 

    print('Default GPU Device:

    {}'.format(tf.test.gpu_device_name()))

else:

   print("Please install GPU version of TF")

It usually prints like

Default GPU Device: /device:GPU:0

Wanna become an Expert in python? Come & join our Python Certification course 

0 votes
ago by (1.3k points)

import tensorflow as tf

gpu_device = tf.config.list_physical_devices('GPU')

if gpu_device:

   print(" GPU is being utilized by TensorFlow")

   for gpu in gpu_device:

       print(f"- {gpu}")

else:print("TensorFlow is not using the GPU.")

To check whether Tensorflow is using GPU, you can verify by running the above code in the Python environment.

After executing the code check the logs for GPU Usage, when you run the code, TensorFlow will log the device placement in the console. Look for messages showing that operations are being executed on GPU 

you can also monitor GPU usage in real-time using the nvidia-smi common in your terminal.

Bash Command: nvidia-smi

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...