Pull Request has been successfully merged by CANN-robot.
(Thank you for xiachanglin's contribution.)变更摘要
本次 PR 主要为 runtime 的 mem-api 增加了 profiling 支持,通过扩展 MsprofCompactInfo 联合体、新增 profiling 数据类型与扩展信息结构体,并在 ApiProfileDecorator 中为内存分配/释放、memcpy、memset 等 API 挂载扩展信息上报逻辑,使 profiler 能够在运行时捕获并上报内存操作的详细信息(字节数、拷贝方向、设备 ID、流 ID 等)。同时还支持了 batch memcpy 按拷贝类型聚合上报,并新增了相应的单元测试。
主要改动
-
新增内存操作 profiling 数据结构: 在
aprof_pub.h中定义MsprofMemcpyInfo、MsprofMemsetInfo、MsprofMemMngInfo三个结构体,并加入MsprofCompactInfo.data联合体,同时通过static_assert确保其大小不超过MSPROF_COMPACT_INFO_DATA_LENGTH。 -
扩展 profiling 类型体系: 在
profiler_struct.hpp中新增RT_PROF_API_SET_MEMCPY_DESCAPI 类型、RT_PROFILE_TYPE_MEMCPY_EXT_INFO/RT_PROFILE_TYPE_MEMSET_INFO/RT_PROFILE_TYPE_MEMMNG_INFO三种数据类型、RuntimeMemMngType枚举,以及RuntimeProfExtInfo联合体和RuntimeProfExtInfoItem结构,同时扩展RuntimeProfApiData以支持单个扩展信息和批量扩展信息数组。 -
实现扩展信息上报逻辑: 在
profiling_agent.cc中新增GetRuntimeExtInfoLen、SetRuntimeExtCompactData、ReportRuntimeExtCompactInfo三个辅助函数,并在ReportProfApi中集成单个扩展信息与批量扩展信息的上报流程,同时注册了新的 profiling 类型名称。 -
在 ApiProfileDecorator 中挂载内存 profiling 钩子: 在
api_profile_decorator.cc中新增FillMemcpyExtInfo、FillMemsetExtInfo、FillMemMngExtInfo、FillMemcpyBatchExtInfoByCopyKind等方法,并在DevMalloc、DevFree、HostMalloc、HostFree、MemCopySync、MemcpyAsync、MemsetD32、MemcpyBatch等大量内存相关 API 的成功路径上调用相应的 Fill 方法,同时新增HostMallocWithCfg、SetMemcpyDesc、ReserveMemAddress、ReleaseMemAddress、MallocPhysical、FreePhysical等方法的重写。 -
新增单元测试覆盖: 在
rt_utest_agent.cc中新增PROF_REPORT_EXT_MEMCPY_INFO、PROF_REPORT_EXT_MEMSET_INFO、PROF_REPORT_EXT_MEMMNG_INFO、PROF_REPORT_BATCH_EXT_MEMCPY_INFO等测试用例;在rt_utest_profiler.cc中新增ApiProfileDecoratorMemCopySyncExtInfo、ApiProfileDecoratorMemcpyBatchMultiKindExtInfo等测试用例,覆盖单条与批量扩展信息的上报正确性。


代码审查
All seven files have been reviewed. Let me write the closing summary.
审查总结
审查覆盖的文件
| 文件 | 审查结论 |
|---|---|
pkg_inc/profiling/aprof_pub.h |
无问题 — 新增结构体 MsprofMemcpyInfo、MsprofMemsetInfo、MsprofMemMngInfo 已正确加入 MsprofCompactInfo union,static_assert 大小检查均通过 (≤40字节) |
src/runtime/core/inc/common/profiler_struct.hpp |
无问题 — 新增枚举 RuntimeMemMngType、联合体 RuntimeProfExtInfo、结构体 RuntimeProfExtInfoItem、常量 RUNTIME_PROF_BATCH_EXT_INFO_NUM,以及 RuntimeProfApiData 新增字段,定义一致 |
src/runtime/core/src/common/profiling_agent.cc |
无问题 — ReportRuntimeExtCompactInfo、SetRuntimeExtCompactData、GetRuntimeExtInfoLen 逻辑正确;ReportProfApi 的 extInfo 和 batch 上报流程正确;新类型注册正确;同时修复了 GetDevArgsAddr 和 MemcpyHostTask 缺少 CallApiEnd/return 的已有 bug |
src/runtime/core/src/profiler/api_profile_decorator.cc |
发现 2 个问题 — P2 双重上报、P3 sentinel 值泄漏 |
src/runtime/core/src/profiler/api_profile_decorator.hpp |
无问题 — 声明与实现一致 |
tests/ut/runtime/runtime/test/rt_utest_agent.cc |
无问题 — 测试覆盖了 ext info 上报、batch 上报和无效类型路径 |
tests/ut/runtime/runtime/test/rt_utest_profiler.cc |
无问题 — 测试覆盖了 Fill 系列函数、batch 归类和 streamId 传递 |
问题统计
- P2: 1 个 — memcpy 操作双重上报 profiling 数据
- P3: 1 个 —
RT_MEMCPY_KIND_MAXsentinel 被当作有效 copyKind 上报 - P1: 0 个
- P0: 0 个
整体风险判断
中低风险。核心功能变更(memory API profiling)实现基本正确。主要风险在于:memcpy 操作会产生重复的 profiling 数据条目(旧格式 type 801 和新格式 type 808 同时上报),可能导致 profiling 分析工具的数据失真。建议在合入前修复此双重上报问题。batch memcpy 中 sentinel 值泄漏的问题影响较小,可在后续迭代中优化。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


/approve


Pull Request
描述
memmng(OperationType/address/bytes/memoryType/deviceId/streamId):
memset(value/bytes/deviceId/streamId):
memcpy(copyKind/bytes/deviceId/streamId):
变更类型
请选择本次引入的变更类型:
关联的Issue
如何测试
核对清单
其他信息
在此添加任何其他关于本次 PR 的说明。