已合并
feat(dsl): support user-provided Ascend C functions #1151
feat(dsl): support user-provided Ascend C functions #1151
已合并
lsjblabla创建于 6 天前
lsjblabla
6 天前

描述

为 TLA DSL 增加调用用户自定义 Ascend C 设备函数的能力。当前是第一版,
后续会继续完善。

主要改动:

  • 新增 @tla.extern 声明 API,通过 Python 类型注解描述外部函数 C ABI。
  • 新增带数据类型和地址空间的 tla.Pointer[dtype, address_space] 类型描述。
  • 新增 tla.call_extern IR,并将指针参数 Lower 为 C ABI 地址参数。
  • 根据外部函数的 AIC/AIV 调用区域,使用 ccec 编译目标专用 bitcode。
  • 将外部 bitcode 接入现有 hivmc-a5 --link-aicore-bitcode 链接流程。
  • 将外部源码及编译器信息纳入 Kernel 缓存键。
  • 禁止 auto_sync="v0" 与外部调用组合,要求用户显式同步。
  • 新增 pytest、lit 回归测试和 extern vecadd 端到端样例。

关联的Issue

https://gitcode.com/cann/catlass/issues/459

原因

为TLA DSL提供功能和性能的兜底方案。当前 TLA DSL 无法直接复用用户已有的
Ascend C 设备函数。该能力允许用户在TLA Kernel 中调用外部设备函数,
同时继续使用 TLA DSL 完成其他计算、同步和数据搬运逻辑。

测试

进行了全量回归测试

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 lsjblabla 的贡献)
Llsjblabla
6 天前 创建了 pull request,commit 3d94b8b1
atomgit-bot
atomgit-bot
6 天前 评论:

变更摘要

本 PR 为 TLA DSL 增加调用用户自定义 Ascend C 设备函数的能力(第一版),作为 DSL 功能和性能的兜底方案:新增 @tla.extern 声明 API、带数据类型与地址空间的 tla.Pointer[dtype, address_space] 类型描述,以及 tla.call_extern IR 及其 Lowering 与编译链接流程,并配套 pytest/lit 回归测试与 extern vecadd 端到端样例。本次改动主要围绕外部函数从声明、前端校验、IR 生成到 ccec 编译 bitcode 并接入 hivmc-a5 --link-aicore-bitcode 的完整链路。

主要改动

  • 新增 @tla.extern 声明 API 与类型描述external_ops.py 新增 extern() 装饰器,通过 Python 类型注解(Pointer[...] 或具体 Numeric 类型)描述外部函数 C ABI,生成 ExternFunctiontyping.py 新增 TypedPointer 类型描述器,并通过 Pointer.__class_getitem__ 支持 tla.Pointer[dtype, address_space] 下标语法。
  • 新增 tla.call_extern IR 及 Lowering 传递Tla.td/TlaOps.cpp/tla_ops_gen.py 新增 tla.call_extern 算子(无返回值、保守建模内存读写、含 verifier);新增 TlaLowerExternCallPass,将其 Lower 为私有 func.func 声明 + func.call,按调用所在 vector/cube 区域设置 AIV/AIC core 类型属性,同一符号在双核调用时以 .vector/.cube 后缀区分。
  • 前端调用校验 _emit_extern_callcore_api.py 校验调用必须恰好嵌套在 tla.vector()tla.cube() 之一且位于 tla.vec.func() 之外,校验参数个数、指针元素类型与地址空间、标量数值类型(拒绝 index),并限制 v1 每个 kernel 最多一个外部函数(同一函数可多次调用)。
  • 外部函数编译与链接、缓存流程execution.py 解析 ccec 编译器与 AscendC 头文件路径,按 AIC/AIV 目标将外部源码编译为专用 bitcode(单/多目标两种 ccec 调用形态),并与模板 bitcode 拼接接入 --link-aicore-bitcode;kernel 缓存键新增 extern_source_sha256extern_targetsextern_compile(含编译器版本指纹与 include 目录),外部源码或编译器变化会使缓存失效。
  • 禁止 auto_sync="v0" 与外部调用组合TlaInsertAutoMutexPass.cpp 新增 validateNoExternCalls 校验,v1 中外部调用要求用户显式同步,不进行自动同步。
likedislike
atomgit-bot
atomgit-bot
6 天前 评论:

代码审查

✅ 未发现问题

likedislike
CANN-robot
CANN-robot成员
6 天前 评论:

Hi @csdn_onlyoh, welcome to submitting your first PR to catlass!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.

likedislike
CANN-robotCANN-robot成员
6 天前 添加了label:cann-cla/no
此处折叠了116条消息 查看更多
CANN-robotCANN-robot成员
1 天前 添加了label:lgtmapproved
CANN-robot
CANN-robot成员
1 天前 评论:

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
Mmdrumond成员
1 天前 解决了最后一个问题
CANN-robotCANN-robot成员
1 天前 合入了pull request
CANN-robot
CANN-robot成员
1 天前 评论:

Pull Request 已合并或已关闭。

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

likedislike