已合并
feat: 提供 AICPU CpuKernel V2 注册与查询接口 #1522
pantong创建于 4月11日
feat: 提供 AICPU CpuKernel V2 注册与查询接口 #1522
已合并
pantong创建于 4月11日
pantong
4月11日

Pull Request

描述

本 PR 在 runtime 仓的 pkg_inc/aicpu_sched/cpu_kernels/ 头文件中补充一套独立于现有 V1 的 CpuKernel V2 注册、查询、执行与枚举接口,为 GE 常量折叠等上层场景按"V2 优先、V1 兜底"渐进式演进提供底层 ABI 能力。

1. cpu_kernel.h

新增 V2 注册入口与对称宏:

AICPU_VISIBILITY bool RegistCpuKernelV2(const std::string &type,
                                        const KERNEL_CREATOR_FUN &fun);

#define REGISTER_CPU_KERNELV2(type, clazz)  /* 形态与 REGISTER_CPU_KERNEL 对称 */

REGISTER_CPU_KERNELV2 通过 file-scope 静态全局变量调用 RegistCpuKernelV2,把 creator 写入独立的 V2 注册表。

2. cpu_kernel_register.h

class CpuKernelRegister 扩展如下 V2 接口(与 V1 对称、互不影响):

接口 作用
std::shared_ptr<CpuKernel> GetCpuKernelV2(const std::string &op_type) 仅查 creatorMapV2_,未命中返回 nullptr不回退 V1;不输出"未注册"日志,避免对回退路径产生误导
bool IsRegisteredV2(const std::string &op_type) const 轻量命中判断,不构造 kernel,供上层在"V2 优先"路由场景避免重复构造开销
std::vector<std::string> GetAllRegisteredOpTypesV2() const 枚举 V2 全量 op_type,让 GE 等上层在 dlopen 后建立 op_type → so handle 反向索引
uint32_t RunCpuKernelV2(CpuKernelContext &ctx) V2 同步执行入口,未命中直接失败
uint32_t RunCpuKernelAsyncV2(CpuKernelContext &ctx, uint8_t wait_type, uint32_t wait_id, std::function<uint32_t()> cb) V2 异步执行入口
class RegisterarV2 V2 静态注册器,与 V1 Registerar 对称

私有侧抽取公共逻辑:

  • RunCpuKernelCommon(ctx, type, kernel):去重 V1/V2 同步执行核心。
  • SetAsyncKernelContext(type, wait_type, wait_id):复用异步 ctx 设置逻辑。
  • RunCpuKernelAsyncCommon(...):去重 V1/V2 异步执行核心。

成员新增 std::map<std::string, KERNEL_CREATOR_FUN> creatorMapV2_,与 V1 creatorMap_ 完全隔离。

变更类型

关联的Issue

关联 Issue #512

如何测试

1. 头文件兼容性

依赖 pkg_inc/aicpu_sched/cpu_kernels/cpu_kernel.hcpu_kernel_register.h 的现有 V1 用户代码回归编译,确认:

  • RegistCpuKernel / REGISTER_CPU_KERNEL / GetCpuKernel / RunCpuKernel / RunCpuKernelAsync 签名零变化。
  • 新增 V2 符号有 AICPU_VISIBILITY 修饰,符号导出与 V1 一致。

2. 配套仓 V2 接口联调

  • cann/opbase#299 提供 RegistCpuKernelV2 / RegisterV2 / V2 系列方法的实现,编译通过。
  • cann/ge#1824 通过 dlsym 绑定 C ABI 裸名 GetAllRegisteredOpTypesV2 / IsRegisteredV2 / RunCpuKernelV2,验证 V2 反向索引建立与 O(1) 命中。

3. UT

依托 opbase 侧 CpuKernelRegister UT 覆盖 V2 注册、查询、执行(同步/异步)行为。

4. 端到端

联合 cann/runtime#1522、cann/ge#1824 进行常量折叠 V2 端到端验证:
image.png
image.png

核对清单

其他信息

  • 与 cann/opbase#299(V2 注册/调度实现)、cann/ge#1824(V2 路由)配套使用。
  • 本 PR 仅扩展头文件 ABI 声明,V1 接口签名/行为/二进制兼容性全部保留。
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 pantong 的贡献)
Ppantong
4月11日 创建了 pull request,commit 0b9434fe
CANN-robot
CANN-robot成员
4月11日 评论:

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
pkg_inc 张子菁, zhangpengpeng8 (2/2) 张子菁 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
4月11日 添加了label:cann-cla/yes
CANN-robotCANN-robot成员
4月11日 将wangtao43,zhangpengpeng8,yanmingxiang,Reyn52166,ykl999,houyanbao,tingwood设为评审人
CANN-robotCANN-robot成员
4月11日 将wangtao43,ykl999,houyanbao,tingwood设为审查人
此处折叠了202条消息 查看更多
CANN-robot
CANN-robot成员
5月18日 评论:

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
Ttingwood成员
5月18日 解决了最后一个问题
CANN-robot
CANN-robot成员
5月18日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: 张子菁.
Reviewers who wrote a comment of /lgtm are: 张子菁, zhangpengpeng8.

likedislike
CANN-robotCANN-robot成员
5月18日 关闭了关联的issue
CANN-robotCANN-robot成员
5月18日 合入了pull request