已合并
为 vector_add 增加 msprof 输入输出元信息上报 #355
qq_51867290创建于 24 天前
为 vector_add 增加 msprof 输入输出元信息上报 #355
已合并
qq_51867290创建于 24 天前
qq_51867290
qq_51867290
24 天前
## 描述 本次改动为 `Samples/0_Introduction/vector_add` 示例增加 msprof 输入输出元信息上报能力。 原始 `vector_add` 是裸 kernel 调用,msprof 可以采集 kernel 执行耗时、Task、Block 等性能信息,但无法在 `op_summary` 中展示输入输出的 shape、dtype 和 format,相关字段显示为 `N/A`。 本次在 `main.asc` 中增加 `aclprofTensor` / `aclprofTensorInfo` 元信息构造,并在 `add_kernel` 执行前后调用 `aclprofRangePushEx` / `aclprofRangePop`,将输入 A、输入 B、输出 C 的 shape、dtype、format 上报给 profiling 系统。同时在 `CMakeLists.txt` 中链接 `msprofiler`。 ## 关联的Issue Fixes [#234](https://gitcode.com/cann/cann-samples/issues/234) ## 测试 已在 Ascend 950 环境完成验证:使用 `cmake --build build --target vector_add` 编译通过,执行 `./build/Samples/0_Introduction/vector_add/vector_add` 后输出 `Vector add completed successfully!`,说明原有计算功能正常;随后使用 `msprof ./build/Samples/0_Introduction/vector_add/vector_add` 进行性能分析,生成的 `op_summary` 中已能看到输入输出的 shape、dtype 和 format 信息,例如 `Input Shapes: 409600;409600`、`Input Data Types: FLOAT;FLOAT`、`Input Formats: ND;ND`、`Output Shapes: 409600`、`Output Data Types: FLOAT`、`Output Formats: ND`。 ## 文档更新 ## 类型标签 - [ ] Bug修复 - [x ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述:
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 qq_51867290 的贡献)
atomgit-bot
atomgit-bot
24 天前 评论:

变更摘要

本次变更为 Samples/0_Introduction/vector_add 示例增加 msprof 性能分析工具的输入输出元信息上报能力。原始示例中 msprof 虽可采集 kernel 执行耗时等性能数据,但 op_summary 中 shape、dtype、format 字段均显示为 N/A。通过引入 aclprofTensor / aclprofTensorInfo 元信息结构,并在 add_kernel 调用前后使用 aclprofRangePushEx / aclprofRangePop 包裹,将向量输入 A、B 和输出 C 的元信息上报至 profiling 系统,使性能分析报告能够展示完整的算子张量信息。

主要改动

  • 新增头文件引入:在 main.asc 中新增 #include "acl/acl_prof.h",引入 profiling 相关接口声明。
  • 定义 profiling 元信息结构体:通过 #ifndef ACL_PROF_TENSOR_INFO_DEFINED 条件编译块定义了 aclprofTensoraclprofTensorInfoaclprofEventAttributes 三个结构体,用于承载算子的 shape、dtype、format 等元信息。
  • 新增 MakeVectorTensor 辅助函数:封装 aclprofTensor 的构造逻辑,统一将向量张量设为 ACL_FORMAT_ND 格式和 ACL_FLOAT 数据类型,并填充 numElements 作为 shape 维度。
  • 在 kernel 调用前后插入 profiling 标记:在 run_vector_add 中构造三个张量的元信息数组(输入 A/B type=0,输出 C type=1),初始化 aclprofTensorInfoaclprofEventAttributes,在 add_kernel 执行前调用 aclprofRangePushEx、执行后调用 aclprofRangePop,完成算子输入输出元信息上报。
  • CMakeLists.txt 链接 msprofiler 库:构建配置中新增对 msprofiler 的链接依赖,确保 profiling 接口可正常解析。
likedislike
atomgit-bot
atomgit-bot
24 天前 评论:

代码审查

审查总结

本次审查覆盖了 2 个变更文件:

  • Samples/0_Introduction/vector_add/CMakeLists.txt — 已审查,发现 1 个 P3 问题(宏内联展开与项目模式不一致)
  • Samples/0_Introduction/vector_add/main.asc — 已审查,发现 4 个 P3 问题

按优先级统计:

优先级 数量
P0 0
P1 0
P2 0
P3 5

整体风险判定:低。 变更范围可控,核心计算逻辑未修改,profiling 元信息上报为纯增量功能(不影响原有计算正确性)。PR 作者已在 Ascend 950 环境完成编译与运行验证,profiling 输出符合预期。5 个 P3 发现均为代码质量 / 可维护性 / 前向兼容性方面的改进建议,不构成当前功能缺陷。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
CANN-robotCANN-robot成员
24 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
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
repo-cann/cann-samples 周奇龙, zhangzijie (2/2) 周奇龙 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
24 天前 将yangyang016,zhou-qilong,rxtfeng,loov1,zhangzijie,zl_hw,gubaocheng设为评审人
此处折叠了81条消息 查看更多
CANN-robotCANN-robot成员
21 天前 添加了label:lgtmapproved
CANN-robot
CANN-robot成员
21 天前 评论:

The MR can not be merged, because of CodeReview discussion not resolved

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

likedislike
Ssunday成员
21 天前 解决了最后一个问题
CANN-robotCANN-robot成员
21 天前 关闭了关联的issue
CANN-robotCANN-robot成员
21 天前 合入了pull request