cuDNN

Also known as: CUDA Deep Neural Network library

On this page 7

cuDNN, the CUDA Deep Neural Network library, is a proprietary NVIDIA library of GPU-accelerated primitives for deep neural networks, such as convolution, normalization, activation, pooling, recurrent layers and attention. Among AI frameworks & tools, it sits below the user-facing frameworks: PyTorch, TensorFlow and JAX do not write most of their GPU kernels themselves but call cuDNN to execute the heavy operators on NVIDIA hardware.

The library matters because the same mathematical operation can run through many different algorithms, and the fastest one depends on tensor shapes, data type, memory layout and GPU generation. cuDNN packages hand-tuned and runtime-compiled kernels, plus heuristics that select an algorithm, so framework developers get near-peak performance in artificial intelligence workloads without writing low-level CUDA code for every case.

How cuDNN executes neural network operations

cuDNN works as a host-side library that launches GPU kernels on behalf of a framework. The framework describes an operation with descriptors (tensor dimensions, strides, data type, convolution padding and stride), asks cuDNN which execution engines can handle it, and then runs the chosen engine with a caller-provided workspace buffer in GPU memory.

Since version 8, the core interface is the graph API: an operation is expressed as a small graph of nodes, for example a convolution followed by a bias addition and a ReLU activation. cuDNN can then fuse several operations into one kernel, which avoids writing intermediate tensors to memory. The open-source cuDNN frontend wraps this C interface in C++ and Python, and it is the recommended entry point for new code. The older legacy API, with fixed calls such as a single convolution forward function, is deprecated in cuDNN 9.

The table below summarizes the main stages of a single cuDNN call as a framework performs it.

StageWhat happensWhy it matters
DescribeTensors and the operation graph are definedShapes and layout decide which kernels apply
Query enginesHeuristics rank candidate engines and configurationsA good ranking avoids slow trial runs
Finalize planAn execution plan is built, sometimes compiled at runtimeFused kernels may need compilation time
ExecuteThe plan runs on a CUDA stream with a workspaceWorkspace size limits the available algorithms
CacheThe framework stores the plan for repeated shapesRepeated steps skip selection overhead
Stages of a cuDNN operation

Operations and algorithms inside cuDNN

cuDNN covers the operators that dominate deep learning compute time. Convolutions have the richest choice of algorithms, because each trades memory, numerical behavior and speed differently. Implicit GEMM maps convolution to matrix multiplication without materializing the expanded input, while Winograd and FFT-based methods reduce arithmetic for specific filter sizes at the cost of extra workspace and slightly different rounding.

The following table lists the major operation families and the algorithmic options cuDNN offers for them.

Operation familyTypical algorithms or featuresCommon use
ConvolutionImplicit GEMM, Winograd, FFT, directImage models, audio models, U-Nets
Matrix multiplicationGraph API matmul with fused epiloguesLinear layers with bias and activation
AttentionFused scaled dot-product attention, flash-styleTransformers and language models
NormalizationBatch, layer, instance and RMS normalizationStabilizing training
Pointwise and reductionActivations, softmax, fused elementwise opsEpilogues after matmul or convolution
Recurrent layersLSTM and GRU kernelsSequence models and older speech systems
Main operation families in cuDNN

Precision support follows the hardware. cuDNN uses Tensor Cores for FP16 and BF16, enables TF32 on Ampere and newer GPUs, and supports FP8 on Hopper and later architectures for selected operations. Lower precision usually doubles throughput or better, but it requires loss scaling or careful accumulation to keep training stable.

cuDNN is one layer in a stack of NVIDIA and third-party libraries, and confusing these layers is a frequent source of misunderstanding. cuDNN supplies operator kernels, while other tools handle linear algebra, communication, model compilation or deployment.

The comparison below places cuDNN next to the neighbors that practitioners most often mix it up with.

