已合并
<<<>>>适配profiling修改 #7444
<<<>>>适配profiling修改 #7444
已合并
yangzeheng创建于 6月24日
yangzeheng成员
6月24日

描述

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 yangzeheng 的贡献)
Yyangzeheng成员
6月24日 创建了 pull request,commit 68968937
CANN-robotCANN-robot成员
6月24日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
6月24日 评论:

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robot成员
6月24日 评论:

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
examples wang-minbo, 刘丹 (2/2) wang-minbo, 刘丹 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
atomgit-bot
atomgit-bot
6月24日 评论:

变更摘要

此 PR 主要针对 profiling(性能剖析)相关接口进行适配性修改。核心改动集中在共享头文件 mc2_profiling.h 中,对 profiling 宏定义和辅助函数进行了较大幅度的精简和重构(净减少约 28 行);同时在三个算子实现文件中进行了少量配套调整,以匹配更新后的 profiling 接口。

主要改动

  • mc2_profiling.h 重构:对该 profiling 公共头文件进行了大幅精简(+4 -32),调整了 INPUTOUTPUTINIT_ACL_PROF_TENSOR_INFO 等 ACL profiling 宏的定义,以及 GetFormatConvertType 等辅助函数,以适配 profiling 接口的最新规范
  • IncreFlashAttention 算子 profiling 适配npu_fused_infer_attention_score.cpp 中微调了 profiling 相关的调用代码(+2 -2),确保与更新后的 mc2_profiling.h 宏保持一致
  • MoE Distribute Combine V2 算子 profiling 适配moe_distribute_combine_v2_torch.cpp 中同步调整了 aclprofTensorInfo/aclprofEventAttributes 的使用方式(+1 -1)
  • MoE Distribute Dispatch V2 算子 profiling 适配moe_distribute_dispatch_v2_torch.cpp 中进行了相同的 profiling 调用适配(+1 -1)
likedislike
atomgit-bot
atomgit-bot
6月24日 评论:

代码审查

审查总结

逐文件审查结果

