Closed
[Bug-Report|缺陷反馈]: Xlog1py 算子缺少 dtype/rank/广播校验、ascend950 binary 配置 bin_filename 错误,存在越界写与结果错误风险 #4565
renshuojianAdd on  5 days agoClosed at  4 days ago
renshuojian
renshuojian
5 days ago Create

一、问题描述 (必填)

算子:Xlog1py(math/xlog1py,arch35 / ascend950)
问题概述:算子在 tiling、InferShape/InferDataType 三个环节缺失必要的入参校验,同时 ascend950 的 binary 配置与 kernel 产物命名不匹配,并存在 fp32 路径输出尾部未初始化的问题。具体如下:

  1. tiling 阶段缺少 rank 上限校验(高危)
    Xlog1pyTiling::RunTiling() 中按 rank_ <= 4 ? 4 : 8 选择 DoTilingAndSet<4> / DoTilingAndSet<8>,但未限制 rank 上限。当输入 rank > 8 时,delta = R - rank_ 为负,tiling->max_bro_shape[d + delta]、tiling->input_shapes[i][d + delta] 等写入下标为负或越界,直接踩踏 tiling data(UB 内存),可导致 tiling 阶段崩溃或下游结果异常。

  2. dtype 校验缺失

    • InferDataTypeForXlog1py 仅把 input[0] 的 dtype 原样透传给输出,未校验 dtype 是否属于 {DT_FLOAT, DT_FLOAT16, DT_BF16},也未校验 x、y、z 之间 dtype 是否一致。
    • tiling 的 GetShapeInfo() 仅读取 input[0] 的 dtype 决定 dtype_size_ / phys_nodes_,未校验 input[1] 与输出 dtype。
    • 失败模式:x 为 FLOAT32、y 为 FLOAT16 时,y 会被按 4 字节宽度读取(或反之),得到错误计算结果且不报错;输出 z dtype 与输入不一致时同样静默出错。
  3. 广播兼容性未校验
    PadAndSqueeze() 对每个维度直接取 max,非广播兼容的 shape(如 [2,3] 与 [2,4])不会报错,会按错误的 max 形状继续执行,产生错误结果。

  4. FLOAT32 kernel 输出缓冲区未初始化
    ProcessFP32() 在调用 CallXlog1pyVF 前未初始化输出 UB(B_Z)。当 count 不是 VL 整数倍时,尾部的 lane 残留上一次迭代的脏数据,存在计算结果不确定 / 精度不达标的风险。

  5. ascend950 binary 配置 bin_filename 错误
    op_host/config/ascend950/xlog1py_binary.json 中 float16/float32/bfloat16 三条配置的 bin_filename 使用了语义化名称(Xlog1py_FLOAT16 / Xlog1py_FLOAT32 / Xlog1py_BF16),未使用 kernel 编译产物的哈希命名(如 Xlog1py_c602838c14701b23ff1861c82ff8afc9),导致 ascend950 上 kernel bin 匹配/加载失败。

  6. 文档维度说明错误
    docs/aclnnXlog1py.md / aclnnXlog1py_en.md 中输出 z 的维度写为 1-8,与实现及约束说明(0 维标量/空 Tensor 场景支持 0-8 维)不一致。

二、环境信息 (可选)

950

三、重现步骤 (可选)

  1. 编译并安装含 Xlog1py 的 ops-math 算子包,在 ascend950 上通过 aclnn 接口 aclnnXlog1py 调用。
  2. 分别构造以下用例:
    • rank 超限:x、y shape 均为 [1,2,3,4,5,6,7,8,9];
    • dtype 不一致:x 为 FLOAT32、y 为 FLOAT16;
    • 输出 dtype 不一致:x、y 为 FLOAT32,输出 z 为 FLOAT16;
    • 非广播兼容:x 为 [2,3]、y 为 [2,4];
    • FLOAT32 尾块:元素个数不是 VL(向量长度/4)整数倍,例如 [1,1,1000];
    • ascend950 上直接加载算子包调用。
  3. 观察报错、精度对比结果及 kernel 加载日志。

四、预期结果 (可选)

  • rank > 8 时,tiling/InferShape 返回 GRAPH_FAILED,aclnn 返回 ACLNN_ERR_PARAM_INVALID(161002),不得发生越界写。
  • dtype 不属于 {FLOAT, FLOAT16, BF16} 或 x/y/z dtype 不一致时,应在 tiling/InferDataType 阶段明确报错。
  • 非广播兼容 shape 应返回参数错误,而不是静默按 max 形状执行。
  • 所有合法 shape(含 0 维标量、空 Tensor、rank 5~8)应输出正确结果,与 golden 精度一致。
  • ascend950 上 kernel bin 能正确匹配加载,功能与精度正常。
  • 文档中 z 的维度说明应与实现一致(0-8)。

💡 备注(选填)

likedislike
陈思陈思Collaborators
5 days ago Assign rsj007 as responsible person
CANN-robotCANN-robotCollaborators
4 days ago Close issue
CANN-robotCANN-robotCollaborators
4 days ago Added label: resolved