已关闭
[feat] arch5162 support datadump #5290
FengHaozhan创建于 10 天前关闭于 9 天前
[feat] arch5162 support datadump #5290
已关闭
FengHaozhan创建于 10 天前关闭于 9 天前
FengHaozhan
FengHaozhan成员
10 天前

Pull Request

描述

请清晰准确地描述本次 Pull Request 的意图和变更内容。

变更类型

请选择本次引入的变更类型:

关联的Issue

如何测试

描述测试此变更的步骤和前提条件:
1.
2.

核对清单

其他信息

在此添加任何其他关于本次 PR 的说明。

likedislike
当前Pull Request已关闭, 关闭人@FengHaozhan
FengHaozhanFengHaozhan成员
10 天前 添加了label:enhancement
FengHaozhanFengHaozhan成员
10 天前 创建了 pull request,commit 6a57ebc6
atomgit-bot
atomgit-bot
10 天前 评论:

变更摘要

本 PR 为 arch5162 平台的运行时线程 AICPU 引入 DataDump 能力。变更围绕一条完整的 DataDump 链路展开:扩展插件协议接口(新增 DataDump SQE 子类型、状态码与请求结构),新增 datadump 子模块负责 TLV 解析(DataDumpParser)、模型/算子信息管理(DataDumpManager)与统计/张量文件落盘(DataDumpWriter),并在 RuntimeThreadAicpuService 中接入 worker 启动、DataDump 加载与回调报告分流处理;同时调整了 API 层 DatadumpInfoLoad 的归档与 arch5162 下发路径,以及在 AI Core SQE 中打上 DataDump 标志。

主要改动

  • 插件协议接口扩展: runtime_thread_aicpu_plugin.h 新增 RuntimeThreadAicpuSqeSubtype::DATADUMP、7 个 DATADUMP_* 状态码,以及 RuntimeThreadAicpuStartRequest、RuntimeThreadAicpuDumpInfoRequest 结构与 startWorker、loadDumpInfo 两个函数指针,插件 API 契约随之扩充。

  • 新增 DataDump 解析、管理与落盘模块: 新增 data_dump_parser、data_dump_manager、data_dump_writer、data_dump_types.hpp、data_dump_tlv.hpp,实现 TLV 二进制协议解析(含版本/魔数校验与层级去重)、按 TaskKey 索引模型与算子信息、按数据类型生成统计 CSV 或按 TLV 布局写出张量文件,并对文件/目录创建与写入失败返回对应状态。

  • 服务层接入与回调分流: RuntimeThreadAicpuService 新增 StartWorker、LoadDumpInfo,将 EnsureStarted 参数由 RuntimeThreadAicpuKernelRequest 改为 deviceId/tsId,并把原先的 ProcessOneReport/FinishReport 拆分为 ProcessAicpuReport/ProcessDumpReport 与带 RuntimeThreadAicpuSqeSubtype 的 FinishReport,在 ProcessReports 中按报告 reserved 字段路由 AICPU 与 DATADUMP 两类回调。

  • 运行时 API 层下发路径调整: 将 DatadumpInfoLoad 从 api_impl.cc 移至 api_impl_cpu_kernel.cc,并在 api_impl_arch5162.cc 新增实现(校验 flag、上下文与设备后调用 LoadRuntimeThreadAicpuDumpInfo);runtime_thread_aicpu.cc 增加 LoadDumpInfo 转发与插件表校验,runtime_thread_aicpu.hpp 导出对应接口。

  • AI Core SQE 打标: davinci_task_arch5162.cc 在 ConstructAICoreSqeForDavinciTask 中当 kernelFlag 含 RT_KERNEL_DUMPFLAG 时设置 header.postP 与 res7[1] |= SQE_BIZ_FLAG_DATADUMP,并加入偏移静态断言约束标志落在第 13 个 word。

