Merged
fix(matmul): 规范 RotateQuant 和 MatmulEmuSplitWeight 错误上报 #13582
fix(matmul): 规范 RotateQuant 和 MatmulEmuSplitWeight 错误上报 #13582
Merged
HKFLYEAdd on 18 days ago
HKFLYE
HKFLYECollaborators
18 days ago

描述

RotateQuant 和 MatmulEmuSplitWeight 的部分失败出口使用泛化内部错误码,部分调用层还会覆盖下层诊断或重复上报,导致参数错误、推导失败和平台异常难以区分。

本次将对应的 shape、rank、dtype、format 和属性错误优先改为公开 log.h 已有语义宏;Tiling、InferShape 和明确能力不支持的失败复用 EZ1008、EZ1014、EZ1009。复用已有 matmul_error_report.h 和 Tiling 上报接口,仅为 log.h 未提供匹配宏的 EZ1009、EZ1014 补充封装。包装层保留原返回值并仅补 PLOG,避免重复首报和重复日志。

本次修改范围为两个算子的 op_api、InferShape、arch22 Tiling、registry 和既有公共头.

关联的Issue

测试

  • 独立 Host UT 工程使用真实生产源码、CANN Context Builder 和 ErrorManager:4 个 target、40/40 用例通过(28 个 InferShape 回归、8 个 API 用例、4 个 arch22 初始化调度用例),验证返回值、正式码、关键诊断字段及唯一首报。arch22 用例验证初始化失败不会进入后续 Tiling;零 vector 核数边界采用测试注入,未替换初始化或报错实现。

文档更新

无仓库文档修改;逐点整改及独立验证记录保存在本地工程。

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for HKFLYE's contribution.)
HKFLYEHKFLYECollaborators
18 days ago Created pull request, commit 68b8fa8b
atomgit-bot
atomgit-bot
18 days ago Comments:

变更摘要

本次变更集中规范 RotateQuant 与 MatmulEmuSplitWeight 两个算子的错误上报语义:新增公共头 matmul/common/op_host/error_report_util.h,以 ReportRegisteredExecutionError 统一构造注册参数,并对外暴露 ReportTilingError(EZ1008)、ReportExecutionError(EZ1009)、ReportInferShapeError(EZ1014)三个封装。原先使用 CUBE_INNER_ERR_REPORT、裸 OP_LOGE 的泛化失败出口,改按类别替换为公开语义宏(shape、rank、dtype、format、属性值等);Tiling、InferShape 及明确能力不支持的分支复用 EZ1008/EZ1014/EZ1009。包装层改用 OP_LOGE_WITHOUT_REPORT 保留原返回值、仅补日志,避免覆盖下层诊断与重复首报。

