Skip to content

refactor(dfx): unify collector headers - #1342

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
vegetabledoww:feature/add-new-feature
Jul 13, 2026
Merged

refactor(dfx): unify collector headers#1342
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
vegetabledoww:feature/add-new-feature

Conversation

@vegetabledoww

@vegetabledoww vegetabledoww commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Unify the duplicated ArgsDump, dependency-generation, and L2 Swimlane collector headers under src/common/platform/include.

The obsolete a2a3/a5 platform-local headers are removed. Repository call sites already use the logical common/..., aicpu/..., and aicore/... include paths, and the affected build targets include the common platform directory directly.

Changes

  • Consolidate the shared collector and layout headers into src/common/platform/include/{common,aicpu,aicore}.
  • Remove the 12 duplicated or forwarding headers from the a2a3/a5 platform include directories.
  • Add ABI layout checks for shared ArgsDump records, buffer state, and ready-queue entries.
  • Keep the L2 Swimlane scheduler-pool allocation and accessor stride fixed at PLATFORM_MAX_AICPU_THREADS.
  • Update documentation links and comments that referenced platform-specific header paths.

Validation

  • git diff --check
  • Pre-commit hooks: all passed
  • python -m pytest examples/a5/tensormap_and_ringbuffer/paged_attention/test_paged_attention.py --platform a5sim --device 0-1 --dump-args 2 --pto-session-timeout 600 -v (1 passed in 21.98s)
  • python -m pytest examples/a2a3/tensormap_and_ringbuffer/paged_attention/test_paged_attention.py --platform a2a3sim --device 0-1 --dump-args 2 --pto-session-timeout 600 -v (1 passed in 21.31s)
  • task-submit --device auto --timeout 1800 --max-time 1800 --run "... --platform a2a3 --device {} --dump-args 2 --pto-session-timeout 600 -v" (1 passed in 18.67s)

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 54eefce6-2df9-4358-a145-eb47ac8bbb3f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change centralizes L2 swimlane, dependency-generation, and tensor-dump definitions under common platform headers. A2A3 and A5 headers become forwarding wrappers, while shared AICore and AICPU collector interfaces are introduced.

Changes

Shared platform profiling and capture

