Skip to content

sync(a5): align host_build_graph runtime with a2a3 implementation#250

Merged
ChaoWao merged 1 commit intohw-native-sys:mainfrom
ChaoZheng109:a5-runtime-host
Mar 11, 2026
Merged

sync(a5): align host_build_graph runtime with a2a3 implementation#250
ChaoWao merged 1 commit intohw-native-sys:mainfrom
ChaoZheng109:a5-runtime-host

Conversation

@ChaoZheng109
Copy link
Collaborator

Synchronize A5 host_build_graph runtime implementation with improvements from a2a3, including cache coherence fixes, API enhancements, and documentation.

Changes:

  • aicore_executor: optimize cache flush timing

    • Remove per-task global DCCI flush (performance bottleneck)
    • Clear EXIT_SIGNAL before main loop to prevent stale signals
    • Add single DCCI flush at kernel exit for cross-core visibility
  • aicpu_executor: improve handshake and naming

    • Rename all_hanks -> all_handshakes for clarity
    • Add AICore register initialization after discovery
    • Update deinit signature to take Runtime parameter
  • runtime.h: add kernel management and API compatibility

    • Track registered kernel func_ids for cleanup
    • Add remove_kernel_binary() host API
    • Add orch_thread_num field for API compatibility with rt2
  • docs: add RUNTIME_LOGIC.md architecture documentation

    • Document core data structures and execution flow
    • Explain build/init, execution, and cleanup phases
    • Reference key implementation files

This sync ensures A5 host_build_graph matches the battle-tested a2a3 implementation for correctness and performance.

Synchronize A5 host_build_graph runtime implementation with improvements
from a2a3, including cache coherence fixes, API enhancements, and documentation.

Changes:
- aicore_executor: optimize cache flush timing
  * Remove per-task global DCCI flush (performance bottleneck)
  * Clear EXIT_SIGNAL before main loop to prevent stale signals
  * Add single DCCI flush at kernel exit for cross-core visibility

- aicpu_executor: improve handshake and naming
  * Rename all_hanks -> all_handshakes for clarity
  * Add AICore register initialization after discovery
  * Update deinit signature to take Runtime parameter

- runtime.h: add kernel management and API compatibility
  * Track registered kernel func_ids for cleanup
  * Add remove_kernel_binary() host API
  * Add orch_thread_num field for API compatibility with rt2

- docs: add RUNTIME_LOGIC.md architecture documentation
  * Document core data structures and execution flow
  * Explain build/init, execution, and cleanup phases
  * Reference key implementation files

This sync ensures A5 host_build_graph matches the battle-tested a2a3
implementation for correctness and performance.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request synchronizes the A5 host_build_graph runtime implementation with the established a2a3 version. The changes primarily focus on enhancing cache coherence, improving API clarity and functionality, and providing comprehensive documentation. This ensures the A5 implementation benefits from battle-tested correctness and performance optimizations, streamlining its operation and maintainability.

Highlights

  • AICore Executor Optimizations: Removed a performance-bottlenecking per-task global DCCI flush, added logic to clear the EXIT_SIGNAL before the main loop, and introduced a single DCCI flush at kernel exit for improved cross-core visibility and cache coherence.
  • AICPU Executor Enhancements: Renamed internal handshake variables for clarity, added initialization of AICore registers after core discovery, and updated the deinit function signature to accept a Runtime parameter, enabling proper cache invalidation during cleanup.
  • Runtime API and Kernel Management: Introduced mechanisms to track registered kernel function IDs and added a remove_kernel_binary() host API, facilitating better resource management and cleanup of kernel binaries. An orch_thread_num field was also added for API compatibility.
  • New Documentation: A new documentation file, RUNTIME_LOGIC.md, was added to comprehensively describe the core data structures, build/init flow, execution flow, and cleanup phases of the host_build_graph runtime.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/a5/runtime/host_build_graph/aicore/aicore_executor.cpp
    • Removed a per-task global DCCI flush.
    • Added logic to clear EXIT_SIGNAL before the main loop.
    • Introduced a single DCCI flush at kernel exit.
  • src/a5/runtime/host_build_graph/aicpu/aicpu_executor.cpp
    • Renamed all_hanks to all_handshakes for better readability.
    • Modified deinit function signature to accept a Runtime* parameter.
    • Added initialization of AICore registers after core discovery.
    • Increased MAX_IDLE_ITERATIONS and decreased WARN_INTERVAL for timeout detection.
    • Added cache invalidation for the Runtime address range during deinitialization.
  • src/a5/runtime/host_build_graph/docs/RUNTIME_LOGIC.md
    • Added a new documentation file detailing the runtime logic, data structures, and execution flow.
  • src/a5/runtime/host_build_graph/host/runtime_compile_info.cpp
    • Updated the platform check in get_incore_compiler from "a5" to "a2a3".
  • src/a5/runtime/host_build_graph/host/runtime_maker.cpp
    • Implemented cleanup logic for registered kernel binaries during runtime validation.
  • src/a5/runtime/host_build_graph/runtime/runtime.cpp
    • Initialized registered_kernel_count_ in the constructor.
  • src/a5/runtime/host_build_graph/runtime/runtime.h
    • Added remove_kernel_binary function pointer to the HostApi struct.
    • Introduced orch_thread_num member for API compatibility.
    • Added registered_kernel_func_ids_ and registered_kernel_count_ members for kernel tracking.
    • Added get_registered_kernel_count, get_registered_kernel_func_id, and clear_registered_kernels methods.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

