Skip to content

BA_pd_spd transpose cache - #115

Merged
dance858 merged 1 commit into
mainfrom
transpose-cache-version-guard
Sep 5, 2026
Merged

BA_pd_spd transpose cache#115
dance858 merged 1 commit into
mainfrom
transpose-cache-version-guard

Conversation

@dance858

@dance858 dance858 commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Claude below.

Summary

BA_pd_spd_fill_values recomputed B's cached dense transpose on every call. This PR skips that work when B's values are unchanged, using the values_version machinery from #113:

  • The refill is guarded by a seen counter stored on the cache pd itself (transpose_seen), seeded deliberately stale by permuted_dense_ensure_transpose_cache so the first fill always refreshes.
  • Soundness bumps: nothing previously called matrix_values_changed on a permuted_dense. The two parameter-refresh paths that memcpy into pd values (refresh_dense_left in left_matmul for A/AT, quad_form for Q) now bump, per the matrix.h contract ("code that writes x directly must call matrix_values_changed on the OWNER"). Without these, the guard would freeze the transpose across problem_update_params.
  • spd-block exception: BA_spd_spd_fill_values passes spd blocks, which have no values_version of their own (writers bump the owning spd). It therefore bypasses the guard and refreshes unconditionally via BTA_pd_spd_fill_values. Two existing spd unit tests caught this during development.

Not included (deliberately): version-guarding the Jchild_CSC mirrors in left_matmul/convolve — subsumed by the affine impl-skip (#114), which prevents those impls from running at all when the child's values are frozen.

Other changes

  • test_BA_pd_spd_alloc_then_fill_values now bumps after mutating B's values, matching the write-then-bump contract.
  • Fixed the stale comment on test_BA_pd_kron_spd_no_cache_staleness (the per-call alloc/free it describes was replaced by the cache; the kron path stays correct because it bypasses the wrapper).
  • New regression test test_BA_pd_spd_transpose_cache_refresh: fill, mutate B + bump, refill, compare against a fresh computation; also checks the seen counter catches up.

Verification

  • All 425 tests pass (Debug and UBSan builds)
  • Guard-malloc + leaks clean: MallocScribble=1 MallocGuardEdges=1 leaks --atExit — 0 leaks
  • PROFILE_ONLY build compiles
  • clang-format applied; no new warnings

🤖 Generated with Claude Code

https://claude.ai/code/session_016rQ3LPdi31kNLmTy9F2oEa

BA_pd_spd_fill_values refreshed B's cached transpose on every call. Now it
refreshes only when B's values_version has moved since the last fill; the
seen counter lives on the cache pd itself.

To make the guard sound, the two parameter-refresh paths that wrote pd
values silently (left_matmul refresh_dense_left, quad_form) now call
matrix_values_changed after their memcpys, per the matrix.h contract.

BA_spd_spd_fill_values passes spd blocks, which have no values_version of
their own (writers bump the owning spd), so it bypasses the guard and
refreshes unconditionally via BTA_pd_spd_fill_values.

Also fixes the stale comment on test_BA_pd_kron_spd_no_cache_staleness
(the cache it says was removed is back; the kron path is correct because
it bypasses the wrapper) and adds a refresh-on-bump regression test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016rQ3LPdi31kNLmTy9F2oEa
@dance858 dance858 changed the title Version-guard the BA_pd_spd transpose cache [WIP] Version-guard the BA_pd_spd transpose cache Aug 31, 2026
@dance858 dance858 changed the title [WIP] Version-guard the BA_pd_spd transpose cache BA_pd_spd transpose cache Sep 5, 2026
@dance858
dance858 merged commit c412a33 into main Sep 5, 2026
12 checks passed
dance858 added a commit that referenced this pull request Sep 5, 2026
…CK_MEMORY

Resolve the test_matmul_dispatchers.h conflict by keeping both #115's
transpose-cache test and the branch's BTDA no-transient-alloc test.

#118 made g_allocated_bytes / g_peak_bytes exist only under
SP_TRACK_MEMORY, so the no-alloc test (which reads those counters) and
its registration are now wrapped in #ifdef SP_TRACK_MEMORY. Default
build: 448 tests pass; -DSP_TRACK_MEMORY=ON: 449 tests pass.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ATepXjts1gBX485mSguzk
@dance858
dance858 deleted the transpose-cache-version-guard branch September 5, 2026 15:24
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