LibraryRoleRelationship to cuDNN
cuDNNNeural network operator kernelsCalled by frameworks for convolution, attention, normalization
cuBLASDense linear algebra (GEMM)Complements cuDNN for plain matrix products
NCCLMulti-GPU collective communicationHandles gradients between GPUs, not compute
TensorRTInference optimizer and runtimeBuilds optimized engines, partly using its own kernels
TritonLanguage for writing custom GPU kernelsAlternative when cuDNN lacks a fused pattern
MIOpenAMD equivalent within ROCmSame purpose on AMD GPUs
oneDNNIntel library for CPUs and GPUsSame purpose on Intel hardware
cuDNN and neighboring libraries

Compilers such as XLA and PyTorch’s TorchInductor increasingly generate their own kernels, yet they still delegate convolutions and attention to cuDNN when its kernels are faster. The choice is therefore not cuDNN or a compiler, but which backend wins for each operator.

Installing and configuring cuDNN in practice

Most users never install cuDNN by hand, because framework packages bundle a compatible build. PyTorch wheels, for instance, depend on an NVIDIA cuDNN wheel matched to the CUDA major version. Manual installation matters for custom builds, containers and C++ applications, where the cuDNN version must match the CUDA toolkit major version and the GPU driver must be recent enough.

Framework settings control how cuDNN chooses algorithms. The table below covers the decisions that affect speed and reproducibility most.

SituationRecommended settingReason
Fixed input shapes in trainingEnable autotuning (benchmark mode)Measured selection finds the fastest kernel
Variable input shapesKeep autotuning offRe-tuning every new shape costs time
Bitwise reproducibility neededRequest deterministic algorithmsSome fast kernels use nondeterministic atomics
Tight GPU memoryLimit workspace sizePrevents out-of-memory errors, may slow kernels
Mixed-precision trainingUse BF16 or FP16 with Tensor CoresLarge throughput gain on modern GPUs
Common configuration decisions

In PyTorch, these choices appear as the cudnn.benchmark and cudnn.deterministic flags. In TensorFlow, determinism is requested through an operation-determinism setting, and JAX reaches cuDNN through XLA.

Limitations and common mistakes

cuDNN is fast within its scope, but its scope is narrow. It runs only on NVIDIA GPUs, it is closed-source except for the frontend layer, and its license permits redistribution only under NVIDIA terms. These facts shape portability decisions for teams that also target AMD, Intel or Apple hardware.

  • Version mismatch errors: a framework built against one cuDNN major version fails to load another; matching the bundled versions avoids this.
  • Assuming determinism by default: identical runs can differ slightly unless deterministic algorithms are explicitly requested.
  • Benchmark mode with dynamic shapes: autotuning every new batch size can make training slower, not faster.
  • Ignoring memory layout: channels-last (NHWC) tensors often run faster with Tensor Cores than channels-first (NCHW) tensors.
  • Expecting every fusion to exist: unsupported graph patterns fall back to separate kernels, so the speedup varies by model.

A plain-language summary

cuDNN is a toolbox of very fast building blocks for neural networks. It runs on NVIDIA graphics cards. Popular AI programs use it in the background. Most people never see it.

Think of a professional kitchen. The chef plans the meal, which is like the AI framework. cuDNN is the set of specialized machines that chop, mix and bake very quickly. The chef does not build those machines. The chef simply uses them. The key point is simple: cuDNN makes AI training and use much faster on NVIDIA hardware.

An example from practice

A medical imaging team trains a 3D U-Net segmentation model on CT scans with PyTorch on four NVIDIA data center GPUs. The first training run uses FP32 tensors in channels-first layout with default settings, and one epoch takes about 95 minutes.

The engineers make three changes that all act through cuDNN. They switch to BF16 mixed precision so convolutions use Tensor Cores, convert tensors to the channels-last layout, and enable benchmark mode because every training crop has the same fixed size. Each change lets cuDNN pick a faster convolution engine for the same shapes.

After the changes, one epoch takes roughly 40 minutes, and validation accuracy stays within normal run-to-run variation. For the final audit run, the team turns on deterministic algorithms and accepts a modest slowdown, so that regulators can reproduce the reported results exactly.