Closed
[Bug-Report|缺陷反馈]: A2 ScatterElementsV2 静态编译因 tiling const 丢失在 INFERCHANNEL 失败 #8028
Zhengyi ZhangAdd on  18 days agoClosed at  18 days ago
Zhengyi Zhang
Zhengyi ZhangCollaborators
18 days ago Create

问题描述

A2 上 ScatterElementsV2 在固定 shape 的静态 kernel 编译中失败,无法进入后续 aclgraph 执行验证。失败发生于 CompileStage.INFERCHANNEL,不是设备执行阶段。

GET_TILING_DATA 在静态编译时生成 static constexpr ScatterElementsV2TilingData tiling_data,算子入口和分派链却使用非 const 指针,导致隐式丢弃 const。常规动态 shape 编包不触发同一错误。

修复 MR:!13499。

环境信息

  • 硬件:Ascend 910B2(A2),aarch64。
  • 已复现工具链:CANN 9.2.0,GCC/G++ 11.4.0。
  • 源码基线:d914358457e25f7815dbff36ae279f1d533b5561;目标 kernel 在提交修复时的主干中仍包含同样的 const 丢失。
  • 本轮复核 Python:3.11.18。
  • 最初问题报告来自 CANN 9.3.0;本次验证没有安装或测试 9.3.0,因为 9.2.0 已能复现。

重现步骤

  1. 使用包含问题的 ScatterElementsV2 源码,source CANN 环境并选择匹配的 Python、GCC/G++。在 aarch64 测试机上还需让编译器找到 GCC 11 的 C++ 头文件:

    source <CANN安装目录>/set_env.sh
    export CC=gcc-11 CXX=g++-11
    export CPLUS_INCLUDE_PATH=/usr/include/c++/11:/usr/include/aarch64-linux-gnu/c++/11:/usr/include/c++/11/backward
    
  2. 单算子构建准备 build/tbe;保留未修复的 scatter_elements_v2.cpp:

    bash build.sh --pkg --soc=ascend910b --ops=scatter_elements_v2 -j16
    

    这一步生成动态 shape 包,本身不等于执行固定 shape 编译。

  3. 从 MR !13499 取出 index/scatter_elements_v2/tests/st/arch22/test_static_compile.py 测试脚本,对上述未修复的 build/tbe 执行:

    python /path/to/test_static_compile.py \
      --impl-root build/tbe --output-dir /tmp/scatter-static-repro \
      --soc Ascend910B2 --dtype float32 --indices-dtype int32 --axis 1 --reduction none
    

    脚本采用固定 shape [4,8],进入真实 CANN 静态编译,触发以下错误。

预期结果

算子在动态 shape 和固定 shape 编译中均能通过。只读 tiling 应在入口及分派函数中保持 const,不应要求可写指针。

日志与定位

Exception: An error occurred during compile phases of CompileStage.INFERCHANNEL
scatter_elements_v2.cpp:86:45: error: cannot initialize a variable of type
'ScatterElementsV2TilingData *__restrict' with an rvalue of type
'const ScatterElementsV2TilingData *'
    ScatterElementsV2TilingData* __restrict tilingDevice = &tiling_data;

引入历史经完整 Git 历史核对:

  • 8d0797ab8(2026-03-28,!2353)新增接收非 const tiling 的分派函数,形成更早的 const 传递隐患。
  • d4afa7499(2026-06-22,!6169)重构 scatter_reduce 分派并删除入口 const,当天被 0962a0f27(!6372)回退。
  • d382188b4(2026-06-25,!6460)重新引入入口 const 删除,是本次第 86 行错误持续存在的引入点。

CANN 9.1.0 的静态 tiling 生成器已经使用 constexpr,因此不能将此归因于 9.3.0 新增 const 规则。

修复与验证

MR !13499 将入口和四层分派函数的 tiling 参数统一改为 const 指针;底层 Init 已支持 const,不改变算法、tiling 布局或公开 ABI。

已验证:原源码静态编译失败、修复后通过;四组 dtype/index dtype 的固定 shape 编译通过;14 个动态 kernel 变体编译及单算子 run 包构建通过;FP32/none 的静态二进制普通执行一次及 aclgraph 回放三次均与 CPU 预期一致。

运行数值检查仅覆盖上述 FP32/none 场景;未执行 A3、310P、CANN 9.3.0 或全量数值/性能验收。详细条件和边界见关联 MR。

likedislike
Zhengyi ZhangZhengyi ZhangCollaborators
18 days ago Added label: bug-report
Zhengyi ZhangZhengyi ZhangCollaborators
18 days ago Associated pull request
yuning_chenyuning_chenCollaborators
18 days ago Assign zzy1205 as responsible person
CANN-robotCANN-robotCollaborators
18 days ago Close issue
CANN-robotCANN-robotCollaborators
18 days ago Added label: resolved