[WIP] Better BTA without allocation - #117
Open
dance858 wants to merge 3 commits into
Open
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
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:
Removes the last "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.Tests:
BTDA_pd_pdcorrectness on both the matching-row_perm (fast) and gather paths vs the diag-decomposition oracle — the fast path withdis new code.g_peak_bytes/g_allocated_bytes; it fails against the previous kernels.multiplyHessian with dense operators (new_left_matmul_dense) — the first wsum_hess-level coverage of multiply's pd/pd BTDA dispatch, verified by numerical differentiation.Verified: 448 tests in Release, UBSan clean, guard-malloc +
leaks --atExitclean,PROFILE_ONLYbuilds, clang-format clean on all edited regions (the one pre-existing violation in the dead_via_transpose_deadfunction is untouched).🤖 Generated with Claude Code