Pull Request已成功合入, 合并人@CANN-robot
(感谢 raoliang_sac 的贡献)变更摘要
本 PR 包含两部分改动:一是将 TensorRedirect 算子的 InferDataType 从 op_host 迁移至 op_graph 目录并对齐交付件规范(新增防重定义宏),同时修复 Tiling 层对负维与 shape 乘积溢出的防御缺失以及 PrecisionReduceFlag 与 bit-exact 语义冲突的问题;二是删除 AddV2 算子中 4 组不可达的混合 dtype 组合(FP16+FP32、FP32+FP16、BF16+FP32、FP32+BF16)及其关联的类型提升表、AddMixDtypeCompute 模板和混合精度 binary,使实现与 canonical AddV2 的「x1/x2 同 dtype」契约一致。同步更新了相关文档与 golden 测试脚本。
主要改动
-
TensorRedirect InferDataType 按规范迁移至
op_graph:在conversion/tensor_redirect/op_graph/tensor_redirect_graph_infer.cpp中新增InferDataType4TensorRedirect,透传SetOutputDataType返回值;op_host/tensor_redirect_infershape.cpp中移除原有的InferDataType注册,仅保留InferShape。 -
TensorRedirect 原型增加防重定义宏:在
op_graph/tensor_redirect_proto.h中为REG_OP(TensorRedirect)包裹#ifndef OPS_PROTO_DEF_TENSORREDIRECT/#define/#endif守卫,与 canndev legacy 侧同名宏配对以防止链接期重定义错误。 -
TensorRedirect Tiling 增加负维与溢出拦截、修正精度策略:
tensor_redirect_tiling_arch35.cpp中新增逐维非负校验及GetShapeSize()溢出哨兵kInvalidDimValue拦截(置于numel == 0之前);tensor_redirect_def.cpp中将PrecisionReduceFlag从true改为false,避免混合精度编译选项将 FP32 节点降为 FP16 而破坏恒等拷贝的 bit-exact 语义。 -
AddV2 删除不可达的 4 组混合 dtype 组合:
add_v2_def.cpp中 DataType 列表从 13 组收缩为 9 组同 dtype;add_v2_binary.json删除 4 个混合 binary;add_v2_graph_infer.cpp删除 34×34 类型提升表,InferDataType改为 y 与 x1 同 dtype 并显式拒绝异类型输入;add_v2_tiling_arch35.cpp将IsMixedDtype替换为CheckDtype前置校验;add_v2.cpp与add_v2_dag.h删除isMixDtype分支和AddMixDtypeCompute模板。 -
文档与 golden 脚本同步更新:
math/add_v2/README.md删除混合精度组合表并补充 x1/x2 同 dtype 约束;tests/assets/golden.py删除已不注册的 bool logical_or 分支,对异类型输入直接抛ValueError。


Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| */*/README.md | ✅ 陈娇, 汤平川 (2/2) | ✅ 陈娇 (1/1) |
| */*/op_graph/*_proto.h | ✅ 王永光, 汤平川 (2/2) | ✅ 王永光 (1/1) |
| */*/op_host/*_def.cpp | ✅ 王永光, 汤平川 (2/2) | ✅ 王永光 (1/1) |
| repo-cann/ops-math | ✅ 汤平川, 宋恺 (2/2) | ✅ 汤平川, 宋恺 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
raoliang_sac, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


流水线任务触发成功
任务链接 [861ef9718e534fb5b81286c48b073020][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test | ✅ SUCCESS | ||
| UT_Test_experimental | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-math | ✅ SUCCESS | ||
| UT_Test_harmony-infer-cpro-math | ✅ SUCCESS |
[2026-08-10 10:21:35] CI执行结束


流水线任务触发成功
任务链接 [2679221ba2b94ff8967de78419d55549][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-08-10 10:07:11] CI执行结束


/approve


/lgtm
/approve


/approve


描述
本 PR 包含三部分改动,均针对
conversion/tensor_redirect与math/add_v2两个新增算子。一、TensorRedirect 对齐 issue #4553 的两条交付件规范
issue 提出两条要求,TensorRedirect 两条都不满足:
InferDataType 须交付在
op_graph目录(仅图场景使用);InferShape 图与算子双用,保留在op_host。InferDataType4TensorRedirect和 InferShape 一起注册在op_host/tensor_redirect_infershape.cpp。op_graph/tensor_redirect_graph_infer.cpp承载 InferDataType,op_host只保留IMPL_OP_INFERSHAPE(TensorRedirect).InferShape(...)。SetOutputDataType返回值无条件返回 SUCCESS,现改为透传。原型从 legacy 挪出后须补防重定义宏。
ops/built-in/op_proto/inc/ops_proto_legacy.h:13857确实存在REG_OP(TensorRedirect),且已用OPS_PROTO_DEF_TENSORREDIRECT包裹;本仓op_graph/tensor_redirect_proto.h无守卫。error: redefinition of 'class ge::op::TensorRedirect',加守卫后编译通过。OPS_PROTO_DEF_TENSORREDIRECT,与 legacy 侧配对。两个算子的
REG_OP均未改动,与 canndev 保持逐字符一致(忽略空白后比对:AddV2 vselewise_calculation_ops.h:1390;TensorRedirect vselewise_calculation_ops.h:3779及ops_proto_legacy.h:13857)。二、代码检视报告问题修复
DoTiling产生usedCoreNum == 0/SetBlockDim(0)< 0;GetShapeSize()后拦截溢出哨兵kInvalidDimValue,且置于numel == 0判断之前PrecisionReduceFlag(true)与 bit-exact 语义冲突:allow_mix_precision下允许把 FP32 节点降为 FP16,破坏 README 声明的逐 bit 相等(含负零 / NaN payload / 非规格化数)PrecisionReduceFlag(false)docs/zh/op_list.md删除 add_v2 已不存在的 bool logical_or 声明;README 删除混合精度组合表关于 AddV2 的 4 个混合 dtype 组合(FP16+FP32、FP32+FP16、BF16+FP32、FP32+BF16):
canonical AddV2 契约要求 x1/x2 同 dtype —— canndev
ops/built-in/op_proto/elewise_calculation_ops.cc:475的AddV2Verify调用CheckTwoInputDtypeSame,原型注释也写明x2: A tensor of the same dtype as "x1"。既然本仓REG_OP与 canndev 保持一致,OpDef 里注册异类型组合就与自身原型契约矛盾。已实测复现:
FP16+FP32离线构图被 Verifier 拒绝(The AddV2_0 op dtype is not same, type1:DT_FLOAT16, type2:DT_FLOAT),FP16+FP16对照组构图成功。本算子无 ACLNN,因此这 4 个已编译 binary 对公开调用方实际不可达。删除范围(
REG_OP不动):add_v2_def.cpp:x1/x2/y 的 DataType 列表 13 → 9 组同 dtype,ADD_V2_FORMAT_LIST同步收缩add_v2_binary.json:删除 4 个混合 binary,13 → 9add_v2_graph_infer.cpp:删除 34×34 类型提升表,InferDataType 改为 y 与 x1 同 dtype,并显式拒绝异类型输入add_v2_tiling_arch35.cpp:IsMixedDtype与 4 个混合分支改为CheckDtype前置校验add_v2.cpp/add_v2_dag.h:删除isMixDtype分支与AddMixDtypeCompute模板tests/assets/golden.py:删除已不注册的 bool logical_or 死分支;对异类型输入直接抛错,避免静默按x1.dtype生成错误标杆三、AddV2 支持空 Tensor
上板回归时补的空张量用例暴露出一个既有能力缺口:AddV2 对
numel == 0的输入一律OPTILING_FAILURE,9 种 dtype × 4 种空场景 36/36 全挂。根因是 ATVOSS 的BroadcastBaseTiling在合轴之后显式拒绝 0 元素(broadcast_tiling.h的"tensor check is empty, check failed"),空 Tensor 根本落不到DoTiling。按
math/select的既有惯例另开一条自定义模板分支承接:add_v2_struct_arch35.h:新增userDef模板键(0 常规 / 1 空 Tensor),空分支复用BRC_TEMP_SCH_CUSTOM_MODE_KEY_SEL的schMode 999;并补AddV2EmptyTilingData—— opc 靠 kernel 里的GET_TILING_DATA_WITH_STRUCT反推每个模板实例的 tiling 结构体大小,自定义分支不引用任何结构体会导致编译期tiling_struct_size未定义。add_v2.cpp:kernel 增加userDef模板参数,userDef == 1时直接返回。add_v2_tiling_arch35.cpp:抽出SetWorkspace(),新增HandleEmptyTensor();按输出 y 的元素数判空,blockDim = 1、tilingKey 走自定义分支。判空之前先拦截GetShapeSize()的溢出哨兵(负值),否则负的 numel 会被当成非空穿透到DoTiling。userDef = 0,编码后取值不变(仍为 8),原有 UT 的expectTilingKey无需调整。关联的Issue
测试
单元测试
./build.sh -u --ophost --soc=ascend950 --ops=add_v2:22/22 通过(10 条 tiling,含新增 4 条空 Tensor;12 条 infershape)。上板回归(Ascend950PR,TTK kernel 模式)
全部以
--binary-only(-d=false -b=release)+--pc=1串行执行,只采信BIN_*列(bin_compile_s = BINARY_MATCH才算真正匹配到部署的.o,而非 JIT 现编兜底)。其中 36 条空 Tensor 用例全部
BINARY_MATCH+ 100%,tiling_key = 65550 (0x1000e)、block_dim = 1,确认走的是新增的自定义分支(改动前为 36/36INVALID_TILING)。负向对照
add_v2_removed_mixed_dtype.csv12 条(已删除的 4 组混合 dtype)如期 全部BINARY_MATCH_FAILURE。历史交付件里这 4 组是BINARY_MATCH+ 100% PASS —— 前后翻转,可作为"部署的确实是本 PR 代码"的直接证据。编译
./build.sh --pkg --soc=ascend950 --ops=add_v2,tensor_redirect:AddV2 产出 9 个 binary(原 13),TensorRedirect 4 个,无残留混合 dtype binary。REG_OP(TensorRedirect)的 TU,加守卫前编译失败、加守卫后通过。需要评审者注意的测试局限(如实说明)
GRAPH_FAILED(并非因为走到了新增的显式校验)。这些用例锁定了契约,但不能证明新增守卫本身生效;真实 GE 通路的行为需由 GEIR 测试覆盖。GRAPH_FAILED"这条也因此未被测到。conversion/tensor_redirect源码相对该版本零改动,且重新编译产出的 4 个 binary 配置 json 与已部署版本逐字段一致(仅豁免随构建变化的sha256;.o本身构建不可复现,MD5 不具可比性)。文档更新
math/add_v2/README.md:删除混合精度组合表;x2/y 描述改为"与 x1 一致";约束说明补充"输入 x1 和 x2 的数据类型需相同"docs/zh/op_list.md:删除 add_v2 条目中已不存在的"bool 输入按 logical_or 处理";描述补充"支持空Tensor"math/add_v2/README.md:约束说明补充"支持空Tensor。当输出y的元素个数为0时,算子不下发有效计算,直接返回成功。"类型标签