diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a426a7425d..be59dd82d5 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,8 +2,8 @@ - [ ] I agree to license this contribution under the terms of [LICENSE.txt](https://github.com/NVIDIA/cudnn-frontend/blob/develop/LICENSE.txt). - [ ] I ran `pre-commit run` and committed any formatting changes. -- [ ] I added GitHub labels: one `cat-*`, one or more `mod-*`, and one `orig-*` (see [label list](https://github.com/NVIDIA/cudnn-frontend/labels)). -- [ ] I set the **Milestone** and **Projects** fields in the sidebar (required to merge; maintainers can set these for external contributions). +- [ ] I reviewed the Hard Rules in the `AGENTS.md` for each directory this PR touches (see [root AGENTS.md § Reviewing a PR](https://github.com/NVIDIA/cudnn-frontend/blob/develop/AGENTS.md#reviewing-a-pr-human-or-agent)) and my changes comply, or I explain the exception below. +- [ ] I added GitHub labels: one `cat-*`, one or more `area:*` / `op:*`, and one `orig-*` (see [label list](https://github.com/NVIDIA/cudnn-frontend/labels)). ## Affected area diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5a87729d36..6dabf552eb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,3 +30,12 @@ repos: types_or: [python, pyi, jupyter] additional_dependencies: [".[jupyter]"] args: ["--line-length", "160"] +- repo: local + hooks: + - id: spdx-license-header + name: SPDX license header + description: "Every first-party source file carries a commented SPDX-License-Identifier line with a non-empty identifier" + language: pygrep + entry: '^\s*(?:#|//|\*|/\*)\s*SPDX-License-Identifier:\s*\S+' + args: [--negate] + types_or: [c++, c, cuda, python] diff --git a/AGENTS.md b/AGENTS.md index 553598023e..dfdb656951 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -52,6 +52,8 @@ pip install --group jax # + jax for the CuTeDSL APIs (jax >= 0.5; XLA ent `setup.py` honors env vars: `CUDNN_PATH`, `CUDA_PATH` / `CUDAToolkit_ROOT`, `DEBUG=1` (debug build), `CMAKE_BUILD_PARALLEL_LEVEL`, `CMAKE_GENERATOR`. +**Editable installs pin one checkout — a worktree or second clone is silently not under test.** `pip install -e .` installs a `sys.meta_path` finder whose `MAPPING` hard-codes the absolute path of the checkout it was installed from; meta-path finders run before `sys.path`, so `PYTHONPATH` cannot shadow it. Before trusting any measurement from a worktree or second clone, confirm the import actually resolves there: `python -c "import cudnn; print(cudnn.__file__)"`. If a deliberately destructive probe changes nothing, suspect the import path before the code. + ## Test ```bash @@ -85,6 +87,9 @@ First invocation builds the hook environments and can take >5 minutes; later run - Frontend-only OSS APIs are experimental; keep the `[cutedsl]` optional-dependency boundary intact (no eager `torch`/`cutlass` imports at `cudnn` import time). - Version lives in three places that must stay in sync: `CMakeLists.txt` (`project(... VERSION ...)`), `include/cudnn_frontend_version.h`, `python/cudnn/__init__.py` (`__version__`). - Runtime debugging: set `CUDNN_FRONTEND_LOG_INFO=1` and `CUDNN_FRONTEND_LOG_FILE=stderr` for FE logs; backend logs via `CUDNN_LOGLEVEL_DBG=3 CUDNN_LOGDEST_DBG=stderr`. +- Public-API signatures evolve **append-only**: new parameters go at the end (with defaults), never inserted mid-signature — positional callers across C++, pybind, and Python wrappers break silently otherwise (review on PR #266). +- Never delete an existing log or diagnostic statement in a cleanup/refactor — several were added after repeated hard-to-repro failures and are the only tripwire for a recurrence (review on PR #280). If one looks redundant, ask before removing. +- Every new source file needs the repo's SPDX/license header (flagged in review on PR #747) — enforced by the `spdx-license-header` pre-commit hook. ## Agent skills @@ -101,6 +106,10 @@ Reusable task recipes live in `skills/` (auto-discovered by Claude Code via `.cl ## PR labels -When opening a pull request, apply **at minimum one label from each group**: one `cat-*` (change type), one or more `mod-*` (affected module), and one `orig-*` (originator). See the full label list at . +When opening a pull request, apply **at minimum one label from each group**: one `cat-*` (change type), one or more `area:*` / `op:*` (affected area), and one `orig-*` (originator). See the full label list at . + +Leave `closed-*` and `open-*` labels for maintainers; Milestone/Projects sidebar fields are set by reviewers/maintainers, not authors. + +## Reviewing a PR (human or agent) -Leave `closed-*` and `open-*` labels for maintainers. +Each Hard Rule is numbered so it can be cited by number in review comments. Before approving or requesting changes on a diff, check it against every Hard Rules section whose directory it touches: [python/cudnn/AGENTS.md](python/cudnn/AGENTS.md) (Rules 1-5, `execute()`/import-time), [python/cudnn/sdpa/AGENTS.md](python/cudnn/sdpa/AGENTS.md) (SDPA Rules S1+), [include/cudnn_frontend/AGENTS.md](include/cudnn_frontend/AGENTS.md) (header-only, warnings-as-errors), plus the conventions in [test/AGENTS.md](test/AGENTS.md) and [samples/AGENTS.md](samples/AGENTS.md). Where a rule names a detector (grep pattern, `set_sync_debug_mode` snippet, a `RED-then-green` test), prefer running or citing it over an eyeballed read. When a review surfaces a new concrete, checkable technique or trap that these guides don't already cover, land it in the relevant `AGENTS.md` in the same PR rather than leaving it in a review comment. diff --git a/include/cudnn_frontend/AGENTS.md b/include/cudnn_frontend/AGENTS.md index 223e30a2be..e9d0dc413c 100644 --- a/include/cudnn_frontend/AGENTS.md +++ b/include/cudnn_frontend/AGENTS.md @@ -7,7 +7,7 @@ The header-only C++ library (CMake INTERFACE target `cudnn_frontend`, C++17). Um - **Header-only**: no `.cpp` files, no link-time dependencies beyond cuDNN/CUDA. New third-party code must be vendored under `thirdparty/` (currently only `nlohmann/json.hpp`, excludable via `CUDNN_FRONTEND_SKIP_JSON_LIB`). - Builds with `-Wall -Wextra -Wpedantic -Werror` (GCC/Clang) and `/W4 /WX` (MSVC) — code must be warning-clean on both. - C++17 only in `include/` (the pybind11 layer under `python/` is C++20). -- Guard anything needing a newer cuDNN with runtime `detail::get_backend_version()` checks (compare against `CUDNN_FRONTEND_VERSION`-style integers, e.g. 9.12.0 → 91200); the same headers must compile against older cuDNN 9.x. +- Guard anything needing a newer cuDNN with runtime `detail::get_backend_version()` checks (compare against `CUDNN_FRONTEND_VERSION`-style integers, e.g. 9.12.0 → 91200); the same headers must compile against older cuDNN 9.x. **Declare unconditionally, gate in the body**: an `#if`-conditional declaration bakes the build-time cuDNN version into the artifact, so a wheel built against 9.23 silently loses the symbol on a 9.24 system — declare the API always and return not-supported at runtime instead (review on PR #246). - clang-format (Google-based, indent 4, 120 cols, `SortIncludes: false`) via `pre-commit run`. ## Layering diff --git a/python/cudnn/AGENTS.md b/python/cudnn/AGENTS.md index babedb9ffa..cc4de0106d 100644 --- a/python/cudnn/AGENTS.md +++ b/python/cudnn/AGENTS.md @@ -38,6 +38,12 @@ Numbered so reviews can cite them; the list grows — append, never renumber. launches, and a second copy of the semantics that can drift). If a packed extent would be zero, bind a never-dereferenced dummy view over storage the contract already guarantees. +- **Overlapping optional declarations are validated as a set, not one by + one.** When two mechanisms can declare the same thing (ragged offsets vs + `cu_seqlen` vs plain `seq_len` tensors), each combination is either + defined or explicitly rejected — an unhandled overlap is an untested code + path with unspecified semantics, and "both supplied" is exactly the case + no per-argument check catches (raised in review on PR #266). **Rule 2 — `execute()` launches exactly the kernels the plan promised: serve the declared layout natively, or decline — never adapt.** @@ -168,6 +174,15 @@ not become a compile key. (#493) still keys `SQ`/`SKV` under `THD_VARLEN` — migrate it to dynamic token extents like the SM100/SM120 THD compiles rather than copying its pattern. +- **Key on exactly the contract-relevant set — no more, no less.** Both + failure modes shipped on PR #553 and were caught in review: *under-keying* + (the cache keyed only `x.shape`/`w.shape` while `check_support()` + validated weight, RoPE, and scale descriptors — a hit can return an + artifact compiled for a different contract, i.e. wrong results) and + *over-keying* (`alpha` passed at launch, `m`/`n`/`k` on a shape-generic + kernel — every miss is a spurious multi-second recompile). Enumerate what + `check_support()` validates and what the kernel specializes on; the key + is that set. **Rule 5 — every torch operation on the execute path is ordered on the LAUNCH stream, never implicitly on torch's current stream.** @@ -192,6 +207,17 @@ the kernel that reads it). context is a no-op — the race only bites direct graph-API users with an explicit handle stream, which is exactly why tests miss it. Order the work by construction rather than relying on the common case. +- **The device is implicit state exactly like the stream.** A `torch.empty` + (or any allocator call) without a device context silently allocates on the + *current* GPU, not the input tensor's — wrap execute-path allocations in + the right device context as well as the stream context. And a raw pointer + argument is a contract: validate device-residency and dtype (a CUDA int64 + tensor, not a host tensor) before handing its address to a kernel — both + flagged in review on PR #517. + +SDPA-specific hard rules (cited as Rule S1, S2, ...) live in +[sdpa/AGENTS.md](sdpa/AGENTS.md) — read it before touching anything under +`python/cudnn/sdpa/`. ## Frontend-only kernel package layout diff --git a/python/cudnn/linear_attention/frost/kernel/gdn2_bprop_f16.py b/python/cudnn/linear_attention/frost/kernel/gdn2_bprop_f16.py index 464416d1d2..3ff24299f6 100644 --- a/python/cudnn/linear_attention/frost/kernel/gdn2_bprop_f16.py +++ b/python/cudnn/linear_attention/frost/kernel/gdn2_bprop_f16.py @@ -1,3 +1,20 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# This kernel is derived from cuDNN, NVIDIA Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from dataclasses import dataclass from functools import lru_cache from typing import NamedTuple, Optional, Type diff --git a/python/cudnn/linear_attention/frost/kernel/kda_bprop_f16.py b/python/cudnn/linear_attention/frost/kernel/kda_bprop_f16.py index bfc27b92de..73cd6a5072 100644 --- a/python/cudnn/linear_attention/frost/kernel/kda_bprop_f16.py +++ b/python/cudnn/linear_attention/frost/kernel/kda_bprop_f16.py @@ -1,3 +1,20 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# This kernel is derived from cuDNN, NVIDIA Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from dataclasses import dataclass from functools import lru_cache from typing import NamedTuple, Optional, Type diff --git a/python/cudnn/ops/fft_causal_conv1d.py b/python/cudnn/ops/fft_causal_conv1d.py index 61c62bf7c5..bebbbd5e46 100644 --- a/python/cudnn/ops/fft_causal_conv1d.py +++ b/python/cudnn/ops/fft_causal_conv1d.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + from typing import List, Tuple import torch diff --git a/python/cudnn/sdpa/AGENTS.md b/python/cudnn/sdpa/AGENTS.md new file mode 100644 index 0000000000..eedeb04f47 --- /dev/null +++ b/python/cudnn/sdpa/AGENTS.md @@ -0,0 +1,34 @@ +# python/cudnn/sdpa — Agent Guide + +SDPA-specific hard rules, on top of the package-wide Rules 1-5 in +[../AGENTS.md](../AGENTS.md). Numbered `S1, S2, ...` so reviews can cite them +without colliding with the package-wide numbering; the list grows — append, +never renumber. + +## Hard rules + +**Rule S1 — THD/packed Stats (LSE) must stay packed: token-major or +head-major, never dense-padded.** + +- Consumers read Stats through the same `cu_seqlen` packing as Q/O: TE and + Megatron take token-major `(T, H)` (cuDNN's TH1 recipe) natively, FA-style + callers take head-major `(H, head_stride)`. A dense-padded declaration + (per-sequence stride) mis-addresses under that packing — it must be + rejected at validation time, not silently accepted and mis-read. +- Validate by stride, not by a `thd`/`packed` flag: token-major is + `stride_h == 1 and stride_s == H`; head-major is `stride_s == 1` with + `stride_h` the declared head stride, which must cover the **packed token + count `T`** — `stride_h >= H` is not the bound; at `T > stride_h` the + per-head slices alias. `T` is a runtime total, so plan-time + classification can only check `stride_s == 1 and stride_h >= 1`. In the + THD path the packed total is a *device* value — Rule 3 bans reading it + back, so `stride_h >= T` is **caller contract** (stated in + `_thd_lse_view`'s docstring), not something the adapter verifies: + `as_strided` bounds-checks storage capacity, never overlap. Do not "fix" + this with a host-side length read; an in-kernel assert is the only + legal detector. See the THD classification sites in `fwd/api_dsl.py` + (duplicated at the two THD compile-key call sites — extract rather than + re-copy if you touch it, per Rule 3's "suspect duplicated logic first"). +- Covered by `test_fwd_probe_rejects_invalid_stats_metadata` and the + `stats_layout`-parametrized THD tests (`test_dsl_sm100_thd_stats` and + siblings) in `test/python/sdpa/frost/`. diff --git a/samples/cpp/causal_conv1d/fft_causal_conv1d.cpp b/samples/cpp/causal_conv1d/fft_causal_conv1d.cpp index 2704e6b495..1f695f44d2 100644 --- a/samples/cpp/causal_conv1d/fft_causal_conv1d.cpp +++ b/samples/cpp/causal_conv1d/fft_causal_conv1d.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. + * SPDX-License-Identifier: MIT * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), diff --git a/test/AGENTS.md b/test/AGENTS.md index ff216bfca8..af652bdaff 100644 --- a/test/AGENTS.md +++ b/test/AGENTS.md @@ -43,6 +43,7 @@ pytest fe_api/gemm/ # OSS kernel tests ### Conventions for new tests - Mark with a level (`@pytest.mark.L0` ... `L4`): L0 must stay fast (default CI smoke); big parameter sweeps go to higher levels. +- **Check for a module-level `pytestmark` before adding per-test markers.** Many files apply a level or capability marker file-wide (`pytestmark = ...` near the top); duplicating it on each test is noise, and suggesting it in review wastes a round-trip (recurred on PRs #814, #811, #797). - Gate on capability, don't assume it: skip via `check_support()` failures, `cudnn.backend_version()`, and `torch.cuda.get_device_capability()`. - Compare against a reference implementation (see existing `*_ref.py` / `*_reference.py` patterns) with dtype-appropriate tolerances. - **Scale the tolerance to the tensor, not to the dtype alone.** A fixed absolute bound quietly becomes wrong when magnitudes grow: GQA dK/dV sum over `h_q/h_kv` query heads, so at a group size of 4 the *relative* error stays ~0.5% while `|dv|` peaks near 9.6 and blows a bound that passed at `h_kv == h_q`. Compare against `TOL * max(|ref|.max(), 1.0)`, or the next GQA ratio someone adds will look like a correctness regression. diff --git a/test/python/fe_api/grouped_gemm/test_grouped_gemm_glu_hadamard_quant.py b/test/python/fe_api/grouped_gemm/test_grouped_gemm_glu_hadamard_quant.py index 5d5b20e3e3..7daaa6c1b1 100644 --- a/test/python/fe_api/grouped_gemm/test_grouped_gemm_glu_hadamard_quant.py +++ b/test/python/fe_api/grouped_gemm/test_grouped_gemm_glu_hadamard_quant.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + """Tests for grouped GEMM GLU + Hadamard + Quant forward fusion (SM100+).""" from typing import Dict, Optional diff --git a/test/python/gemm/frost/test_template_epilogue_parity.py b/test/python/gemm/frost/test_template_epilogue_parity.py index d000958ab0..4d91965c35 100644 --- a/test/python/gemm/frost/test_template_epilogue_parity.py +++ b/test/python/gemm/frost/test_template_epilogue_parity.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + """The epilogue drain is ONE logic across all 20 kernel templates. Source-level only -- no GPU, no render, no JIT. See CLAUDE.md diff --git a/test/python/test_fft_causal_conv1d.py b/test/python/test_fft_causal_conv1d.py index f718902399..ae5c5611f3 100644 --- a/test/python/test_fft_causal_conv1d.py +++ b/test/python/test_fft_causal_conv1d.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + import math import pytest diff --git a/test/python/test_sdpa_benchmark_single_sdpa.py b/test/python/test_sdpa_benchmark_single_sdpa.py index 1ff794d494..cbc821c792 100644 --- a/test/python/test_sdpa_benchmark_single_sdpa.py +++ b/test/python/test_sdpa_benchmark_single_sdpa.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + import sys from pathlib import Path from typing import Optional