Merged
新增位运算、整数点积、64 位原子操作和小向量构造接口 #7264
baixueyanAdd on 19 days ago
新增位运算、整数点积、64 位原子操作和小向量构造接口 #7264
Merged
baixueyanAdd on 19 days ago
baixueyan
baixueyanCollaborators
19 days ago

描述

新增位运算、整数点积、64 位原子操作和小向量构造接口

关联的Issue

https://gitcode.com/cann/asc-devkit/issues/1980

测试

文档更新

修改以下文件:
docs/zh/api/README.md
docs/zh/api/SIMT-API/SIMD_SIMT_hybrid_programming_intro/extended_syntax/builtin_data_types.md
docs/zh/api/SIMT-API/SIMT_programming_intro/extended_syntax/builtin_data_types.md
docs/zh/api/SIMT-API/atomic_operations/asc_atomic_add.md
docs/zh/api/SIMT-API/atomic_operations/asc_atomic_and.md
docs/zh/api/SIMT-API/atomic_operations/asc_atomic_max.md
docs/zh/api/SIMT-API/atomic_operations/asc_atomic_min.md
docs/zh/api/SIMT-API/atomic_operations/asc_atomic_or.md
docs/zh/api/SIMT-API/atomic_operations/asc_atomic_xor.md
docs/zh/api/SIMT-API/math_functions/float_math_functions/float_math_functions.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/integer_math_functions.md
impl/simt_api/device_atomic_functions_impl.h
impl/simt_api/device_functions_impl.h
impl/simt_api/math_functions_impl.h
impl/simt_api/vector_functions_impl.h
include/simt_api/device_atomic_functions.h
include/simt_api/device_functions.h
include/simt_api/math_functions.h
include/simt_api/vector_functions.h
新增以下文件:
docs/zh/api/SIMT-API/math_functions/float_math_functions/__fmaf_ieee_rn.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/__dp2a_hi.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/__dp2a_lo.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/__dp4a.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/__funnelshift_l.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/__funnelshift_lc.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/__funnelshift_r.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/__funnelshift_rc.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/asc_bswap16.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/asc_bswap32.md
docs/zh/api/SIMT-API/math_functions/integer_math_functions/asc_bswap64.md

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for baixueyan's contribution.)
baixueyanbaixueyanCollaborators
19 days ago Created pull request, commit 618e4a3c
baixueyanbaixueyanCollaborators
19 days ago Associated issue: [Requirement|需求建议]: 提供Ascend C软仿接口实现
atomgit-bot
atomgit-bot
19 days ago Comments:

变更摘要

本 PR 面向 simt_api 的 SIMT 设备侧接口进行扩展,在 math_functions、device_atomic_functions 和 vector_functions 三组头文件与实现文件中补充新接口:包括字节序翻转与漏斗移位(funnel shift)等位运算、__dp2a_lo/__dp2a_hi/__dp4a 整数点积、long long/unsigned long long 与 float2 的原子操作重载,以及带 16/32 字节对齐的长整型四元向量构造接口。所有新增项均在头文件声明与 impl/simt_api 下的实现文件之间成对出现,属于纯新增接口,未改动既有实现。

主要改动

  • 位运算与点积接口新增: 在 math_functions.h 与 math_functions_impl.h 中新增 asc_bswap16/asc_bswap32/asc_bswap64 字节序翻转、__funnelshift_l/__funnelshift_lc/__funnelshift_r/__funnelshift_rc 移位(区分循环与非循环、移位量取模或截断),以及 __fmaf_ieee_rn。
  • 整数点积接口新增: 新增 __dp2a_lo、__dp2a_hi 与 __dp4a,每种均提供整型位打包和 short2/ushort2、char4/uchar4 向量参数两类重载,带符号与无符号版本分别实现,hi/lo 变体分别取 srcB 的高/低 16 位参与乘加。
  • 64 位原子操作重载: 在 device_atomic_functions.h 与 device_atomic_functions_impl.h 中为 asc_atomic_max、asc_atomic_min、asc_atomic_and、asc_atomic_or、asc_atomic_xor 增加 long long 与 unsigned long long 重载,内部转换为 int64_t/uint64_t 后调用对应实现,覆盖 __gm__ 与非 __gm__ 两个分支。
  • float2 原子加接口: 新增 asc_atomic_add(__gm__ float2*, float2) 与 asc_atomic_add(float2*, float2),通过将 float2 按位视为 uint64_t、以 asc_atomic_cas 循环比较交换实现双分量加法,并返回旧值。
  • 对齐四元向量类型与构造: 在 vector_functions.h/vector_functions_impl.h 中新增 alignas(16) 的 long4_16a、ulong4_16a 与 alignas(32) 的 long4_32a、ulong4_32a 结构体,以及对应的 make_long4_16a、make_ulong4_16a、make_long4_32a、make_ulong4_32a 构造接口。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
19 days ago Comments:

代码审查

审查结论

文件 结论
impl/simt_api/device_atomic_functions_impl.h 5 条中的 3 条问题来源(float2 原子加丢 __gm__、8 字节对齐/尺寸假设、long long 重载不对称);max/min/and/or/xor 的 long long / unsigned long long 委托实现逻辑本身与 int64_t/uint64_t 版本一致,其余无问题
impl/simt_api/math_functions_impl.h dp2a/dp4a 引用打洞 1 条;__fmaf_ieee_rn、asc_bswap16/32/64(含 x<<56、x<<24 高位自然丢弃)与 __funnelshift_l/lc/r/rc(n=0 / n=32 边界、32U-n 移位数、& 31 循环位)逐一核对均与契约一致,无问题
impl/simt_api/vector_functions_impl.h 无问题(与同文件 make_ulong4 风格一致,返回类型 ulong4_16a/32a 与头文件声明匹配,未出现设计文档里 make_long4_16a(unsigned long…) 的命名笔误)
include/simt_api/device_atomic_functions.h float2 缺 __ubuf__ 重载 1 条;新增的 long long 声明与 impl 的 10+10 个定义逐条对应,无遗漏
include/simt_api/math_functions.h 无问题(18 个声明与 impl 定义一一对应,无重复/遗漏)
include/simt_api/vector_functions.h 无问题(结构体与 make_* 声明均在 __NPU_ARCH__ 守卫内、全局作用域,与 impl 的全局作用域一致)

问题数量:P1 × 1、P2 × 1、P3 × 3。

整体风险判断:中等。位运算/点积/小向量构造这批接口的位级语义实现正确,主要风险集中在 float2 原子加这一处——混合编程分支丢弃 __gm__ 地址空间限定,很可能直接导致包含该头文件的 device 编译失败(同文件其余转换全部保留 __gm__,重载集里也没有无地址空间的 asc_atomic_cas 可兜底),需在合入前修正;其余为契约/一致性类问题,不阻塞。

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

⛔ 需要修改

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
19 days ago Added label: cann-cla/yes
363 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
6 days ago Added label: lgtm
wulinyu
wulinyuCollaborators
6 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
6 days ago Added label: approved
CANN-robotCANN-robotCollaborators
6 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
6 days ago Merged pull request