Why Do cuDNN Execution Plans Differ? Checking Choices Across Input Shapes
cuDNN is NVIDIA’s library for deep-learning operations on NVIDIA GPUs, including convolution, matrix multiplication, attention, normalization, and fused operations. Even the same model can have different supported implementations when tensor shapes, data types, memory layouts, GPU, or cuDNN version change. When investigating a speed difference, do not assume that the same model implies the same execution path: compare the actual workload and the selected plan.
Why Do cuDNN Execution Plans Differ? Checking Choices Across Input Shapes
cuDNN is NVIDIA’s library for deep-learning operations on NVIDIA GPUs, including convolution, matrix multiplication, attention, normalization, and fused operations. Even the same model can have different supported implementations when tensor shapes, data types, memory layouts, GPU, or cuDNN version change. When investigating a speed difference, do not assume that the same model implies the same execution path: compare the actual workload and the selected plan.
How does cuDNN turn operations into GPU work?
In the cuDNN graph API, an operation graph describes the relationships among tensor computations. For example, it can describe a convolution whose output is added to a bias and passed through an activation. This graph is a mathematical specification, not a request for one particular GPU kernel. Several engines and configurations may implement the same graph.
cuDNN uses heuristics to produce candidate execution plans, checks whether they support the graph and device, then builds and executes a plan. Candidates are ordered by expected performance, not by a guarantee from benchmarking your application. Mode A searches quickly; Mode B may spend more CPU time finding candidates. Fallback heuristics can find functional alternatives without promising optimal performance. With the cuDNN Frontend API directly, an application can inspect the plan count, support checks, built plan, and per-plan workspace. Through a framework, the framework may own graph construction and selection, so your application code may not expose all of those details.
A cuDNN operation graph is also different from a CUDA Graph. The former describes tensor-operation dataflow; the latter is a CUDA mechanism for reusing submitted GPU work. They can be used together, but the terms are not interchangeable.
Why can a shape change the candidates?
Plan eligibility and ranking depend on more than an operation’s name. Tensor dimensions and strides, data type, graph connections, GPU architecture, and installed library/backend versions can limit the candidates. cuDNN tensor descriptions include both dimension sizes and strides, so two tensors that look alike at a high level may still have different memory layouts.
Hypothetical example: Run the same image-classification convolution with batch sizes 1 and 32. The weights and layer are unchanged, but the input dimensions differ. That may change which plans are available or efficient; cuDNN could choose a different plan, or the same plan could take a different amount of GPU time. This is a possibility, not a promise that increasing batch size changes the plan or makes it faster. To narrow down the cause, also hold data type, strides/layout, fused neighboring operations, available memory, and software versions constant.
What should you compare for each symptom?
Start by checking that the measurements represent the same input and execution path. Record the framework backend, tensor dimensions, data type and strides, GPU, cuDNN version, workspace requirement, and what interval was timed.
| Symptom | Compare first | Caution |
|---|---|---|
| Latency changes when only batch size changes | Actual dimensions, plan list/selection, throughput and per-batch latency | Separate a plan change from the greater amount of work. |
| One input is unsupported or plan building fails | Data type, strides/layout, operation combination, and version’s GPU/library support | Check the installed version’s support conditions before blaming the GPU. |
| Time changes after a library update | cuDNN backend actually loaded by the framework, driver/CUDA combination, plan and workspace | The installed package version may not be the library loaded at runtime. |
| cuDNN call looks fast but the model is slow | Pre/post-processing, data movement, synchronization, and end-to-end request time | One kernel’s time is not the full model’s throughput. |
A five-step diagnostic procedure
Assume a compatible NVIDIA GPU and CUDA/cuDNN installation and an application that can reproduce the workload. Check API and support combinations against the installed cuDNN and framework integration.
Freeze a baseline input. Record batch size, dimensions, data type, strides/layout, operation graph, GPU, and software versions. Change one property at a time between a fast and slow input.
Enable logging and reproduce in a new process. Backend API logs can record public API parameters and error information. Set environment variables before starting the process because cuDNN reads them during initialization. Logs may contain device pointers and execution details and can add overhead; use them only for a diagnostic run.
CUDNN_LOGLEVEL_DBG=3 CUDNN_LOGDEST_DBG=stderr python app.pyFrontend logging uses separate settings such as
CUDNN_FRONTEND_LOG_INFO=1andCUDNN_FRONTEND_LOG_FILE=stderr. Enabling one logger does not capture both layers.If you use Frontend directly, inspect candidates and support. Build the graph, create heuristic plans, check
check_support(), and record the selected plan index and its workspace. Candidate priority is not guaranteed to match measured performance.Use a profiler to confirm GPU work. If a framework hides the plan, combine available Frontend/API logs with supported kernel traces. Separate CPU plan construction and initialization from repeated execution; inspect errors for rejected plans or fallback paths.
Turn logging off and measure again under the same conditions. Control warm-up and synchronization, then record repeated execution time, end-to-end latency, and throughput. If the result is unexpected, change one baseline property at a time: dimensions, strides, data type, workspace constraint, or software version.
How do heuristic rank and actual speed differ?
Heuristics narrow the candidates for a graph. NVIDIA describes the first supported candidate from Mode A or B as expected to perform well, not as guaranteed to be fastest in a particular application. With the direct API, autotuning can execute and time candidates on the target device. The search and build cost may exceed the benefit for a short task, so compare plans using a representative input and repeated measurements on the same device.
Workspace is GPU memory the application must provide to execute a plan. Check each plan’s requirement against memory limits imposed by your application or framework. Whether such a limit changes candidate selection depends on the selection API and integration; do not assume every framework automatically switches plans in the same way. Even if a profiler shows a faster kernel, preprocessing, transfers, or synchronization may still dominate end-to-end latency.
In practice, tabulate the differences between fast and slow inputs, inspect the observable plan or kernel path, change one condition, and measure again. If a framework does not expose plan selection, use its supported logs and a profiler, and state what you could actually observe. When support or results differ, consult the support matrix and release notes for the installed cuDNN version.
References
[NVIDIA cuDNN Overview](https://docs.nvidia.com/cudnn/overview)
[NVIDIA cuDNN Graph API](https://docs.nvidia.com/cudnn/developer/graph-api)
[NVIDIA cuDNN Core Concepts: Tensors and Layouts](https://docs.nvidia.com/cudnn/developer/core-concepts)
[NVIDIA cuDNN Frontend Developer Overview](https://docs.nvidia.com/cudnn/developer/overview)
[NVIDIA cuDNN Frontend Debugging](https://docs.nvidia.com/cudnn/latest/developer/debugging/)
[NVIDIA cuDNN Backend Troubleshooting](https://docs.nvidia.com/deeplearning/cudnn/backend/latest/reference/troubleshooting.html)