BA_pd_spd transpose cache - #115
Merged
Merged
Conversation
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claude below.
Summary
BA_pd_spd_fill_valuesrecomputed B's cached dense transpose on every call. This PR skips that work when B's values are unchanged, using thevalues_versionmachinery from #113:transpose_seen), seeded deliberately stale bypermuted_dense_ensure_transpose_cacheso the first fill always refreshes.matrix_values_changedon apermuted_dense. The two parameter-refresh paths that memcpy into pd values (refresh_dense_leftin left_matmul forA/AT, quad_form forQ) now bump, per thematrix.hcontract ("code that writes x directly must call matrix_values_changed on the OWNER"). Without these, the guard would freeze the transpose acrossproblem_update_params.BA_spd_spd_fill_valuespasses spd blocks, which have novalues_versionof their own (writers bump the owning spd). It therefore bypasses the guard and refreshes unconditionally viaBTA_pd_spd_fill_values. Two existing spd unit tests caught this during development.Not included (deliberately): version-guarding the
Jchild_CSCmirrors 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_valuesnow bumps after mutating B's values, matching the write-then-bump contract.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).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
MallocScribble=1 MallocGuardEdges=1 leaks --atExit— 0 leaksPROFILE_ONLYbuild compiles🤖 Generated with Claude Code
https://claude.ai/code/session_016rQ3LPdi31kNLmTy9F2oEa