已合并
【PR】: aclGraph optimize #3457
houyanbao创建于 7月7日
【PR】: aclGraph optimize #3457
已合并
houyanbao创建于 7月7日
houyanbao成员
7月7日

Pull Request

描述

1、优化model sequenceid的分配逻辑,在添加task的地方统一分配,避免流程出现遗留
2、aclGraph模型执行时,当notify资源不足时,当前只释放了notifyid,没有释放sqcq,这会导致被释放的模型,下次再次执行时,没有更新notifyid,为简化流程,提升代码可读性,模型资源释放时,sqcq和notify整体释放

变更类型

请选择本次引入的变更类型:

关联的Issue

NA

如何测试

描述测试此变更的步骤和前提条件:

  1. 验证SK功能
    2.验证aclGraph notify资源不足,触发模型资源回收流程

核对清单

其他信息

在此添加任何其他关于本次 PR 的说明。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 houyanbao 的贡献)
Hhouyanbao成员
7月7日 添加了label:enhancement
Hhouyanbao成员
7月7日 创建了 pull request,commit d02977d4
atomgit-bot
atomgit-bot
7月7日 评论:

变更摘要

本次 PR 主要对 aclGraph 中 CaptureModel 的资源管理进行两项优化:一是将 modelSeqId 的分配逻辑统一收敛到 StarsAddTaskToStream 中添加任务的位置,消除此前分散在多个调用点的重复或遗漏风险;二是将 ReleaseSqCq 重构为 ReleaseSqCqAndNotifyId,使 sqcq 和 notifyId 在同一加锁临界区内整体释放,解决此前 notify 资源不足时仅释放 notifyId 而不释放 sqcq 导致下次执行时 notifyId 未更新的问题,同时简化了 TryRecycleCaptureModelResource 的回收流程。

主要改动

  • ReleaseSqCq 重构为 ReleaseSqCqAndNotifyId:在 capture_model.hpp / capture_model.cc 中将方法签名改为 ReleaseSqCqAndNotifyId(uint32_t &releaseSqNum, uint32_t &releaseNtyNum),内部同时释放 sqcq 和 notifyId,并从 ReleaseSqCqInternal 中移除 ReleaseNotifyId 调用,确保资源整体回收。
  • modelSeqId 分配逻辑集中化:移除 task_david.ccAllocCaptureTaskInfo)、stream_capture.ccAllocCaptureTaskWithoutLock)和 context_aclgraph.ccAddNotifyToAddedCaptureStream)中的 GenerateSeqId 调用,统一在 stream.ccstream_david.ccStarsAddTaskToStream 中延迟回收任务(delayRecycleTaskid_)路径下分配 modelSeqId
  • TryRecycleCaptureModelResource 回收流程简化:在 context_standard_soc_aclgraph.cc 中将原来分开判断 sq 和 notify 资源的两个 if 块合并为一个,条件改为 (allocSqNum > totalReleaseSqNum) || (ntfCnt > totalReleaseNtfNum),统一调用 ReleaseSqCqAndNotifyId 一次性回收两类资源。
  • UpdateNotifyId 错误码覆盖问题修复:在 capture_model.ccUpdateNotifyId 中引入局部变量 errorTmp 接收 TryRecycleCaptureModelResource 的返回值,避免覆盖 AllocId 的错误码 error,防止循环异常提前退出。
  • 测试用例同步适配rt_utest_capture_mode.ccrt_utest_david_task.ccrt_utest_tiny_stub.cc 等测试文件中所有 ReleaseSqCq 调用均更新为 ReleaseSqCqAndNotifyId 双参数形式;ModelDebugJsonPrint_AicpuTask 测试用例新增 InitByStream 初始化调用以确保 task 字段完整性。
likedislike
不准确?
atomgit-bot
atomgit-bot
7月7日 评论:

代码审查

我已全面审查了所有 15 个变更文件。以下是我的审查总结:


审查总结

已审查的文件

