Merged
feat(pypto_pro): Upload for vf api - merge mask and reg api #4946
liuyu205Add on Jul 18
feat(pypto_pro): Upload for vf api - merge mask and reg api #4946
Merged
liuyu205Add on Jul 18
liuyu205
liuyu205
Jul 18

upload for vf api - merge mask and reg api

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for liuyu205's contribution.)
liuyu205liuyu205
Jul 18 Created pull request, commit 356c4571
atomgit-bot
atomgit-bot
Jul 18 Comments:

变更摘要

此 PR 将 VF API 中独立的 MaskReg 操作(如 vf.mask_and、vf.mask_load 等)统一合并到对应的通用操作中(如 vf.and_、vf.load_align 等),通过检测目标/源寄存器的类型(MaskReg 或 RegTensor)在代码生成阶段自动分派到 p* 或 v* CCE 指令。这模仿了 AscendC 的函数重载模型,消除了冗余的 IR 操作定义、后端发射函数及 Python API 声明。

主要改动

  • 移除独立 Mask 操作的 IR 注册与后端发射函数:删除了 vf_ops.cpp 中 13 个 vf.mask_* IR 操作注册,以及在 backend_cce_vf_ops.cpp 中对应的 EmitVFMask* 函数和 REGISTER_BACKEND_OP 绑定,新增辅助函数 IsDstMaskReg 用于在统一发射函数中判断目标寄存器类型。

  • 增强统一操作的 MaskReg 分派逻辑:在 EmitVFLoadAlign、EmitVFStoreAlign、EmitVFStoreUnAlign、EmitVFAnd、EmitVFBinaryBitwise、EmitVFNot、EmitVFInterleave、EmitVFPack、EmitVFUnpack、EmitVFDeInterleave、EmitVFSelect、EmitVFMove 等函数中,添加 IsDstMaskReg 判断分支,当目标为 MaskReg 时发射 p*(pand/por/pxor/pnot/psel/ppack/punpack/pintlv/pdintlv/plds/psts/pstu 等)指令。

  • Python 解析器适配统一操作:在 _call_parser.py 中新增 _VF_UNIFIED_OPS(支持 RegTensor/MaskReg 双类型目标的操作集合)和 _VF_MASK_PRODUCING_OPS(产出 MaskReg 的操作集合);在 _assignment_parser.py 中通过检测源操作数是否为 MaskReg 变量来推断目标的寄存器类型;在 _scope_manager.py 中新增 mask_reg_vars 集合及 register_mask_reg_var/is_mask_reg_var 方法以追踪 MaskReg 变量。

  • 清理枚举类型与 Python 绑定:从 op_attr_types.h 中删除 MaskLoadDist 和 MaskStoreDist 枚举定义,从 ir.cpp 中删除对应的 pybind11 绑定,从 Python 的 ir/__init__.py 和 language/__init__.py 中移除相关导出,统一使用已有的 LoadDist 和 StoreDist 枚举。

  • 附带修复 EmitVFArange 的 DECREASE_ORDER 支持:通过 vci + vneg + vadds 组合生成递减序列;同时修复了 FP32 交错存储(INTLV)场景下 vsts 的类型转换问题,将 RegTensor<fp32> 强制转为 RegTensor<uint32_t> 以匹配可用的指令重载。

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Jul 18 Comments:

代码审查

审查总结

本次审查覆盖了全部 12 个变更文件,发现 7 个问题,按优先级分布如下:

优先级 数量 说明
P0 1 arange DECREASE_ORDER 测试未更新,期望的 DEC_ORDER 子串已不再生成,测试必定失败并阻断 CI
P1 1 EmitVFStoreUnAlign 的 MaskReg 路径中 pstu 三个参数顺序错误(ureg 与 ub_ptr 颠倒),导致生成错误的 CCE 代码
P2 2 统一后的 store_align 对 MaskReg 的默认 dist 从 PK 变为 NORM;统一后的 load_align 对 MaskReg 的默认 mode 从 US 变为 NORM——二者均为行为退化
P3 3 dtype=None 可能被注入 IR kwargs;mask_reg_vars 未按作用域管理;vf_ops.cpp 中 _VF_OP_NAME_MAP 的注释已过时

各文件审查确认

文件 结果
framework/include/ir/op_attr_types.h 无问题(移除未使用的枚举,引用已清理完毕)
framework/src/interface/ir/op/vf_ops.cpp P3:注释不准确
framework/src/interface/pypto_pro/backend/backend_cce_vf_ops.cpp P1:pstu 参数顺序;P2:默认值退化(x2)
framework/src/interface/pypto_pro/codegen/cce/cce_codegen.cpp 无问题
framework/tests/ut/interface/src/pypto_pro/backend/test_backend_cce_vf_ops.cpp P0:arange 测试未更新;测试对 pstu 仅校验前缀,覆盖不足
python/pypto/ir/__init__.py 无问题
python/pypto_pro/language/__init__.py 无问题
python/pypto_pro/language/_api.py 无问题
python/pypto_pro/language/parser/_assignment_parser.py P3:dtype=None 注入
python/pypto_pro/language/parser/_call_parser.py 无问题
python/pypto_pro/language/parser/_scope_manager.py P3:作用域管理
python/src/bindings/ir/ir.cpp 无问题

整体风险判断

高风险。P0 测试回归会立即导致 CI 失败;P1 的 pstu 参数顺序错误会在 MaskReg 非对齐存储场景下生成错误的目标代码,导致运行时数据损坏;P2 的行为退化可能静默改变现有代码的语义。建议在合并前优先修复 P0 和 P1,并确认 P2 的默认值变更是有意为之。

类型 数量
🔴 阻塞 2
🟡 建议 2

⛔ 需要修改

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 18 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 18 Comments:

CLA Signature Pass

liuyu205, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
438 messages are collapsed here。 See more
gaoxiang618
gaoxiang618Collaborators
Aug 26 Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Aug 26 Added label: lgtm
CANN-robot
CANN-robotCollaborators
Aug 26 Comments:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
gaoxiang618gaoxiang618Collaborators
Aug 26 Resolved final issue
CANN-robotCANN-robotCollaborators
Aug 26 Merged pull request