Open
增加C API样例 #7443
LycheeeeeAdd on 12 days ago
增加C API样例 #7443
Open
LycheeeeeAdd on 12 days ago
Lycheeeee
LycheeeeeCollaborators
12 days ago

描述

增加C API样例

关联的Issue

测试

文档更新

类型标签

likedislike
Merge blocked
LycheeeeeLycheeeeeCollaborators
12 days ago Created pull request, commit e03bbe19
Lycheeeee
LycheeeeeCollaborators
12 days ago Comments:

compile

likedislike
CANN-robotCANN-robotCollaborators
12 days ago Added label: cann-cla/yes
LycheeeeeLycheeeeeCollaborators
12 days ago Pre merge succeeded (commit_id: 7590e836219c94231eae95e6bce511c1307b507b)
CANN-robot
CANN-robotCollaborators
12 days ago Comments:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
examples ❌ (0/2)(You can also ask: houyuyang, wuyang_hw, wangxiaozhi, munanhw, bianque) ❌ (0/1)(You can also ask: ai_xin, 诸葛洵, changxianyu, 黄金华, bianque)
scripts ❌ (0/2)(You can also ask: DragonBornHD84, bianque, wangxiaozhi, 曾娟, kong0808) ❌ (0/1)(You can also ask: kevin365, 诸葛洵)

💡 Tip:

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

CLA Signature Pass

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

likedislike
118 messages are collapsed here。 See more
bianque
bianqueCollaborators7 days agoStart code review1
examples/02_simd_c_api/06_ops/activation/CMakeLists.txt
@@ -0,0 +1,0 @@
1+# ----------------------------------------------------------------------------------------------------------
bianque
bianque7 days agoComments:

这个 PR 类型标签是 docs,但实际新增了 .asc、CMakeLists 和 Python 脚本这类可编译运行的代码,描述里「测试」章节还是空的。能否补上验证依据:用的 CANN 版本、在 dav-3510 上跑的是 sim 还是 npu、./demo 实际输出的 test pass!?确认后建议把类型标签改成 feat/test 之类更贴切的。

likedislike
bianque
bianqueCollaborators7 days agoStart code review1
examples/02_simd_c_api/06_ops/README.md
@@ -0,0 +10,4 @@
10+ 
11+| 目录 | 功能描述 |
12+| --- | --- |
13+| [activation](./activation) | 基于C API实现bfloat16_t类型的SiLU、GELU、SwiGLU和GeGLU,支持动态多维shape、Erf分段多项式、寄存器融合及多核双缓冲流水 |
bianque
bianque7 days agoComments:

样例列表列了 activation/normalization/rms_norm_quant/attention 四个目录,但这次 diff 只看到 activation 目录下的文件。能否确认另外三个目录是同 PR 一起提交还是别处补上?避免 README 链到还不存在的目录。

likedislike
bianque
bianqueCollaborators7 days agoStart code review1
examples/02_simd_c_api/06_ops/activation/CMakeLists.txt
@@ -0,0 +21,4 @@
21+ activation.asc
22+)
23+ 
24+if(NOT CMAKE_ASC_ARCHITECTURES STREQUAL "dav-3510")
bianque
bianque7 days agoComments:

arch 和 run mode 的校验放在 add_executable 之后了。建议把这两个 if 挪到 find_package/project 之后、add_executable 之前,架构或运行模式填错时能更早报错。

likedislike
bianque
bianqueCollaborators7 days agoStart code review1
examples/02_simd_c_api/06_ops/activation/README.md
@@ -0,0 +64,4 @@
64+- GELU和GeGLU:先计算`g*0.7071067811865476f`,转为BF16后再转回FP32;计算Erf,再做一次相同舍入;随后依次计算`erf+1`、`g*0.5`及两者的乘积。GeGLU继续乘u,最后将输出转为BF16。
65+- Erf分段计算:按输入绝对值与`0x1.00c1fcp+0f`(FP32位模式`0x3F8060FE`)比较,选择两个多项式计算路径之一。两个路径都在寄存器中计算,由比较掩码和`asc_select`选取结果。代码保留乘法和加法顺序,不改写为融合乘加或tanh公式。
66+ 
67+中间舍入通过以下函数完成,使用[asc_float2bfloat16_rn](../../../../docs/zh/api/SIMD-API/c_api/reg_compute/reg_convert/asc_float2bfloat16.md)转换后再扩展:
bianque
bianque7 days agoComments:

这里以及后面几处都用了 ../../../../docs/zh/... 的相对链接(asc_float2bfloat16.md、asc_sync_notify.md、reg_vector_computation.md)。能否确认这些路径在当前分支的 docs 目录下确实存在?避免死链。

likedislike
izanaami
izanaamiCollaborators
6 days ago Comments:

🤖 GitCode 检视报告

结论:未发现需要新增提交的行动项,新增行内意见0条;可以合入。未发送审批命令。

PR:https://gitcode.com/cann/asc-devkit/pulls/7443
base:6be6d04c2416cc4ca8d377a3aada5fc7b72a421b
head:ade58c145233c8e90580872d8a10cc3b4409ec6d

首次检视,分页读取36条评论与回复,完整走读42个变更文件和四组算子完整实现、tiling、数据生成/校验脚本、双语说明及冒烟接入。API文件列表与固定base三点diff一致。检查激活的BF16中间舍入、尾部掩码与双缓冲;FlashAttention的因果块索引、五槽P/V/alpha生命周期、Cube/双Vector握手、尾块与独立参考;LayerNorm三类归约、统计区及输入输出槽复用;RmsNormQuant四类归约、RO/RN转换及标量参数布局。

验证:原始四个tiling头文件配合仓库实际ceil_div实现运行Host C++边界检查,分别45/28512/49152/33组通过,涵盖整行UB容量、核/行覆盖、对齐、长行归约与片上布局。仅移除设备修饰符并跳过未使用的设备数学头,其余Host逻辑直接编译;不等于设备实现验收。新增Python脚本AST解析、Shell语法检查通过,34个相对链接均存在,git diff --check通过。冒烟四项均有runner、manifest及3510分片接入,normalization/quant额外运行数值脚本,activation/attention由主程序内置校验。

去重与反证:旧202125252所述仅activation不符合当前head,另外三个目录已齐备;202125302列举的相对链接当前全部存在。旧范围说明、类型全名、变量命名及公式说明对应当前实现已核对。不重复发布已有测试依据/标签等202125232意见,也不修改他人discussion。RmsNormQuant允许非正epsilon为文档显式契约,不当作新增校验遗漏;BF16中间舍入与饱和行为也按本样例声明判断。

未覆盖:本机没有CANN SDK、bisheng、设备仿真器和NPU,未执行真实样例编译、设备精度/异步流水/越界哨兵验收;文档已有设备验证陈述未被当成本轮独立实测。

likedislike