Skip to content

Commit 110ac9d

Browse files
grissom.wangclaude
andcommitted
chore: strengthen check_skills.py, refresh CLAUDE.md, drop AGENTS.md
check_skills.py gains two checks closing a blind spot found while upgrading the knowledge base: file-count claims in search guides and cuda-knowledge/SKILL.md are verified against the filesystem, and every doc file/dir named in structure trees or backticked paths must exist. Negative-tested by injecting 4 error classes (all caught, md5-verified restore). CLAUDE.md: add Development Environment section (remote GPU server workflow, rsync skill deployment), CI validation note, --gpu flag, 13.4 refresh. Remove AGENTS.md - it duplicated CLAUDE.md for Qoder and had drifted out of sync. Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent c819ad7 commit 110ac9d

3 files changed

Lines changed: 161 additions & 102 deletions

File tree

‎AGENTS.md‎

Lines changed: 0 additions & 97 deletions
This file was deleted.

‎CLAUDE.md‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
A multi-skill monorepo for CUDA kernel development assistance, combining scraped NVIDIA documentation (offline RAG knowledge base) with Agent skills that form an automated profile→analyze→optimize loop for GPU kernels. Designed for AI IDE integration (Claude Code, Trae, Qoder). A parallel `AGENTS.md` provides equivalent guidance for Qoder (qoder.com).
7+
A multi-skill monorepo for CUDA kernel development assistance, combining scraped NVIDIA documentation (offline RAG knowledge base) with Agent skills that form an automated profile→analyze→optimize loop for GPU kernels. Designed for AI IDE integration (Claude Code, Trae, Qoder).
88

99
## Commands
1010

@@ -43,6 +43,9 @@ python3 skills/kernel-benchmarker/scripts/benchmark.py <solution.cu> --N=1000000
4343
# Override GPU arch detection (e.g., for cross-compilation)
4444
python3 skills/kernel-benchmarker/scripts/benchmark.py <solution.cu> --N=1000000 --arch=sm_89
4545

46+
# Select a specific GPU device on multi-GPU systems
47+
python3 skills/kernel-benchmarker/scripts/benchmark.py <solution.cu> --N=1000000 --gpu=1
48+
4649
# Force recompilation (bypass PTX cache)
4750
python3 skills/kernel-benchmarker/scripts/benchmark.py <solution.cu> --N=1000000 --force-recompile
4851

@@ -151,7 +154,7 @@ git submodule update --init
151154
### Validation
152155

153156
```bash
154-
# Check cross-skill interface consistency
157+
# Check cross-skill interface consistency + search-guide count/reference claims
155158
python3 scripts/check_skills.py
156159

157160
# Check all documented counts match the filesystem
@@ -162,6 +165,13 @@ python3 scripts/check_counts.py
162165
uv run scripts/check_links.py
163166
```
164167

168+
All three checks run in CI (`.github/workflows/validate.yml`) on every push/PR to `main` — run them locally before committing skill or documentation changes.
169+
170+
## Development Environment
171+
172+
- **No local NVIDIA GPU** — the dev machine is macOS. `nvcc`, `benchmark.py`, and NCU/nsys profiling run on a remote Linux GPU server; the pre-approved `sshpass`/`scp`/`rsync` commands in `.claude/settings.local.json` hold the connection details. Typical flow: copy the kernel + scripts to the server, benchmark/profile there, pull generated reports back into the repo (e.g. `examples/ncu-profile/`) for analysis.
173+
- **Skills deploy via rsync** — `skills/` in this repo is the source of truth; the copies under `~/.claude/skills/` are deployed with `rsync -av skills/<skill-name>/ ~/.claude/skills/<skill-name>/`. Re-run the rsync after editing a skill here, or Claude Code keeps using the stale deployed copy.
174+
165175
## Architecture
166176

167177
### Skills Pipeline (skills/)
@@ -178,7 +188,7 @@ cuda-optimizer (orchestrator)
178188
└── cuda-code-generator → generate/rewrite .cu files with optimizations
179189
```
180190

181-
`cuda-knowledge` (~1420 markdown files) provides API reference based on CUDA Toolkit 13.3 (PTX ISA 9.3, cuBLAS 13.3, Runtime/Driver/Math API 13.3); `cuda-samples` (SKILL.md ~13 KB, 10 reference files 48 KB; ~50 curated entries) provides concrete working code patterns from official NVIDIA samples with GitHub permalinks and key snippets. Both follow progressive disclosure: lightweight SKILL.md stays in context, detailed references load on demand. All three action skills ground their work in both to reduce hallucination. The optimizer drives this loop: **benchmark → evaluate exit conditions → NCU profile → implement optimizations → repeat** until performance converges (<2% improvement over 2 consecutive rounds).
191+
`cuda-knowledge` (~1570 markdown files) provides API reference based on CUDA Toolkit 13.4 (PTX ISA 9.4, cuBLAS 13.4, Runtime/Driver/Math API 13.4); `cuda-samples` (SKILL.md ~13 KB, 10 reference files 48 KB; ~50 curated entries) provides concrete working code patterns from official NVIDIA samples with GitHub permalinks and key snippets. Both follow progressive disclosure: lightweight SKILL.md stays in context, detailed references load on demand. All three action skills ground their work in both to reduce hallucination. The optimizer drives this loop: **benchmark → evaluate exit conditions → NCU profile → implement optimizations → repeat** until performance converges (<2% improvement over 2 consecutive rounds).
182192

183193
### Kernel Interface Convention
184194

@@ -210,8 +220,8 @@ A single-file script with three scraper classes for different NVIDIA doc formats
210220

211221
```text
212222
skills/
213-
cuda-knowledge/references/ # ~1420 .md files, CUDA Toolkit 13.3 (PTX ISA 9.3)
214-
*-docs/ # Scraped documentation: ptx(679), cublas(354), runtime(104), driver(129), math(41), nccl(57)
223+
cuda-knowledge/references/ # ~1570 .md files, CUDA Toolkit 13.4 (PTX ISA 9.4)
224+
*-docs/ # Scraped documentation: ptx(870), cublas(357), runtime(104), driver(129), math(45), nccl(61)
215225
*.md # 11 search guides with grep patterns per API
216226
cuda-samples/
217227
SKILL.md # Quick reference table, optimization mapping, arch compatibility

