Better BTA without allocation - #117
Merged
Merged
Conversation
BTDA_pd_pd_fill_values and BTDA_pd_spd_fill_values allocated, filled, and freed a diag(d) @ A intermediate on every Hessian evaluation (the "must remove this allocation. Very important" TODOs), and the blockwise BTDA_spd_pd/spd_spd variants compounded that to n_blocks temps per fill. Restructure each BTA kernel into a shared core taking an optional d (NULL = identity) that scales A's rows by d[global_row] while they are being gathered into the pre-sized kernel_dwork scratch — the same pattern BTDA_pd_csc/BTDA_csc_pd already use — so the BTDA entry points become thin wrappers and no fill allocates. The pd_pd fast path (identical row_perms) scales into A->kernel_dwork, which BTA_pd_pd_alloc already sizes to exactly m0*n0 on that path. New tests: direct BTDA_pd_pd correctness on both the matching-row_perm and gather paths against the diag-decomposition oracle; a no-transient-allocation regression test over pd_pd (both paths), pd_spd, and blockwise spd_pd using the tracked allocator's peak-bytes counter (fails on the previous kernels); and an end-to-end multiply Hessian test with dense operators — the first wsum_hess coverage of multiply's pd/pd dispatch. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HRnTPZsCXK6x2PSGUzanmg
Replace the hand-written scale-copy loops with an unconditional memcpy gather followed by a per-row cblas_dscal pass when d is given, matching the existing DA_pd_fill_values / ATDA_pd_fill_values idiom. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HRnTPZsCXK6x2PSGUzanmg
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HRnTPZsCXK6x2PSGUzanmg
…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.
This PR improves the matmul functionality by removing one intermediate allocation for BTDA involving permuted dense. It's been on my todo list for a long time, so it's very nice to get it done.
Claude below:
Removes the last "(Daniel) must remove this allocation. Very important" TODOs:
BTDA_pd_pd_fill_valuesandBTDA_pd_spd_fill_valuesallocated and freed adiag(d) @ Aintermediate on every Hessian evaluation, and the blockwise spd BTDA variants multiplied that by n_blocks.Each BTA kernel is now a shared core with an optional
d(NULL = identity) folded into the existing row-gather into pre-sizedkernel_dwork— the patternBTDA_pd_csc/BTDA_csc_pdalready used — so the BTDA entry points are thin wrappers and no fill path allocates. The blockwiseBTDA_spd_pd/BTDA_spd_spdinherit the fix automatically.