已合并
[simd vf debug] fix printf/asc_dump bugs #4601
ChenZhoujie创建于 7月25日
[simd vf debug] fix printf/asc_dump bugs #4601
已合并
ChenZhoujie创建于 7月25日
ChenZhoujie成员
7月25日

描述

  1. simd_vf的asc_dump接口添加2KB拦截并给出打屏信息;
  2. 头文件顺序利用traits模板特性解耦,kernel_operator.h和asc_printf.h/asc_dump.h不再存在顺序依赖;
  3. asc_dump在float数据类型下能打印最大的数据长度64;

关联的Issue

无

测试

问题场景验证

文档更新

无

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 ChenZhoujie 的贡献)
CChenZhoujie成员
7月25日 创建了 pull request,commit c64cdc73
atomgit-bot
atomgit-bot
7月25日 评论:

变更摘要

此 PR 主要修复了 SIMD VF 调试(printf/asc_dump)中的缓冲区溢出和代码组织问题。核心改动包括:引入基于 traits 的 SimdVfDebugTraits<SimdVfDebugTag> 机制替代旧的 ASCENDC_SIMD_VF_DEBUG 宏来控制调试功能的使能;将原本集中在 npu_arch_3510/ 目录下的 dump 和 printf 实现提取到独立的通用头文件中;为缓冲区写入增加了容量预留检查(reserve_debug_tlv)和溢出标志(BlockVFBufInfo.flag),并在溢出时提供截断警告;修复了 asc_vf_debug_ub2gm 中未对齐字节拷贝遗漏及缺少头部合法性校验的问题。

主要改动

  • 引入 SIMD VF Debug Traits 机制:新增 asc_simd_debug_traits.h 和 asc_simd_debug_enable.h,通过 SimdVfDebugTraits<SimdVfDebugTag>::enabled 编译期常量控制调试功能开关,替代了原先全局 #define ASCENDC_SIMD_VF_DEBUG 的方式。AscVFCallImpl 利用 if constexpr 根据 traits 选择性调用 AscVFDebugInitUb/AscVFDebugTransferUb,避免未启用时的无效开销。

  • 缓冲区溢出检测与警告:BlockVFBufInfo.flag 字段被赋予溢出语义(非零表示溢出),新增 reserve_debug_tlv 函数在写入每条 TLV 前检查容量,溢出时设置 flag=1 并拒绝写入。AscVFDebugTransferUb 返回 bool 溢出状态,AscVFCallImpl 在条件编译开启时通过 printf_impl 输出 [WARNING]: SIMD VF debug buffer overflow... 截断警告。

  • 代码重构:dump/printf 实现从 npu_arch_3510 提取至独立文件:将 asc_aicore_dump_utils.h 和 asc_aicore_printf_utils.h 中 __asc_simd_vf 命名空间的 dump/printf 实现分别迁移到 asc_simd_dump_impl.h、asc_simd_printf_impl.h 和 asc_simd_vf_utils.h,消除了架构特定目录下的重复代码,并使 asc_dump.h/asc_printf.h 的 include 结构更清晰。

  • 修复 asc_vf_debug_ub2gm 数据搬运与校验缺陷:新增对 BlockVFBufInfo 头部 magic、length、writeLen 的合法性校验;修复了之前仅按 4 字节对齐搬运导致尾部字节遗漏的问题(现先搬完整 4 字节块,再逐字节搬运余数);仅在 tlvLen > 0 时才执行搬运和更新 RingBufWriteInfo。

  • 测试与头文件隔离验证:新增 kernel_operator_simd_vf_debug_trait_default.cpp、kernel_simt_print_intf.cpp 和 simt_asc_simt_debug_trait_default.cpp 三个编译期静态断言测试,验证仅包含对应头文件时 SimdVfDebugTag 对应的 traits 默认处于禁用状态,确保调试功能不会意外开启。

likedislike
不准确?
atomgit-bot
atomgit-bot
7月25日 评论:

代码审查

I've completed my thorough review. Here's the closing summary:


审查总结

已审查的文件 (21个)

文件 结果
impl/basic_api/kernel_utils.h 无问题
impl/utils/debug/asc_aicore_printf_impl.h 无问题
impl/utils/debug/asc_debug_types.h 无问题
impl/utils/debug/asc_debug_utils.h 无问题
impl/utils/debug/asc_simd_debug_enable.h 无问题 (新文件)
impl/utils/debug/asc_simd_debug_traits.h 无问题 (新文件)
impl/utils/debug/asc_simd_dump_impl.h 无问题 (新文件)
impl/utils/debug/asc_simd_printf_impl.h P2: copy_fmt_to_ubuf 越界读取 (新文件)
impl/utils/debug/asc_simd_vf_utils.h 无问题 (新文件)
impl/utils/debug/npu_arch_3510/asc_aicore_dump_utils.h 无问题 (仅删除)
impl/utils/debug/npu_arch_3510/asc_aicore_printf_utils.h 无问题 (仅删除)
impl/utils/debug/npu_arch_3510/asc_debug_utils_impl.h 无问题
include/basic_api/kernel_common.h 无问题
include/basic_api/kernel_operator_dump_tensor_intf.h 无问题
include/simt_api/common_functions.h 无问题
include/simt_api/cpp/kernel_simt_print_intf.h 无问题
include/utils/debug/asc_dump.h 无问题
include/utils/debug/asc_printf.h 无问题
tests/api/basic_api/ascendc_header_checker/kernel_operator_simd_vf_debug_trait_default.cpp P0: 符号名错误 SimdVfTraits (新文件)
tests/api/basic_api/ascendc_header_checker/kernel_simt_print_intf.cpp P0: include 不存在的头文件 + 符号名错误 (新文件)
tests/api/basic_api/ascendc_header_checker/simt_asc_simt_debug_trait_default.cpp P0: include 不存在的头文件 + 符号名错误 (新文件)

统计

  • P0: 3 个 (均为测试文件的编译阻断问题)
  • P1: 0 个
  • P2: 1 个 (越界读取)
  • P3: 0 个

总体风险评估

高风险 — 3 个新增测试文件存在编译阻断问题(include 不存在的头文件 + 使用错误的符号名),会导致 CI 编译失败。核心逻辑代码(kernel_utils.h、debug_utils 系列)的变更质量较好:overflow 检测、header 校验、边界保护等逻辑正确,asc_vf_debug_ub2gm 的 word+byte 两段式拷贝也比旧代码的 ceiling-division word copy 更精确。copy_fmt_to_ubuf 的越界问题是旧有缺陷的搬迁(非本次引入),实际危害较低但在严格模式下是 UB。

类型 数量
🔴 阻塞 4
🟡 建议 1

⛔ 需要修改

likedislike
不准确?
CANN-robotCANN-robot成员
7月25日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月25日 评论:

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
9.1.0 ✅ chenyiyuan, Andy-lb, chentianyu19 (3/2) ✅ Andy-lb (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
此处折叠了131条消息 查看更多
CANN-robotCANN-robot成员
8月6日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月6日 添加了label:ci-pipeline-passed
Andy-lb成员
8月6日 评论:

/approve

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