已合并
[simd_vf debug] fix debug api cpu debug compile error #4749
[simd_vf debug] fix debug api cpu debug compile error #4749
已合并
ChenZhoujie创建于 25 天前
ChenZhoujie成员
25 天前

描述

修复simd_vf调测接口printf/asc_dump在cpu模式下存在的编译问题

关联的Issue

测试

// printf走std下的实现,能够正常打印
printf("[simd_vf] ------------1\n");
__asc_simd_vf::printf("[simd_vf] ------------2\n");

// asc_dump正确触发不支持
asc_dump(yAddr, 5, 32);
__asc_simd_vf::asc_dump(yAddr, 6, 32);
asc_dump_ubuf(yAddr, 5, 32);
__asc_simd_vf::asc_dump_ubuf(yAddr, 6, 32);

// asc_dump_reg正确触发不支持
asc_dump_reg(yReg, 8, 32);
__asc_simd_vf::asc_dump_reg(yReg, 7, 32);
asc_dump(yReg, 8, 32);
__asc_simd_vf::asc_dump(yReg, 7, 32);

文档更新

类型标签

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

变更摘要

此 PR 主要修复了 simd_vf 调试 API 在 CPU Debug 模式(ASCENDC_CPU_DEBUG)下的编译错误。通过对 asc_simd_dump_impl.hasc_simd_printf_impl.h 添加 CPU 模式的 fallback 实现(dump 使用 assert(false) 断言,printf 转发到 std::printf),并调整 asc_printf.h 的条件编译使其在 CPU 模式下也能引入 simd_vf 头文件,确保相关 API 在 CPU 调试场景下可以正常编译和链接。同时新增了对应的单元测试来验证这些 CPU fallback 的行为。

主要改动

  • asc_simd_dump_impl.h 添加 CPU 模式 stub:将 sys_macros.h 提升到条件编译之外使其始终可用,并在 ASCENDC_CPU_DEBUG 分支下为 asc_dump_regasc_dump_ubufasc_dump 提供了带 assert(false) 断言提示的 stub 实现,明确告知这些接口在 CPU 模式下不支持。
  • asc_simd_printf_impl.h 添加 CPU 模式 printf:在 #ifndef ASCENDC_CPU_DEBUG 内保留原有 NPU 实现,在 #else 分支新增 CPU 模式下的 printf_implprintf,直接转发到 std::printf,并在 ASCENDC_DUMP == 0 时静默输出。
  • asc_printf.h 放宽 include 条件:移除 #if __NPU_ARCH__ == 3510 条件中对 !defined(ASCENDC_CPU_DEBUG) 的限制,使 asc_simd_printf_impl.h 在 CPU 调试模式下也能被包含。
  • 新增测试用例:在 test_dump_tensor.cpptest_operator_printf.cpp 中增加了 CPU 模式下 simd_vf dump/printf 的回归测试;新增 test_simd_vf_debug_dump_disabled.cpp 测试 ASCENDC_DUMP=0 时 printf 静默且 dump 仍断言的行为;新增 simd_vf_debug.cpp 作为头文件包含检查用例。
likedislike
atomgit-bot
atomgit-bot
25 天前 评论:

代码审查

审查总结

已完成对全部 7 个变更文件的审查:

文件 审查结论
impl/utils/debug/asc_simd_dump_impl.h 无问题 — sys_macros.h 移至条件编译外正确;CPU 调试桩实现正确
impl/utils/debug/asc_simd_printf_impl.h 无问题 — 新增 CPU 调试路径将 printf 转发到 std::printfASCENDC_DUMP 守卫正确
include/utils/debug/asc_printf.h 无问题 — 移除 !defined(ASCENDC_CPU_DEBUG) 使得 CPU 调试下也能包含 asc_simd_printf_impl.h,与其新增的 #else 分支匹配
tests/.../test_dump_tensor.cpp 无问题 — SimdVfDumpCpuFallbacks 测试正确使用 #ifndef NDEBUG 保护 EXPECT_DEATH
tests/.../test_operator_printf.cpp 无问题 — SimdVfPrintfMatchesAicoreCpuFallback 测试逻辑正确,ASCENDC_DUMP=1 使 printf 正常输出
tests/.../test_simd_vf_debug_dump_disabled.cpp 1 个 P2 问题EXPECT_DEATH 缺少 #ifndef NDEBUG 保护
tests/.../simd_vf_debug.cpp 无问题 — 头文件检查器仅验证编译通过,不执行运行时断言

问题统计:P2 × 1(共 1 个)

总体风险判断:低风险。核心实现变更(asc_simd_dump_impl.hasc_simd_printf_impl.hasc_printf.h)正确且一致,新增的 CPU 调试桩函数和 printf 转发逻辑符合预期。唯一的问题是新增测试文件中 EXPECT_DEATH 缺少 NDEBUG 守卫,当 Release 构建(定义了 NDEBUG)时该测试会失败,但不影响生产代码。

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

⛔ 需要修改

likedislike
CANN-robotCANN-robot成员
25 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
25 天前 添加了label:cann-cla/yes
此处折叠了88条消息 查看更多
chenyiyuan成员
20 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
20 天前 添加了label:lgtm
wuzhaolin成员
20 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
20 天前 添加了label:approved
CANN-robotCANN-robot成员
20 天前 合入了pull request