Choose a reason for hiding this comment

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

Code Review

The pull request introduces significant changes to the AICore and AICPU executors, focusing on cache coherence, inter-core communication, and runtime cleanup. Key changes include removing explicit DCCI from execute_task and adding it before kernel exit in aicore_execute, along with clearing stale exit signals. The AicpuExecutor::deinit method was updated to invalidate the Runtime cache and now accepts a Runtime* argument. Variable names like all_hanks were refactored to all_handshakes for clarity, and timeout constants MAX_IDLE_ITERATIONS and WARN_INTERVAL were adjusted. A new RUNTIME_LOGIC.md document was added to detail the system's architecture and execution flow. Additionally, the Runtime class was enhanced to track registered kernel binaries for proper cleanup, and the get_incore_compiler platform check was updated from 'a5' to 'a2a3'.

Review comments highlight several improvement opportunities: the MAX_IDLE_ITERATIONS and WARN_INTERVAL values in aicpu_executor.cpp are identified as magic numbers needing better explanation or a time-based timeout. The newly added RUNTIME_LOGIC.md documentation is noted as being out of sync with the actual register-based communication protocol used by the executors and requires an update. Finally, the set_function_bin_addr method in runtime.h has a potential bug where func_id could be added multiple times to the registered_kernel_func_ids_ array, risking overflow and double-free issues during cleanup, suggesting a check for duplicates.

@ChaoWao ChaoWao merged commit 56a2c61 into hw-native-sys:main Mar 11, 2026
3 checks passed
ChaoZheng109 added a commit to ChaoZheng109/simpler that referenced this pull request Mar 18, 2026
…HEAD)

Synchronize A5 tensormap_and_ringbuffer runtime and platform with
a2a3 improvements introduced after 56a2c61. Follows the sync pattern
established in hw-native-sys#250 and hw-native-sys#300.

