Closed
[Requirement|需求建议]: SIMT API 软仿实现上移至仓内及软软仿提示 #1942
ruoshuisixueAdd on  28 days agoClosed at  17 hours ago
ruoshuisixue
ruoshuisixueCollaborators
28 days ago Create

Background(背景信息)

SIMT API(simt_api/asc_fp16.h、asc_bf16.h、device_functions.h)中部分接口(fp16/bf16 的比较、算术、NaN 类接口,以及 __clz/__popc/__ffs/__mul24 等整数/位操作接口)此前依赖毕昇编译器内置的软仿(soft implementation)实现。

当用户关闭编译器软仿(定义 __BISHENG_DISABLE_SOFT_IMPL__)时,这些接口没有可用实现,导致编译失败;同时软仿语义由编译器维护,与仓内头文件演进不同步,不便于统一维护和问题修复。

需要将上述软仿实现从编译器上移至 asc-devkit 仓内 impl/simt_api/ 目录,使其与公开头文件在同一仓内维护。

Origin(信息来源)

NA

Benefit / Necessity (价值/作用)

  1. 接口完整性:关闭编译器软仿(定义 __BISHENG_DISABLE_SOFT_IMPL__)的场景下,SIMT 头文件对外暴露的全部接口仍有仓内实现可用,编译不再失败;
  2. 解耦编译器版本:软仿语义不再随编译器版本漂移,仓内可独立演进、独立修复精度或语义问题;
  3. 可维护性:软仿实现与接口声明同仓,代码评审、UT 覆盖和问题定位都在一处完成;
  4. CPU debug 场景:配套补充 CPU 仿真桩(simt_stub.h),CPU debug 模式下同样可用。

Design(设计方案)

公开头文件(include/simt_api/asc_fp16.h、asc_bf16.h、device_functions.h)中以 __BISHENG_DISABLE_SOFT_IMPL__ 宏区分两条路径:

#ifndef __BISHENG_DISABLE_SOFT_IMPL__
// 原路径:static 声明,实现由编译器内置提供
static __SIMT_DEVICE_FUNCTIONS_DECL__ bool __heq(half x, half y);
#else
// 新路径:inline 声明,实现在仓内 impl 头中
__SIMT_DEVICE_FUNCTIONS_DECL__ inline bool __heq(half x, half y);
#endif

// 文件末尾统一引入实现:
#include "impl/simt_api/asc_fp16_impl.h"

新增实现文件:

  • impl/simt_api/asc_fp16_impl.h:fp16 软仿实现(比较类 __heq/__hne/__hle/... 及 u 后缀、x2 向量化版本,算术类 __hadd/__hsub/__hmul/__hdiv/__hfma_relu/__hcmadd 等,NaN 相关 __hmax_nan/__hisnan/__isnanx2 等),约 60 个接口;
  • impl/simt_api/asc_bf16_impl.h:bf16 同类软仿实现,约 58 个接口;
  • impl/simt_api/device_functions_impl.h:整数/位操作软仿实现(__clz/__popc/__ffs/__saturatef/__mul24/__rhadd/__sad/__usad/__mul64hi/__umul64hi/__brev/__byte_perm 及 asc_nop/asc_dcci_single 等),19 个实现。
likedislike
ruoshuisixueruoshuisixueCollaborators
28 days ago Added label: requirement
ruoshuisixueruoshuisixueCollaborators
10 days ago Change title to "[Requirement|需求建议]: SIMT API 软仿实现上移至仓内及软软仿提示", originally titled "[Requirement|需求建议]: SIMT API 软仿实现上移至仓内".
ruoshuisixueruoshuisixueCollaborators
17 hours ago changed custom state from 待办的 to 已解决
ruoshuisixueruoshuisixueCollaborators
17 hours ago Close issue
CANN-robotCANN-robotCollaborators
15 hours ago Added label: resolved