Skip to content

Refactor: consolidate per-task markers into one TaskAttrs byte (a2a3/hbg)#1441

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
ChaoZheng109:refactor/issue-1402-a2a3-hbg-task-attrs
Jul 23, 2026
Merged

Refactor: consolidate per-task markers into one TaskAttrs byte (a2a3/hbg)#1441
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
ChaoZheng109:refactor/issue-1402-a2a3-hbg-task-attrs

Conversation

@ChaoZheng109

Copy link
Copy Markdown
Collaborator

Summary

Mirrors the tensormap_and_ringbuffer consolidation (#1402) to the a2a3 host_build_graph runtime. Folds the four scattered per-task markers into a single TaskAttrs byte on PTO2TaskSlotState and reverts active_mask to a pure subtask-slot mask.

hbg gained predicated dispatch in #1434, so it now carries the same four markers as tmr (allow_early_resolve, sync_start, has_predicate, timing tag) — this is a 1:1 port of the settled tmr design. Based on latest main (includes #1434).

Changes

  • New TaskAttrs (pto_submit_types.h) — one byte: bit0 allow_early_resolve, bit1 sync_start, bit2 has_predicate, bit3 is_timed, bits4-7 timing_tag (0..15).
  • ActiveMask reverts to pure subtask-slot mask — dropped SYNC_START/HAS_PREDICATE bits/accessors; only core_mask (bits 0-2) remains.
  • task_timing_slot removed from PTO2TaskDescriptor — tag now rides the hot slot_state line. Descriptor 40B / packed_buffer_base offset unchanged (ABI preserved). PTO2TaskSlotState stays 64B (task_attrs reuses the byte allow_early_resolve occupied, alongside the atomic lifecycle_flags).
  • Attributes written once per submit in prepare_task; all scheduler read sites updated. static_assert couples the 4-bit tag to NUM_TASK_TIMING_SLOTS <= 16 / TASK_TIMING_SLOT_NONE == -1.
  • Accessor naming matches the tmr baseline: predicate getters (allow_early_resolve/requires_sync_start/has_predicate/is_timed), set_<concept> setters.

Testing

  • a2a3sim st: predicated_dispatch, matmul, bgemm, paged_attention, vector_example
  • Build clean (static_asserts confirm 64B slot_state / 40B descriptor)
  • The a2a3 cpput timing/wiring tests build against tmr headers (add_a2a3_test include path), unchanged here — no UT edits needed.

Relation to #1402

a2a3 host_build_graph mirror. Companion PR #1410 covers a2a3/tmr + a5/tmr. Remaining: a5 host_build_graph (legacy Runtime::Task path). Part of #1402.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 22, 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 Plus

Run ID: 78d872df-714f-44d9-954c-3b0816a70b3b

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

Task scheduling metadata is consolidated into a packed TaskAttrs object stored in PTO2TaskSlotState. Submission, orchestration, scheduler routing, early dispatch, timing publication, and completion now use TaskAttrs instead of legacy descriptor fields or ActiveMask flags.

Changes

TaskAttrs scheduling metadata migration

Layer / File(s) Summary
Packed attribute contract
src/a2a3/runtime/host_build_graph/runtime/pto_submit_types.h, src/a2a3/runtime/host_build_graph/runtime/pto_runtime2_types.h, src/a2a3/runtime/host_build_graph/runtime/pto_types.h
ActiveMask retains only subtask-slot bits; TaskAttrs stores early-resolve, sync-start, predicate, and timing metadata, with updated ABI and compile-time checks.
Orchestrator attribute propagation
src/a2a3/runtime/host_build_graph/runtime/orchestrator_core/pto_orchestrator.cpp
Task preparation and submission pass TaskAttrs into slot state for regular, dummy, and hidden allocation tasks.
Scheduler routing and early dispatch
src/a2a3/runtime/host_build_graph/runtime/scheduler/pto_scheduler.h, src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_dispatch.cpp
Predicate routing, sync-start gating, early-resolve propagation, timing publication, and dispatch checks read TaskAttrs.
Completion and timing handling
src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp
Completion uses TaskAttrs for timed-task notifications, pending-task gating, and sync-start promotion.

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

Possibly related issues

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant PTO2OrchestratorState
  participant PTO2TaskSlotState
  participant PTO2Scheduler
  participant AICPUTaskTiming
  PTO2OrchestratorState->>PTO2TaskSlotState: prepare task with TaskAttrs
  PTO2TaskSlotState->>PTO2Scheduler: route using TaskAttrs
  PTO2Scheduler->>PTO2Scheduler: evaluate predicate, sync-start, and early dispatch
  PTO2Scheduler->>AICPUTaskTiming: finish timed task using timing slot
Loading

Poem

A rabbit packed the flags just right,
Early hops and timing bright.
Masks now guard the slots below,
While task attrs steer the flow.
Sync and predicates find their place—
Completion bounds the run with grace.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% 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
Title check ✅ Passed The title clearly matches the main change: consolidating per-task markers into TaskAttrs in a2a3 host_build_graph.
Description check ✅ Passed The description is directly related to the changeset and accurately describes the TaskAttrs consolidation and scheduler updates.
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.

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

🧹 Nitpick comments (1)
src/a2a3/runtime/host_build_graph/runtime/pto_runtime2_types.h (1)

206-220: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Consider restoring an offsetof check alongside the sizeof assertion.

The comment explicitly states the scheduler/shared-memory ABI depends on packed_buffer_base's offset staying fixed, but only sizeof(PTO2TaskDescriptor) == 40 is asserted now. sizeof alone doesn't lock down where packed_buffer_base lands within the struct — a future insertion elsewhere in the struct that happens to preserve total size (e.g., another compensating pad removal) would pass this assertion while silently moving the offset the ABI comment says must stay fixed.

🛡️ Suggested addition
 static_assert(sizeof(PTO2TaskDescriptor) == 40, "PTO2TaskDescriptor size is part of the shared-memory ABI");
+static_assert(
+    offsetof(PTO2TaskDescriptor, packed_buffer_base) == 24,
+    "packed_buffer_base offset is part of the shared-memory ABI"
+);
🤖 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/a2a3/runtime/host_build_graph/runtime/pto_runtime2_types.h` around lines
206 - 220, Add a static_assert using offsetof(PTO2TaskDescriptor,
packed_buffer_base) to enforce the documented fixed offset, alongside the
existing size assertion. Keep the assertion aligned with the current ABI layout
and retain the sizeof check for the overall descriptor size.
🤖 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.

Nitpick comments:
In `@src/a2a3/runtime/host_build_graph/runtime/pto_runtime2_types.h`:
- Around line 206-220: Add a static_assert using offsetof(PTO2TaskDescriptor,
packed_buffer_base) to enforce the documented fixed offset, alongside the
existing size assertion. Keep the assertion aligned with the current ABI layout
and retain the sizeof check for the overall descriptor size.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a9f6e83f-948d-4ad0-ab9c-08d8ccda8f39

📥 Commits

Reviewing files that changed from the base of the PR and between 56919a7 and ad9d409.

📒 Files selected for processing (7)
  • src/a2a3/runtime/host_build_graph/runtime/orchestrator_core/pto_orchestrator.cpp
  • src/a2a3/runtime/host_build_graph/runtime/pto_runtime2_types.h
  • src/a2a3/runtime/host_build_graph/runtime/pto_submit_types.h
  • src/a2a3/runtime/host_build_graph/runtime/pto_types.h
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/pto_scheduler.h
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_completion.cpp
  • src/a2a3/runtime/host_build_graph/runtime/scheduler/scheduler_dispatch.cpp

…hbg)

Mirror of the tensormap_and_ringbuffer consolidation (hw-native-sys#1402) to the a2a3
host_build_graph runtime: fold the four scattered per-task markers into a
single TaskAttrs byte on PTO2TaskSlotState, and revert active_mask to a
pure subtask-slot mask.

hbg gained predicated dispatch in hw-native-sys#1434, so it now carries the same four
markers as tmr (allow_early_resolve, sync_start, has_predicate, timing tag)
and this is a 1:1 port of the settled tmr design.

- Add TaskAttrs (pto_submit_types.h): bit0 allow_early_resolve,
  bit1 sync_start, bit2 has_predicate, bit3 is_timed, bits4-7 timing_tag.
- Drop SYNC_START/HAS_PREDICATE flag bits and accessors from ActiveMask;
  it now carries only core_mask (bits 0-2).
- Remove task_timing_slot from PTO2TaskDescriptor; the tag now rides the
  scheduler's hot slot_state line. Descriptor size/ABI (40B,
  packed_buffer_base offset) unchanged; PTO2TaskSlotState stays 64B
  (task_attrs reuses the byte allow_early_resolve occupied, alongside the
  atomic lifecycle_flags).
- prepare_task writes task_attrs per submit alongside active_mask;
  attributes are assembled at each submit entry point (submit_task,
  submit_dummy_task, alloc_tensors).
- Update all scheduler read sites (dispatch/completion/scheduler.h) to
  read the attributes off slot_state.
- Static-assert NUM_TASK_TIMING_SLOTS <= 16 and TASK_TIMING_SLOT_NONE
  == -1 so the 4-bit tag field and the untagged sentinel stay coupled.

Accessor naming matches the settled tmr baseline: predicate getters
(allow_early_resolve / requires_sync_start / has_predicate / is_timed),
set_<concept> setters (set_early_resolve / set_sync_start / set_predicate /
set_timing_slot).

Behavior-neutral refactor. Verified: a2a3sim st (predicated_dispatch,
matmul, bgemm, paged_attention, vector_example). The a2a3 cpput timing/wiring
tests build against tmr headers (unchanged here). Part of hw-native-sys#1402.
@ChaoZheng109
ChaoZheng109 force-pushed the refactor/issue-1402-a2a3-hbg-task-attrs branch from ad9d409 to 2f7cadc Compare July 23, 2026 09:10
@ChaoZheng109
ChaoZheng109 merged commit d0bc661 into hw-native-sys:main Jul 23, 2026
15 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