likedislike
不准确?
atomgit-bot
atomgit-bot
10 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
10 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
10 天前 评论:

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

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
pkg_inc ❌ (0/2)(You can also ask: yanmingxiang, Reyn52166, 王涛, 张子菁, 卢煜坤) ❌ (0/1)(You can also ask: 张子菁, 卢煜坤, 侯延保, 王涛)
src/aicpu_sched ❌ (0/2)(You can also ask: 张子菁, 卢煜坤, Reyn52166, LiWei79, yanmingxiang) ❌ (0/1)(You can also ask: LiWei79, ZhaiPeiChao)
src/runtime ❌ (0/2)(You can also ask: sunnana_004434229, yanmingxiang, weiying_101, WangHuiH, zhangpengpeng8) ❌ (0/1)(You can also ask: Turing_JasonWen, WangHuiH, YzQnWyx, turing_yhy, Henry_ascend)
tests/ut/aicpu_sched ❌ (0/2)(You can also ask: LiWei79, 侯延保, zhangpengpeng8, Reyn52166, 张子菁) ❌ (0/1)(You can also ask: ZhaiPeiChao, LiWei79)
tests/ut/runtime ❌ (0/2)(You can also ask: Reyn52166, 张子菁, turing_yhy, zhangpengpeng8, zhaozhixuan) ❌ (0/1)(You can also ask: sunnana_004434229, 卢煜坤, Axiaolei, turing_yhy, WangHuiH)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
10 天前 将SongAnyin,zhaozhixuan,wda1991,wangtao43,zhangpengpeng8,vaceciliachen,yanmingxiang,weiying_101,LiWei79,turing_yhy,ZhaiPeiChao,Henry_ascend,Reyn52166,dragon_q,Turing_JasonWen,phy-zhao,WangHuiH,Axiaolei,ykl999,sunnana_004434229,YzQnWyx,houyanbao,wangluyao17,zhou-wuxiao,tingwood,liubin1986设为评审人
CANN-robotCANN-robot成员
10 天前 将SongAnyin,zhaozhixuan,wda1991,wangtao43,zhangpengpeng8,vaceciliachen,yanmingxiang,weiying_101,LiWei79,turing_yhy,ZhaiPeiChao,Henry_ascend,Reyn52166,dragon_q,Turing_JasonWen,phy-zhao,WangHuiH,Axiaolei,ykl999,sunnana_004434229,YzQnWyx,houyanbao,wangluyao17,zhou-wuxiao,tingwood,liubin1986设为审查人
FengHaozhan
FengHaozhan成员10 天前进行代码检视2
src/runtime/api/impl/api_impl_arch5162.cc
@@ -58,0 +61,4 @@
61+ CHECK_CONTEXT_VALID_WITH_RETURN(context, RT_ERROR_CONTEXT_NULL);
62+ Device* const device = context->Device_();
63+ COND_RETURN_ERROR(device == nullptr, RT_ERROR_DEVICE_NULL, "Device is null.");
64+ return LoadRuntimeThreadAicpuDumpInfo(this, device->Id_(), device->DevGetTsId(), dumpInfo, length);
FengHaozhan
FengHaozhan10 天前评论:

🔴 Critical:这里把现有 rtDatadumpInfoLoad 载荷直接转给 Host 侧 TLV 解析,破坏了当前跨仓接口契约。

当前 GE V1/OM2 在调用该接口前都会先把 OpMappingInfo protobuf H2D 拷到 Device,再传入 Device 地址(runtime/v1/common/dump/data_dumper.cc:1016-1023、runtime/om2/dump/data_dump_impl.cc:128-140);而新路径最终在 DataDumpParser::Parse 中直接对 dumpInfo 做 Host memcpy,并要求内容是 0x5A5A5A5A TLV。这样现有 arch5162 调用会把 Device 地址当 Host 指针解引用,可能直接异常,即使地址可访问也必然因 protobuf/TLV 格式不符而加载失败。

建议先同步生产端与接口契约:要么由 GE 通过明确的 Host-TLV 接口传入完整 TLV,要么保留现有 Device-protobuf 通路;同时补一条从真实 GE 调用形态进入该实现的集成用例。

likedislike
FengHaozhan
FengHaozhan成员
10 天前 评论:

5162架构不区分host和device,不会有这个问题