主要改动

  • 新增公共错误上报头文件: 新增 matmul/common/op_host/error_report_util.h,通过 detail::ReportRegisteredExecutionError 用固定 opName/reason 键值调用 REPORT_PREDEFINED_ERR_MSG,并提供 ReportTilingError、ReportExecutionError、ReportInferShapeError 对应 EZ1008、EZ1009、EZ1014。
  • Tiling 侧错误码分类重构: matmul_emu_split_weight 的 arch22/arch35 tiling、registry 与 rotate_quant 的 arch22/arch35 tiling 中,平台信息、属性、原始 tiling data、workspace 等空指针与 tiling 尺寸/容量、memcpy_s 失败改为 ReportTilingError;aicNum:aivNum 比例不匹配与 DAV_3510 架构不支持改走 ReportExecutionError。
  • 参数类错误改用公开语义宏: 两个算子的 tiling 与 InferShape 中 rank、shape、dtype、format、属性取值等校验由 CUBE_INNER_ERR_REPORT/OP_LOGE 替换为 OP_LOGE_FOR_INVALID_SHAPEDIM(_WITH_REASON)、OP_LOGE_FOR_INVALID_SHAPES(_WITH_REASON)、OP_LOGE_FOR_INVALID_DTYPE(S)_WITH_REASON、OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON、OP_LOGE_FOR_INVALID_VALUE_WITH_REASON、OP_LOGE_FOR_INVALID_TENSORNUM(S) 等,并补充具体数值与原因描述。
  • 包装层避免重复上报: GetShapeAttrsInfo、CheckAlphaInput、ValidateRotShape、ValidateScaleShape 等下游校验失败处,以及 DoOpTiling、CalcVecTilingData 中的 OP_LOGE/OP_LOGE_IF 改为 OP_LOGE_WITHOUT_REPORT/OP_CHECK_IF,保留原始返回值语义而不覆盖首报。
  • op_api 层失败出口调整: MatmulEmuSplitWeight 与 RotateQuant 的 AllocTensor 空指针、INFER_SHAPE、ADD_TO_LAUNCHER_LIST_AICORE 失败由 OP_CHECK_* 改为显式 if + OP_LOGE_WITHOUT_REPORT 并附加返回码;aclnn_rotate_quant.cpp 对不支持架构改调 ReportExecutionError,CheckOutDtypeValid 在支持列表为空时使用 OP_LOGE_WITHOUT_REPORT 避免二次上报。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
18 days ago Comments:

代码审查

审查结论

总体判断:本次改动以“错误码/日志口径规范化”为主,绝大多数是把 CUBE_INNER_ERR_REPORT / OP_LOGE 换成 OP_LOGE_FOR_INVALID_* 语义宏或 EZ1008/EZ1009/EZ1014 统一上报,未发现 kernel 侧逻辑或数值行为变更,也未发现 P0/P1 级缺陷。风险集中在新增的集中上报头(空指针保护退化、与既有封装重复)以及个别上报调用的参数类型/口径不一致,属于诊断可靠性风险,非功能回归。

发现统计:P0 0 个,P1 0 个,P2 1 个,P3 3 个。

  • P2 matmul/common/op_host/error_report_util.h:18-23:ReportRegisteredExecutionError 未对 opName/reason 做 nullptr 兜底,同目录既有 matmul_error_report.h 有兜底,本次集中化丢掉了该保护。
  • P3 matmul/common/op_host/error_report_util.h:26-29:与既有 Ops::NN::ReportMatmulTilingError(同为 EZ1008 + {opName, reason})重复,形成两套并存的 tiling 上报入口。
  • P3 matmul/rotate_quant/op_host/rotate_quant_infershape.cpp:82:OP_LOGE_FOR_INVALID_TENSORNUM 实际值传 size_t、期望值传字符串字面量,与同函数/同文件写法不一致。
  • P3 matmul/rotate_quant/op_host/arch35/rotate_quant_tiling.cpp:126-153:IsCapable() 内两种“平台核配置不满足”分支上报口径不一致(一处仅日志、两处登记 EZ1009)。

逐文件审查确认

