已关闭
[Bug-Report|缺陷反馈]: MaskedSoftmaxWithRelPosBias算子存在整型溢出问题 #3028
huang-wei-chen创建于  6月1日关闭于  6月3日
huang-wei-chen成员
6月1日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

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

HIGH R1: B-tiling stackNum 计算中 uint64_t 无符号减法回绕

文件: op_host/masked_softmax_with_rel_pos_bias_tiling.cpp:573

uint32_t stackNum = (aicoreParams_.ubSize
    - static_cast<uint32_t>(attenBiasAndTempSize - bf16AttenAndBiasCastTempSize))
    / (xYUbSize * 2 + static_cast<uint32_t>(bf16XCastTempSize) + softMaskMinTmpSize);

问题: attenBiasAndTempSize - bf16AttenAndBiasCastTempSize 在 uint64_t 下为负时回绕为极大值,然后 static_cast<uint32_t> 截断。
触发: 所有 FP16/BF16 B-tiling 路径均受影响。
后果: stackNum 垃圾值(被 std::min 部分掩盖但不可靠)。

HIGH R2: BWN 内核 GM 偏移 int64_t → uint32_t 截断

文件: op_kernel/masked_softmax_with_rel_pos_bias_BWN.h:52

uint32_t offsets1s2_ = offset * s1s2_; // offset 是 int64_t, s1s2_ 是 uint32_t

触发: bwns1s2 > 4.29B(接近 64GB 上限时可触发)。
后果: 读写错误的 GM 地址 → 数据损坏。
修复: offsets1s2_ 改为 int64_t。

HIGH R3-R4: totalSize / singleCoreSize 在 uint32_t 域计算后赋给 int64_t

文件: tiling.cpp:969-971 (S1Bias), tiling.cpp:1304 (BWNS1), tiling.cpp:1436 (ONES2)

int64_t totalSize = b_ * w_ * n_ * s1_;   // RHS 全 uint32_t,溢出后赋给 int64_t

触发: b_*w_*n_*s1_ > 4.29B(FP16 下 ≈ 8.6GB,可触发)。
后果: totalSize 截断为 0 或小值 → 所有核处理零元素。
修复: static_cast<int64_t>(b_) * w_ * n_ * s1_

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

910B/910_93

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

输入shape导致乘法链超过int32上限

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

不存在int32/uint32溢出风险

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

likedislike
Hhuang-wei-chen成员
6月1日 关联了pull request:修复MaskedSoftmaxWithRelPosBias整型溢出问题
oscillatedoscillated成员
6月1日 将 huang-wei-chen 设为负责人
CANN-robotCANN-robot成员
6月3日 关闭了 issue
CANN-robotCANN-robot成员
6月3日 添加了label:resolved