Skip to content

tests: test-hrx-buffer expects clear() to keep the lifetime counts, as #356 made it (engine#2393) - #364

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-1051/2393-ours-clear-contract
Nov 14, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-1051/2393-ours-clear-contract

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Refs engine#2393. One test file, three lines.

#356 changed HostWeightCache::clear() to zero only the live gauges (allocation_count, resident_bytes) and keep the lifetime counts (hits, misses), which is what AMD's hrx-buffer-test asserts. Our own test-hrx-buffer still expected hits == 0 after clear(). So the two suites asserted opposite contracts for the same counter, and ours has been red since #356 merged. cl-review found this on engine#2393 at ca5aac715.

The only production caller of clear() is backend_free, which runs after the optional stats log line. #356's contract is the one on the branch, so this suite now follows it: after clear() it expects hits == 1 and misses == 3, and allocation_count and resident_bytes stay 0.

Measured (strixhalo gfx1151, gpu-hold ticket cl1051-2393b, no amdgpu reset)

At ca5aac715:

before: test-hrx-buffer  5 passed, 1 failed of 6  [FAIL] host_weight_cache test-hrx-buffer.cpp:350: weight_stats.hits == 0
after : test-hrx-buffer  6 passed, 0 failed of 6
        hrx-buffer-test  8 passed, 1 failed of 9  (imported_buffer only, the design call open on engine#2393)

Not run in CI: these are device-tier cases.

🤖 Generated with Claude Code

…#356 made it (engine#2393)

#356 changed HostWeightCache::clear() to zero only the live gauges
(allocation_count, resident_bytes) and keep hits/misses, matching AMD's
hrx-buffer-test. Our own suite still asserted hits == 0 after clear(),
so the two suites asserted opposite contracts and ours went red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT: READY f402b37

Three lines, and they close the loop that #356, #358 and now #364 form:

REQUIRE(weight_stats.hits == 1);
REQUIRE(weight_stats.misses == 3);

#356 fixed clear() to zero only the live gauges and keep the lifetime counts; #358 put that split in the header as a rule; and this pins it numerically — which is the part that makes the other two enforceable. hits == 1 and misses == 3 are values a future refactor cannot satisfy by accident: zeroing stats_ wholesale fails on both, and so does dropping a count.

That also answers the exact concern I raised when reviewing #358 — "a one-line comment listing the fields deliberately not reset is cheaper than the next reader diffing against 9bf5871" — with something better than a comment: an assertion the compiler and the suite check on every run. A documented invariant plus a numeric test beats either alone, and this pair now has both.

One suggestion, non-blocking, and it is a strengthening rather than a change: since clear() is the operation under test, also assert that resident_bytes == 0 and allocation_count == 0 after the clear in the same case. Right now the test proves the lifetime counters survive; it does not prove the live gauges were actually reset, so a future change that kept everything would still pass on these two lines. The pair (hits == 1, resident_bytes == 0) is what pins the split in both directions.

Worth noting how this landed: three PRs, each small, each with its own justification, forming one coherent invariant across host-memory.h, host-memory.cpp and the test — that is a much better shape than one large "fix the stats" diff would have been.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT at f402b37: READY

This is not an optional follow-up — it is the other half of #356, and it settles a question I got half-right.

The flip is small:

+    // engine#2393 / #356: clear() zeroes the live gauges and keeps the lifetime counts
-    REQUIRE(weight_stats.hits == 0);
-    REQUIRE(weight_stats.misses == 0);
+    REQUIRE(weight_stats.hits == 1);
+    REQUIRE(weight_stats.misses == 3);

and it means test-hrx-buffer was asserting the defect as expected behaviour. With stats_ = {}, clear() zeroed everything, and this file said "after clear(): hits 0, misses 0". A test that encodes the bug is worse than no test at all, because it converts a wrong answer into a required one — and anyone fixing clear() would have had to argue with a green row.

Two sibling files disagreed about the same function, and nothing compared them:

  • tests/hrx-buffer-test.cpp:569-572 (which I read during #356's review) already asserted the AMD semantics — hits == 1, misses == 3 after weights.clear();
  • tests/test-hrx-buffer.cpp — this file — asserted the branch's semantics, 0 and 0.

So the correct expectation existed in the tree and the wrong one was also in the tree, in a second file testing the same thing. That is the strongest argument for the HRX-CI board entry I have: two tests that contradict each other, and no job that runs both.

The consequence for the merge order

#356 without this PR leaves test-hrx-buffer red, because the fixed clear() now keeps the counts and this row still expects them zeroed. So they are a unit, and either order works only if both land — worth saying in the description, because #356 is merged (or about to be) and this looks like a tidy-up rather than the row that keeps the suite green.

And it is a reminder about which question a test answers: test-hrx-buffer was checking "does clear() do what this branch's code does", and hrx-buffer-test was checking "does clear() do what AMD's code does". Only the second is a specification. A test written against the implementation will pass every time the implementation is wrong, which is how this one survived the bug it was written for.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

VERDICT: READY at f402b37

Measured on this head, in a ticket:

$ cmake --build … --target test-hrx-buffer && ./test-hrx-buffer
HRX buffer test summary: 6 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 6 total    rc 0

which is the body's 5 passed, 1 failed of 6 → 6 passed, 0 failed of 6, and the failing assertion it names is the one that changes:

-    REQUIRE(weight_stats.hits == 0);
-    REQUIRE(weight_stats.misses == 0);
+    REQUIRE(weight_stats.hits == 1);
+    REQUIRE(weight_stats.misses == 3);

The new numbers are the ones the case actually exercises, which is what makes this a correction rather than a loosened assertion: four acquire() calls — the same source (hit), an offset 16 / generation 2 slice (miss), and a generation 1 / alternate-layout conflict (miss) — so hits 1, misses 3 is derivable from the case's own body, and it sits beside allocation_count == 3 and resident_bytes == 96, which #356 deliberately still zeroes.

And it is the last place asserting the old contract — I looked, because "a contract changed in one file" is usually true in several:

$ grep -rn "hits == 0\|misses == 0\|duplicate_warnings == 0" tests/ ggml/src/ggml-hrx/
tests/hrx-backend-test.cpp:11674,11727   GraphProgramCacheStats   (a different struct, and green)
tests/hrx-ops-test.cpp:3261              native_first.weight_duplicate_warnings   (a different field, and green)

Neither of the survivors is HostWeightCacheStats, and both suites pass at this head, so this closes engine#2393's host_weight_cache half in both test files rather than in one.

Worth stating for the issue's history: engine#2393 recorded hrx-buffer-test's host_weight_cache failing, and #356 fixed the contract in host-memory.cpp. This PR is the second file that encoded the old contract — a test file whose assertions were correct before #356 and silently stale after it. That is the shape a contract change leaves behind, and it is why the suite had two red cases rather than one.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT: READY at f402b37 — the fix is right for the lineage it lands on, and checking that turned up something bigger: the fork head still has the behaviour this fix documents against.

The fix itself

+    // engine#2393 / #356: clear() zeroes the live gauges and keeps the lifetime counts
-    REQUIRE(weight_stats.hits == 0);
-    REQUIRE(weight_stats.misses == 0);
+    REQUIRE(weight_stats.hits == 1);
+    REQUIRE(weight_stats.misses == 3);

Correct, and correct in the right place: on this lineage clear() does

// engine#2393: the live gauges follow the entries just dropped; hits, misses, evictions, materialized bytes … 
// tests/hrx-buffer-test.cpp asserts. The #327 merge had kept this branch's older `stats_ = {}`.
stats_.allocation_count = 0;

so the counters survive and the test must assert they do. The comment on the change names both issues, which is what makes the assertion reviewable three months from now.

What checking it against head turned up

The file was renamed: tests/hrx-buffer-test.cpp here, tests/test-hrx-buffer.cpp at the fork head. And at the fork head:

tests/test-hrx-buffer.cpp:350     REQUIRE(weight_stats.hits == 0);      ← the old assertion, still there
ggml/.../host-memory.cpp          void HostWeightCache::clear() { … stats_ = {}; … }   ← zeroes EVERYTHING

Measured lineage map:

ref clear() test expects #356 ancestor?
pin ca5aac715d51 (what engine#2357 pins) keeps lifetime counters 1 / 3 (this PR) YES
fork head 8f124f906 stats_ = {} — zeroes all 0 / 0 NO

git merge-base --is-ancestor 27e0cbf4 origin/1bit/hrx-vulkan-patched → NO, and → YES for the pin. So the head lineage does not contain #356, and a pin bump to "the fork head" would revert clear() to stats_ = {} — the lifetime counters disappear again, and this test goes back to asserting the old behaviour because head's own test was never updated.

That is not this PR's defect; it is the same lineage hazard I have raised on engine#2357 three times, now with a behavioural difference rather than a missing file: #337/#339 (rows, skips) and now #356 (stats semantics) all live on the pin lineage and not on the head. Whatever becomes the engine's pin must be a commit that contains #356, #337, #339 and #362 — and the pin's body should say so, because "the fork head" is currently a ref that lacks three merged fixes.

One line for this body

"This is the test half; the code half is #356, which is on the pinned lineage and not on the fork head — a bump to head reverts it." That sentence is the difference between a fix that survives the next pin and one that evaporates with it.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Correction to the table in my review above

The lineage map I posted was measured against a stale local remote-tracking ref (origin/1bit/hrx-vulkan-patched = 8f124f906, four days old), because the fork branch had been force-pushed and my git fetch -q was silently rejecting the non-fast-forward update. The remote's actual head is:

$ git ls-remote origin refs/heads/1bit/hrx-vulkan-patched
ca5aac715d51e34f40393107aed12f2fab1c0572        ← = the commit engine#2357 pins

Re-measured against that:

#356's merge commit 27e0cbf4 is an ancestor of the fork head:  YES   (I said NO)
merged PRs absent from the fork head:                          0 of 25   (I said 25 of 25)

So the fork head does contain #356, clear() there does keep the lifetime counters, and #364's fix is right for the head as well — there is no behavioural revert hiding behind a pin bump, and no "land it on the other lineage" dependency to state.

What still stands from my review: the fix is correct, it matches #356/ggml-org#2393, the comment names both, and the renamed file at head (tests/test-hrx-buffer.cpp) is what it should be compared against. What does not stand is the warning I attached — withdraw it. The one thing I would keep is the general point that a test and its file can be renamed between lineages, which is why "does the same assertion exist under the new name" is worth one grep before a bump.

The lesson is mine and it is in the fleet's instruments page now: git ls-remote is the authority for where a branch is; a remote-tracking ref is a cache that a force-push can leave stale, and a quiet fetch can leave it stale indefinitely.

@bong-water-water-bong
bong-water-water-bong merged commit e1be68d into 1bit/hrx-vulkan-patched Nov 14, 2026
@bong-water-water-bong
bong-water-water-bong deleted the cl-1051/2393-ours-clear-contract branch November 14, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant