Skip to content

Refactor: flatten executing_reg_task_ids; add orch_to_sched control#325

Open
poursoul wants to merge 1 commit intohw-native-sys:mainfrom
poursoul:opt-scheduler
Open

Refactor: flatten executing_reg_task_ids; add orch_to_sched control#325
poursoul wants to merge 1 commit intohw-native-sys:mainfrom
poursoul:opt-scheduler

Conversation

@poursoul
Copy link
Collaborator

@poursoul poursoul commented Mar 18, 2026

executing_reg_task_ids refactor:

  • Core IDs are globally unique, so the per-thread dimension on
    executing_reg_task_ids_ was redundant and complicated reassignment
  • Remove executing_reg_task_ids parameter threading through
    check_running_cores_for_completion and dispatch_subtask_to_core
  • Simplify reassign_cores_for_all_threads by using a bool running
    lookup instead of collecting separate running/idle lists
  • Reorder CoreTypeTracker fields: counts before arrays
  • Add profiling instrumentation for core reassignment cost
  • Remove perf_aicpu_record_orch_phase from PHASE_END macro

orch_to_sched control (PTO2_ORCH_TO_SCHED env var):

  • When disabled (default), orchestrator threads exit after orchestration
    without converting to scheduler threads or reassigning cores
  • Enable with PTO2_ORCH_TO_SCHED=1 to restore the previous behavior
    where orchestrators become schedulers after orchestration completes

@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 enhances the runtime's thread management by introducing a new environment variable, PTO2_ORCH_TO_SCHED, which dictates the post-orchestration behavior of orchestrator threads. This provides greater flexibility, allowing these threads to either terminate or seamlessly convert into scheduler threads. The changes also include internal refactoring to optimize how task IDs are tracked and cores are reassigned, improving the overall efficiency and clarity of the thread execution model.

Highlights

  • Configurable Orchestrator-to-Scheduler Transition: Introduced a new environment variable, PTO2_ORCH_TO_SCHED, allowing control over whether orchestrator threads exit after orchestration or transition into scheduler threads.
  • Task ID Tracking Refactoring: Refactored the executing_reg_task_ids_ member in AicpuExecutor from a 2D array to a 1D array, simplifying task ID management across cores.
  • Updated Core Reassignment Logic: Modified core reassignment and task dispatch functions to integrate the new orch_to_sched_ flag and streamline core state handling.
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.

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

This pull request introduces the PTO2_ORCH_TO_SCHED environment variable to control the transition of orchestrator threads to scheduler threads. The implementation correctly adds the feature flag and applies it to the relevant logic paths. The pull request also includes a significant and beneficial refactoring of executing_reg_task_ids_ to be a global array, which simplifies the code. I've found one potential issue where a profiling call seems to have been accidentally removed.

@poursoul poursoul force-pushed the opt-scheduler branch 2 times, most recently from 4f2d3a6 to 5deaaf3 Compare March 18, 2026 08:13
@poursoul poursoul changed the title feat(runtime): add PTO2_ORCH_TO_SCHED env var to control orchestrator-to-scheduler transition Refactor: flatten executing_reg_task_ids; add orch_to_sched control Mar 18, 2026
executing_reg_task_ids refactor:
- Core IDs are globally unique, so the per-thread dimension on
  executing_reg_task_ids_ was redundant and complicated reassignment
- Remove executing_reg_task_ids parameter threading through
  check_running_cores_for_completion and dispatch_subtask_to_core
- Simplify reassign_cores_for_all_threads by using a bool running
  lookup instead of collecting separate running/idle lists
- Reorder CoreTypeTracker fields: counts before arrays
- Add profiling instrumentation for core reassignment cost
- Remove perf_aicpu_record_orch_phase from PHASE_END macro

orch_to_sched control (PTO2_ORCH_TO_SCHED env var):
- When disabled (default), orchestrator threads exit after orchestration
  without converting to scheduler threads or reassigning cores
- Enable with PTO2_ORCH_TO_SCHED=1 to restore the previous behavior
  where orchestrators become schedulers after orchestration completes
Copy link
Collaborator

@hw-native-sys-bot hw-native-sys-bot left a comment

Choose a reason for hiding this comment

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

Review: commented-out code should be removed

Comment on lines +744 to +749
// // 这里的初始化可能不需要,因为状态没发生变化
// memset(trackers_[i].core_idle, 0, sizeof(trackers_[i].core_idle));
// // 这里的初始化可能不需要,因为对于没有重分配到其他核上的core,本身状态不变,而其他核上初始已经修改过了
// for (int32_t j = 0; j < MAX_CORES_PER_THREAD; j++) {
// executing_reg_task_ids_[i][j] = AICPU_TASK_INVALID;
// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

这段注释掉的旧代码应该直接删除而不是留着。如果确认"状态没发生变化"这个判断是正确的,那就不需要保留;如果还不确定,应该加个 TODO 或者先验证再合入。注释掉的代码会增加维护负担,后续开发者不清楚是"暂时禁用"还是"已废弃待删"。

另外 executing_reg_task_ids_ 已经从二维降为一维了,这里注释中的 executing_reg_task_ids_[i][j] 已经无法编译,如果取消注释会直接报错,进一步说明应该删除。

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