Layer / File(s) Summary
Common data contracts
src/common/platform/include/common/*
Adds shared-memory layouts, records, queues, ABI assertions, enums, and sizing/pointer helpers for L2 swimlane profiling, dependency generation, and tensor dumping.
Collector interfaces and recording paths
src/common/platform/include/aicore/*, src/common/platform/include/aicpu/*
Adds AICore task recording, AICPU L2 swimlane lifecycle and phase APIs, and dependency-generation configuration and capture declarations.
Platform forwarding wrappers
src/a2a3/platform/include/*, src/a5/platform/include/*
Replaces duplicated platform-specific header bodies with guarded includes of the common implementations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Poem

A bunny hops through headers bright,
Shared records settle just right.
Old wrappers point the way,
New queues bloom today—
L2 hops cleanly into flight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title accurately summarizes the main change: consolidating collector headers into shared/common includes.
Description check ✅ Passed The description matches the changeset and correctly describes the header consolidation and validation performed.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the platform headers by consolidating duplicate definitions from the a2a3 and a5 platform directories into a unified common/platform directory. Specifically, headers for AICore/AICPU swimlane collectors, dependency generation, profiling, and tensor dumping are moved to the common location, and the platform-specific headers are updated to simply include these common files. This reduces code duplication and improves maintainability across platforms. As there are no review comments provided, I have no feedback to provide on the review itself.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/common/platform/include/common/tensor_dump.h (1)

142-145: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Verify DumpMetaBuffer count placement is intentional; consider matching DepGenBuffer's header-first layout.

DepGenBuffer places volatile uint32_t count in the first 64-byte header so the host "copies this alone first to learn count" before reading records. DumpMetaBuffer places count at the end of the buffer (after all records), forcing the host to seek to the tail to learn how many records are valid. If the host-side dump collector uses a two-phase read (count first, then records), this layout degrades that pattern.

If the tail placement is intentional (e.g., the writer fills records then publishes count naturally), please document the rationale. Otherwise, consider moving count to a 64-byte header at the front for consistency.

♻️ Suggested header-first layout (if tail placement is not intentional)
 struct DumpMetaBuffer {
-    TensorDumpRecord records[PLATFORM_DUMP_RECORDS_PER_BUFFER];
-    volatile uint32_t count;  // Current record count
+    // Header (first 64 bytes) — host copies this alone first to learn count.
+    volatile uint32_t count;  // Current record count
+    uint32_t _pad0[15];       // Pad count to 64 B; isolates count's cache line.
+
+    // Records (up to PLATFORM_DUMP_RECORDS_PER_BUFFER)
+    TensorDumpRecord records[PLATFORM_DUMP_RECORDS_PER_BUFFER];
 } __attribute__((aligned(64)));
+
+static_assert(offsetof(DumpMetaBuffer, records) == 64, "DumpMetaBuffer header must be exactly 64 bytes");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/common/platform/include/common/tensor_dump.h` around lines 142 - 145,
Verify the intended host read pattern for DumpMetaBuffer and update the struct
accordingly: if the dump collector reads count before records, move volatile
uint32_t count into a 64-byte header at the beginning, matching DepGenBuffer’s
layout, while preserving the existing record storage and alignment. If tail
placement is required by the writer protocol, retain it and document that
rationale near DumpMetaBuffer.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/common/platform/include/common/l2_swimlane_profiling.h`:
- Around line 662-665: Update calc_perf_data_size_with_phases so the
scheduler-phase allocation always reserves PLATFORM_MAX_AICPU_THREADS
L2SwimlaneAicpuSchedPhasePool entries, matching the fixed stride used by
get_orch_phase_buffer_states(); keep the orchestration-phase sizing based on
num_orch_phase_threads.

In `@src/common/platform/include/common/tensor_dump.h`:
- Around line 104-129: Add compile-time layout checks alongside the existing
structure definitions: assert that DumpReadyQueueEntry is exactly 32 bytes, and
assert that offsetof(TensorDumpRecord, start_offset) equals 64 to preserve the
documented cache-line boundary. Use static_assert with the existing type and
field symbols, without changing the structures’ layout.

---

Nitpick comments:
In `@src/common/platform/include/common/tensor_dump.h`:
- Around line 142-145: Verify the intended host read pattern for DumpMetaBuffer
and update the struct accordingly: if the dump collector reads count before
records, move volatile uint32_t count into a 64-byte header at the beginning,
matching DepGenBuffer’s layout, while preserving the existing record storage and
alignment. If tail placement is required by the writer protocol, retain it and
document that rationale near DumpMetaBuffer.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e541ff1d-099c-4068-a42c-b3aba9b10230

📥 Commits

Reviewing files that changed from the base of the PR and between 55a670c and 659a4ea.

📒 Files selected for processing (18)
  • src/a2a3/platform/include/aicore/l2_swimlane_collector_aicore.h
  • src/a2a3/platform/include/aicpu/dep_gen_collector_aicpu.h
  • src/a2a3/platform/include/aicpu/l2_swimlane_collector_aicpu.h
  • src/a2a3/platform/include/common/dep_gen.h
  • src/a2a3/platform/include/common/l2_swimlane_profiling.h
  • src/a2a3/platform/include/common/tensor_dump.h
  • src/a5/platform/include/aicore/l2_swimlane_collector_aicore.h
  • src/a5/platform/include/aicpu/dep_gen_collector_aicpu.h
  • src/a5/platform/include/aicpu/l2_swimlane_collector_aicpu.h
  • src/a5/platform/include/common/dep_gen.h
  • src/a5/platform/include/common/l2_swimlane_profiling.h
  • src/a5/platform/include/common/tensor_dump.h
  • src/common/platform/include/aicore/l2_swimlane_collector_aicore.h
  • src/common/platform/include/aicpu/dep_gen_collector_aicpu.h
  • src/common/platform/include/aicpu/l2_swimlane_collector_aicpu.h
  • src/common/platform/include/common/dep_gen.h
  • src/common/platform/include/common/l2_swimlane_profiling.h
  • src/common/platform/include/common/tensor_dump.h

Comment thread src/common/platform/include/common/l2_swimlane_profiling.h Outdated
Comment thread src/common/platform/include/common/tensor_dump.h Outdated
@vegetabledoww
vegetabledoww force-pushed the feature/add-new-feature branch 2 times, most recently from 820dc4b to db58469 Compare July 13, 2026 03:24
@vegetabledoww

Copy link
Copy Markdown
Contributor Author

Regarding the DumpMetaBuffer::count placement nitpick: I kept the existing tail layout intentionally. ProfilerAlgorithms::process_entry() copies the full sizeof(DumpMetaBuffer) from device before TensorDumpCollector reads either count or records[], and the unflushed-buffer recovery path also copies the full buffer first. There is no count-first/two-phase host read to optimize, so moving the field would change the shared host/device ABI without a benefit. The device continues to write each record before publishing the incremented count.

@vegetabledoww
vegetabledoww force-pushed the feature/add-new-feature branch 5 times, most recently from 6168f2e to acea2a4 Compare July 13, 2026 07:29
@ChaoZheng109

Copy link
Copy Markdown
Collaborator

Doc nit — arch-specific comment in a now-shared header (src/common/platform/include/common/l2_swimlane_profiling.h:172)

 * Delta fits in 32 bits at any platform clock (1 GHz @ 32-bit ≈ 4.3 s).

This line is unchanged by the diff (it came over verbatim with the a5→common rename), so it does not show up as a changed line — but this PR is what makes the header shared by a2a3 and a5, which turns the comment into arch-specific text living in a common header. The 1 GHz @ 32-bit ≈ 4.3 s figure is the a5 clock; the a2a3 copy deleted in this PR read 50 MHz @ 32-bit ≈ 85 s. The concrete 1 GHz value now only describes a5 and understates a2a3's wrap window.

Not a correctness problem (32-bit suffices on both), but per the doc-consistency / comments conventions a shared header should stay arch-neutral. Suggestion:

 * Delta fits in 32 bits at any platform clock (worst case at the fastest
 * platform clock: 1 GHz @ 32-bit ≈ 4.3 s).

@vegetabledoww
vegetabledoww force-pushed the feature/add-new-feature branch from acea2a4 to 16743a5 Compare July 13, 2026 09:31
Move shared dep_gen, tensor_dump, and l2_swimlane collector headers under src/common/platform/include.

Keep the a2a3 and a5 platform include paths as forwarding headers so existing includes continue to resolve while the shared layouts and interfaces have a single source of truth.

Add layout offset checks for DumpBufferState and refresh common comments that previously referenced platform-specific names or paths.
@ChaoZheng109
ChaoZheng109 merged commit aea4d46 into hw-native-sys:main Jul 13, 2026
16 checks passed
@vegetabledoww
vegetabledoww deleted the feature/add-new-feature branch July 14, 2026 01:55
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.

2 participants