Skip to content

Make peak-memory tracking a compile-time option (SP_TRACK_MEMORY) - #118

Merged
dance858 merged 2 commits into
mainfrom
sp-track-memory-option
Sep 5, 2026
Merged

Make peak-memory tracking a compile-time option (SP_TRACK_MEMORY)#118
dance858 merged 2 commits into
mainfrom
sp-track-memory-option

Conversation

@dance858

@dance858 dance858 commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Put peak memory behind a development flag so library can be called from multiple threads at the same time without race conflicts in production.

dance858 and others added 2 commits September 4, 2026 20:17
The sp_malloc/sp_free counters g_allocated_bytes and g_peak_bytes were the
only mutable global state in the library, and every allocation updated them
without synchronization. They feed nothing but the "Peak memory" line in the
verbose problem summary.

Gate them behind a CMake option, SP_TRACK_MEMORY, default OFF. In the default
build the sp_* wrappers are plain malloc/calloc/realloc/free and the globals
do not exist, so the library carries no shared state and is safe to use from
multiple threads as long as each expression tree is touched by one thread.
Verbose output prints "n/a" for peak memory unless built with
-DSP_TRACK_MEMORY=ON. Stays on C99.

Alternative to #100, which used _Thread_local and required C11.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbYHhSoJ1BpEohQrjhdrG7
With SP_TRACK_MEMORY off the verbose summary now simply omits the peak
memory line. Also reformat permuted_dense_linalg.c, which was failing the
clang-format CI check on main.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FbYHhSoJ1BpEohQrjhdrG7
@dance858 dance858 changed the title [WIP] Make peak-memory tracking a compile-time option (SP_TRACK_MEMORY) Make peak-memory tracking a compile-time option (SP_TRACK_MEMORY) Sep 5, 2026
@dance858
dance858 merged commit 6e64401 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 sp-track-memory-option branch September 5, 2026 15:23
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