Merged
fix(machine): Improve ctrl cache replay performance #6382
可惜春残风雨又Add on Sep 16
fix(machine): Improve ctrl cache replay performance #6382
Merged
可惜春残风雨又Add on Sep 16
可惜春残风雨又
可惜春残风雨又Collaborators
Sep 16

1、将 PredCount 以及 readyque 改为 A B 两份,通过pingpong 结构,当前轮次 ctrl push task 之后,对 B 做 restore ,利用 ctrl 结尾空闲时间掩盖 restore 开销

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 可惜春残风雨又's contribution.)
可惜春残风雨又可惜春残风雨又Collaborators
Sep 16 Created pull request, commit 6cf6707f
可惜春残风雨又可惜春残风雨又Collaborators
Sep 16 Associated issue: [Task|任务跟踪]:ControlFlow Cache Reloc/Restore 性能优化
atomgit-bot
atomgit-bot
Sep 16 Comments:

变更摘要

本 PR 旨在提升 ctrl cache 回放(replay)性能。核心思路是将 PredCount 与 readyQueue/dieReadyQueue 改为 A/B 两份缓冲的 ping-pong 结构:每次启动前只做指针切换(PingPongSwap),而把真正的数据恢复(PingPongRestore)推迟到本轮 ctrl push task 结束后的空闲尾段(PingPongRestoreAll)执行,用 ctrl 尾部空闲时间掩盖 restore 的 memcpy 开销。同时针对 full cache 场景做了优化:BitmapDataRestoreTask 只需执行一次,且 full cache 下跳过 ResetRerun。相关改动覆盖 device_execute_context.cpp/h、device_ctrl.h、dev_encode.cpp、dev_encode_function_dupped_data.h、dev_encode_program_ctrlflow_cache.cpp/h、queues.h 及对应 UT。

主要改动

  • PredCount 改为 ping-pong 双缓冲:dev_encode.cpp 中 predCount 数据区大小乘以 PRED_COUNT_PINGPONG_NUM(2);DynFuncDataCache 新增 predCountPing/predCountPong 指针并随 dynFuncDataCacheList 一起重定位;备份时将快照同时写入 PONG 切片,PredCountPingPongSwap 仅交换切片指针(predCount 指向当前 PING),PredCountPingPongRestore 在后台刷新非活跃切片,避免启动前的整片 memcpy。
  • ready/die 队列改为 ping-pong 元素缓冲:ReadyQueueCache/DieReadyQueueCache 新增 pingElem/pongElem 指针数组并在备份时分配影子缓冲、拷贝快照;queues.h 的 QueueGeneric 新增 Data() 与 FillFrom 用于直接重绑 elem_;ReadyQueueDataPingPongSwap/DieReadyQueuePingPongSwap 在 push 前只重绑到干净缓冲,ReadyQueueDataPingPongRestore/DieReadyQueuePingPongRestore 延迟刷新另一份。
  • restore 推迟到 ctrl 尾部执行:DeviceExecuteContext 新增 PingPongRestoreAll,在 GELaunchPartialCache 中于 RunControlFlow 之后统一执行 PredCount 与 ready/die 队列的 ping-pong restore;GELaunchRunCached 内改为仅做 swap 与必要的 DrcoPredCountDataRestore,以此掩盖 restore 开销。
  • full cache 场景优化:新增 bitmapRestoreDone 标志,full cache 下 BitmapDataRestoreTask 只执行一次,并在 PingPongRestoreAll 中置位;device_ctrl.h 在 full cache 时跳过 devProg->ResetRerun()。
  • 接口调整与测试补充:IsActivatedPartialCache 更名为 IsActivatedCache(device_ctrl.h、device_execute_context.cpp 同步使用);device_stitch_context.cpp 中 dynFuncDataCacheList 初始化补充 ping/pong predCount 指针;UT 新增 PredCountPingPongRoundTrip、ReadyQueuePingPongRoundTrip 等用例覆盖连续多轮回放下双缓冲协议的正确性。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 16 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 16 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 16 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
framework/src/machine ✅ jason_yuan_ye, gaoxingwang (2/2) ✅ jason_yuan_ye (1/1)
repo-cann/pypto ✅ jason_yuan_ye, gaoxingwang (2/2) ✅ jason_yuan_ye (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

qq_52905393, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robotCANN-robotCollaborators
Sep 16 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
可惜春残风雨又
可惜春残风雨又Collaborators
Sep 16 Comments:

/compile

likedislike
可惜春残风雨又可惜春残风雨又Collaborators
Sep 16 Pre merge succeeded (commit_id: 27c5fd6a4851273d2979ac97cab591a818d5401c)
CANN-robot
CANN-robotCollaborators
Sep 16 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 16 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 16 Added label: ci-pipeline-passed
袁野
袁野Collaborators
Sep 16 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: approved
gaoxingwang
gaoxingwangCollaborators
Sep 16 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 16 Merged pull request