Pull Request已成功合入, 合并人@CANN-robot
(感谢 Chang-an-HW 的贡献)变更摘要
本次变更围绕 Eager 自定义算子的辅流资源编译期统计能力展开:新增能力接口 ge::ResourceReportingOp(方法 DeclareResourceUsage)与上报上下文 gert::ResourceUsageContext(继承 ExtendedKernelContext,零成员且 standard_layout),算子在编译期按节点申报运行期将通过 RequestAttachedStream 请求的辅流 key;框架在 ModelBuilder::BuildModelDefForStream 前遍历 device 侧自定义算子节点并按 key 求 union 去重,将结果写入新增模型属性 eager_custom_op_stream_num,最终在 CompiledGraphSummary::GetStreamNum() 这一唯一合并点与框架流数相加返回。该统计为纯编译期旁路观测,不进入运行时资源链路,无上报算子的模型产物与返回值保持不变。
主要改动
- 新增资源申报能力接口与上下文: 在
custom_op.h新增ge::ResourceReportingOp能力接口(DeclareResourceUsage(gert::ResourceUsageContext &ctx)),并新增gert::ResourceUsageContext,提供ReportAttachedStreamKeys、GetInputTensor、GetOutputTensor及通过基类访问节点信息的能力,同时以static_assert约束其为零成员 standard_layout 视图类。 - 新增编译期收集器与去重/错误粘滞语义: 新增
gert::ResourceUsageCollector,通过CollectAttachedStreamKeys按 key 去重收集,空 key 报错并置位粘滞的HasError(),使算子即便吞掉错误码也可被编译窗口复核拦截。 - 新增模型侧采集与属性写入: 在
model_builder.cc新增ModelBuilder::CollectEagerCustomOpStreamNum,仅遍历 kernel lib 为kCustomOpKernelLibName的节点、跳过声明式kAnnotatedArgs节点以防双计,命中上报算子时将 key union 数量写入新属性ATTR_MODEL_EAGER_CUSTOM_OP_STREAM_NUM,无上报算子时不写属性。 - 新增模型属性及根/子模型聚合: 在
ge_attr_define中定义ATTR_MODEL_EAGER_CUSTOM_OP_STREAM_NUM = "eager_custom_op_stream_num",并在GraphBuilder::RefreshInfoOfDynamicShapeGraph中对根/子模型求和不去重聚合写回,且仅在任一子模型带该属性时才写根模型属性。 - Summary 观测出口合并:
CompiledGraphSummary::SummaryData新增私有成员eager_custom_op_stream_num_与SetEagerCustomOpStreamNum,GetStreamNum()改为返回框架流数与 Eager 辅流统计之和,且该读取置于动态图 early-return 之前。 - 能力位与类型转换注册: 在
CustomOpCapability中新增kResourceReporting能力位,并在cast.h中为ResourceReportingOp补充CustomOpCapabilityTrait特化以支持CustomOpCast转换。


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 |
|---|---|---|
| inc/graph_metadef/external | ✅ 王涛, yangyongqiang0606 (2/2) | ✅ 王涛 (1/1) |
| repo-cann/ge | ✅ 王涛, yangyongqiang0606 (2/2) | ✅ 王涛 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
Chang-an-HW, thanks for your pull request. All authors of the commits have signed the CLA. 👍


Pull Request
描述
为 Eager 自定义算子新增辅流资源编译期统计能力:
ge::ResourceReportingOp能力接口与gert::ResourceUsageContext上下文(继承ExtendedKernelContext,零成员变量、standard_layout 断言)。算子编译期按节点申报运行期将通过RequestAttachedStream请求的辅流 key(ReportAttachedStreamKeys(const std::vector<ge::AscendString>&),元素类型与运行期接口同型)。ModelBuilder::BuildModelDefForStream前遍历 device 侧自定义算子节点(跳过声明式kAnnotatedArgs节点防双计),按模型对 key 求 union 去重统计,写入模型属性eager_custom_op_stream_num,随 OM/模型 cache 持久化(无上报算子不写属性,产物零变化);根/子模型聚合求和不去重(各执行实例独立建流)。CompiledGraphSummary::SummaryData新增私有成员,GetStreamNum()返回"框架流数 + Eager 辅流统计"(唯一合并点,置于动态图 early-return 之前);无上报算子的模型返回值逐一不变。ATTR_MODEL_STREAM_NUM、runtime_param.stream_num与 V2stream_resource,运行时 V1/V2 零改动,纯编译期旁路观测。ResourceReportingOp/ResourceUsageContext两组共 8 篇,更新GetStreamNum行为说明与 README 索引(并补齐 EagerOpExecutionContext 遗漏的 RequestAttachedStream 索引行)。聚合与查询路径说明
针对"纯静态图的根模型 eager 属性聚合走哪条路径、summary 读到的是根模型还是子模型"(检视意见)的确认结论:
GeGenerator::GenerateModel → graph_manager_.BuildGraph,ge_generator.cc:1658-1662)与在线 Session 编译均走GraphBuilder::Build(graph_builder.cc:302)。ATTR_NAME_DYNAMIC_SHAPE_PARTITIONED || GetGraphUnknownFlag()时进入BuildForDynamicShapeGraph(:323-324);纯静态走BuildForKnownShapeGraph,整图仅产生一个 GeModel(:330-335)。引擎分区在 known-shape 路径的产物是任务级的(各引擎 TaskDef 下沉同一 DavinciModel),不产生多个子模型,故不存在"静态多子图独立聚合点"。BuildForUnknownShapeAllGraphs:717),聚合点唯一为RefreshInfoOfDynamicShapeGraph(全仓唯一调用点 :620);stream_num/event_num 的既有根模型聚合同在此处,eager 属性在同一循环内同型求和与溢出检查。GetCompiledGraphSummary在 graph_manager.cc:5335 选取 ge_model 传入Builder::Build,SetStreamNum与SetEagerCustomOpStreamNum读取同一模型——静态图为 map 唯一 entry(即根模型),动态图为带聚合值的根模型;两属性任何路径下行为一致,无独立漏计面。变更类型
关联的Issue
无
如何测试
ut_exe_graph --gtest_filter=ResourceUsageContextUT.*:key 上报/去重/空 key 粘滞错误/节点信息与 tensor 访问(5 个);ut_libge_multiparts_utest --gtest_filter=UtestModelBuilderTest.CollectEagerCustomOpStreamNum*:per-node 按 shape 分桶申报 union 精确、跨节点去重、声明式/未实现接口/非自定义节点跳过、无命中不写属性、失败传播(含算子吞错误码拦截)(4 个);ut_libge_multiparts_utest --gtest_filter=GraphBuilderTest.RefreshInfo*:聚合求和不去重、全缺省不写根属性、溢出失败(3 个);ut_libge_common_utest --gtest_filter=UtestGraphCompileSummaryImpl.*:合并点求和、属性缺省 0 与基线一致、隔离回归(新增 2 个)。ut_exe_graph全量 681 个、UtestModelBuilderTest/GraphBuilderTest/UtestCustomOpFactory共 79 个全部通过;lowering/stub_lowering/ge_compiler 增量编译零告警。核对清单
其他信息
ResourceReportingOp::DeclareResourceUsage)+ 1 个上报方法(ReportAttachedStreamKeys);GetStreamNum为行为变化(仅含上报算子的模型返回值增大),已在 API 文档声明,提请接口评审关注。std::vector<AscendString>只读传引用参数与已发布的AnnotatedKernelArgs::ExtractArgsData(9.2.0)跨界形态同类,无所有权/分配器跨界。