文件 结论
docs/design/features/aclgraph.md 无问题 — 仅文档名称更新
src/runtime/core/inc/model/capture_model.hpp 无问题 — 接口签名重命名
src/runtime/core/src/stream/stream.cc 无问题 — 添加 modelSeqId 分配逻辑
src/runtime/core/src/stream/stream_david.cc 无问题 — 添加 modelSeqId 分配逻辑
src/runtime/core/src/task/task_submit/v200/task_david.cc 无问题 — 移除冗余的 modelSeqId 分配
src/runtime/feature/aclgraph/capture_model.cc 1 个 P3 问题UpdateNotifyId 缺少休眠
src/runtime/feature/aclgraph/context_aclgraph.cc 无问题 — 移除冗余的 modelSeqId 分配
src/runtime/feature/aclgraph/context_standard_soc_aclgraph.cc 无问题 — 合并 SQ/CQ 与 Notify 释放为单次加锁
src/runtime/feature/aclgraph/stream_capture.cc 无问题 — 移除冗余的 modelSeqId 分配
src/runtime/feature/aclgraph/tiny/capture_model_tiny_stub.cc 无问题 — stub 函数签名同步更新
tests/ut/runtime/runtime/test/platform/910B/rt_utest_capture_mode.cc 无问题 — 测试适配新接口
tests/ut/runtime/runtime/test/platform/910B/rt_utest_cloudv2_disable_thread_test.cc 无问题 — 测试适配(添加 InitByStream)
tests/ut/runtime/runtime/test/platform/950/rt_utest_david_task.cc 无问题 — 测试适配新接口
tests/ut/runtime/runtime/test/platform/others/rt_utest_cloudv2_disable_thread_test.cc 无问题 — 测试适配(添加 InitByStream)
tests/ut/runtime/runtime/test/rt_utest_tiny_stub.cc 无问题 — 测试适配新接口

发现统计

  • P0: 0
  • P1: 0
  • P2: 0
  • P3: 1

整体风险评估:低风险

此 PR 的两项核心变更(modelSeqId 统一分配、SQ/CQ 与 Notify 整体释放)逻辑正确:

  1. modelSeqId 分配统一化:将分散在 AllocCaptureTaskInfoAllocCaptureTaskWithoutLockAddNotifyToAddedCaptureStream 三处的 GenerateSeqId() 调用统一收敛到 StarsAddTaskToStream,消除了遗漏路径,且修复了旧代码中 AddNotifyToAddedCaptureStream 对已提交任务的回溯赋值冗余。

  2. 资源释放合并ReleaseSqCqReleaseSqCqAndNotifyId 重构正确地将 SQ/CQ 和 Notify 释放合并为原子操作,同时消除了 ReleaseSqCqInternal 中对子模型 Notify 的重复释放(旧代码中 ReleaseSqCqReleaseSqCqInternal 各调一次 ReleaseNotifyId 处理子模型)。

  3. TryRecycleCaptureModelResource 简化:将两次加锁/解锁合并为一次,减少锁竞争,语义等价。