文件 审查结论
examples/fast_kernel_launch_example/csrc/common/inc/kernel/mc2_profiling.h 发现 1 个 P2 问题(struct 关键字不一致),1 个 P3 预存问题(C99 compound literal)
examples/fast_kernel_launch_example/csrc/incre_flash_attention/ascend910_93/npu_fused_infer_attention_score.cpp 无新增问题(仅类型重命名 aclProfTensorInfoaclprofTensorInfoaclProfTensoraclprofTensor
examples/fast_kernel_launch_example/csrc/moe_distribute_combine_v2/ascend910_93/moe_distribute_combine_v2_torch.cpp 无新增问题(仅类型重命名 aclProfTensorInfoaclprofTensorInfo
examples/fast_kernel_launch_example/csrc/moe_distribute_dispatch_v2/ascend910_93/moe_distribute_dispatch_v2_torch.cpp 无新增问题(仅类型重命名 aclProfTensorInfoaclprofTensorInfo

问题统计

  • P0: 0
  • P1: 0
  • P2: 1(struct 关键字不一致,可能导致编译失败)
  • P3: 1(C99 compound literal 预存问题,非本次引入)

整体风险评估

低风险。本次变更的核心目的是适配 profiling SDK 的类型命名变更,将本地自定义的 aclProfTensor/aclProfTensorInfo/aclprofEventAttributes 结构体定义移除,统一使用 SDK 提供的 aclprofTensor/aclprofTensorInfo/aclprofEventAttributes。三个 .cpp 文件的改动均为纯类型重命名,不涉及逻辑变更。

唯一的实际风险点在 mc2_profiling.h 第 102 行:INIT_ACL_PROF_TENSOR_INFO 宏中使用了 struct aclprofTensor(带 struct 关键字),而其他所有位置均直接使用 aclprofTensor(不带 struct)。若 SDK 将此类型定义为匿名 struct 的 typedef,将导致编译失败。建议移除多余的 struct 关键字以与代码库其余部分保持一致并消除该风险。

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

💬 仅评论

likedislike
atomgit-bot
atomgit-bot6月24日进行代码检视2
examples/fast_kernel_launch_example/csrc/common/inc/kernel/mc2_profiling.h
@@ -91,3 +63,3 @@
9163 
9264#define INIT_ACL_TENSOR_ARRAY(tensors1, ...) aclTensor* tensors1[] = {__VA_ARGS__}
93-#define INPUT(x) aclProfTensor { \
65+#define INPUT(x) aclprofTensor { \
atomgit-bot
atomgit-bot6月24日评论:

🔵 Low Priority

mc2_profiling.h 中,INPUT 宏(第 65 行)和 OUTPUT 宏(第 82 行)使用 compound literal 语法 aclprofTensor { ... }。此语法是 C99 的 compound literal 特性,在 C++ 中并非标准语法,仅在 GCC/Clang 中作为 GNU 扩展支持。

由于该头文件被 .cpp 文件包含(如 npu_fused_infer_attention_score.cppmoe_distribute_combine_v2_torch.cppmoe_distribute_dispatch_v2_torch.cpp),如果使用不同的编译器或禁用 GNU 扩展的编译选项,将导致编译失败。

注:此问题在本次 diff 前已存在(旧代码同样使用 aclProfTensor { ... } compound literal),本次 diff 未改变该语法模式,仅重命名了类型名。

建议:这是一个 C/C++ 兼容性问题但不是本次 diff 引入的。如果需要在纯 C++ 环境下编译,可以考虑:将 compound literal 替换为临时变量的显式构造,或为每个 tensor 定义一个具名初始化函数/宏。不过鉴于这是一个预存问题且项目已依赖 GNU 扩展,可在后续统一处理。

likedislike
yangzeheng成员
6月24日 评论:

profiling组件提供的写法,已经过验证

atomgit-bot
atomgit-bot6月24日进行代码检视2
examples/fast_kernel_launch_example/csrc/common/inc/kernel/mc2_profiling.h
@@ -129,3 +101,2 @@
129101 uint64_t opTypeId = aclprofStr2Id(opType); \
130- struct aclProfTensor _macro_prof_tensors[] = {__VA_ARGS__}; \
131- tensorInfo = {opNameId, opTypeId, 0, sizeof(_macro_prof_tensors)/sizeof(aclProfTensor), kernelType, blockdim, stream, _macro_prof_tensors}
102+ struct aclprofTensor _macro_prof_tensors[] = {__VA_ARGS__}; \
atomgit-bot
atomgit-bot6月24日评论:

🟡 Medium Priority

mc2_profiling.h 第 102 行,INIT_ACL_PROF_TENSOR_INFO 宏使用了 struct aclprofTensor _macro_prof_tensors[],但同一文件中第 65 行的 INPUT 宏、第 82 行的 OUTPUT 宏以及第 103 行的 sizeof(aclprofTensor) 均直接使用 aclprofTensor(无 struct 关键字)。三个 .cpp 调用方文件中也都使用 aclprofTensor / aclprofTensorInfostruct

本次 diff 删除了本地 struct aclProfTensor / struct aclProfTensorInfo / struct aclprofEventAttributes 的定义,改为依赖 SDK 头文件 (acl/acl_prof.h) 提供的类型。如果 SDK 将 aclprofTensor 定义为匿名 struct 的 typedef(即 typedef struct { ... } aclprofTensor;),则第 102 行的 struct aclprofTensor 会因找不到对应的 struct tag 而导致编译失败。移除多余的 struct 关键字可消除此风险,并与代码库中所有其他引用保持一致。

建议:将第 102 行的 struct aclprofTensor 改为 aclprofTensor(去掉 struct 关键字),与其他所有使用处保持一致。

改动建议
102
- struct aclprofTensor _macro_prof_tensors[] = {__VA_ARGS__}; \
102
+ aclprofTensor _macro_prof_tensors[] = {__VA_ARGS__}; \
应用建议
likedislike
yangzeheng成员
6月24日 评论:

profiling组件提供的写法,已经过验证

yangzeheng成员
6月24日 评论:

compile

likedislike
Yyangzeheng成员
6月24日 update merge request[project id: 7673863, iid: 7444, commit_id: f681ac66cd98836f6f69910aa1050371ffee1b39] virtual merging success
CANN-robotCANN-robot成员
6月24日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月24日 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-06-24 11:39:48]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
6月24日 评论:

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

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

[2026-06-24 11:26:00]    CI执行结束

likedislike
CANN-robotCANN-robot成员
6月24日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6月24日 添加了label:ci-pipeline-passed
wang-minbo成员
6月24日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
6月24日 添加了label:approved
wang-minbo成员
6月24日 评论:

/lgtm
/approve

likedislike
liudan12成员
6月24日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
6月24日 添加了label:lgtm
CANN-robotCANN-robot成员
6月24日 合入了pull request