Skip to content

feat(libopenbuenos): raise & auto-size weight cache cap (>916 MB) with telemetry (#40) - #45

Merged
saariuslystoned merged 7 commits into
mainfrom
feat/40-openbuenos-weight-cache-cap
Dec 1, 2026
Merged

saariuslystoned merged 7 commits into
mainfrom
feat/40-openbuenos-weight-cache-cap

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #40 (host implementation, MemAvailable-guarded dynamic auto-sizing, explicit OPENBUENOS_CACHE_CAP / OPENBUENOS_WEIGHT_CACHE_MB >= 1.5 GiB support, weight-cache stats API, and outlier/overflow/concurrency hardening; live Pixel 10 solo + DSpark silicon benchmark proof remains open on #40).

Summary

  • Preserve Public C ABI (libopenbuenos/include/openbuenos.h, libopenbuenos/src/ob_device.cpp, llama-cpp-edgetpu/openbuenos_shim.c): keeps ob_config_t (48 B on LP64) and ob_profile_stats_t (216 B on LP64, swiglu_calls at offset 192) identical to main, exposing the dedicated ob_weight_cache_stats_t, ob_context_set_weight_cache_cap, and ob_context_get_weight_cache_stats APIs guarded cleanly with OB_HAS_WEIGHT_CACHE_STATS so openbuenos_shim.c compiles and links cleanly against both main and this branch.
  • Exact outlier-byte accounting (libopenbuenos/src/ob_gemm.cpp, libopenbuenos/src/ob_internal.h): centralizes tile untracking (weight_cache_untrack_locked) across ordinary LRU eviction, hit-triggered self-eviction, and async timeout buffer detachment so ext2_bytes + outlier_cols_bytes are subtracted together without leaving phantom resident bytes.
  • RAM detection, env parsing & 32-bit overflow guards (libopenbuenos/src/ob_gemm.cpp, llama-cpp-edgetpu/ggml-edgetpu.cpp):
    • Linux /proc/meminfo: distinguishes MemAvailable: 0 kB from missing/unreadable lines, skips overlong lines safely, excludes pageable outlier columns from DMA add-back, and passes pending DMA allocation bytes consistently across both prepack and ordinary insertion.
    • macOS vm_statistics64: sums free_count + inactive_count without double-counting speculative_count or purgeable_count.
    • Monotonic explicit headroom clamping across the 1,024 MiB threshold, 1 MiB floor, size_t overflow-safe subtraction (weight_cache_would_exceed_locked), non-evicting prepack budget checks that avoid accruing weight_pack_ns on precheck skips, and validated unsigned env parsing preserving leading + compatibility.
  • Host & adversarial test coverage (libopenbuenos/tests/openbuenos_host_test.cpp, libopenbuenos/tests/openbuenos_adversarial_test.cpp, libopenbuenos/tests/openbuenos_selftest.cpp): adds LP64 ABI static_asserts, Linux 0 kB /proc/meminfo parsing checks, real ob_gemm_matmul_f32_quant_batch pack/eviction thrash tests, end-to-end production outlier column admission + eviction/self-eviction/detach tests returning resident bytes cleanly to 0, TSan concurrent shrink/churn tests, and CMake/Make integration.

Verification (HEAD 2f69e176feaf00970aca99d3b99d2391ec0f9648)

  • make -C libopenbuenos verify (-Wall -Wextra -Wpedantic -Werror, host 28/28 suites + ob_quant_unpack_test + Android arm64 NDK ELF check): PASS
  • CMake Release ctest: libopenbuenos (5/5), freetile (5/5), llama-cpp-cloudtpu (2/2): PASS
  • CMake ASan+UBSan (libopenbuenos 5/5 ctest) & TSan (openbuenos_adversarial_test): PASS
  • make -C libopentpu verify-header-host host test (16/16 host tests + mock VFIO/matmul proof): PASS
  • Android NDK ARMv7 (armv7a-linux-androideabi34-clang++ -Wall -Wextra -Wpedantic -Werror) syntax checks & llama-cpp-edgetpu/openbuenos_shim.c compatibility against both main and HEAD headers: PASS
  • Python unit tests (283/283) & clean-room tracked-file scan (201 tracked files): PASS (verify_* corpus scripts skipped without external FREETPU_CORPUS_DIR)
  • Open on #40 (out of host PR scope): live Pixel 10 solo + DSpark silicon benchmark comparison.

- Reject negative/malformed env values instead of letting strtoul wrap
  to ULONG_MAX and clamp to 8 GiB (OPENBUENOS_WEIGHT_CACHE_MB=-16 was
  accepted as a massive explicit cap).
- Saturating size_t arithmetic for cache accounting adds, meminfo
  add-back, and platform MemAvailable conversion (SIZE_MAX guards).
- Reclaim orphaned tiles in weight_cache_sim_access when find_locked
  self-evicts an oversized entry (object leak).
- Fix byte accounting: evict/detach/find now credit weight_cache_bytes
  for ext2 bytes only and decrement outlier_cache_bytes separately.
- Deallocate macOS mach host port in the MemAvailable probe.
- Guard ob_gemm_emitter op640 mask shift for n_c32 >= 64 (UBSan hit).
- Add openbuenos_adversarial_test (env extremes, churn/shrink, SIZE_MAX,
  oversize, concurrent stats/cap churn); wire into CMake.
@saariuslystoned

Copy link
Copy Markdown
Collaborator Author

Adversarial Hardening & Public-Roads Audit Receipt (4ab7b1d2)

  • Prior PR head: cfc30100 → Hardened head: 4ab7b1d2
  • Bugs fixed (ob_gemm.cpp, emitter & tests):
    • Negative env value wrapping to 8 GiB cap; unsaturating size_t additions on budget/meminfo checks
    • Orphan tile leak in weight_cache_sim_access after budget shrink
    • Outlier byte over-subtraction & stale outlier_cache_bytes on evict/detach
    • macOS mach port leak; 1ULL << 64 shift UB in op640 mask builder
  • Verification: make verify-header-host test (28/28 PASS), openbuenos_adversarial_test + full host suite under ASan+UBSan (0 errors) and TSan (0 warnings), CTest 100% PASS, public-roads diff scan clean.

@saariuslystoned
saariuslystoned merged commit b6ee168 into main Dec 1, 2026
2 checks passed
@saariuslystoned
saariuslystoned deleted the feat/40-openbuenos-weight-cache-cap branch December 1, 2026 18:57
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