FengHaozhanFengHaozhan成员
10 天前 预合并成功(commit_id: c8481a5cd261e16c16c762b00450ae5217c3c0f9)
此处折叠了9条事件消息 查看更多
CANN-robotCANN-robot成员
10 天前 删除了label:stat/needs-squash
CANN-robot
CANN-robot成员
10 天前 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): stat/needs-squash.

likedislike
CANN-robotCANN-robot成员
10 天前 添加了label:cann-cla/yes
yanhaiyan成员10 天前进行代码检视3
src/aicpu_sched/runtime_thread_aicpu/datadump/data_dump_writer.cc
@@ -0,0 +157,4 @@
157+ reinterpret_cast<const volatile uint64_t*>(static_cast<uintptr_t>(config.stepIdAddress));
158+ const uint64_t stepId = *stepIdAddress;
159+ dumpDirectory = JoinPath(dumpDirectory, std::to_string(config.modelId));
160+ dumpDirectory = JoinPath(dumpDirectory, config.modelName);
yanhaiyan10 天前评论:

modelName 直接 JoinPath 进 dump 目录路径且不经 SanitizeFileNamePart(opName/opType 有消毒、modelName 没有);parser 对 modelName 无字符集校验。TLV 中 modelName 含 "../" 或绝对路径分量时,CreateDirectories 按 '
mkdir 可在 dumpPath 之外建目录/写文件。
建议 parser 或 writer 侧对 modelName 做与 opName 相同的消毒。

likedislike
FengHaozhan
FengHaozhan成员
10 天前 评论:

modelName不需要,GE能保证模型名没有这些特殊字符

FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改

yanhaiyan成员10 天前进行代码检视2
src/aicpu_sched/runtime_thread_aicpu/datadump/data_dump_writer.cc
@@ -0,0 +38,4 @@
38+constexpr char STATS_FILE_SUFFIX[] = ".csv";
39+constexpr char STATS_HEADER[] =
40+ "Input/Output,Index,Data Size,Data Type,Format,Shape,Max Value,Min Value,Avg Value,Count,Nan Count,"
41+ "Negative Inf Count,Positive Inf Count\n";
yanhaiyan10 天前评论:

Nagative 》 Negative?

likedislike
FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改

