Pull Request已成功合入, 合并人@CANN-robot
(感谢 houyanbao 的贡献)变更摘要
本次 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.cc(AllocCaptureTaskInfo)、stream_capture.cc(AllocCaptureTaskWithoutLock)和context_aclgraph.cc(AddNotifyToAddedCaptureStream)中的GenerateSeqId调用,统一在stream.cc和stream_david.cc的StarsAddTaskToStream中延迟回收任务(delayRecycleTaskid_)路径下分配modelSeqId。TryRecycleCaptureModelResource回收流程简化:在context_standard_soc_aclgraph.cc中将原来分开判断 sq 和 notify 资源的两个if块合并为一个,条件改为(allocSqNum > totalReleaseSqNum) || (ntfCnt > totalReleaseNtfNum),统一调用ReleaseSqCqAndNotifyId一次性回收两类资源。UpdateNotifyId错误码覆盖问题修复:在capture_model.cc的UpdateNotifyId中引入局部变量errorTmp接收TryRecycleCaptureModelResource的返回值,避免覆盖AllocId的错误码error,防止循环异常提前退出。- 测试用例同步适配:
rt_utest_capture_mode.cc、rt_utest_david_task.cc、rt_utest_tiny_stub.cc等测试文件中所有ReleaseSqCq调用均更新为ReleaseSqCqAndNotifyId双参数形式;ModelDebugJsonPrint_AicpuTask测试用例新增InitByStream初始化调用以确保 task 字段完整性。


代码审查
我已全面审查了所有 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 整体释放)逻辑正确:
-
modelSeqId 分配统一化:将分散在
AllocCaptureTaskInfo、AllocCaptureTaskWithoutLock、AddNotifyToAddedCaptureStream三处的GenerateSeqId()调用统一收敛到StarsAddTaskToStream,消除了遗漏路径,且修复了旧代码中AddNotifyToAddedCaptureStream对已提交任务的回溯赋值冗余。 -
资源释放合并:
ReleaseSqCq→ReleaseSqCqAndNotifyId重构正确地将 SQ/CQ 和 Notify 释放合并为原子操作,同时消除了ReleaseSqCqInternal中对子模型 Notify 的重复释放(旧代码中ReleaseSqCq和ReleaseSqCqInternal各调一次ReleaseNotifyId处理子模型)。 -
TryRecycleCaptureModelResource简化:将两次加锁/解锁合并为一次,减少锁竞争,语义等价。
唯一的 P3 发现是 UpdateNotifyId 中回收成功但分配失败时缺少退避休眠,触发条件苛刻,实际影响极低。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


🟡 Medium Priority
变更行:capture_model.cc 第 698-702 行(ReleaseSqCqAndNotifyId 的提前返回条件)。
受影响的合约/行为:旧代码中 ReleaseSqCq 与 ReleaseNotifyId 是两次独立调用,各自有独立的执行条件。新代码将二者合并为 ReleaseSqCqAndNotifyId,但在 sqCqNum_ == 0U 时直接 return RT_ERROR_NONE,此时 Notify 释放代码(第 724 行的 (void)ReleaseNotifyId(releaseNtyNum))被跳过。
失败模式:
TryRecycleCaptureModelResource首次调用时,ReleaseSqCqAndNotifyId成功释放 SQ(sqCqNum_变为 0),但ReleaseNotifyId内部的Notify::FreeId()失败 →releaseNtyNum保持为 0。- 后续再次调用
TryRecycleCaptureModelResource需要释放 Notify 时,进入同一 model,但sqCqNum_ == 0U触发提前返回,Notify 永远不会被释放。 - 类似情况同样影响
DeconstructSqCq和Update两个调用点。
建议:修改 ReleaseSqCqAndNotifyId 的早期返回逻辑:即使在 sqCqNum_ == 0U 时,也应尝试释放 Notify(ReleaseNotifyId 自身有 refCount_ == 0U 保护,不会误释放)。可将第 698-702 行改为仅当 refCount_ != 0U 时提前返回;当仅 sqCqNum_ == 0U 时,仍调用 (void)ReleaseNotifyId(releaseNtyNum) 后再返回。


/lgtm


/approve


/approve


Pull Request
描述
1、优化model sequenceid的分配逻辑,在添加task的地方统一分配,避免流程出现遗留
2、aclGraph模型执行时,当notify资源不足时,当前只释放了notifyid,没有释放sqcq,这会导致被释放的模型,下次再次执行时,没有更新notifyid,为简化流程,提升代码可读性,模型资源释放时,sqcq和notify整体释放
变更类型
请选择本次引入的变更类型:
关联的Issue
NA
如何测试
描述测试此变更的步骤和前提条件:
2.验证aclGraph notify资源不足,触发模型资源回收流程
核对清单
其他信息
在此添加任何其他关于本次 PR 的说明。