Samples leveraging FE's Python interface are located in samples/python. Where a notebook needs a specific GPU, cuDNN version or driver, it checks this itself and skips the affected cells; those requirements are noted below.
-
00_introduction Introduction to the cuDNN Frontend Python API.
-
01_graph_building Overview of the
cudnn.Graphwrapper. Uses CuPy in addition to PyTorch. -
02_low_level_api Overview of the lower-level
pygraphbinding API. -
03_localized_tensors Runs a graph on tensors placed in one locality domain of the GPU. Needs a GPU that reports at least two locality domains (for example Rubin) and a CUDA 13.4 or newer driver.
-
10_matrix_multiplication Matrix multiplication with the graph API.
-
20_layernorm, 21_layernorm, 22_layernorm LayerNorm forward training, backward and inference.
-
23_layer_norm Shows how to run pointwise add and layer norm fusion with intermediate bfloat16 output.
-
24_layernorm, 25_layernorm LayerNorm with zero-centered gamma: forward training and backward, and inference.
-
26_layer_norm Shows how to use layer norm with fusion pattern for relu using a bitmask.
-
27_adaptive_layernorm, 28_adaptive_layernorm Adaptive LayerNorm: forward training and backward, and inference.
-
29_rmsnorm RMSNorm forward and backward.
-
30_batchnorm BatchNorm forward, fused with a ReLU and a comparison mask.
-
31_instancenorm, 32_instancenorm Instance norm, and instance norm fused with an add and a ReLU.
-
50_sdpa Shows how to run causal self attention with dropout in forward pass.
-
51_sdpa Shows how to run causal self attention in bprop.
-
52_sdpa Shows how to run scaled dot product attention (prefill phase) where the K and V caches are stored in non contiguous memory.
-
53_sdpa Shows how to run scaled dot product attention (decode phase) where the K and V caches are stored in non contiguous memory.
-
60_causal_conv1d, 61_causal_conv1d Causal Conv1D forward and backward.
-
62_causal_conv1d_nwh, 63_causal_conv1d_nwh Causal Conv1D in the NWH layout, forward and backward.
-
64_b2b_causal_conv1d, 65_b2b_causal_conv1d Back-to-back Causal Conv1D, forward and backward.
-
66_fft_causal_conv1d, 67_fft_causal_conv1d FFT-based Causal Conv1D, forward and backward. Needs cuDNN 9.26.0 or newer.
-
70_boolean_cmp_logic Boolean comparison and logic fusion. The cuDNN graph cells need a data-center Blackwell GPU.
-
71_custom_reduction_argmax Shows how to pick LLM tokens with the custom-reduction argmax helper: greedy decoding, the NaN rules, speculative-decoding verify, masked argmax and Gumbel-max sampling (cuDNN 9.29 or later, data center Blackwell).
-
gemm_swiglu_mlp_fusion.py The dense bf16 SwiGLU-MLP autograd op (
cudnn.gemm.ops.swiglu_mlp): gate and up GEMMs, SiLU and multiply fused into one forward kernel. Needs an SM100 or newer (Blackwell) GPU.
Standalone scripts for the FROST (CuTeDSL) engines, pure cuDNN frontend Python API, each checked against a torch or fp64 reference:
- frost/gemm: matmul across dtypes, fused epilogues, mainloop fusion, mixed input types, dual-GEMM SwiGLU, MoE grouped matmul. Needs a data-center Blackwell-family GPU (
100 <= SM < 120); on other parts the scripts print[NN] SKIP needs a data-center Blackwell-family GPU (100 <= SM < 120)and exit 0. - frost/linear_attention: GDN, KDA, GDN-2, GDP and Mamba-2 prefill and backward, plus the per-span summary nodes (forward and backward) used for context parallelism.
27_gdn_forward_context.py to 30_gdp_forward_context.py run the forward with
output_context=Trueand hand its context to the backward, under autograd and through the backward op directly. 26_gdn_decode_fused.py drives the fused GDN decode step (cudnn.GdnDecodeFused) from a slot pool for 32 steps at 1 and 4 rows, checked against an fp64-accumulated PyTorch step; the entry serves compute capability 10.x and 12.x GPUs, and elsewhere the script prints[26] SKIPwith the requirement and exits 0. - frost/gated_attention_block: the gated attention block's training forward (
save_for_backward=True) -- the caller-ownedSavedForBackwardrecord and the zero-copysaved_slab_viewsof its projection slab, checked against torch (Rubin only).
python samples/frost/linear_attention/01_gdn_prefill.py
End-to-end samples of open-weight model families in samples/models: one process, a printed table of which provider serves every block of the model, and a self-check against a plain-PyTorch reference. They are not a serving engine and carry no performance table; see models/README.md.
- models/qwen_dense: the dense Qwen 3.5-architecture model.
00_decode.pyruns a plain greedy decode on the reduced seeded model (2 layers at the published widths, no checkpoint, no extra package), token ids in and token ids out, with the linear-attention step oncudnn.GdnDecodeFused. Needs a GPU of compute capability 10.x or 12.x; elsewhere it prints[00] SKIP <requirement>and exits 0. With--model DIRit runs a checkpoint from local disk, text in and text out, with the checkpoint's own tokenizer and chat template: from a prompt, chat messages or the request body a chat client sends (--messages), with the generated text on standard output and every other line of the run on standard error; that needs the packages ofsamples/models/requirements.txt, the checkpoint on local disk (your own download: the sample fetches nothing) and a GPU with room for a bf16 copy of every weight, about 57 GiB free for the 27B checkpoint.02_speculative_decode.pyruns speculative decoding with the checkpoint's drafter for one request: the prompt through decode steps, then per step the drafter's passes on reference blocks, one verify step oncudnn.GdnVerifyFusedand one host read; by default on the reduced seeded model with a seeded drafter, self-checking against decode steps of the same tokens; with--model DIR, a draft vocabulary (--draft-vocab FILE) and, as a JSON object, the speculative configuration of a serving engine (--speculative-config) it writes the text of a checkpoint and reports the tokens a step kept.
python samples/models/qwen_dense/00_decode.py
python samples/models/qwen_dense/02_speculative_decode.py
pip install -r samples/models/requirements.txt
hf download nvidia/Qwen3.8-27B-NVFP4 --local-dir /data/Qwen3.8-27B-NVFP4
python samples/models/qwen_dense/00_decode.py --model /data/Qwen3.8-27B-NVFP4 --prompt "Why is the sky blue?"
python samples/models/qwen_dense/00_decode.py --model /data/Qwen3.8-27B-NVFP4 --messages request.json --max-tokens 256 > answer.txt
Samples leveraging FE's C++ interface are located in samples/cpp.
mkdir build
cd build
cmake -DCUDNN_PATH=/path/to/cudnn -DCUDAToolkit_ROOT=/path/to/cuda ../
cmake --build . -j16
bin/samples
To run a single sample, for eg. TEST_CASE("Cached sdpa", "[graph][sdpa][flash]")
./bin/samples "Cached sdpa"
samples/cpp/sdpa shows how to use cudnn's sdpa operation.
Users are expected to build a graph once and then execute it multiple times. This example shows how to cache cudnn sdpa graph building.
cudnn's sdpa operation enables various customizations on itself. These examples show how to build a graph with sdpa operation for your own custom sdpa needs.
Similar to Fwd SDPA, but here with the ability to use non contiguous K and V caches in combination with page tables, as described in the PagedAttention paper.
- Fwd FP8 SDPA and Bwd SDPA
Extends the sdpa sample to fp8 precision.
Demonstrates the building and execution of a CUDA graph representing the SDPA operation, followed by the update (and another execution) of the CUDA graph with new variant pointers.
The same CUDA graph build-and-update flow for the SDPA backward pass. Needs cuDNN 9.6.0 or newer.
SDPA with score modifiers (softcap and bias) built from graph operations. Needs cuDNN 9.4.0 or newer; the backward sample needs Hopper or newer and is not yet supported on SM120 and above.
Also returns the row max and the sum of exponentials of the attention scores. Needs cuDNN 9.13 or newer.
Attention with a learned sink token. Needs cuDNN 9.13 or newer.
Passes a caller-provided dropout mask and scale. Not supported on Blackwell.
Variable-length sequences described by cumulative sequence lengths. Needs cuDNN 9.24.0 or newer.
Decode and prefill over the same paged K/V caches. Needs cuDNN 9.8.0 or newer.
Block-sparse masking. Needs compute capability 10.x and cuDNN 9.26 or newer.
One graph built with shape overrides enabled and executed for different problem sizes. Needs cuDNN 9.21 or newer at build time.
Measures graph API runtimes. Long-running, so it is off by default.
FP8 attention with a bottom-right aligned causal mask. The forward sample needs a Hopper or data-center Blackwell GPU; the backward sample needs compute capability 10.x.
FP8 attention whose scales are computed from the current tensors. Needs compute capability 10.x and cuDNN 9.13.0 or newer.
MXFP8 block-scaled attention; the backward file covers MHA, GQA and MLA. Needs a data-center Blackwell GPU and cuDNN 9.21.0 or newer.
samples/cpp/convolution shows how to use cudnn fprop, dgrad, wgrad operation and some fusions with them.
Showcases a simple fprop, fprop with pointwise fusion of scale bias and relu, fprop with bias and relu for channels first layout and fusions before convolution in the form of scale bias relu conv and stats. Also epilogue fusion of concatenate.
Showcases fp8 convolution with scaling and amax reduction.
Showcases Int8 convolution.
Has samples for simple dgrad, fusion for dgrad + drelu and Dgrad + Drelu + DBNweight fused operation.
Similar to dgrad was simple wgrad and scale+bias+relu+wgrad fused operation.
Measures convolution graph API runtimes across shapes. This long-running benchmark is included in the samples executable and runs in an unfiltered invocation on supported setups; select tests explicitly to avoid running it unintentionally.
Matmul showcases different matmul samples.
Has samples for simple Matmul, matmul fusions like matmul+abs, matmul+bias and matmul+scale+bias+relu operation.
Showcases fp8 matmul with scaling and amax reduction.
Showcases Int8 matmul.
Mixed precision multiplication between int8 and bf16 data-type with int8 operand being upcasted to bf16
Complex-valued FP32 matmul. Needs cuDNN 9.14.0 or newer.
Matmul with block-scaled operands. Needs cuDNN 9.11.0 or newer.
Hardware-accelerated NVFP4 and MXFP8 block-scaled matmul, with quantize and SwiGLU epilogues and dynamic shape overrides. Needs Blackwell or newer; the quantize epilogue needs compute capability 10.x.
Norm showcases different normalization samples.
Eg for layernorm training, inference and back propagation
Eg for adaptive layernorm training, inference and back propagation
Eg for rmsnorm training, inference and back propagation. Needs Ampere or newer.
Shows different fusions in batch norm fprop and bprop. And split batch norm fusions.
Showcases normalization with block scale quantize epilogue fusion.
Showcases layer normalization with zero centered gamma usage.
Showcases layer normalization and relu with bitmask.
samples/cpp/membound shows how to use the custom reduction (cuDNN 9.29 or later, data center Blackwell).
- Custom reduction: a sum with a helper, mixed precisions, several streams, a body with a constant, and plan serialization.
- argmax and argmin rules:
reduction_modifiers::argmaxandargminwith each NaN rule, checked against a host reference. - LLM token selection: greedy decoding, speculative-decoding verify, masked argmax and Gumbel-max sampling.
- XLA HLO examples: the argmax that XLA emits, at all 31 distinct argmax operand shapes of an XLA HLO corpus, with the XLA and the torch NaN rule. The shapes and their source models are listed in docs/operations/CustomReduction.md.
Misc Miscellaneous samples
pointwise fusions with scalar are shown in this sample.
resample fprop operation with different resampling modes.
How to serialize a graph into a file and read it back on another thread/process.
How to choose the best performing plan among multiple plans suggested by the heuristics.
Shows how to use the native cuda graph API. The samples show how to create cudnn's cuda graph, and how to repeatedly update it with new device buffers for multiple execution.
Showcases a Batch norm example, where only a partial number of SMs participate in executing the kernel.
Showcases how to do deviceless ahead-of-time compilation with the device property descriptor (instead of a cuDNN handle).
Enumerates the engines and their knobs and builds a plan from an explicit engine configuration instead of the heuristics.
Builds a graph's plans from several threads. Long-running, so it is off by default.
A slice of an input tensor feeding a matmul.
Matmul on tensors placed in one locality domain of the GPU. Needs CUDA 13.4 or newer and a driver that provides locality domains.
Scalars baked into the graph at compile time. Needs cuDNN 9.22.0 or newer and a data-center Blackwell GPU.
Reproducer for the CUDA graph topology and lifecycle questions in #186. The multi-device cases need two visible GPUs.
Membound shows the TensorIR memory-bound engine. These samples need a data-center Blackwell GPU and cuDNN 9.22.0 or newer.
- Reshape, Transpose, Slice and Concatenate
Single data-movement operations.
Data movement fused with pointwise operations (reshape then ReLU, transpose then bias add).
Comparison and logical operations fused into one kernel.
Causal conv1d shows the causal conv1d operations. They are not supported on Windows (MSVC).
Forward and backward in the default and NWH layouts. The NWH sample needs cuDNN 9.24.0 or newer.
Two causal conv1d operations fused back to back, forward and backward. Needs cuDNN 9.24.0 or newer.
FFT-based causal conv1d for medium and long sequences, forward and backward. Needs cuDNN 9.26.0 or newer.
Weight-only-quantized grouped matmul over experts, and the BF16 backward. Needs cuDNN 9.18.0 or newer (9.22.0 for the backward).
Samples leveraging FE's C++ 0.x interface are located in samples/legacy_samples.