Platform (src/a5/platform/):
- 2f58a2f (hw-native-sys#267): add AICPU thread affinity (platform_aicpu_affinity.h/cpp),
  PLATFORM_MAX_AICPU_THREADS_JUST_FOR_LAUNCH, device_runner, kernel.cpp,
  CMakeLists.txt
- b903e7b: sync perf_profiling.h for multi-ring support
- 334d355 (hw-native-sys#254): sync performance_collector_aicore.h for slim dispatch

Runtime host_build_graph (src/a5/runtime/host_build_graph/):
- 334d355 (hw-native-sys#254): slim dispatch payload in aicore_executor.cpp
- dd7ada4: standardize register init and exit handshake in aicore_executor.cpp
- 2f58a2f (hw-native-sys#267): AICPU affinity gate in aicpu_executor.cpp

Runtime tensormap_and_ringbuffer (src/a5/runtime/tensormap_and_ringbuffer/):
- e2e38b9 (hw-native-sys#249): cluster-based mixed-task dispatch; add pto_submit_types.h
  and SUBMIT_BY_CLUSTER.md
- a842263 (hw-native-sys#255): separate local ready queue by CoreType in pto_scheduler.h
- cf6462c (hw-native-sys#268): consolidate per-task state into PTO2TaskSlotState
  (pto_runtime2_types.h, pto_scheduler.cpp, pto_orchestrator.cpp)
- b903e7b: multi-ring buffer architecture (pto_shared_memory, MULTI_RING.md,
  aicpu_executor.cpp, perf_profiling.h)
- 5d92137 (hw-native-sys#264): DepListPool ring buffer reclamation (pto_ring_buffer.h/cpp)
- 54d082c (hw-native-sys#281): replace task_id with slot-state pointer across scheduler,
  orchestrator, ring buffer, executor, RUNTIME_LOGIC.md
- d305376 (hw-native-sys#277): add scope deadlock detection in pto_orchestrator
- 1e41a3a (hw-native-sys#274): per-thread orchestrator phase profiling
- f5da078 (hw-native-sys#275): progress-aware ring buffer spin detection
  (pto_ring_buffer.h, pto_orchestrator.cpp, runtime_maker.cpp)
- 10f6415 (hw-native-sys#284): tighten PTO2_PROFILING macro guards; sync profiling_levels.md
- 9c158e0 (hw-native-sys#291): emergency shutdown on fatal error
  (aicpu_executor, pto_orchestration_api.h, pto_orchestrator, pto_shared_memory)
- 94f39ff (hw-native-sys#301): refactor PTOParam to aggregated container with parallel arrays
  (pto_types.h, pto_runtime2_types.h, pto_scheduler, pto_shared_memory,
  pto_tensormap, pto_orchestrator, runtime2)
- 15e6034 (hw-native-sys#308): refactor Tensor fields and pto_tensormap for cache locality
- 77a81aa (hw-native-sys#306): replace PTOParam assert with orchestration error handling

Examples & tests (examples/a5/, tests/device_tests/a5/):
- 8cf8981 (hw-native-sys#293): replace PipeSyncFunc with FULL_MEMORY_BARRIER in kernels
- b88eed3 (hw-native-sys#302): optimize paged attention pipeline, eliminate GM round-trips
- 94f39ff (hw-native-sys#301) + 15e6034 (hw-native-sys#308): update orchestration to new PTOParam API
ChaoZheng109 added a commit to ChaoZheng109/simpler that referenced this pull request Mar 19, 2026
…HEAD)

Synchronize A5 tensormap_and_ringbuffer runtime and platform with
a2a3 improvements introduced after 56a2c61. Follows the sync pattern
established in hw-native-sys#250 and hw-native-sys#300.

Platform (src/a5/platform/):
- 2f58a2f (hw-native-sys#267): add AICPU thread affinity (platform_aicpu_affinity.h/cpp),
  PLATFORM_MAX_AICPU_THREADS_JUST_FOR_LAUNCH, device_runner, kernel.cpp,
  CMakeLists.txt
- b903e7b: sync perf_profiling.h for multi-ring support
- 334d355 (hw-native-sys#254): sync performance_collector_aicore.h for slim dispatch

Runtime host_build_graph (src/a5/runtime/host_build_graph/):
- 334d355 (hw-native-sys#254): slim dispatch payload in aicore_executor.cpp
- dd7ada4: standardize register init and exit handshake in aicore_executor.cpp
- 2f58a2f (hw-native-sys#267): AICPU affinity gate in aicpu_executor.cpp

Runtime tensormap_and_ringbuffer (src/a5/runtime/tensormap_and_ringbuffer/):
- e2e38b9 (hw-native-sys#249): cluster-based mixed-task dispatch; add pto_submit_types.h
  and SUBMIT_BY_CLUSTER.md
- a842263 (hw-native-sys#255): separate local ready queue by CoreType in pto_scheduler.h
- cf6462c (hw-native-sys#268): consolidate per-task state into PTO2TaskSlotState
  (pto_runtime2_types.h, pto_scheduler.cpp, pto_orchestrator.cpp)
- b903e7b: multi-ring buffer architecture (pto_shared_memory, MULTI_RING.md,
  aicpu_executor.cpp, perf_profiling.h)
- 5d92137 (hw-native-sys#264): DepListPool ring buffer reclamation (pto_ring_buffer.h/cpp)
- 54d082c (hw-native-sys#281): replace task_id with slot-state pointer across scheduler,
  orchestrator, ring buffer, executor, RUNTIME_LOGIC.md
- d305376 (hw-native-sys#277): add scope deadlock detection in pto_orchestrator
- 1e41a3a (hw-native-sys#274): per-thread orchestrator phase profiling
- f5da078 (hw-native-sys#275): progress-aware ring buffer spin detection
  (pto_ring_buffer.h, pto_orchestrator.cpp, runtime_maker.cpp)
- 10f6415 (hw-native-sys#284): tighten PTO2_PROFILING macro guards; sync profiling_levels.md
- 9c158e0 (hw-native-sys#291): emergency shutdown on fatal error
  (aicpu_executor, pto_orchestration_api.h, pto_orchestrator, pto_shared_memory)
- 94f39ff (hw-native-sys#301): refactor PTOParam to aggregated container with parallel arrays
  (pto_types.h, pto_runtime2_types.h, pto_scheduler, pto_shared_memory,
  pto_tensormap, pto_orchestrator, runtime2)
- 15e6034 (hw-native-sys#308): refactor Tensor fields and pto_tensormap for cache locality
- 77a81aa (hw-native-sys#306): replace PTOParam assert with orchestration error handling

Examples & tests (examples/a5/, tests/device_tests/a5/):
- 8cf8981 (hw-native-sys#293): replace PipeSyncFunc with FULL_MEMORY_BARRIER in kernels
- b88eed3 (hw-native-sys#302): optimize paged attention pipeline, eliminate GM round-trips
- 94f39ff (hw-native-sys#301) + 15e6034 (hw-native-sys#308): update orchestration to new PTOParam API
ChaoZheng109 added a commit to ChaoZheng109/simpler that referenced this pull request Mar 19, 2026
Synchronize A5 tensormap_and_ringbuffer runtime and platform with
a2a3 improvements introduced after 56a2c61. Follows the sync pattern
established in hw-native-sys#250 and hw-native-sys#300.

Platform (src/a5/platform/):
- 2f58a2f (hw-native-sys#267): add AICPU thread affinity (platform_aicpu_affinity.h/cpp),
  PLATFORM_MAX_AICPU_THREADS_JUST_FOR_LAUNCH, device_runner, kernel.cpp,
  CMakeLists.txt
- b903e7b: sync perf_profiling.h for multi-ring support
- 334d355 (hw-native-sys#254): sync performance_collector_aicore.h for slim dispatch

Runtime host_build_graph (src/a5/runtime/host_build_graph/):
- 334d355 (hw-native-sys#254): slim dispatch payload in aicore_executor.cpp
- dd7ada4: standardize register init and exit handshake in aicore_executor.cpp
- 2f58a2f (hw-native-sys#267): AICPU affinity gate in aicpu_executor.cpp
- 83473ba (hw-native-sys#323): replace block core assignment with round-robin in AICPU executor

Runtime tensormap_and_ringbuffer (src/a5/runtime/tensormap_and_ringbuffer/):
- e2e38b9 (hw-native-sys#249): cluster-based mixed-task dispatch; add pto_submit_types.h
  and SUBMIT_BY_CLUSTER.md
- a842263 (hw-native-sys#255): separate local ready queue by CoreType in pto_scheduler.h
- cf6462c (hw-native-sys#268): consolidate per-task state into PTO2TaskSlotState
  (pto_runtime2_types.h, pto_scheduler.cpp, pto_orchestrator.cpp)
- b903e7b: multi-ring buffer architecture (pto_shared_memory, MULTI_RING.md,
  aicpu_executor.cpp, perf_profiling.h)
- 5d92137 (hw-native-sys#264): DepListPool ring buffer reclamation (pto_ring_buffer.h/cpp)
- 54d082c (hw-native-sys#281): replace task_id with slot-state pointer across scheduler,
  orchestrator, ring buffer, executor, RUNTIME_LOGIC.md
- d305376 (hw-native-sys#277): add scope deadlock detection in pto_orchestrator
- 1e41a3a (hw-native-sys#274): per-thread orchestrator phase profiling
- f5da078 (hw-native-sys#275): progress-aware ring buffer spin detection
  (pto_ring_buffer.h, pto_orchestrator.cpp, runtime_maker.cpp)
- 10f6415 (hw-native-sys#284): tighten PTO2_PROFILING macro guards; sync profiling_levels.md
- 9c158e0 (hw-native-sys#291): emergency shutdown on fatal error
  (aicpu_executor, pto_orchestration_api.h, pto_orchestrator, pto_shared_memory)
- 94f39ff (hw-native-sys#301): refactor PTOParam to aggregated container with parallel arrays
  (pto_types.h, pto_runtime2_types.h, pto_scheduler, pto_shared_memory,
  pto_tensormap, pto_orchestrator, runtime2)
- 15e6034 (hw-native-sys#308): refactor Tensor fields and pto_tensormap for cache locality
- 77a81aa (hw-native-sys#306): replace PTOParam assert with orchestration error handling
- e4348eb (hw-native-sys#315): move reclamation state into owning data structures
- c17770e (hw-native-sys#320): encapsulate dep pool operations and reorder orchestrator pipeline
- 83473ba (hw-native-sys#323): replace block core assignment with round-robin in AICPU executor

Tests (tests/device_tests/a5/):
- 439ccd4 (hw-native-sys#322): unify paged attention golden cases across test variants

Examples & tests (examples/a5/, tests/device_tests/a5/):
- 8cf8981 (hw-native-sys#293): replace PipeSyncFunc with FULL_MEMORY_BARRIER in kernels
- b88eed3 (hw-native-sys#302): optimize paged attention pipeline, eliminate GM round-trips
- 94f39ff (hw-native-sys#301) + 15e6034 (hw-native-sys#308): update orchestration to new PTOParam API
ChaoZheng109 added a commit that referenced this pull request Mar 19, 2026
Synchronize A5 tensormap_and_ringbuffer runtime and platform with
a2a3 improvements introduced after 56a2c61. Follows the sync pattern
established in #250 and #300.

Platform (src/a5/platform/):
- 2f58a2f (#267): add AICPU thread affinity (platform_aicpu_affinity.h/cpp),
  PLATFORM_MAX_AICPU_THREADS_JUST_FOR_LAUNCH, device_runner, kernel.cpp,
  CMakeLists.txt
- b903e7b: sync perf_profiling.h for multi-ring support
- 334d355 (#254): sync performance_collector_aicore.h for slim dispatch

Runtime host_build_graph (src/a5/runtime/host_build_graph/):
- 334d355 (#254): slim dispatch payload in aicore_executor.cpp
- dd7ada4: standardize register init and exit handshake in aicore_executor.cpp
- 2f58a2f (#267): AICPU affinity gate in aicpu_executor.cpp
- 83473ba (#323): replace block core assignment with round-robin in AICPU executor

Runtime tensormap_and_ringbuffer (src/a5/runtime/tensormap_and_ringbuffer/):
- e2e38b9 (#249): cluster-based mixed-task dispatch; add pto_submit_types.h
  and SUBMIT_BY_CLUSTER.md
- a842263 (#255): separate local ready queue by CoreType in pto_scheduler.h
- cf6462c (#268): consolidate per-task state into PTO2TaskSlotState
  (pto_runtime2_types.h, pto_scheduler.cpp, pto_orchestrator.cpp)
- b903e7b: multi-ring buffer architecture (pto_shared_memory, MULTI_RING.md,
  aicpu_executor.cpp, perf_profiling.h)
- 5d92137 (#264): DepListPool ring buffer reclamation (pto_ring_buffer.h/cpp)
- 54d082c (#281): replace task_id with slot-state pointer across scheduler,
  orchestrator, ring buffer, executor, RUNTIME_LOGIC.md
- d305376 (#277): add scope deadlock detection in pto_orchestrator
- 1e41a3a (#274): per-thread orchestrator phase profiling
- f5da078 (#275): progress-aware ring buffer spin detection
  (pto_ring_buffer.h, pto_orchestrator.cpp, runtime_maker.cpp)
- 10f6415 (#284): tighten PTO2_PROFILING macro guards; sync profiling_levels.md
- 9c158e0 (#291): emergency shutdown on fatal error
  (aicpu_executor, pto_orchestration_api.h, pto_orchestrator, pto_shared_memory)
- 94f39ff (#301): refactor PTOParam to aggregated container with parallel arrays
  (pto_types.h, pto_runtime2_types.h, pto_scheduler, pto_shared_memory,
  pto_tensormap, pto_orchestrator, runtime2)
- 15e6034 (#308): refactor Tensor fields and pto_tensormap for cache locality
- 77a81aa (#306): replace PTOParam assert with orchestration error handling
- e4348eb (#315): move reclamation state into owning data structures
- c17770e (#320): encapsulate dep pool operations and reorder orchestrator pipeline
- 83473ba (#323): replace block core assignment with round-robin in AICPU executor

Tests (tests/device_tests/a5/):
- 439ccd4 (#322): unify paged attention golden cases across test variants

Examples & tests (examples/a5/, tests/device_tests/a5/):
- 8cf8981 (#293): replace PipeSyncFunc with FULL_MEMORY_BARRIER in kernels
- b88eed3 (#302): optimize paged attention pipeline, eliminate GM round-trips
- 94f39ff (#301) + 15e6034 (#308): update orchestration to new PTOParam API
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