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

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

在 ascend950(arch35)上,ForeachAtan 的 Tiling 入口 ForeachAtanTilingFunc
只读取输入列表第 0 个 Tensor 的 dtype 和各输入 shape,未实现文档声明的入参校验,
同时示例代码存在资源泄漏、文档错误码口径与实现/同族算子不一致。具体表现为:

  1. 列表内 Tensor dtype 不一致不拒绝:仅用第 0 个 Tensor 的 dtype 作为 tiling key,
    其余 Tensor 的 dtype 不校验。混合 dtype 列表会按首张量位宽解释全部数据,
    首张量为 4 字节、后续为 2 字节类型时存在越界读写风险。
  2. 完全不读取输出(out)信息:不校验 out 的 Tensor 数量、dtype、shape size,
    out 数量少于 x、out dtype 与 x 不一致、out shape size 小于/大于 x 时不会拒绝,
    kernel 按输入元素数写入,存在越界写风险。
  3. 输入/输出维度 > 8 不拒绝:文档声明维度 0–8,arch35 Tiling 无 GetDimNum() 校验。
  4. Tensor 数量 > 256 的拒绝不完整/元素累计溢出无保护:totalElements += numel
    无溢出检查,也未拒绝 gert::Shape::GetShapeSize() 在维度乘积溢出时返回的 INT64_MIN 哨兵值。
  5. 文档错误码口径与实现不符:文档把“列表内 dtype 不一致”“shape 约束”归到
    561002(ACLNN_ERR_INNER_TILING_ERROR),而同族算子(foreach_abs/exp/sin/acos)
    与 aclnn 实现均为 161002(ACLNN_ERR_PARAM_INVALID),且缺少“Tensor 数量 > 256 → 561002”一行。
  6. 示例代码资源泄漏:CreateAclTensor 中 aclrtMemcpy 失败未释放已申请的 device 内存;
    main 失败路径直接 return,不释放 device 内存/tensorList/stream,不 aclResetDevice/aclFinalize。
  7. ST executor 存在未使用导入与格式问题(executor_aclnnForeachAtan.py)。

另外 README.md 仍写“输出不支持非连续Tensor”,但实现(foreach_contiguous_helper.h
的 ForeachMakeContiguousTensorList + ForeachViewCopyToOutputTensorList)与
docs/aclnnForeachAtan.md 均已支持非连续 out,文档自相矛盾。

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

  • 产品/芯片:Ascend950PR(arch35)
  • CANN:/data/whb/1104Ascend/cann-9.3.0(9.3.0 weekly 20261104)
  • 测试框架:TTK(ops-test-kit)
  • 仓库:ops-nn,算子目录 foreach/foreach_atan
  • 关联 commit:d9c3e90efcebf38c3c1187bd72ab5f34eb4fdcb8
  • 验证设备:device 6

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

以下非法输入在修复前不会被 arch35 Tiling 拒绝(需通过 kernel/GEIR 直调路径,绕过 aclnn 适配层):

  1. 列表内 dtype 混用:x = [float32(4), float16(4)]
  2. out dtype 与 x 不一致:x=float32(4),out=float16(4)
  3. out shape size 小于/大于 x:x=(8,)、out=(4,),或 x=(4,)、out=(8,)
  4. 列表内 Tensor 数量 > 256:257 个 (1,) 张量
  5. 单个 Tensor 维度 > 8:x=(1,1,1,1,1,1,1,1,2)

以 TTK 为例(修复前会进入 kernel,或在 aclnn 层返回与文档不一致的错误码):

source /data/whb/1104Ascend/cann-9.3.0/bin/setenv.bash
cd /data/w00842359/ops-test-kit

# kernel 直调路径:列表 dtype 混用 / out dtype / out shape / 257 个 Tensor
python3 -m ttk kernel -i <foreach_atan_min_l2.csv> \
  --plugin <golden.py> --run 1 --seed 42 --devices 6 \
  --task-prof false --compare mixed -o <result.csv>

