TensorFlow
CUDA
cuDNN
GPU
Machine Learning

How do I know if tensorflow using cuda and cudnn or not?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

To know whether TensorFlow is actually using CUDA and cuDNN, you need more than “TensorFlow imported successfully.” The useful checks are: does TensorFlow see a GPU, was the build linked for CUDA, and do real GPU-friendly operations execute on that GPU. cuDNN is even more specific, because TensorFlow uses it only for certain supported operations such as convolutions and some recurrent layers.

Check Whether TensorFlow Sees a GPU

The first basic check is whether TensorFlow detects any GPU devices.

python
import tensorflow as tf

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

If the result is an empty list, TensorFlow is not using the GPU at all, which means CUDA and cuDNN are not active for your workload.

If a GPU appears, that is a strong first sign that CUDA support is working.

Inspect TensorFlow Build Info

TensorFlow can also report whether the installed build was compiled with CUDA support.

python
1import tensorflow as tf
2
3build_info = tf.sysconfig.get_build_info()
4print(build_info)

Useful fields often include whether CUDA and cuDNN support were compiled into the package and which versions the build expects.

This does not prove a specific model is currently using the GPU, but it tells you whether the TensorFlow package is even capable of it.

Run a Real Operation and Watch Device Placement

The next step is to execute GPU-relevant work and inspect placement.

python
1import tensorflow as tf
2
3tf.debugging.set_log_device_placement(True)
4
5with tf.device('/GPU:0'):
6    a = tf.random.normal([1024, 1024])
7    b = tf.random.normal([1024, 1024])
8    c = tf.matmul(a, b)
9
10print(c.shape)

If TensorFlow logs placement on /device:GPU:0, then TensorFlow is truly running the operation on the GPU rather than falling back to the CPU.

Use nvidia-smi While the Program Runs

A practical external check is NVIDIA’s process monitor.

bash
nvidia-smi

While your TensorFlow script is actively running GPU work, nvidia-smi should show:

  • the Python process or notebook kernel
  • GPU memory allocation
  • some level of utilization during computation

This is one of the fastest reality checks because it confirms activity outside the Python process itself.

What About cuDNN Specifically?

cuDNN is not a generic “GPU on” switch. TensorFlow uses cuDNN for certain supported deep-learning kernels, especially:

  • convolution operations
  • some RNN implementations
  • related neural-network primitives

So to infer cuDNN usage, test an operation that normally maps to cuDNN, such as a convolution layer.

python
1import tensorflow as tf
2
3model = tf.keras.Sequential([
4    tf.keras.layers.Input(shape=(64, 64, 3)),
5    tf.keras.layers.Conv2D(32, 3, activation='relu'),
6    tf.keras.layers.Conv2D(64, 3, activation='relu')
7])
8
9x = tf.random.normal([8, 64, 64, 3])
10y = model(x)
11print(y.shape)

If the TensorFlow build is GPU-enabled and the environment is correct, these ops typically use GPU kernels backed by cuDNN where applicable.

Read the Startup Logs

TensorFlow often emits useful startup messages about GPU discovery, loaded libraries, and oneDNN or CUDA initialization. Those logs can reveal:

  • GPU device registration
  • missing CUDA libraries
  • missing cuDNN libraries
  • version mismatch problems

If TensorFlow cannot load the necessary runtime libraries, the logs usually say so early.

Common Failure Modes

You may have one of these situations:

  • TensorFlow sees no GPU at all
  • TensorFlow sees the GPU, but your workload still runs on CPU
  • TensorFlow sees the GPU, but cuDNN-backed ops are unavailable because of version mismatch
  • the Python package was installed without GPU support for that environment

That is why one check is not enough. Device detection, build info, and real operation placement together give a much more reliable answer.

Common Pitfalls

A common mistake is assuming that successful import means CUDA and cuDNN are active. Import success alone proves very little.

Another issue is checking only list_physical_devices('GPU') and stopping there. A visible GPU is good, but actual operation placement still matters.

Developers also sometimes expect every TensorFlow op to use cuDNN. cuDNN is used only for supported GPU kernels, not for every possible operation.

Finally, if nvidia-smi shows no active process during real work, TensorFlow is probably not using the GPU the way you think it is.

Summary

  • First check whether TensorFlow detects any GPU devices.
  • Inspect build info to confirm the package was built with CUDA support.
  • Run real operations and enable device-placement logging to see where they execute.
  • Use nvidia-smi during execution as an external sanity check.
  • cuDNN usage is best inferred from successful GPU execution of supported deep-learning ops such as convolutions.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design