Closed
[Bug-Report|缺陷反馈]: ForeachAddList算子经Agent扫描发现多个问题 #8883
m0_46386992Add on  5 days agoClosed at  5 days ago
m0_46386992
m0_46386992Collaborators
5 days ago Create

[ForeachAddList] Ascend950 的 FP16+FP32 alpha 不支持、950 资料口径不一致,且 arch35 tiling 存在 int64 溢出边界

Describe the current behavior / 问题描述 (Mandatory / 必填)

在 Ascend950PR/950DT(arch35)上发现 ForeachAddList 存在以下问题(对应 PR d9c3e90efcebf38c3c1187bd72ab5f34eb4fdcb8 的修复项):

  1. FP16 x1 + FLOAT32 alpha 的 V2 调用被错误拒绝

    • aclnnForeachAddListV2 文档的 950 小节声明:x1 为 FLOAT16 时,scalar 支持 FLOAT16、FLOAT32、DOUBLE。
    • 实际实现中 FLOAT16 的 scalar 白名单仅 {FLOAT16, DOUBLE},FLOAT32 scalar 在 GetWorkspaceSize 第一段即返回 ACLNN_ERR_PARAM_INVALID (161002),文档承诺的合法用法不可用。
  2. FP16 x1 + DOUBLE alpha 的精度损失

    • V2 路径把 DOUBLE scalar 先 ConvertToTensor 成 x1 的 dtype(FLOAT16),进入 kernel 前多了一次 half 中间舍入。
    • 例:x1=0、x2=3(FP16)、alpha=2049.0(可被 FLOAT32 精确表示,不能被 FP16 精确表示),公式精确结果 6147,正确半精度舍入应为 6148;现实现得到 6144(alpha 被先舍入为 2048)。
  3. 950 文档与实际能力不一致

    • 文档 950 小节声明 x1/x2/y 最大 Tensor 个数为 50,实际 arch35 tiling 上限为 256(51~256 个成员可正常执行)。
    • 950 小节的 alpha 映射只写了 INT32,遗漏了实际支持的 INT16/INT8/UINT8(这些 dtype 的 alpha 映射应为 INT32/INT64)。
  4. 共享 arch35 flat tiling 存在 int64 溢出风险

    • foreach_utils/op_host/foreach_flat_regbase_tiling.h 的 Build() 对列表元素总数累加、以及每核分块的 blockCount * elementsPerBlock 对齐乘法没有溢出保护。
    • 当列表元素总数接近 INT64_MAX(如两个 [2^62] 张量的元数据即可到达 tiling,无需物化数据)时,会发生有符号整数溢出(UB),tensorStart/End 等字段可能得到回绕后的错误值并被 kernel 消费。

Environment Information / 环境信息 (Mandatory / 必填)

  • 硬件:Ascend950PR(arch35),8 卡环境
  • CANN:9.3.0
  • 算子仓:ops-nn,分支基线为 d9c3e90efcebf38c3c1187bd72ab5f34eb4fdcb8 之前
  • 调用路径:ACLNN 直调(aclnnForeachAddList / aclnnForeachAddListV2),以及 kernel/tiling 直调
  • 发现来源:validation-runs/ForeachAddList-20261022,对应发现 CODE.10/1、DOC.03/2、CODE.01/3、CODE.06/2

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

复现 1:FP16 x1 + FLOAT32 scalar 被拒绝

import torch
import torch_npu

x1 = [torch.zeros(1, dtype=torch.float16).npu()]
x2 = [torch.full((1,), 3.0, dtype=torch.float16).npu()]

# 走 aclnnForeachAddListV2,alpha 为 FLOAT32 标量
out = torch._foreach_add(x1, x2, alpha=2.0)

现象:aclnnForeachAddListV2GetWorkspaceSize 返回 161002,日志提示 scalar 的 dtype 不在支持范围。

复现 2:DOUBLE alpha 精度损失

x1 = [torch.zeros(1, dtype=torch.float16).npu()]
x2 = [torch.full((1,), 3.0, dtype=torch.float16).npu()]
out = torch._foreach_add(x1, x2, alpha=2049.0)  # DOUBLE scalar
# 期望 out == 6148(6147 的正确 half 舍入)
# 实际 out == 6144(alpha 先被舍入为 half 2048)

复现 3:950 最大 Tensor 个数文档与实现不一致

  • 按 docs/aclnnForeachAddListV2.md 的 950 小节,成员数应不超过 50;
  • 实际构造 51~256 个成员的 TensorList 可正常执行,仅 >256 被 tiling 拒绝。

复现 4:tiling 溢出边界(无需上板分配大张量)

  • 构造两个形状为 [2^62] 的输入张量元数据,使元素总数累加超过 INT64_MAX;
  • 或用 coreCount=1、totalElements=INT64_MAX-1、elementsPerBlock=1024 复算分块逻辑,可观察到:
runtime error: signed integer overflow: 9007199254740992 * 1024 cannot be represented in type 'long int'

Describe the expected behavior / 预期结果 (Mandatory / 必填)

  1. Ascend950PR/950DT 上 aclnnForeachAddListV2 的 FLOAT16 x1 应支持 FLOAT16、FLOAT32、DOUBLE scalar:
    • FLOAT32/DOUBLE 应在进入 kernel 前转换为 FLOAT,按 FP32 alpha 参与计算,不应先降为 FP16;
    • x1=0、x2=3、alpha=2049.0 应得到 6148。
  2. 950 的 OpDef 注册、V2 dtype 校验、arch35 tiling 和 binary 配置应保持一致,F16 x1 同时支持 F16/F32 alpha。
  3. 950 文档的最大 Tensor 个数应为 256,且 alpha 映射覆盖 INT32/INT16/INT8/UINT8(对应 INT32/INT64)。
  4. tiling 对元素总数溢出应返回受控错误(GRAPH_FAILED),分块对齐乘法不得产生有符号溢出;常规输入的分核结果保持不变。
  • FLOAT32 scalar 被拒:
aclnnForeachAddListV2 execute failed:
ACLNN_ERR_PARAM_INVALID (161002)
Check result != nullptr failed.
  • 仅更新 V2 API、但未同步 def/binary 时,op 选择阶段报错(说明 def、binary、tiling 必须一起修改):
Failed to execute operator aclnnForeachAddListV2_0_ForeachAddListV2.
Reason: The dtype or format of the actual input or output parameter of the operator
is inconsistent with that defined in the operator prototype OpDef.
Cannot find binary for op ForeachAddList.
  • 溢出边界(UBSan 复算):
runtime error: signed integer overflow: 9007199254740992 * 1024 cannot be represented in type 'long int'
likedislike
m0_46386992m0_46386992Collaborators
5 days ago Added label: bug-report
m0_46386992m0_46386992Collaborators
5 days ago Modify description of issue
yuning_chen
yuning_chenCollaborators
5 days ago Comments:

感谢反馈,问题已收到。我们会按「资料声明与实现一致性」的方向排查:确认是资料需要收敛,还是实现需要补齐校验;定位后在本 issue 回贴结论与修复 PR。

本条要点: [ForeachAddList] Ascend950 的 FP16+FP32 alpha 不支持、950 资料口径不一致,且 arch35 tiling 存在 int64 溢出边界

likedislike
CANN-robotCANN-robotCollaborators
5 days ago Close issue
CANN-robotCANN-robotCollaborators
5 days ago changed custom state from 待办的 to 已完成
CANN-robotCANN-robotCollaborators
5 days ago Added label: resolved