‎scripts/check_skills.py‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
3. Bottleneck type names consistent across optimizer, analyzer, generator
88
4. All ../ relative paths in SKILL.md files resolve
99
5. Every skill the optimizer references exists
10+
6. File-count claims in search guides / cuda-knowledge SKILL.md match the
11+
filesystem (per-API totals, "N files" body claims, structure-tree
12+
"# N files" comments, "`dir/` (N files)" sub-counts)
13+
7. Doc files/dirs referenced by search-guide structure trees and backticked
14+
paths in guides + SKILL.md actually exist
15+
(version strings and dates are NOT verifiable against the filesystem)
1016
1117
Usage: python3 scripts/check_skills.py
1218
"""
@@ -17,6 +23,17 @@
1723

1824
ROOT = Path(__file__).resolve().parent.parent
1925
SKILLS_DIR = ROOT / "skills"
26+
REFS_DIR = SKILLS_DIR / "cuda-knowledge" / "references"
27+
28+
# search guide -> doc directory it describes
29+
GUIDE_DOCS = {
30+
"ptx-isa.md": "ptx-docs",
31+
"cuda-runtime.md": "cuda-runtime-docs",
32+
"cuda-driver.md": "cuda-driver-docs",
33+
"cuda-math.md": "cuda-math-docs",
34+
"cublas.md": "cublas-docs",
35+
"nccl.md": "nccl-docs",
36+
}
2037

2138
# ---------------------------------------------------------------------------
2239
# Helpers
@@ -198,6 +215,134 @@ def check_cross_reference_consistency() -> list[str]:
198215
return errors
199216

200217

218+
# ---------------------------------------------------------------------------
219+
# Search-guide claim checks (counts + references)
220+
# ---------------------------------------------------------------------------
221+
222+
def _count_md(d: Path) -> int:
223+
return len(list(d.rglob("*.md"))) if d.is_dir() else -1
224+
225+
226+
def _check_count_claims(label: str, text: str, docs_dir: Path, errors: list[str]) -> None:
227+
"""Verify every recognizable file-count claim in `text` against `docs_dir`."""
228+
total = _count_md(docs_dir)
229+
subdir_counts = {
230+
d.name: _count_md(d) for d in docs_dir.iterdir() if d.is_dir()
231+
} if docs_dir.is_dir() else {}
232+
233+
def err(claim: str, actual: int, what: str):
234+
errors.append(f"{label}: claims {claim} but {what} has {actual}")
235+
236+
# "✅ 870 files organized by chapter/topic" and "✅ 45 files: ..."
237+
for m in re.finditer(r'✅ (\d+) files[:\s]', text):
238+
if int(m.group(1)) != total:
239+
err(f"{m.group(1)} files", total, f"{docs_dir.name} total")
240+
241+
# "**Files**: 357 files across 8 chapters"
242+
for m in re.finditer(r'\*\*Files\*\*: (\d+) files across (\d+) chapters', text):
243+
if int(m.group(1)) != total:
244+
err(f"{m.group(1)} files", total, f"{docs_dir.name} total")
245+
chapters = len([d for d in docs_dir.iterdir() if d.is_dir()])
246+
if int(m.group(2)) != chapters:
247+
err(f"{m.group(2)} chapters", chapters, f"{docs_dir.name}")
248+
249+
# "14 modules + 30 data structures" (TOC lines and **Files** lines)
250+
for m in re.finditer(r'(\d+) modules \+ (\d+) data structures', text):
251+
for claimed, name in ((int(m.group(1)), "modules"), (int(m.group(2)), "data-structures")):
252+
actual = subdir_counts.get(name, -1)
253+
if actual >= 0 and claimed != actual:
254+
err(f"{claimed} {name}", actual, f"{docs_dir.name}/{name}")
255+
256+
# Structure-tree comments: "├── data-structures/ # 30 files" and
257+
# "├── 9-instruction-set/ # Complete instruction reference (475 files!)"
258+
for line in text.splitlines():
259+
m = re.match(r'(?:│\s{3})*[├└]──\s+([\w\-.]+)(/)?\s*#.*?(\d+) files', line)
260+
if not m:
261+
continue
262+
name = m.group(1)
263+
actual = subdir_counts.get(name, -1)
264+
if actual >= 0 and int(m.group(3)) != actual:
265+
err(f"{m.group(3)} files in {name}/", actual, f"{docs_dir.name}/{name}")
266+
267+
# "`modules/` (14 files)" sub-counts in SKILL.md per-API blocks
268+
for m in re.finditer(r'`([\w\-/]+)/`\s*\((\d+) files', text):
269+
name = m.group(1).rstrip('/').split('/')[-1]
270+
actual = subdir_counts.get(name, -1)
271+
if actual >= 0 and int(m.group(2)) != actual:
272+
err(f"{m.group(2)} files in {name}/", actual, f"{docs_dir.name}/{name}")
273+
274+
275+
def _check_tree_and_backtick_refs(label: str, text: str, docs_dir: Path,
276+
errors: list[str]) -> None:
277+
"""Every doc file/dir named in structure trees or backticked paths exists."""
278+
DOC_PREFIXES = ("modules/", "data-structures/", "usage/", "api/",
279+
"nccl4py/", "troubleshooting/")
280+
281+
# 1) Structure-tree entries (```text blocks): track nesting via '│ ' depth
282+
stack: list[str] = []
283+
for line in text.splitlines():
284+
m = re.match(r'^((?:│\s{3})*)[├└]──\s+([\w\-.][\w\-./\*]*)', line)
285+
if not m:
286+
continue
287+
depth = len(m.group(1)) // 4
288+
name = m.group(2)
289+
if '*' in name or not name.strip('.'): # globs (9.7.1-*) and ellipsis (...)
290+
continue
291+
stack = stack[:depth]
292+
rel = "/".join(stack + [name.rstrip('/')])
293+
if not (docs_dir / rel).exists():
294+
errors.append(f"{label}: tree entry '{rel}' not found in {docs_dir.name}/")
295+
if name.endswith('/'):
296+
stack.append(name.rstrip('/'))
297+
298+
# 2) Backticked doc paths in prose (e.g. `modules/group__x.md`,
299+
# `ptx-docs/9-instruction-set/...`, `2-using-the-cublas-api/2.7-*.md`)
300+
for ref in set(re.findall(r'`([A-Za-z0-9_\-./]+\.md)`', text)):
301+
if not (ref.startswith(DOC_PREFIXES) or re.match(r'^\d[\w\-]*/', ref)
302+
or re.match(r'^[\w\-]+-docs/', ref)):
303+
continue
304+
rel = re.sub(r'^[\w\-]+-docs/', '', ref)
305+
if '*' in rel: # glob in examples
306+
continue
307+
if not (docs_dir / rel).exists():
308+
errors.append(f"{label}: referenced '{ref}' not found in {docs_dir.name}/")
309+
310+
311+
def check_guide_claims() -> list[str]:
312+
"""Validate count claims and doc references in search guides + SKILL.md."""
313+
errors: list[str] = []
314+
315+
for guide, docs in GUIDE_DOCS.items():
316+
guide_path = REFS_DIR / guide
317+
docs_dir = REFS_DIR / docs
318+
if not guide_path.exists():
319+
errors.append(f"{guide}: guide file not found")
320+
continue
321+
text = guide_path.read_text()
322+
_check_count_claims(guide, text, docs_dir, errors)
323+
_check_tree_and_backtick_refs(guide, text, docs_dir, errors)
324+
325+
# cuda-knowledge/SKILL.md: per-API blocks bind claims to one docs dir
326+
skill_path = SKILLS_DIR / "cuda-knowledge" / "SKILL.md"
327+
if skill_path.exists():
328+
text = skill_path.read_text()
329+
current: list[str] = [] # lines of the current per-API block
330+
current_dir: Path | None = None
331+
for line in text.splitlines() + ["**END** — `references/x-docs/`"]:
332+
m = re.match(r'\*\*.+?\*\* — `references/([\w\-]+)-docs/`', line)
333+
if m or line.startswith("**END**"):
334+
if current_dir is not None:
335+
block = "\n".join(current)
336+
_check_count_claims("SKILL.md", block, current_dir, errors)
337+
_check_tree_and_backtick_refs("SKILL.md", block, current_dir, errors)
338+
current_dir = (REFS_DIR / f"{m.group(1)}-docs") if m else None
339+
current = []
340+
elif current_dir is not None:
341+
current.append(line)
342+
343+
return errors
344+
345+
201346
# ---------------------------------------------------------------------------
202347
# Main
203348
# ---------------------------------------------------------------------------
@@ -213,6 +358,7 @@ def main() -> int:
213358
("Bottleneck type consistency", check_bottleneck_types()),
214359
("Cross-skill paths", check_relative_paths()),
215360
("Cross-reference consistency", check_cross_reference_consistency()),
361+
("Search guide claims & references", check_guide_claims()),
216362
]
217363

218364
total_errors = 0

0 commit comments

Comments
 (0)