Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
mhc/mhc_pre/op_host/op_tiling/arch35/mhc_pre_tiling.cpp 中,IR 定义 norm_eps 和 hc_eps 均为 Float 类型(对应 float,4字节),但 Tiling 代码使用 GetAttrPointer<double>(8字节)读取。类型不匹配可能导致内存越界读取或数据精度错误。
mhc/mhc_pre/op_host/op_tiling/arch35/mhc_pre_tiling.cpp
norm_eps
hc_eps
Float
float
GetAttrPointer<double>
IR 定义(mhc_pre_def.cpp 行 91-92):
mhc_pre_def.cpp
this->Attr("norm_eps").AttrType(OPTIONAL).Float(1e-6f); this->Attr("hc_eps").AttrType(OPTIONAL).Float(1e-6f);
代码片段(mhc_pre_tiling.cpp 行 478-481):
mhc_pre_tiling.cpp
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),但越界读取本质上是内存安全缺陷。
double
static_cast<float>
mhc/mhc_pre/op_host/mhc_pre_def.cpp
构造 MhcPre 算子 Tiling 路径,传入非默认 norm_eps/hc_eps 属性值,观察 Tiling 层读取到的 eps 值与实际传入值是否一致。检查在属性存储紧凑排列时是否出现相邻属性数据污染。
将 GetAttrPointer<double> 改为 GetAttrPointer<float>,并移除多余的 static_cast<float>:
GetAttrPointer<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;
无
/assign @liweijian16
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_eps和hc_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 / 必填)
mhc/mhc_pre/op_host/op_tiling/arch35/mhc_pre_tiling.cpp、mhc/mhc_pre/op_host/mhc_pre_def.cppSteps 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;Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
无
Special notes for this issue/备注 (Optional / 选填)