文件 结论
matmul/common/op_host/error_report_util.h 已审,2 个发现(P2 空指针保护、P3 重复封装)
matmul/matmul_emu_split_weight/op_api/matmul_emu_split_weight.cpp 已审,无问题(ACLNN_ERR_INNER_STATIC_WORKSPACE_INVALID 与仓库既有 launcher 失败用法一致;WITHOUT_REPORT 由内层 INFER_SHAPE/ADD_TO_LAUNCHER_LIST_AICORE 首报,包装层仅补 PLOG,符合 PR 设计)
matmul/matmul_emu_split_weight/op_host/matmul_emu_split_weight_infershape.cpp 已审,无问题(null 分支判定与 x/w_high/w_low、y、attrs 的归因逻辑正确;K/N 维度校验条件未变)
matmul/matmul_emu_split_weight/op_host/op_tiling/arch22/matmul_emu_split_weight_tiling.cpp 已审,无问题(ExtractAttrs 中 w_low_scale 未做空指针判断属未改动的既有代码,本次未改变可达性,故未上报)
matmul/matmul_emu_split_weight/op_host/op_tiling/arch35/matmul_emu_split_weight_tiling.cpp 已审,无问题(ValidateInputsNotNull 逐项判空与原 OPS_CHECK_NULL_WITH_CONTEXT 等价;PostTiling 新增判空与 arch22 对齐)
matmul/matmul_emu_split_weight/op_host/op_tiling/matmul_emu_split_weight_tiling_registry.cpp 已审,无问题(PlatformInfo/CompileInfo 判空及分流逻辑未变)
matmul/rotate_quant/op_api/aclnn_rotate_quant.cpp 已审,无问题(FormatString 所需头文件第 22 行已包含;不支持架构时避免重复首报的分支处理正确)
matmul/rotate_quant/op_api/rotate_quant.cpp 已审,无问题
matmul/rotate_quant/op_host/arch22/rotate_quant_tiling.cpp 已审,无问题(CheckContext 判空顺序正确,GetCapacity 使用前已保证非空;PostTiling 未判 GetWorkspaceSizes 为空属既有问题,非本次引入)
matmul/rotate_quant/op_host/arch35/rotate_quant_tiling.cpp 已审,1 个发现(P3 IsCapable 上报口径);ValidateScaleShape 实际值/期望值未被写反,AnalyzeDtype 大括号与分支结构正确
matmul/rotate_quant/op_host/rotate_quant_infershape.cpp 已审,1 个发现(P3 宏参数类型混用)

未验证项(受只读范围限制,已在置信度中体现):OP_LOGE_FOR_INVALID_*、REPORT_PREDEFINED_ERR_MSG 等宏定义位于 matmul/ 之外的 opbase 头文件,本次无法读取,故上述 P3 结论按“与仓库既有调用写法不一致”的可验证事实给出,未断言编译必定失败;EZ1014 的键集约定同样未能核实。

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

💬 仅评论


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
18 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
18 days ago 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
matmul ✅ 朱如意, 陈律丞 (2/2) ✅ 陈律丞, 朱如意 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robotCollaborators
18 days ago Comments:

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
18 days ago Set zengjuan,oscillated,sxb154714,chaotang233,crystalhu,yangyang016,fanqirui,chenqi317,LinPX,liubo75,tangweiwei2,wangzitao_leo,void_ptr,xubinglin,zhaoyingchao2,rueenov11,pingchuantang,liuyang_806 as approver
CANN-robotCANN-robotCollaborators
18 days ago Set oscillated,sxb154714,chaotang233,yangyang016,fanqirui,chenqi317,LinPX,tangweiwei2,wangzitao_leo,void_ptr,xubinglin,zhaoyingchao2,rueenov11,liuyang_806 as approver
atomgit-bot
atomgit-bot18 days agoStart code review2
matmul/common/op_host/error_report_util.h
Outdated
@@ -0,0 +20,4 @@
20+ const std::vector<const char*> keys = {"opName", "reason"};
21+ const std::vector<const char*> values = {opName, reason};
22+ REPORT_PREDEFINED_ERR_MSG(code, keys, values);
23+}
atomgit-bot
atomgit-bot18 days agoComments:

🟡 Medium Priority

建议:在构造 values 前对空指针兜底:const char* name = (opName == nullptr) ? "NN" : opName; const char* msg = (reason == nullptr) ? "" : reason;,再用 name/msg 构造 values,避免空指针进入错误消息参数表。

Suggestions
23
+ inline void ReportRegisteredExecutionError(const char* code, const char* opName, const char* reason)
24
+ {
25
+ const char* name = (opName == nullptr) ? "NN" : opName;
26
+ const char* msg = (reason == nullptr) ? "" : reason;
27
+ const std::vector<const char*> keys = {"opName", "reason"};
28
+ const std::vector<const char*> values = {name, msg};
29
+ REPORT_PREDEFINED_ERR_MSG(code, keys, values);
23
30
  }
