Skip to content

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

Open
saariuslystoned wants to merge 2 commits into
mainfrom
feat/40-openbuenos-weight-cache-cap
Open

saariuslystoned wants to merge 2 commits into
mainfrom
feat/40-openbuenos-weight-cache-cap

Conversation

@saariuslystoned

Copy link
Copy Markdown
Collaborator

Closes #40 (host implementation, MemAvailable-guarded dynamic auto-sizing, explicit OPENBUENOS_CACHE_CAP >= 1.5 GB support, cache telemetry, and zero-thrash host unit tests; live Pixel 10 silicon re-benchmark tracked on the dedicated device lane).

Summary

  • Dynamic MemAvailable-guarded auto-sizing & raised ceiling (libopenbuenos/include/openbuenos.h, libopenbuenos/src/ob_internal.h, libopenbuenos/src/ob_gemm.cpp, libopenbuenos/src/ob_device.cpp, llama-cpp-edgetpu/openbuenos_shim.c): sizes weight cache budget cleanly from MemAvailable (1,536 MiB default on 16 GiB systems with safe OOM headroom on smaller devices; injectable ob::MemAvailableProbe for deterministic host testing) and supports explicit OPENBUENOS_CACHE_CAP overrides >= 1.5 GB.
  • Weight cache telemetry: adds ob_context_get_weight_cache_stats (hits, misses, evictions, resident/peak/budget bytes, pack_count, pack_us, entry count) plus weight_pack_count in ob_profile_stats_t.
  • Host tests (libopenbuenos/tests/openbuenos_host_test.cpp, libopenbuenos/tests/openbuenos_selftest.cpp): verifies auto-sizing across RAM tiers, explicit >= 1.5 GB overrides, telemetry accuracy, and proves 0 steady-state evictions at w_peak = 916 MiB under the 16 GiB default cap vs. thrashing at 896 MiB.

Verification

  • make -C libopenbuenos verify-header-host host test (-Wall -Wextra -Wpedantic -Werror): 28/28 PASS + quant unpack PASS.
  • ASan+UBSan run of libopenbuenos host tests: 28/28 PASS (0 ASan errors).
  • CMake/Ninja ctest (libopenbuenos 3/3, freetile 4/4, llama-cpp-cloudtpu 1/1), libopentpu host tests, Python ISA/router self-tests, and clean-room audit across 192 files: PASS.
  • Pending (out of host-only PR scope): live Pixel 10 silicon benchmark receipt comparing 896 MB vs. zero-thrash cap (to be attached by the dedicated USB device lane).

- 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.

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.

Raise/auto-size libopenbuenos weight cache cap (> 916 MB) to eliminate thrashing on PocketCoder-13B-A3B

1 participant