|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """Verify documented file counts match actual filesystem. |
3 | 3 |
|
4 | | -File sizes are documented as `du -sh` (disk usage), which includes filesystem |
5 | | -block overhead. This script compares counts exactly and sizes within tolerance. |
| 4 | +File sizes are documented as summed file bytes (deterministic on every |
| 5 | +platform). `du -sh` was rejected because its block-size accounting differs |
| 6 | +between filesystems — macOS and Linux CI disagreed on the same tree. |
| 7 | +Counts are compared exactly and sizes within tolerance. |
6 | 8 |
|
7 | 9 | Usage: python3 scripts/check_counts.py |
8 | 10 | """ |
9 | 11 |
|
10 | 12 | import re |
11 | | -import subprocess |
12 | 13 | import sys |
13 | 14 | from pathlib import Path |
14 | 15 |
|
|
38 | 39 | } |
39 | 40 |
|
40 | 41 | SKILL_MD_CHECKS = [ |
41 | | - ("PTX ISA", "ptx-docs", 505, "6.8MB"), ("CUDA Runtime API", "cuda-runtime-docs", 101, "1.2MB"), |
42 | | - ("CUDA Driver API", "cuda-driver-docs", 135, "2.0MB"), ("cuBLAS", "cublas-docs", 320, "2.9MB"), |
43 | | - ("CUDA Math API", "cuda-math-docs", 45, "548K"), ("NCCL", "nccl-docs", 61, "876K"), |
| 42 | + ("PTX ISA", "ptx-docs", 505, "5.6MB"), ("CUDA Runtime API", "cuda-runtime-docs", 101, "892K"), |
| 43 | + ("CUDA Driver API", "cuda-driver-docs", 135, "1.8MB"), ("cuBLAS", "cublas-docs", 320, "2.1MB"), |
| 44 | + ("CUDA Math API", "cuda-math-docs", 45, "455K"), ("NCCL", "nccl-docs", 61, "753K"), |
44 | 45 | ] |
45 | 46 |
|
46 | 47 |
|
47 | 48 | def count_md_files(d: Path) -> int: |
48 | 49 | return len(list(d.rglob("*.md"))) |
49 | 50 |
|
50 | 51 |
|
51 | | -def du_size_str(d: Path) -> str: |
52 | | - """Return 'du -sh' style size string, e.g. '2.3M' or '528K'.""" |
53 | | - result = subprocess.run(["du", "-sh", str(d)], capture_output=True, text=True) |
54 | | - return result.stdout.split()[0] # e.g. "2.3M" or "528K" |
| 52 | +def byte_size_str(d: Path) -> str: |
| 53 | + """Return deterministic size string from summed .md file bytes. |
| 54 | +
|
| 55 | + e.g. '5.6M' or '455K' — identical on macOS dev machines and Linux CI. |
| 56 | + """ |
| 57 | + total = sum(f.stat().st_size for f in d.rglob("*.md")) |
| 58 | + if total >= 1024 * 1024: |
| 59 | + return f"{total / 1024 / 1024:.1f}M" |
| 60 | + return f"{round(total / 1024)}K" |
55 | 61 |
|
56 | 62 |
|
57 | 63 | def parse_size(s: str) -> float: |
@@ -102,7 +108,7 @@ def main() -> int: |
102 | 108 | print("\n=== cuda-knowledge/SKILL.md Counts ===") |
103 | 109 | for api_name, dir_name, expected_files, expected_size in SKILL_MD_CHECKS: |
104 | 110 | actual_files = count_md_files(REFS_DIR / dir_name) |
105 | | - actual_size = du_size_str(REFS_DIR / dir_name) |
| 111 | + actual_size = byte_size_str(REFS_DIR / dir_name) |
106 | 112 |
|
107 | 113 | if actual_files != expected_files: |
108 | 114 | print(f" ✗ {api_name}: {expected_files} documented, {actual_files} actual files") |
|
0 commit comments