Skip to content

feat(a5): route DFX collectors through MemoryAllocator so committed_device_memory counts them - #1602

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
ChaoZheng109:feat/a5-dfx-mem-alloc
Jul 31, 2026
Merged

ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
ChaoZheng109:feat/a5-dfx-mem-alloc

Conversation

@ChaoZheng109

Copy link
Copy Markdown
Collaborator

What

Route the a5 onboard DFX collectors (l2_swimlane, args_dump, pmu,
scope_stats, dep_gen) through the per-runner MemoryAllocator instead of
raw rtMalloc / rtFree.

Why

committed_device_memory() (added in #1592) reports the device HBM tracked by
MemoryAllocator. On a2a3, the DFX collectors already allocate their device
buffers through mem_alloc_ (init_pmu / init_dep_gen / init_scope_stats),
so their HBM is counted. On a5 they used prof_alloc_cb / prof_free_cb —
raw rtMalloc(RT_MEMORY_HBM) — bypassing mem_alloc_, so a5 profiling buffers
were invisible to committed_device_memory().

That made the #1592 docstring ("excludes HCCL/VMM comm windows", which implies
profiling buffers are counted) correct on a2a3 but wrong on a5. This PR
closes that platform gap.

How

Replace the two file-static callbacks with capturing alloc_cb / free_cb
lambdas (mem_alloc_.alloc / mem_alloc_.free) at each collector init and in
finalize_collectors, matching a2a3's style. Both paths call the same
rtMalloc(RT_MEMORY_HBM) / rtFree underneath, so device-buffer properties are
unchanged — the only effect is that a5 DFX buffers are now tracked and counted,
including the runtime watermark replenishment.

Scope / testing

…evice_memory counts them

The a5 profiling collectors (l2_swimlane, args_dump, pmu, scope_stats,
dep_gen) allocated their device buffers via raw rtMalloc (prof_alloc_cb /
prof_free_cb), bypassing the per-runner MemoryAllocator. As a result their
HBM was invisible to committed_device_memory() (added in hw-native-sys#1592), while a2a3
already routes DFX through mem_alloc_ and counts it — a platform-inconsistent
gap the hw-native-sys#1592 docstring ("excludes HCCL/VMM comm windows", implying profiling
buffers ARE counted) now describes correctly for both platforms.

Replace the raw-rtMalloc callbacks with capturing `alloc_cb` / `free_cb`
lambdas that call mem_alloc_.alloc / mem_alloc_.free, matching a2a3's
init_pmu / init_dep_gen / init_scope_stats. Both allocators use the same
rtMalloc(RT_MEMORY_HBM) underneath, so the device-buffer properties are
unchanged; the only effect is that DFX buffers are now tracked and counted.

Completes the a5 coverage deferred from hw-native-sys#1592 to keep that PR single-purpose.
Onboard a5 DFX scene tests (test_pmu / test_dep_gen / test_scope_stats /
test_args_dump) exercise the new alloc path.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c1ed3041-0a55-44f8-be5d-edb1ac34b9bc

📥 Commits

Reviewing files that changed from the base of the PR and between ce81c97 and 834293e.

📒 Files selected for processing (1)
  • src/a5/platform/onboard/host/device_runner.cpp

📝 Walkthrough

Walkthrough

Profiling collector initialization and finalization now use per-run allocation callbacks backed by mem_alloc_, replacing shared profiling allocator wrappers across the affected collectors.

Changes

Profiling allocator ownership

Layer / File(s) Summary
Collector initialization callbacks
src/a5/platform/onboard/host/device_runner.cpp
L2 swimlane, argument dump, PMU, scope stats, and dependency-generation collectors use mem_alloc_-backed allocation and free lambdas.
Collector finalization callbacks
src/a5/platform/onboard/host/device_runner.cpp
Initialized collectors are finalized with a mem_alloc_.free callback, while scope-stats state cleanup remains in place.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

A bunny hops through buffers bright,
With mem_alloc_ guiding every byte.
Collectors gather, then safely free,
Scope stats clear as neat as can be.
No shared wrappers in sight—
Hop, hop, memory right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: routing a5 DFX collectors through MemoryAllocator for committed memory tracking.
Description check ✅ Passed The description matches the change set and explains the motivation, implementation, and testing for the allocator routing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ChaoZheng109
ChaoZheng109 merged commit 67ecbaf into hw-native-sys:main Jul 31, 2026
17 checks passed
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