Closed
【问题】GetVRegSize在部分产品上接口获取失败返回0导致算子计算失败 #548
wuxueningAdd on 25 days agoClosed at 21 days ago
25 days ago Close issue
25 days ago Added label: resolved
ren-botao
21 days ago Comments:
21 days ago Comments:
/assign @wuxuening


21 days ago Assign wuxuening as responsible person
wuxuening
21 days ago Comments:
21 days ago Comments:
问题定位
- 接口位置:
include/op_common/op_host/util/platform_util.hhost 侧GetVRegSize(const T *context) - 引入来源:PR !1031 将该接口由硬编码
256U改为透传PlatformAscendC::GetVecRegLen()返回值 - 失败表现:部分产品上
GetVecRegLen()返回 0,GetVRegSize透传 0 → 下游 tiling 以 0 作除数(如elePerVreg = vRegSize / sizeof(T)、repeatTimes = CeilDiv(totalLen, oneRepeat))→ tiling 计算失败,算子执行报错 - 影响面:host 侧公共接口的全部下游调用方(ops-math/ops-nn/ops-cv/ops-transformer 各仓经 tiling 使用 vRegSize 的算子);kernel 侧
op_kernel/platform_util.h为编译期宏实现(__CCE_AICORE__ == 310/920取AscendC::VECTOR_REG_WIDTH,其余 256U),不受本问题影响
根因分析
GetVecRegLen()的取值来源是 tiling context 携带的平台信息(platform info)中的向量寄存器宽度属性,该属性按产品填充,并非全产品覆盖;- 平台信息未携带该属性的产品上,接口以 0 作为"不可用"的隐式返回值,无错误信号;
- PR !1031 假设返回值恒有效、未做判零防御,将"接口能力的产品差异"引入为"运行时除零"缺陷。
本质是接口契约缺陷(失败以 0 隐式表达)与调用侧无防御(无判零兜底)叠加所致。
处理方案(两阶段,均已合入 master)
阶段一:判零兜底(!1056,commit 2c92ec2)
GetVecRegLen() 返回 0 时回落默认值 256U(OP_LOGD 记录便于定位),接口可正常获取的产品行为不变。同步更新 GetVRegSize.md 返回值说明("平台信息或接口获取失败时默认返回256bytes")。
阶段二:按架构隔离取值(!1059,commit aed23b2,最终方案)
不再依赖 GetVecRegLen() 返回值,按 GetCurNpuArch() 架构直接取值:
auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr);
if (ascendcPlatform.GetCurNpuArch() == Ops::Base::DAV_5162) {
return 32U; // Ascend5162A:VL = 32B
}
return 256U; // 其余平台:256B
向量寄存器宽度本质上是按架构确定的静态属性,按架构取值从根上消除"接口返回 0"这一失败模式。
验证情况
- 双平台取值符合预期(950=256B、5162A=32B);
- 下游仓 5162A 编包验证通过(ops-cv resize 类算子
--soc=ascend5162a编译零 error,tiling 链路使用该接口); - 建议 issue 关闭前确认下游各仓(math/nn/cv/transformer)已同步至含 !1059 的 opbase 基线。


问题背景
PR !1031 将 host 侧
GetVRegSize由硬编码 256B 改为经PlatformAscendC::GetVecRegLen()接口动态获取后,部分产品上该接口获取不到向量寄存器宽度(返回 0),算子以 0 作除数(如elePerVreg = vRegSize / sizeof(T))导致 tiling 计算失败。问题内容
include/op_common/op_host/util/platform_util.h中GetVRegSize直接透传GetVecRegLen()返回值,部分产品上该接口返回 0,下游以 0 做除数导致算子计算失败。修复方案
对
GetVecRegLen()返回值增加判零兜底:返回 0 时回落默认值256U(OP_LOGD记录便于定位)。接口可正常获取的产品行为不变(950=256B、5162A=32B)。同步更新
GetVRegSize.md返回值说明。验收标准
GetVRegSize返回 256(不再返回 0),算子 tiling 正常;