唯一的 P3 发现是 UpdateNotifyId 中回收成功但分配失败时缺少退避休眠,触发条件苛刻,实际影响极低。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
不准确?
CANN-robotCANN-robot成员
7月7日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月7日 评论:

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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
** gcw_kUomxQ2l, yanmingxiang (2/2) gcw_kUomxQ2l (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
7月7日 将wangtao43,zhangpengpeng8,yanmingxiang,Reyn52166,ykl999,gcw_kUomxQ2l,Andy-lb,tingwood设为评审人
CANN-robotCANN-robot成员
7月7日 将gcw_kUomxQ2l,Andy-lb设为审查人
houyanbao成员
7月7日 评论:

/compile

likedislike
Hhouyanbao成员
7月7日 update merge request[project id: 8810053, iid: 3457, commit_id: 70cff5953a8d0d1dcfc44d558ddf81c23fe2f68b] virtual merging success
CANN-robotCANN-robot成员
7月7日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月7日 评论:

流水线任务触发成功
任务链接 [ae850c89d06949ec95f14f3f71016ae3][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
UT_Test_acl ✅ SUCCESS >>>>>
UT_Test_rts_v201 ✅ SUCCESS >>>>>
UT_Test_rts_c ✅ SUCCESS >>>>>
UT_Test_rts_david ✅ SUCCESS >>>>>
UT_Test_rts_910b ✅ SUCCESS >>>>>
UT_Test_rts_common ✅ SUCCESS >>>>>
UT_Test_platform ✅ SUCCESS >>>>>
UT_Test_qs ✅ SUCCESS >>>>>
UT_Test_aicpusd ✅ SUCCESS >>>>>
UT_Test_tsd ✅ SUCCESS >>>>>
UT_Test_error_manager ✅ SUCCESS >>>>>
UT_Test_slog ✅ SUCCESS >>>>>
UT_Test_atrace ✅ SUCCESS >>>>>
UT_Test_adump ✅ SUCCESS >>>>>
UT_Test_mmpa ✅ SUCCESS >>>>>
PreSmoke_A900_npupool ✅ SUCCESS >>>>>
UT_Test_msprof ✅ SUCCESS >>>>>
UT_Test_rts_report ✅ SUCCESS >>>>>
UT_Test_msprof_report ✅ SUCCESS

[2026-07-07 10:26:36]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7月7日 评论:

流水线任务触发成功
任务链接 [dbc55d126aea42d89bce50a2f260aa99][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Check_Pr ✅ SUCCESS
codecheck_style ✅ SUCCESS >>>>>
codecheck_precommit ⚠️ WARNING >>>>> >>>>>
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS

[2026-07-07 10:18:04]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月7日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月7日 添加了label:ci-pipeline-passed
atomgit-bot
atomgit-bot7月7日进行代码检视1
src/runtime/feature/aclgraph/capture_model.cc
@@ -587,30 +587,30 @@
587- COND_PROC(error != RT_ERROR_NONE, mmSleep(1U));
587+ COND_PROC(error != RT_ERROR_NONE, errorTmp = Context_()->TryRecycleCaptureModelResource(0U, 1U, this));
588+ COND_PROC(errorTmp != RT_ERROR_NONE, mmSleep(1U));
588589 } while (error != RT_ERROR_NONE);
589590 
590591 if (!this->IsSubCaptureModel()) { // 只有根模型才刷新,其他各层级子模型发给ts的notify id均为根模型的id,异常时直接解执行流的endgraph wait
@@ -682,16 +683,18 @@ rtError_t CaptureModel::BuildSqCq(Stream * const exeStream)
682683 
683684void CaptureModel::DeconstructSqCq(void)
684685{
685- uint32_t releaseNum = 0U;
686+ uint32_t releaseSqNum = 0U;
687+ uint32_t releaseNtyNum = 0U;
686688 const std::unique_lock<std::mutex> lk(sqBindMutex_);
687689 
688- (void)ReleaseSqCq(releaseNum);
690+ (void)ReleaseSqCqAndNotifyId(releaseSqNum, releaseNtyNum);
689691 return;
690692}
691693 
692-rtError_t CaptureModel::ReleaseSqCq(uint32_t &releaseNum)
694+rtError_t CaptureModel::ReleaseSqCqAndNotifyId(uint32_t &releaseSqNum, uint32_t &releaseNtyNum)
693695{
694- releaseNum = 0U;
696+ releaseSqNum = 0U;
697+ releaseNtyNum = 0U;
695698 if ((sqCqNum_ == 0U) || (refCount_ != 0U)) {
696699 RT_LOG(RT_LOG_DEBUG, "model cannot be released, model_id=%u, sqCqNum=%u, refCount=%u.",
697700 Id_(), sqCqNum_, refCount_);
@@ -699,7 +702,7 @@ rtError_t CaptureModel::ReleaseSqCq(uint32_t &releaseNum)
699702 }
atomgit-bot
atomgit-bot7月7日评论:

🟡 Medium Priority

变更行:capture_model.cc 第 698-702 行(ReleaseSqCqAndNotifyId 的提前返回条件)。

受影响的合约/行为:旧代码中 ReleaseSqCqReleaseNotifyId 是两次独立调用,各自有独立的执行条件。新代码将二者合并为 ReleaseSqCqAndNotifyId,但在 sqCqNum_ == 0U 时直接 return RT_ERROR_NONE,此时 Notify 释放代码(第 724 行的 (void)ReleaseNotifyId(releaseNtyNum))被跳过。

失败模式:

  1. TryRecycleCaptureModelResource 首次调用时,ReleaseSqCqAndNotifyId 成功释放 SQ(sqCqNum_ 变为 0),但 ReleaseNotifyId 内部的 Notify::FreeId() 失败 → releaseNtyNum 保持为 0。
  2. 后续再次调用 TryRecycleCaptureModelResource 需要释放 Notify 时,进入同一 model,但 sqCqNum_ == 0U 触发提前返回,Notify 永远不会被释放。
  3. 类似情况同样影响 DeconstructSqCqUpdate 两个调用点。

建议:修改 ReleaseSqCqAndNotifyId 的早期返回逻辑:即使在 sqCqNum_ == 0U 时,也应尝试释放 Notify(ReleaseNotifyId 自身有 refCount_ == 0U 保护,不会误释放)。可将第 698-702 行改为仅当 refCount_ != 0U 时提前返回;当仅 sqCqNum_ == 0U 时,仍调用 (void)ReleaseNotifyId(releaseNtyNum) 后再返回。

likedislike
不准确?
yanmingxiang成员
7月7日 评论:

/lgtm

likedislike
yanmingxiang成员
7月7日 评论:

/approve

likedislike
Hhouyanbao成员
7月7日 解决了最后一个问题
liulun0308成员
7月7日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
7月7日 添加了label:lgtmapproved
CANN-robotCANN-robot成员
7月7日 合入了pull request