样例 CSV 关键行:

kr_rej_mixed_x,   input_dtypes=(('float32','float16'),)
kr_rej_out_dtype, input_dtypes=(('float32',),)  output_dtypes=(('float16',),)
kr_rej_out_smaller, input_shapes=(((8,),),)     output_shapes=(((4,),),)
kr_rej_out_larger,  input_shapes=(((4,),),)     output_shapes=(((8,),),)
kr_rej_count257,  257 个 (1,) 张量
kr_rej_rank9,     input_shapes=(((1,1,1,1,1,1,1,1,2),),)

示例程序资源泄漏可用 test_aclnn_foreach_atan.cpp 人为触发 aclrtMemcpy 失败/中途返回复现。

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

  1. arch35 Tiling 入口应对非法输入明确拒绝(ge::GRAPH_FAILED),不进入 kernel:
    • 列表内 dtype 不一致、dtype 不支持;
    • out Tensor 数量与 x 不一致、out dtype 与 x 不一致;
    • x/out 维度超过 8;
    • 单个 TensorList 的 Tensor 数量超过 256;
    • 元素数非负且累计不溢出。
  2. out 与 x 对应位置 Tensor 的 shape size 必须相等(与文档、生成 aclnn 层一致)。
  3. 文档第一段接口错误码与实现/同族算子一致:
    • dtype/数量/shape/rank/format/空 Tensor → 161002;
    • 单个 TensorList 的 Tensor 数量 > 256 → 561002。
  4. README 对 out 非连续的描述与实现一致(支持非连续 out)。
  5. 示例程序在任意失败路径释放已申请资源,无 device 内存/stream 泄漏。
  6. 合法输入(fp32/fp16/bf16、空 Tensor、rank0、列表长度 1/2/3/256、各分核桶)行为不变。

修复后 kernel 直调路径的拒绝日志(INVALID_TILING):

[ERROR] OP(...)[foreach_atan_tiling.cpp:67][OPS_NN][ValidateForeachAtan] OpName:[] Parameter x of  has invalid tensor num 257. It should be within the range [0, 256].
[ERROR] OP(...)[foreach_atan_tiling.cpp:96][OPS_NN][ValidateForeachAtan] OpName:[] Parameter x of  has incorrect dtype DT_FLOAT16. Reason: The dtypes of all tensors in the tensor list must be the same. Currently, the dtype of the 1th tensor is inconsistent with that (DT_FLOAT) of other tensors
[ERROR] OP(...)[foreach_atan_tiling.cpp:131][OPS_NN][ValidateForeachAtan] OpName:[] Parameter out of  has incorrect dtype DT_FLOAT16. Reason: The dtype of out must be the same as x.
[ERROR] OP(...)[foreach_atan_tiling.cpp:145][OPS_NN][ValidateForeachAtan] OpName:[] Parameters x and out of  have incorrect shape sizes 8 and 4. Reason: The shape size of the 0th tensor in tensor list out must be equal to that of the tensor in the same position of the tensor list x

修复后回归结果(ascend950 / device 6):

路径 结果
kernel 合法集(fp32/fp16/bf16 × B0–B6 + rank + 列表长度 + 值域) 41/41 PASS
kernel BIN(-b=release) 41/41 PASS
kernel 拒绝集 5 条 INVALID_TILING 命中新校验;rank9 框架拦截;out 数量工具无法表达
aclnn 9 PASS(含 bf16×7),拒绝项错误码符合文档
GEIR 静态 / 动态 / 动静态混合 各 41/41 PASS
torchapi eager 41/41 PASS
torchair 静态 / aclgraph 各 41/41 PASS(动态被 torchair/sympy 环境问题阻塞,非算子问题)

Special notes for this issue/备注 (Optional / 选填)

likedislike
m0_46386992m0_46386992Collaborators
5 days ago Added label: bug-report
yuning_chen
yuning_chenCollaborators
5 days ago Comments:

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

本条要点: Describe the current behavior / 问题描述 (Mandatory / 必填)

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