hipDNN clang-tidy (post-build, changed files only)
Use this skill when the user asks to run clang-tidy over hipDNN, lint what they
changed, or confirm a branch is tidy-clean before pushing.
Do not reach for -DENABLE_CLANG_TIDY=ON for this. That option runs
clang-tidy inline with every compile: it roughly quadruples a clean Windows
build and re-runs on every recompile. clang-tidy needs only the compile
database, so this skill runs it afterwards over a normal build and narrows the
work to what changed.
How it works
scripts/tidy_changed.py drives LLVM's run-clang-tidy against
compile_commands.json:
- Derives changed files from git: the merge base with the base ref, plus
staged, unstaged, and untracked edits.
- Resolves changed headers to translation units. Headers are not
translation units and never appear in the compile database, so a changed
header is walked backwards through the include graph to every
.cpp that
reaches it, transitively. The scan reads #include lines, so it works on a
configured-but-never-compiled tree.
- Writes a filtered
compile_commands.json containing exactly the selected
entries and points run-clang-tidy at it. This is exact, unlike
run-clang-tidy's positional path regexes, which both over- and
under-match.
Diagnostics and exit code match a full run: the configuration comes from
projects/hipdnn/.clang-tidy (211 checks, WarningsAsErrors: '*'), so any
finding exits non-zero.
Inputs
Infer from the user request:
- Build directory: required. Any configured hipDNN build directory holding
compile_commands.json. It does not need ENABLE_CLANG_TIDY=ON; a normal
build (or even a configure-only tree) is the intended input.
- Base ref:
--base <ref>, default origin/develop. Use the branch the
work will merge into.
- Explicit files:
--files <path>... to check specific paths instead of
deriving them from git. Headers are resolved to their includers exactly as
git-derived changes are.
- Everything:
--all to check every translation unit in the database.
- Preview:
--dry-run to list the selected translation units without
running clang-tidy. Use this first when a change touches a widely-included
header, so the user can see the scope before committing to the run.
- Jobs:
-j <n>, default processor count.
- Tool overrides:
--clang-tidy and --run-clang-tidy. Normally omitted:
both are read from the build's CMakeCache.txt (CLANG_TIDY_EXE,
RUN_CLANG_TIDY_EXE), which the configure step already version-checked.
Workflow
Find the build directory. Prefer one the user names; otherwise look for
compile_commands.json under the repository's build directories and confirm
the choice before running.
Then choose the scope. Default to changed files; use --all for a full pass
over every translation unit in the compile database when the user asks to
check the whole project, wants a CI-equivalent result, or when the change
invalidates a per-file scope: edits to .clang-tidy, to compiler flags, or
to a build option that alters preprocessor branches. A full pass on hipDNN
core is roughly 554 translation units and takes minutes, so say so before
starting one, and prefer changed-file scope when a branch is the subject.
Run the script from the repository root, where <skill-directory> is the
directory holding this SKILL.md:
python <skill-directory>/scripts/tidy_changed.py --build-dir <build-dir> [options]
<skill-directory> is the directory of the skill you were invoked from;
use the scripts bundled there. Keep full output in a log when the run is
large, and show the diagnostics rather than the progress lines.
Report the selected translation unit count against the database total, then
the diagnostics. Group repeated header diagnostics: a defect in a header is
reported once per including translation unit, so the raw count overstates
the number of distinct problems.
On a non-zero exit, show each unique diagnostic with its check name. Fix the
code rather than adding suppressions unless the user asks otherwise; a
finding inside a system or vendor header is the exception worth raising with
them.
Report
Summarize:
- Changed files detected and the base ref used
- Selected translation units versus the compile database total
- Unique diagnostics, each with file, line, and check name
- Clean or not, and the exit code
Notes
- The build directory must be configured. Compiled objects are not required:
hipDNN's generated headers (
*_export.h, version.h) are written at
configure time and the FlatBuffers *_generated.h files are committed, so a
configure-only tree analyses identically to a fully built one.
- The compile database is regenerated at configure time. After adding a source
file, reconfigure or the new translation unit will not be in the database.
- The database encodes one configuration's flags. Checking against a Debug or
sanitizer build analyses different preprocessor branches than a Release one.
- On Windows the script disables
bugprone-exception-escape and
performance-noexcept-move-constructor, mirroring the WIN32 block in
projects/hipdnn/cmake/ClangTidy.cmake. Both fire on Microsoft STL internals
rather than on hipDNN code and are clean against libstdc++. Keep the two in
sync.
- Per-directory
.clang-tidy files are not applied. Passing -config-file
disables clang-tidy's directory discovery, so the nested configs under
frontend/tests/, tests/frontend/, and test_sdk/tests/ are inert. This
matches the behaviour of the in-tree tidy targets and of an
ENABLE_CLANG_TIDY=ON build.
- Changing a widely-included header selects many translation units, which is
correct but slow.
--dry-run shows the scope first.
1---2name: hipdnn-tidy3description: Run clang-tidy on hipDNN after a build, scoped to the translation units affected by changed files. Much faster than ENABLE_CLANG_TIDY=ON, which runs clang-tidy inline with every compile. Resolves changed headers to the translation units that include them. Use when asked to run clang-tidy, lint changed files, or check tidy cleanliness before pushing.4argument-hint: "[build-dir] [base=<ref>] [files=<path>...] [all] [dry-run] [jobs=<n>]"5allowed-tools: Bash, Read, Grep, Glob6metadata:7 source: https://skillmd.com/skills/rocm/hipdnn-tidy8---910# hipDNN clang-tidy (post-build, changed files only)1112Use this skill when the user asks to run clang-tidy over hipDNN, lint what they13changed, or confirm a branch is tidy-clean before pushing.1415Do **not** reach for `-DENABLE_CLANG_TIDY=ON` for this. That option runs16clang-tidy inline with every compile: it roughly quadruples a clean Windows17build and re-runs on every recompile. clang-tidy needs only the compile18database, so this skill runs it afterwards over a normal build and narrows the19work to what changed.2021## How it works2223`scripts/tidy_changed.py` drives LLVM's `run-clang-tidy` against24`compile_commands.json`:25261. Derives changed files from git: the merge base with the base ref, plus27 staged, unstaged, and untracked edits.282. Resolves changed **headers** to translation units. Headers are not29 translation units and never appear in the compile database, so a changed30 header is walked backwards through the include graph to every `.cpp` that31 reaches it, transitively. The scan reads `#include` lines, so it works on a32 configured-but-never-compiled tree.333. Writes a filtered `compile_commands.json` containing exactly the selected34 entries and points `run-clang-tidy` at it. This is exact, unlike35 `run-clang-tidy`'s positional path regexes, which both over- and36 under-match.3738Diagnostics and exit code match a full run: the configuration comes from39`projects/hipdnn/.clang-tidy` (211 checks, `WarningsAsErrors: '*'`), so any40finding exits non-zero.4142## Inputs4344Infer from the user request:4546- **Build directory**: required. Any configured hipDNN build directory holding47 `compile_commands.json`. It does **not** need `ENABLE_CLANG_TIDY=ON`; a normal48 build (or even a configure-only tree) is the intended input.49- **Base ref**: `--base <ref>`, default `origin/develop`. Use the branch the50 work will merge into.51- **Explicit files**: `--files <path>...` to check specific paths instead of52 deriving them from git. Headers are resolved to their includers exactly as53 git-derived changes are.54- **Everything**: `--all` to check every translation unit in the database.55- **Preview**: `--dry-run` to list the selected translation units without56 running clang-tidy. Use this first when a change touches a widely-included57 header, so the user can see the scope before committing to the run.58- **Jobs**: `-j <n>`, default processor count.59- **Tool overrides**: `--clang-tidy` and `--run-clang-tidy`. Normally omitted:60 both are read from the build's `CMakeCache.txt` (`CLANG_TIDY_EXE`,61 `RUN_CLANG_TIDY_EXE`), which the configure step already version-checked.6263## Workflow64651. Find the build directory. Prefer one the user names; otherwise look for66 `compile_commands.json` under the repository's build directories and confirm67 the choice before running.6869 Then choose the scope. Default to changed files; use `--all` for a full pass70 over every translation unit in the compile database when the user asks to71 check the whole project, wants a CI-equivalent result, or when the change72 invalidates a per-file scope: edits to `.clang-tidy`, to compiler flags, or73 to a build option that alters preprocessor branches. A full pass on hipDNN74 core is roughly 554 translation units and takes minutes, so say so before75 starting one, and prefer changed-file scope when a branch is the subject.76772. Run the script from the repository root, where `<skill-directory>` is the78 directory holding this `SKILL.md`:7980 ```bash81 python <skill-directory>/scripts/tidy_changed.py --build-dir <build-dir> [options]82 ```8384 `<skill-directory>` is the directory of the skill you were invoked from;85 use the scripts bundled there. Keep full output in a log when the run is86 large, and show the diagnostics rather than the progress lines.87883. Report the selected translation unit count against the database total, then89 the diagnostics. Group repeated header diagnostics: a defect in a header is90 reported once per including translation unit, so the raw count overstates91 the number of distinct problems.92934. On a non-zero exit, show each unique diagnostic with its check name. Fix the94 code rather than adding suppressions unless the user asks otherwise; a95 finding inside a system or vendor header is the exception worth raising with96 them.9798## Report99100Summarize:101102- Changed files detected and the base ref used103- Selected translation units versus the compile database total104- Unique diagnostics, each with file, line, and check name105- Clean or not, and the exit code106107## Notes108109- The build directory must be configured. Compiled objects are not required:110 hipDNN's generated headers (`*_export.h`, `version.h`) are written at111 configure time and the FlatBuffers `*_generated.h` files are committed, so a112 configure-only tree analyses identically to a fully built one.113- The compile database is regenerated at configure time. After adding a source114 file, reconfigure or the new translation unit will not be in the database.115- The database encodes one configuration's flags. Checking against a Debug or116 sanitizer build analyses different preprocessor branches than a Release one.117- On Windows the script disables `bugprone-exception-escape` and118 `performance-noexcept-move-constructor`, mirroring the `WIN32` block in119 `projects/hipdnn/cmake/ClangTidy.cmake`. Both fire on Microsoft STL internals120 rather than on hipDNN code and are clean against libstdc++. Keep the two in121 sync.122- Per-directory `.clang-tidy` files are not applied. Passing `-config-file`123 disables clang-tidy's directory discovery, so the nested configs under124 `frontend/tests/`, `tests/frontend/`, and `test_sdk/tests/` are inert. This125 matches the behaviour of the in-tree tidy targets and of an126 `ENABLE_CLANG_TIDY=ON` build.127- Changing a widely-included header selects many translation units, which is128 correct but slow. `--dry-run` shows the scope first.