yanhaiyan成员10 天前进行代码检视3
src/aicpu_sched/runtime_thread_aicpu/datadump/data_dump_writer.cc
已过期
@@ -0,0 +296,4 @@
296+T ReadValue(const uint8_t* const data, const size_t index)
297+{
298+ T value = {};
299+ (void)std::memcpy(&value, data + (index * sizeof(T)), sizeof(T));
yanhaiyan10 天前评论:

使用 std::memcpy 而非 memcpy_s:定长无溢出但违反仓库安全编码规范,请确认是否OK。
同 parser.cc 的 Cursor::Read。

likedislike
System
系统消息系统
10 天前 评论:

changed this line on 9edb0d0e view diff detail

FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改

yanhaiyan成员10 天前进行代码检视3
src/aicpu_sched/runtime_thread_aicpu/datadump/data_dump_writer.cc
已过期
@@ -0,0 +402,4 @@
402+ uint32_t exponent = static_cast<uint32_t>(value & 0x7C00U);
403+ uint32_t mantissa = static_cast<uint32_t>(value & 0x03FFU);
404+ if (exponent == 0x7C00U) {
405+ exponent = 0x3FC00U;
yanhaiyan10 天前评论:

魔数?是不是转换成名称有意义的常量或变量?

likedislike
System
系统消息系统
10 天前 评论:

changed this line on 9edb0d0e view diff detail

FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改

yanhaiyan成员10 天前进行代码检视3
src/aicpu_sched/runtime_thread_aicpu/runtime_thread_aicpu_service.cc
已过期
@@ -721,0 +787,4 @@
787+ success = false;
788+ }
789+ } else {
790+ aicpusd_err(
yanhaiyan10 天前评论:

未知 CallbackReportType(reserved 非 0/1):
(1) 不调 FinishReport → SQ finish command 不回写 → 该 report 对应 event 永不 complete,上层 stream/event 同步挂起;
(2) success=false → WorkerLoop 置 failed_ 并永久退出 → 整个 runtime_thread_aicpu 服务(含普通 AICPU 算子)不可用。

既有失败策略(funcPtr 校验失败等)为"单条失败→setStreamError+回写 finish,不杀 worker",未知 type 处理与之不一致。

请确认是否存在上述问题,请确认是否OK?

likedislike
System
系统消息系统
10 天前 评论:

changed this line on 9edb0d0e view diff detail

FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改,未知type打warn后跳过

yanhaiyan成员10 天前进行代码检视2
src/runtime/feature/runtime_thread_aicpu/runtime_thread_aicpu.cc
@@ -92,6 +92,9 @@ constexpr char STREAM_OBSERVER_NAME[] = "Inner#RuntimeThreadAicpu";
9292static_assert(
9393 static_cast<uint32_t>(RuntimeThreadAicpuSqeSubtype::AICPU) == static_cast<uint32_t>(RT_SQE_SUBTYPE_AICPU),
9494 "RuntimeThreadAicpu SQE subtype does not match the runtime protocol");
95+static_assert(
96+ static_cast<uint32_t>(RuntimeThreadAicpuSqeSubtype::DATADUMP) == static_cast<uint32_t>(RT_SQE_SUBTYPE_DATADUMP),
97+ "RuntimeThreadAicpu DataDump SQE subtype does not match the runtime protocol");
9598 
9699RuntimeThreadAicpuStatus ToPluginStatus(const rtError_t error)
97100{
@@ -116,6 +119,7 @@ rtError_t ToRuntimeStatus(const RuntimeThreadAicpuStatus status)
116119 case RuntimeThreadAicpuStatus::OK:
117120 return RT_ERROR_NONE;
118121 case RuntimeThreadAicpuStatus::INVALID_PARAM:
122+ case RuntimeThreadAicpuStatus::DATADUMP_PARSE_FAILED:
yanhaiyan10 天前评论:

ToRuntimeStatus 仅映射 DATADUMP_PARSE_FAILED,其余 6 个新 DATADUMP_* 落 default→RT_ERROR_AICPU_INTERNAL_ERROR;DumpOp 失败时这些枚举值经 FinishReport→setStreamError 直接写入 Stream errCode(用
8-13,非 rtError_t 语义);RUNTIME_ERROR(设备不匹配)同样落 default 语义失配(arch5162 UT 已将该失配固化为断言)。
建议补全映射或定义 executeResult 转换值。

likedislike
FengHaozhan
FengHaozhan成员
10 天前 评论:

插件和runtime侧错误语义未对齐的检视意见已记录,后续单提PR修改

yanhaiyan成员10 天前进行代码检视2
src/aicpu_sched/runtime_thread_aicpu/runtime_thread_aicpu_service.cc
@@ -35,6 +35,11 @@ constexpr int32_t REPORT_WAIT_TIMEOUT_MS = 1000;
3535constexpr uint8_t CALLBACK_EVENT_RECORD_COMMAND = 15U;
3636constexpr char RUN_KERNEL_WITH_BLOCK[] = "RunCpuKernelWithBlock";
3737 
38+enum class CallbackReportType : uint8_t {
39+ AICPU = 0U,
40+ DATADUMP = 1U,
41+};
42+ 
3843struct CallbackReport {
3944 volatile uint16_t phase : 1;
4045 volatile uint16_t sop : 1;
@@ -47,7 +52,7 @@
4752 volatile uint16_t sqHead;
4853 volatile uint16_t sequenceId;
4954 volatile uint8_t isBlock;
5055 volatile uint8_t reserved;
yanhaiyan10 天前评论:

CallbackReport.reserved 从"保留"变为 report type 载荷(设备侧填写):跨软硬件协议(谁写、值域、老微码默认 0 兼容假设)无说明;davinci_task 经 SQE res7 biz flag+postP 传递,设备侧配套微码变更本仓不可见,存在跨仓配套风险。
建议修改名称或者增加注释说明

likedislike
FengHaozhan
FengHaozhan成员
10 天前 评论:

已记遗留检视意见,和runtime、tsdrv约定好后改名

yanhaiyan成员10 天前进行代码检视3
src/aicpu_sched/runtime_thread_aicpu/datadump/data_dump_parser.cc
已过期
@@ -0,0 +53,4 @@
53+ 
54+ bool ReadString(std::string& value)
55+ {
56+ value.assign(reinterpret_cast<const char*>(data_ + offset_), Remaining());
yanhaiyan10 天前评论:

ReadString/ParseStringList 对 TLV 长度无上限:恶意/损坏 TLV(length≈4GB)触发数 GB 单次分配,bad_alloc 兜底不崩溃但内存尖峰可能 OOM-kill 调度进程。
建议增加单字段上限(如 1MB)或累计限流。

likedislike
FengHaozhan
FengHaozhan成员
10 天前 评论:

tlv不来自外部输入,而是内部组件GE提供的,可以保证没有超长tlv存在

System
系统消息系统
10 天前 评论:

changed this line on 9edb0d0e view diff detail

yanhaiyan成员10 天前进行代码检视3
src/aicpu_sched/runtime_thread_aicpu/datadump/data_dump_parser.cc
已过期
@@ -0,0 +36,4 @@
36+ if (sizeof(T) > Remaining()) {
37+ return false;
38+ }
39+ (void)std::memcpy(&value, data_ + offset_, sizeof(T));
yanhaiyan10 天前评论:

用 std::memcpy 而非 memcpy_s,确认是否存在安全问题

likedislike
System
系统消息系统
10 天前 评论:

changed this line on 9edb0d0e view diff detail

FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改

yanhaiyan成员10 天前进行代码检视3
src/aicpu_sched/runtime_thread_aicpu/datadump/data_dump_parser.cc
已过期
@@ -0,0 +88,4 @@
88+bool ReadString(Cursor& cursor, std::string& value, std::string& errorDetail)
89+{
90+ if (!cursor.ReadString(value)) {
91+ return Fail(errorDetail, "failed to read TLV string");
yanhaiyan10 天前评论:

cursor.ReadString(value) 恒 true,包装层 Fail("failed to read TLV string") 为死代码。

likedislike
System
系统消息系统
10 天前 评论:

changed this line on 9edb0d0e view diff detail

FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改

yanhaiyan成员10 天前进行代码检视2
src/runtime/api/impl/api_impl_arch5162.cc
@@ -54,1 +54,4 @@
5454 
55+rtError_t ApiImpl::DatadumpInfoLoad(const void* const dumpInfo, const uint32_t length, const uint32_t flag)
56+{
57+ if (flag != RT_KERNEL_DEFAULT) {
yanhaiyan10 天前评论:

和其他芯片相比,丢失日志RT_LOG(RT_LOG_DEBUG, "length=%u, flag=%u."),导致flag != RT_KERNEL_DEFAULT 拒绝路径无日志,用户无从得知不支持原因。建议补充。

likedislike
FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改

yanhaiyan成员10 天前进行代码检视3
src/runtime/core/src/task/task_info/davinci/davinci_task_arch5162.cc
已过期
@@ -110,1 +115,4 @@
110115 }
116+ if ((aicTaskInfo->comm.kernelFlag & RT_KERNEL_DUMPFLAG) != 0U) {
117+ sqe->header.postP = RT_STARS_SQE_INT_DIR_TO_TSCPU;
118+ sqe->res7[1U] |= SQE_BIZ_FLAG_DATADUMP;
yanhaiyan10 天前评论:

建议增加注释,描述清楚 使用哪个字节的哪个bit,或者将其剥离出来,便于后续维护

likedislike
System
系统消息系统
10 天前 评论:

changed this line on 9edb0d0e view diff detail

FengHaozhan
FengHaozhan成员
10 天前 评论:

已修改

FengHaozhan
FengHaozhan成员
10 天前 评论:

compile

likedislike
FengHaozhanFengHaozhan成员
10 天前 预合并成功(commit_id: e774acff07224a845fcaf70146a1d65c3a7750b2)
CANN-robot
CANN-robot成员
10 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
10 天前 添加了label:ci-pipeline-running
此处折叠了6条事件消息 查看更多
CANN-robotCANN-robot成员
10 天前 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
10 天前 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robot成员
10 天前 添加了label:cann-cla/yes
FengHaozhanFengHaozhan成员
9 天前 关闭了 pull request