已关闭
[Bug-Report|缺陷反馈]: mhc_pre: GetAttrPointer 类型与 IR 原型 Float 不一致 #2673
dingxu创建于  5月26日关闭于  6月10日
dingxu
5月26日 创建

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

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

mhc/mhc_pre/op_host/op_tiling/arch35/mhc_pre_tiling.cpp 中,IR 定义 norm_epshc_eps 均为 Float 类型(对应 float,4字节),但 Tiling 代码使用 GetAttrPointer<double>(8字节)读取。类型不匹配可能导致内存越界读取或数据精度错误。

IR 定义mhc_pre_def.cpp 行 91-92):

this->Attr("norm_eps").AttrType(OPTIONAL).Float(1e-6f);
this->Attr("hc_eps").AttrType(OPTIONAL).Float(1e-6f);

代码片段mhc_pre_tiling.cpp 行 478-481):

auto normEpsPtr = attrs->GetAttrPointer<double>(1);   // IR Float → 应为 float
normEps_ = (normEpsPtr != nullptr) ? static_cast<float>(*normEpsPtr) : DEFAULT_NORM_EPS;
auto hcEpsPtr = attrs->GetAttrPointer<double>(2);     // IR Float → 应为 float
hcEps_ = (hcEpsPtr != nullptr) ? static_cast<float>(*hcEpsPtr) : DEFAULT_HC_EPS;

问题分析:IR 中 Float 类型在运行时存储为 float(4字节),GetAttrPointer<double>double(8字节)读取,会越界读取相邻属性的内存。虽然当前 static_cast<float> 后精度影响可能有限(float 提升到 double 再截断回 float),但越界读取本质上是内存安全缺陷。

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

  • 算子仓:ops-transformer
  • 算子名:MhcPre
  • 涉及文件:mhc/mhc_pre/op_host/op_tiling/arch35/mhc_pre_tiling.cppmhc/mhc_pre/op_host/mhc_pre_def.cpp
  • 涉及行号:478-481(tiling)、91-92(IR 定义)

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

构造 MhcPre 算子 Tiling 路径,传入非默认 norm_eps/hc_eps 属性值,观察 Tiling 层读取到的 eps 值与实际传入值是否一致。检查在属性存储紧凑排列时是否出现相邻属性数据污染。

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

GetAttrPointer<double> 改为 GetAttrPointer<float>,并移除多余的 static_cast<float>

// 修复后
auto normEpsPtr = attrs->GetAttrPointer<float>(1);
normEps_ = (normEpsPtr != nullptr) ? *normEpsPtr : DEFAULT_NORM_EPS;
auto hcEpsPtr = attrs->GetAttrPointer<float>(2);
hcEps_ = (hcEpsPtr != nullptr) ? *hcEpsPtr : DEFAULT_HC_EPS;

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

likedislike
huang-chuhong成员
5月26日 评论:

/assign @liweijian16

likedislike
CANN-robotCANN-robot成员
5月26日 将 liweijian16 设为负责人
CANN-robotCANN-robot成员
6月10日 关闭了 issue
CANN-robotCANN-robot成员
6月10日 添加了label:resolved