Skip to content

hip_f16_audit: order by narrowings and roll up the tail after 20 rows - #2417

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-prs2/audit-rollup
Nov 14, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-prs2/audit-rollup

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

The table this tool prints is now 62 rows long, and the files that matter were buried alphabetically

engine#2415 made the narrowing arm count (_Float16) casts. On gpu-kernels 96593660718d that is 62 narrowings across 68 kernel files, and the closing line — "3 narrowing(s), which are format writes unless a file says otherwise" — was a footnote under a table nobody reads in full. I raised it on that PR; this is the change.

What it does

$ hip_f16_audit.py --dir <gpu-kernels @ 96593660718d>
  hrx_dense_prefill.hip                926 lines  narrowings  11  f16 accumulators -
  hrx_prefill_gemm.hip                1567 lines  narrowings  10  f16 accumulators -
  gptoss_attn_sink_decode.hip          323 lines  narrowings   4  f16 accumulators -
  gptoss_rope_kv_decode.hip             79 lines  narrowings   3  f16 accumulators -
  …
  … 48 more file(s), 4 narrowing(s) among 4 of them (--top 0 for every row)
hip_f16_audit: 68 kernel file(s), no f16 accumulator; 62 narrowing(s), which are format writes unless a file says otherwise

Rows sort by (-narrowings, -accumulators, file), so the files with something to look at come first — before this change the top of the list was alphabetical (f16_mask.hip first, and the two 10-plus files 40 rows down).

Verified

$ hip_f16_audit.py --top 0 | grep -c narrowings     -> 68 rows
$ hip_f16_audit.py --json | jq length               -> 68
$ hip_f16_audit.py --self-test                      -> ok   (two arms: the busiest file sorts first, and its count)
$ ctest -R hip_f16_audit                            -> passed
$ ./scripts/pre-pr-checks.sh                        -> all 9 check(s) green, 0 skipped

No change to what is counted or what fails: an f16 accumulator still fails, a narrowing is still a note, and the exit codes are the same.

Refs engine#2415 (the count this makes readable), engine#2409 / #2411 / #2413 (the tool and its gates), engine#2406 (the scope line it discharges).

engine#2415 made the narrowing arm count (_Float16) casts, which on gpu-kernels
96593660718d is 62 rows across 68 kernel files. A closing line saying '3
narrowing(s), which are format writes unless a file says otherwise' was a footnote
under a table nobody reads in full, and the files worth looking at -- 11 and 10
narrowings in hrx_dense_prefill.hip and hrx_prefill_gemm.hip -- were buried
alphabetically. I raised this on #2415; this is the change.

  rows sort by (-narrowings, -accumulators, file)
  the first 20 print, then '... 48 more file(s), 4 narrowing(s) among 4 of them (--top 0 for every row)'
  --top N overrides, --top 0 prints every row (the pre-rollup behaviour)
  --json unchanged: still exactly the JSON, no rollup line

Measured on the real tree: the first four rows are hrx_dense_prefill 11,
hrx_prefill_gemm 10, gptoss_attn_sink_decode 4, gptoss_rope_kv_decode 3; --top 0
still prints 68 rows; --json still parses as 68.

Two arms added to --self-test, and the ctest row (hip_f16_audit_self) passes.
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Rollup Logic Clarity

The rollup behavior introduced by the --top option may be unclear to users. Specifically, when --top 0 is used, it prints all rows without any rollup, but the message indicating this behavior ("--top 0 for every row") could be more explicit about what the default behavior is when --top is not specified.

ordered = sorted(rows, key=lambda r: (-r["narrowings"], -len(r["accumulators"]), r["file"]))
limit = 20 if top is None else top
shown = ordered if limit <= 0 else ordered[:limit]
for row in shown:
    acc = ", ".join(row["accumulators"]) if row["accumulators"] else "-"
    print(f"  {row['file']:34} {row['lines']:5} lines  narrowings {row['narrowings']:3}  "
          f"f16 accumulators {acc}")
rest = ordered[len(shown):]
if rest:
    with_narrowings = sum(1 for row in rest if row["narrowings"])
    print(f"  … {len(rest)} more file(s), {sum(row['narrowings'] for row in rest)} narrowing(s) among "
          f"{with_narrowings} of them (--top 0 for every row)")
Sorting Key Consistency

The sorting key used for ordering rows in the report (-narrowings, -accumulators, file) may not be consistent with the intent of prioritizing files with the most narrowings. The current implementation sorts by the number of narrowings in descending order, but also considers the number of accumulators and the file name, which could lead to unexpected ordering in edge cases.

ordered = sorted(rows, key=lambda r: (-r["narrowings"], -len(r["accumulators"]), r["file"]))

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 1441c1b

Independent of the wiring question (see my notes on #2418/#2419/#2420), and right on its own terms: a 62-row table that buries the files that matter is a table nobody reads, and solving it by ordering rather than by truncating keeps every row visible. Sorting by something that puts the add-on's own kernels first — rather than alphabetically — is the correct fix for an audit whose consumer is "is our code clean", not "what does the tree contain".

One suggestion: if the order is now meaningful (ours first), say so in the header line. An ordering that looks arbitrary invites the next person to restore alphabetical sort and re-bury the rows.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 1441c1b: READY

The presentation change is right and the ordering is the part that matters, because it sorts by the failing property first:

ordered = sorted(rows, key=lambda r: (-r["narrowings"], -len(r["accumulators"]), r["file"]))
limit = 20 if top is None else top
shown = ordered if limit <= 0 else ordered[:limit]
  • accumulators sort ahead of everything (-len(r["accumulators"]) before file), so the files that fail the audit are the ones inside the window even when 62 rows are competing for it;
  • --top 0 prints every row, so the pre-rollup table is one flag away rather than gone;
  • and the tail is counted rather than dropped — … N more file(s), M narrowing(s) among … — which is the difference between a rollup and a truncation;
  • the threshold is justified by a measurement: "on gpu-kernels 965936607 is 62 rows — more than a reader scans."

One note, and it is the rollup counting the wrong column

The hidden-tail summary counts narrowings, which is the informational property, and not accumulators, which is the one that fails the run. The with_narrowings sum is computed and there is no equivalent for accumulators.

That matters only in the case where more than 20 files carry an f16 accumulator — then the tail holds failing rows and the summary line would report them as "N more files, M narrowings" with no mention of the failures it is hiding. The exit code is unaffected (it is computed from all rows, so CI still fails), which is why this is a note and not a condition — but the summary is read by a human deciding what to fix, and the audit's own severity split says narrowings are context and accumulators are the defect. One term in the same f-string:

… {len(rest)} more file(s), {sum(r['narrowings'] for r in rest)} narrowing(s),
{sum(1 for r in rest if r['accumulators'])} with an f16 accumulator

Nothing else to change. #2417 is the one PR in this cluster that is orthogonal to the caller collision on #2418/#2419/#2420 — it changes how the audit reports, not how it is invoked — so it can land in any order.

And the description's own framing is worth keeping: "order by narrowings and roll up the tail after 20 rows" is a display change described as one, with the number of rows and the flag that undoes it. That is the shape a presentation PR should take.

@bong-water-water-bong
bong-water-water-bong merged commit 982ae8f into main Nov 14, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-prs2/audit-rollup branch November 14, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant