已关闭
test: track IsInf MaskedFill E2E compile-only validation #160
Jett_Woo创建于  7月4日关闭于  7月7日
Jett_Woo成员
7月4日 创建

问题背景

在将 isinf_maskedfill_test_e2e 纳入 backend E2E 执行列表时,发现 IsInf + MaskedFill 场景存在两类需要区分的问题:

  1. CANN 9.1.0 下 IsInfExtend<float> 如果直接走 DoIsInf<int> 并调用 AscendC::Abs<int>,DAV C220 头文件会报 vabs(int*, ...) 无匹配函数,属于编译期兼容问题。
  2. 修复后使用 ReinterpretCast<float>() / ReinterpretCast<half>() 调用 Abs 可以覆盖编译问题,但 CPU simulator 对该 ReinterpretCast aliasing 路径模拟不准确,导致仿真执行阶段不适合作为正确性验证。

原因分析

IsInf 的计算流程会先将浮点输入按位处理成整型中间 buffer,再执行符号位清理和差值判断。CANN 9.1.0 在 910B/DAV C220 上没有 Abs<int32_t> 对应的 vabs(int*) 重载,因此中间 buffer 不能直接以 int32_t 调用 AscendC::Abs。

当前修复采用与 isfinite.h 类似的方式:对整型中间 buffer 使用 ReinterpretCast<float>() 或 ReinterpretCast<half>() 后调用 Abs,从而避免 Abs<int32_t> 编译错误。真实设备路径验证正常,但 CPU simulator 对该 reinterpret aliasing 行为存在已知限制。

处理方案

  • 保留 V1 IsInf 对 DT_FLOAT16 和 DT_FLOAT 的注册,避免收窄 FP32 支持。
  • 将 isinf_maskedfill_test_e2e 加入 backend E2E 执行列表,作为生成 kernel 的 compile-only 覆盖。
  • 由于 CPU simulator 执行阶段不可靠,该 gtest 当前使用 GTEST_SKIP(),不作为正确性验证。
  • PR 描述中明确该 target 仅提供 compile-only 覆盖,真实正确性验证以设备侧验证记录为准。

测试验证

编译验证

环境:隔离安装的 CANN 9.1.0 + 910B ops 包。

命令:

source /tmp/opencode/cann-9.1.0-latest/install/cann/set_env.sh
cmake --build build --target isinf_maskedfill_test_e2e -j 8

结果:

[100%] Built target isinf_maskedfill_test_e2e

说明:中间出现 libgcov profiling error ... overwriting an existing profile data with a different timestamp,属于覆盖率 .gcda 时间戳噪声,不是编译失败。

真实设备正确性验证

环境:910B3 真实设备。

验证场景:PyTorch + Autofuse 的 IsInf + LogicalOr + MaskedFill。

结果:

Max diff: 0.0
Mismatch count: 0 / 6400
PASSED: All results match!

关联 PR

likedislike
JJett_Woo成员
7月4日 将 Jett_Woo 设为负责人
Jett_Woo成员
7月4日 评论:

问题在910B环境复现

likedislike
Jett_Woo成员
7月6日 评论:

最新 NPU 设备验证结果(2026-07-06)

已基于当前最新本地代码重新编译并执行设备验证。

1. 重新编译

环境:

source /home/developer/Ascend/master/cann-9.1.0/set_env.sh

编译命令:

cmake --build build --target pyautofuse test_main -j 8

结果:

[100%] Built target pyautofuse
[100%] Built target test_main

设备信息:

NPU 7, 910B3, Health OK
No running processes found in NPU 7

2. PyTorch + Autofuse NPU 示例验证

执行命令:

ASCEND_DEVICE_ID=0 python3 autofuse/examples/af_pointwise/af_isinf_maskedfill_ge.py

结果:

Shape: torch.Size([128, 50])
Max diff: 0.0
Mismatch count: 0 / 6400

Inf position checks:
  x[0,0] was +inf, result: -10000.0, expected: -10000.0
  x[1,1] was -inf, result: -10000.0, expected: -10000.0
  x[10,10] was +inf, result: -10000.0, expected: -10000.0
  x[20,20] was -inf, result: -10000.0, expected: -10000.0
  x[5,5] was masked, result: -10000.0, expected: -10000.0
  x[3,3] was normal, result: -0.23828125, expected: -0.23828125

PASSED: All results match!

结论:PyTorch/Autofuse 端到端 NPU 执行结果与 golden 完全一致。

3. ASCIR Tool NPU ST 验证

执行命令:

source /home/developer/Ascend/master/cann-9.1.0/set_env.sh
export ASCEND_CUSTOM_PATH=/home/developer/Ascend/master/cann-9.1.0
export ASCEND_DEVICE_ID=0
export PYTHONPATH=/tmp/opencode/local_autofuse_cannpkg/python/site-packages:/mnt/workspace/gitCode/Jett_Woo/graph-autofusion/build/autofuse/tests:$PYTHONPATH
export LD_LIBRARY_PATH=/mnt/workspace/gitCode/Jett_Woo/graph-autofusion/build/autofuse/graph_metadef/graph/ascendc_ir/generator:/mnt/workspace/gitCode/Jett_Woo/graph-autofusion/build/autofuse/graph_metadef/graph:/mnt/workspace/gitCode/Jett_Woo/graph-autofusion/build/autofuse/graph_metadef/graph/expression:/mnt/workspace/gitCode/Jett_Woo/graph-autofusion/build/autofuse/graph_metadef/graph/ascendc_ir:/mnt/workspace/gitCode/Jett_Woo/graph-autofusion/build/autofuse/ascir/meta:/mnt/workspace/gitCode/Jett_Woo/graph-autofusion/build/autofuse/ascir/generator:/home/developer/Ascend/master/cann-9.1.0/lib64:/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/common:/usr/local/Ascend/driver/lib64/driver:$LD_LIBRARY_PATH
bash test_ascir.sh --mode=0 --case=isinf_maskedfill_fusion

结果关键输出:

################# end to launch kernel.
#################TEST RESULT#####################
output result: [-1.000e+04 -3.933e-01  1.964e-01 ...  6.255e-01 -7.783e-01  9.326e-01]
golden result: [-1.000e+04 -3.933e-01  1.964e-01 ...  6.255e-01 -7.783e-01  9.326e-01]
error ratio: 0.0000, tolrence: 0.0000
testcase:  isinf_maskedfill_fusion , Result: PASS

结论:ASCIR 构图、codegen、device kernel 编译、NPU launch 和 golden 比对链路通过。

4. 环境注意事项

  • torch_npu 示例不能在 source CANN 9.1 后直接运行;当前 Python NPU 栈会优先加载 /home/developer/Ascend/master/cann-9.1.0/lib64/libhccl.so,出现 HCCL 符号不匹配。未注入 9.1 runtime 库路径时,torch 2.7.1+cpu / torch_npu 2.7.1.post2.dev20251226 可正常执行 NPU 示例。
  • ASCIR Tool ST 不依赖 torch_npu,显式 source CANN 9.1 后运行通过。
  • 验证结束后 npu-smi info 显示设备无残留进程。

5. 总结

本次最新设备验证证明:IsInf + LogicalOr + MaskedFill 场景在 910B3 NPU 上执行正确,输出与 golden 完全一致;同时 ASCIR/codegen/kernel launch 链路也已通过设备侧 ST。

likedislike
JJett_Woo成员
7月7日 issue状态由 进行中 改变为 已完成
JJett_Woo成员
7月7日 关闭了 issue
CANN-robotCANN-robot成员
7月7日 添加了label:resolved