Apply suggestion
likedislike
Incorrect?
System
System MessageSystem
18 days ago Comments:

changed this line on 7e2ef59f view diff detail

likedislike
atomgit-bot
atomgit-bot18 days agoStart code review2
matmul/rotate_quant/op_host/arch22/rotate_quant_tiling.cpp
@@ -87,2 +92,4 @@
92+ static_cast<unsigned long>(compileInfo_.aicNum))
93+ .c_str());
8794 return;
8895 }
atomgit-bot
atomgit-bot18 days agoComments:

🟡 Medium Priority

变更行:rotate_quant_tiling.cpp:67-95 中三处失败分支由 OP_LOGE 改为 Ops::NN::ReportTilingError(...)(正式公开错误码上报),但函数签名仍是 void RotateQuantTiling::InitCompileInfo(),失败后只 return;。

影响行为:本次 PR 的核心约定是「每个失败出口只做一次首报,包装层只补 PLOG」。这三处现在会向 ErrorManager 注册一个正式错误码,但控制流不会向上传递失败(void 返回值使调用方无法观察失败),tiling 随即继续执行。

失效模式:当平台信息为空或 compileInfo_.aicNum <= 0 时(例如 GetPlatformInfo() 返回 SUCCESS 但平台未就绪,见本文件 63 行恒返回 SUCCESS),错误码已被记为「首报」,而 CaclVecTilingData() 继续使用 compileInfo_.aicNum/aivNum = 0 计算 ops::CeilDiv(loopM, aivCoreNum)(323-326 行)——整数除零属未定义行为;即使不崩,后续真实失败(如 SetMatmulTiling 的 GetTiling 返回 -1)也无法作为首报呈现,用户看到的是与根因无关的平台错误码,与 PR 目标的「可区分、唯一首报」相悖。

建议:将 InitCompileInfo 改为返回 ge::graphStatus 并在失败时传播到 DoTiling;或在这些上报后不再继续使用 compileInfo_,避免「已上报错误码但流程继续」导致后续二次首报/除零。

likedislike
Incorrect?
HKFLYE
HKFLYECollaborators
18 days ago Comments:

已修复。保留 InitCompileInfo() 的 void 接口,在现有 GetPlatformInfo() 中检查初始化结果:aicNum == 0 时仅补日志并返回 GRAPH_FAILED,复用初始化阶段的 EZ1008;aivNum == 0 时首报一次 EZ1008 并返回失败。基类 DoTiling() 随即终止,不再进入后续除法计算。

likedislike
HKFLYEHKFLYECollaborators
18 days ago Pre merge succeeded (commit_id: fb51742c88766a69dcb0a50c43fa53bda1b3368a)
10 event messages are collapsed here。 See more
HKFLYEHKFLYECollaborators
18 days ago Modify description of pull request
HKFLYE
HKFLYECollaborators
18 days ago Comments:

/compile

likedislike
HKFLYEHKFLYECollaborators
18 days ago Pre merge succeeded (commit_id: cc1767b34c3c6e6165519f9a3c90d99c8e26f4ce)
CANN-robot
CANN-robotCollaborators
18 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
18 days ago Added label: ci-pipeline-running
HKFLYEHKFLYECollaborators
18 days ago Resolved final issue
CANN-robotCANN-robotCollaborators
17 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
17 days ago Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
17 days ago Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!
@oscillated @sxb154714 @rueenov11 @wangzitao_leo @yangyang016 @void_ptr @LinPX

