diff --git a/docs/KERNELS.md b/docs/KERNELS.md index e6c3c96e..4966d301 100644 --- a/docs/KERNELS.md +++ b/docs/KERNELS.md @@ -21,7 +21,7 @@ pass reached; the Rows nothing ran section lists the rest. | library | version | domain | rows | run | ops | graph | cases | pass | fail | worst rel_l2 | median us | |---|---|---|---|---|---|---|---|---|---|---|---| | `libavx` | 0.1.0 | host | 100 | 42 of 100 | 100 of 147 | 43 of 43 | 734 | 734 | 0 | 9.01e-04 | 78.91 | -| `libr4d` | 0.5.0 | device | 287 | 48 of 287 | 142 of 147 | 43 of 43 | 734 | 734 | 0 | 4.27e-03 | 12.78 | +| `libr4d` | 0.5.0 | device | 291 | 48 of 291 | 142 of 147 | 43 of 43 | 734 | 734 | 0 | 4.27e-03 | 12.78 | | `libref` (oracle) | 0.1.0 | host | 123 | 42 of 123 | 123 of 147 | 43 of 43 | 734 | 734 | 0 | 0.00e+00 | - | Rows declaring an optional hook (tuning, fusion, weight layout): @@ -34,7 +34,7 @@ Rows declaring an optional hook (tuning, fusion, weight layout): ## Rows nothing ran -132 of 510 declared row(s) were reached by a case in this pass. +132 of 514 declared row(s) were reached by a case in this pass. `libavx`: 58 row(s) not reached: @@ -99,7 +99,7 @@ Rows declaring an optional hook (tuning, fusion, weight layout): | `avx_silu` | `silu` | | `avx_softmax` | `softmax` | -`libr4d`: 239 row(s) not reached: +`libr4d`: 243 row(s) not reached: | kernel | op | |---|---| diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2d9620da..ed4ff261 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -594,6 +594,18 @@ set_tests_properties(ops_doc PROPERTIES TIMEOUT ${RAD_TEST_TIMEOUT} ENVIRONMENT "ROCR_VISIBLE_DEVICES=99") +# docs/KERNELS.md is generated by rad-kbench and merged by hand; a partial merge leaves a +# library's "rows not reached" header from one run above a table from another (v1.13.0: 239 +# against 243 rows). The counts must agree with each other and with the headline; cheap. +if(EXISTS ${CMAKE_SOURCE_DIR}/docs/KERNELS.md) + add_test(NAME kernel_report_check + COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/kernel_report_check.sh + ${CMAKE_SOURCE_DIR}/docs/KERNELS.md) + set_tests_properties(kernel_report_check PROPERTIES + LABELS "fast;unit" + TIMEOUT ${RAD_TEST_TIMEOUT}) +endif() + # tools/rad-export. Its standard-library checks always run; the merge arithmetic runs where torch # and safetensors import, and the PEFT comparison where peft and transformers do too. find_program(RAD_PYTHON3 NAMES python3) diff --git a/tests/kernel_report_check.sh b/tests/kernel_report_check.sh new file mode 100755 index 00000000..fc411796 --- /dev/null +++ b/tests/kernel_report_check.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# kernel_report_check.sh -- the checked-in kernel report is internally consistent. +# +# docs/KERNELS.md is generated by `rad-kbench --report` and reviewed by hand. A hand-merged +# regeneration can carry a per-library "N row(s) not reached" header from one run and the table +# below it from another: at v1.13.0 the libr4d header says 239 while its table lists 243 rows +# (the four kv_store_streamed rows landed in 486c9331 without the count moving), so the section +# total (378) and the headline "132 of 510 declared row(s) were reached" both read four rows +# short of the tables. The generator cannot produce this from one run -- header and table come +# from one vector -- so the report is checked here, and a partially regenerated file fails. +# +# A check that cannot fail is not a check (docs/DEVLOG-decode-floor.md). +set -u +REPORT=$1 +test -f "$REPORT" || { echo "kernel_report_check: no report at $REPORT"; exit 1; } + +python3 - "$REPORT" <<'PY' +import re, sys +lines = open(sys.argv[1]).read().split("\n") +pat = re.compile(r"`lib\w+`: (\d+) row\(s\) not reached:") +heads = [(i, m.group(1)) for i, l in enumerate(lines) if (m := pat.match(l))] +bad = 0 +for j, (a, claimed) in enumerate(heads): + # The library's table ends at the next library header or the next section header. + b = len(lines) + for i in range(a + 1, len(lines)): + if pat.match(lines[i]) or lines[i].startswith("## "): + b = i + break + rows = sum(1 for l in lines[a:b] if l.startswith("| `")) + name = re.match(r"`(\w+)`", lines[a]).group(1) + print(f" {name}: header {claimed}, table {rows}") + if int(claimed) != rows: + bad += 1 +text = "\n".join(lines) +m = re.search(r"(\d+) of (\d+) declared row\(s\) were reached", text) +if m: + ran, declared = int(m.group(1)), int(m.group(2)) + missed = sum(int(x) for x in pat.findall(text)) + if ran + missed != declared: + print(f" headline: {ran} reached + {missed} not reached != {declared} declared") + bad += 1 +if bad: + print(f"kernel_report_check: {bad} inconsistent count(s); regenerate the report from one run.") + sys.exit(1) +print("kernel_report_check: the report's counts agree.") +PY