likedislike
HKFLYEHKFLYECollaborators
17 days ago Modify description of pull request
HKFLYEHKFLYECollaborators
17 days ago Modify description of pull request
yuning_chen
yuning_chenCollaborators17 days agoStart code review2
matmul/common/op_host/matmul_error_report.h
@@ -20,3 +20,3 @@
2020inline void ReportMatmulParamError(const char* opName, const std::string& message)
2121{
22- OP_LOGE_WITHOUT_REPORT(opName == nullptr ? "Matmul" : opName, "%s", message.c_str());
22+ OP_LOGE_LIBOPAPI_REPORT(opName == nullptr ? "Matmul" : opName, "%s", message.c_str());
yuning_chen
yuning_chen17 days agoComments:

请问这里由 OP_LOGE_WITHOUT_REPORT 换成 OP_LOGE_LIBOPAPI_REPORT 是否会和紧随其后的 REPORT_PREDEFINED_ERR_MSG 重复上报。

  • 现在代码看来 ReportMatmulParamError 和 ReportMatmulTilingError 这两个函数的结构都是「先打一条 OP_LOGE_*,再调 REPORT_PREDEFINED_ERR_MSG 上报 EZ1001 / EZ1008」,原来第一步特意用的是带 _WITHOUT_REPORT 后缀的版本,看起来就是为了把上报这件事单独交给后面的 REPORT_PREDEFINED_ERR_MSG;本次新增的 ReportMatmulExecutionError / ReportMatmulInferShapeError 也沿用了同样的 OP_LOGE_LIBOPAPI_REPORT + REPORT_PREDEFINED_ERR_MSG 组合。
  • 可能存在有同一条错误被登记两次的问题,同时同一个 PR 里 matmul/matmul_emu_split_weight/op_api/matmul_emu_split_weight.cpp 的改动方向正好相反,把原来的 OP_LOGE(ACLNN_ERR_INNER_INFERSHAPE_ERROR, ...) 换成了 OP_LOGE_WITHOUT_REPORT,两处对「要不要上报」的取舍看起来不太一致。
  • 建议可以确认一下 OP_LOGE_LIBOPAPI_REPORT 是否也会向错误管理模块登记一条记录,如果会的话这里保持 OP_LOGE_WITHOUT_REPORT 更贴合原意;另外这个头文件是 matmul 下公共的报错封装,改动会影响所有引用它的 matmul 算子的报错行为,范围比本 PR 涉及的 matmul_emu_split_weight 和 rotate_quant 要大一些,也建议在描述里说明一下。
likedislike
HKFLYE
HKFLYECollaborators
17 days ago Comments:

感谢提醒,已核对本 PR 固定依赖版本的宏定义。OP_LOGE_LIBOPAPI_REPORT 虽然名称含 REPORT,实际只通过 DlogRecord 写 PLOG,没有调用 ErrorManager;正式错误码由紧随其后的 REPORT_PREDEFINED_ERR_MSG 登记一次,因此不会重复上报。

Host 公共头中的定义也能说明两者的关系:


#define OP_LOGE_WITHOUT_REPORT(opName, ...) \
    OP_LOGE_LIBOPAPI_REPORT(opName, __VA_ARGS__)
    

公共封装改为直接调用它,是因为 Host 与 op_api 中的 OP_LOGE_WITHOUT_REPORT 参数约定不同:Host 首参为算子名,op_api 首参为数值错误码。该公共头同时被两层引用,直接使用接受算子名的日志宏可以避免参数语义受宏定义影响。matmul_emu_split_weight.cpp 中使用的是 op_api 版本,传入数值错误码,同样仅补 PLOG;两处遵循的都是“日志与正式上报分离”的原则。

关于公共头的影响范围,建议成立:原有两个封装的日志宏替换会影响其他引用者。Host 场景下与原宏等价;op_api 场景下日志使用显式算子名,日志格式可能变化。原有正式错误码、上报参数及上报次数保持不变。这部分公共影响应在 PR 描述中明确说明。

likedislike
HKFLYEHKFLYECollaborators
17 days ago Resolved final issue
oscillated
oscillatedCollaborators
17 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
17 days ago Added label: approved
rueenov11
rueenov11Collaborators
17 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
17 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
17 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
17 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
17 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike