Skip to content

C API

CANN 9.1.0继续完善Ascend 950PR/Ascend 950DT(3510架构)C API,新增矢量计算、数据搬运、标量操作、矩阵计算、同步控制、系统变量和缓存控制接口,并修复9.0.0中的函数命名、类型声明和地址自更新签名问题。

新增特性

矢量计算

  • asc_bitsortasc_bitsort_sync:分数(Score)和索引(Index)分别存储在两个源操作数中,按分数从大到小排序,将排序后的分数与对应索引组成数据结构存储在目的操作数中。
  • asc_mrgsort4asc_mrgsort4_sync:将已经排好序的最多4条队列合并排列成1条队列,结果按照分数域由大到小排序。
  • asc_transposeasc_transpose_sync:实现16×16的二维矩阵数据块转置。
  • asc_transto5hd_b8asc_transto5hd_b8_syncasc_transto5hd_b16asc_transto5hd_b16_syncasc_transto5hd_b32asc_transto5hd_b32_sync:执行数据格式转换,一般用于将NCHW格式转换成NC1HWC0格式,也可用于二维矩阵数据块转置。
  • asc_set_va_reg:用于设置asc_transto5hd_b8的地址,将操作数地址序列与地址寄存器关联。

数据搬运

  • asc_copy_gm2ubasc_copy_gm2ub_sync:将数据从Global Memory搬运到Unified Buffer。
  • asc_copy_ub2gmasc_copy_ub2gm_sync:将数据从Unified Buffer搬运到Global Memory。
  • asc_copy_ub2ubasc_copy_ub2ub_sync:将数据从Unified Buffer搬运到Unified Buffer。
  • asc_copy_ub2l1asc_copy_ub2l1_sync:将数据从Unified Buffer搬运到L1 Buffer。
  • asc_set_copy_pad_val:与asc_copy_gm2ub_align配合使用,设置连续搬运数据块左右两侧需要填充的数据值。Ascend 950PR/Ascend 950DT支持int8_tuint8_tint16_tuint16_thalfbfloat16_tint32_tuint32_tfloatfp4x2_e2m1_tfp4x2_e1m2_thifloat8_tfp8_e8m0_tfp8_e5m2_tfp8_e4m3fn_t数据需要先转换为int8_t再传入。
  • asc_ndim_copy_dci:执行N维搬运场景所需的数据缓存失效(Data Cache Invalidate,DCI)操作。
  • asc_copy_gm2l1asc_copy_gm2l1_sync:将数据从Global Memory搬运到L1 Buffer。
  • asc_copy_gm2l1_alignasc_copy_gm2l1_align_sync:将Global Memory中的数据填充后搬运到L1 Buffer。
  • asc_copy_gm2l1_nd2nzasc_copy_gm2l1_nd2nz_sync:在Global Memory到L1 Buffer搬运过程中完成ND到NZ格式转换。
  • asc_copy_gm2l1_dn2nzasc_copy_gm2l1_dn2nz_sync:将矩阵数据从Global Memory搬运到L1 Buffer,并完成DN到NZ、NCHW到NC1HWC0或NCHW到C1HWNC0格式转换。D维未按C0大小对齐时,在L1 Buffer最内层维度填充0。
  • asc_copy_l12l0aasc_copy_l12l0a_syncasc_copy_l12l0basc_copy_l12l0b_sync:将L1 Buffer中的512字节矩阵搬运到L0A Buffer或L0B Buffer,支持2D格式搬运、2D格式转置搬运、3D格式搬运。
  • asc_copy_l12l0b_transasc_copy_l12l0b_trans_sync:将矩阵从L1 Buffer转置搬运到L0B Buffer。
  • asc_copy_l12l0b_mxasc_copy_l12l0b_mx_sync:将微缩放(Microscaling,MX)矩阵从L1 Buffer搬运到L0B Buffer。
  • asc_copy_l0c2gmasc_copy_l0c2gm_sync:将L0C Buffer中的数据搬运到Global Memory,支持量化、ReLU、Leaky ReLU、通道拆分和NZ2ND随路控制。
  • asc_copy_l0c2ubasc_copy_l0c2ub_sync:将L0C Buffer中的数据搬运到Unified Buffer,支持量化、ReLU、Leaky ReLU和通道拆分随路控制。
  • asc_copy_l12fbasc_copy_l12fb_sync:将量化参数从L1 Buffer搬运到Fixpipe Buffer。
  • asc_copy_l12btasc_copy_l12bt_sync:将矩阵乘使用的偏置(Bias)数据从L1 Buffer搬运到BiasTable Buffer。
  • asc_copy_l12ubasc_copy_l12ub_sync:将数据从L1 Buffer搬运到Unified Buffer。
  • asc_fill_l1asc_fill_l1_sync:将value的二进制值赋值给目的操作数,对L1 Buffer的Local Memory进行初始化。
  • asc_set_l13d_fmatrix_b:设置特征图属性描述,用于asc_copy_l12l0aasc_copy_l12l0b的3D格式搬运接口配置填充值。从右矩阵获取特征图属性时使用该接口。
  • asc_set_l0c2gm_lrelu_alpha:用于设置asc_copy_l0c2l1asc_copy_l0c2gm计算过程中使用的Leaky ReLU alpha值,该值只支持halffloat两种数据类型。
  • asc_set_l13d_padding:设置填充属性描述,用于调用asc_copy_l12l0a时配置填充值。

标量操作

  • asc_clear_nthbitasc_set_nthbit:清除或设置uint64_t值中的指定比特位。
  • asc_atomic_addasc_atomic_subasc_atomic_maxasc_atomic_minasc_atomic_exchasc_atomic_cas:对Global Memory中的int32_tuint32_tfloatint64_tuint64_t数据执行标量原子操作,并返回操作前的值。
  • asc_atomic_andasc_atomic_orasc_atomic_xor:对Global Memory中的int32_tuint32_tint64_tuint64_t数据执行原子按位运算。
  • asc_atomic_inc:对Global Memory中的uint32_tuint64_t计数器执行原子递增操作;计数器数值大于等于val时赋值为0,否则加1。
  • asc_atomic_dec:对Global Memory中的uint32_tuint64_t计数器执行原子递减操作;计数器数值等于0或大于val时赋值为val,否则减1。

矩阵计算

  • asc_mmadasc_mmad_sync:完成矩阵乘加操作,支持int8_thifloat8_tfp8_e5m2_tfp8_e4m3fn_thalfbfloat16_tfloat同精度和混合精度输入组合。
  • asc_enable_fp8:设置矩阵乘加计算开启FP8模式并关闭HiF8模式,L0A Buffer、L0B Buffer中的FP8数据在参与矩阵乘加计算之前不会转换为hifloat8_t数据。
  • asc_enable_hif8:设置矩阵乘加计算开启HiF8模式,L0A Buffer、L0B Buffer中的8位数据在参与矩阵乘法运算前转换为hifloat8_t数据。
  • asc_enable_hf32_trans:设置HF32模式舍入方式,使用该接口前需要先使用asc_enable_hf32开启HF32模式。
  • asc_enable_hf32:设置矩阵乘加计算开启HF32模式,提升FP32数据的计算性能,但会带来一定的精度损失。
  • asc_set_fp32_mode:设置矩阵乘加计算开启FP32模式,L0A Buffer、L0B Buffer中的FP32数据在参与矩阵乘加计算之前不做舍入处理。
  • asc_set_mmad_direction_masc_set_mmad_direction_n:分别设置矩阵乘加计算优先通过M方向、N方向生成结果。

同步控制

  • asc_lockasc_unlock:用于AI Core内部异步流水线同步。
  • asc_sync_intra_arriveasc_sync_intra_wait:用于核间信号同步。
  • asc_sync_subblock_arriveasc_sync_subblock_wait:用于组内子块(Subblock)间的信号同步。
  • asc_sync_inter_arriveasc_sync_inter_wait:用于组间计算块(Block)的信号同步。
  • asc_sync_data_barrier:等待指定范围内先前发起的内存访问完成。

系统变量

  • asc_get_smmu_tag_versionasc_get_phy_stack_baseasc_get_statusasc_get_sys_virtual_base:分别获取系统内存管理单元(System Memory Management Unit,SMMU)版本信息、物理堆栈基地址、状态信息和系统虚拟基地址。
  • asc_get_block_idx:获取当前运行核的索引。
  • asc_get_sub_block_num:在分离模式下获取一个AI Core上的Cube Core或Vector Core数量。
  • asc_get_sub_block_id:获取AI Core上的Vector Core ID。
  • asc_get_phy_buf_addr:根据偏移量获取片上实际物理地址。
  • asc_get_core_idasc_get_arch_ver:分别获取核ID和架构版本。
  • asc_get_vf_len:获取Tensor位宽VL(Vector Length)的大小。
  • asc_set_gm2l1_nz_para:设置MTE2_NZ_PARA寄存器的值。
  • asc_set_l0c2gm_channel_para:设置通道步长参数专用寄存器的比特位。
  • asc_set_l0c2gm_quant_post:设置QUANT_POST寄存器的值。试验接口。
  • asc_set_l0c2gm_relu_alpha:设置RELU_ALPHA寄存器的值。
  • asc_set_l12l0_padding_val:设置PADDING_B寄存器的值。
  • asc_set_l3d_rpt_b:用于设置asc_copy_l12l0aasc_copy_l12l0b的2D格式搬运repeat参数。

缓存控制

  • asc_dci:使整个数据缓存失效,不回写缓存行,未同步到主存的修改会被丢弃。调用前必须先执行asc_sync_data_barrier(mem_dsb_t::DSB_ALL),等待此前的内存访问完成。

Bug修复

  • asc_sync_block_arrive由9.0.0的asc_sync_block_arrive(pipe, mode, flagID)调整为asc_sync_block_arrive(pipe, flag_id),删除mode参数并统一事件标号命名。
  • asc_sync_block_wait由9.0.0的asc_sync_block_wait(flagID)调整为asc_sync_block_wait(pipe, flag_id),新增流水线参数并统一事件标号命名。
  • asc_get_arch_ver参数名由coreVersion统一为core_version
  • 修复cache_ctrl.h复用原子操作头文件保护宏的问题,避免包含顺序导致缓存控制声明被跳过。
  • 统一asc_simd.hmisc.hcache_ctrl.hsync.hsys_var.hutils_intf.h中的头文件引用路径,避免安装目录变化导致包含失败。
  • asc_loadalign_postupdateasc_loadalign_brc_postupdateasc_loadalign_brc_postupdate_v2asc_loadalign_brc_postupdate_v3asc_loadalign_upsample_postupdateasc_loadalign_downsample_postupdateasc_loadalign_unpack_postupdateasc_loadalign_unpack_postupdate_v2asc_loadalign_deintlv_postupdate中需要自动更新的Unified Buffer源指针参数修正为指针引用,确保调用后地址变化对调用方可见。
  • asc_storealign_postupdateasc_storealign_1st_postupdateasc_storealign_pack_postupdateasc_storealign_pack_postupdate_v2中需要自动更新的Unified Buffer目的指针参数修正为指针引用,确保调用后地址变化对调用方可见。
  • 将不更新地址的asc_storeunalign目的参数由指针引用修正为普通指针,并补齐asc_storeunalign_postupdate的地址更新重载。
  • 修复half转换为int4b_t接口的舍入模式命名。9.0.0将以下四种舍入模式的接口声明为向下舍入函数名,9.1.0修复为与实际舍入模式一致的函数名:
    • 向上舍入:asc_half2int4x2_ruasc_half2int4x2_ru_satasc_half2int4x2_ru_v2asc_half2int4x2_ru_sat_v2asc_half2int4x2_ru_v3asc_half2int4x2_ru_sat_v3asc_half2int4x2_ru_v4asc_half2int4x2_ru_sat_v4
    • 向零舍入:asc_half2int4x2_rzasc_half2int4x2_rz_satasc_half2int4x2_rz_v2asc_half2int4x2_rz_sat_v2asc_half2int4x2_rz_v3asc_half2int4x2_rz_sat_v3asc_half2int4x2_rz_v4asc_half2int4x2_rz_sat_v4
    • 最近偶数舍入:asc_half2int4x2_rnasc_half2int4x2_rn_satasc_half2int4x2_rn_v2asc_half2int4x2_rn_sat_v2asc_half2int4x2_rn_v3asc_half2int4x2_rn_sat_v3asc_half2int4x2_rn_v4asc_half2int4x2_rn_sat_v4
    • 最近远离零舍入:asc_half2int4x2_rnaasc_half2int4x2_rna_satasc_half2int4x2_rna_v2asc_half2int4x2_rna_sat_v2asc_half2int4x2_rna_v3asc_half2int4x2_rna_sat_v3asc_half2int4x2_rna_v4asc_half2int4x2_rna_sat_v4
  • asc_int162half_rc修正为asc_int162half_rz
  • asc_reduce_min_datablock_修正为asc_reduce_min_datablock,去除多余的尾部下划线。
  • asc_half2uint8_rd_sat_v2_implasc_half2uint8_rn_sat_v2_implasc_half2uint8_rna_sat_v2_implasc_half2uint8_ru_sat_v2_implasc_half2uint8_rz_sat_v2_impl分别修正为asc_half2uint8_rd_sat_v2asc_half2uint8_rn_sat_v2asc_half2uint8_rna_sat_v2asc_half2uint8_ru_sat_v2asc_half2uint8_rz_sat_v2
  • 将以下bfloat16_t转换为fp4x2_e1m2_t接口的目的类型从vector_f4e1m2x2修正为vector_fp4x2_e1m2_t
    • 向下舍入:asc_bfloat162e1m2x2_rdasc_bfloat162e1m2x2_rd_v2asc_bfloat162e1m2x2_rd_v3asc_bfloat162e1m2x2_rd_v4
    • 最近偶数舍入:asc_bfloat162e1m2x2_rnasc_bfloat162e1m2x2_rn_v2asc_bfloat162e1m2x2_rn_v3asc_bfloat162e1m2x2_rn_v4
    • 最近远离零舍入:asc_bfloat162e1m2x2_rnaasc_bfloat162e1m2x2_rna_v2asc_bfloat162e1m2x2_rna_v3asc_bfloat162e1m2x2_rna_v4
    • 向上舍入:asc_bfloat162e1m2x2_ruasc_bfloat162e1m2x2_ru_v2asc_bfloat162e1m2x2_ru_v3asc_bfloat162e1m2x2_ru_v4
    • 向零舍入:asc_bfloat162e1m2x2_rzasc_bfloat162e1m2x2_rz_v2asc_bfloat162e1m2x2_rz_v3asc_bfloat162e1m2x2_rz_v4
  • asc_half2uint8asc_min_scalar的非标准类型别名vector_u8vector_f16修正为vector_uint8_tvector_half
  • asc_arangeasc_arange_descend参数名由index统一为value
  • asc_update_mask_b8asc_update_mask_b16asc_update_mask_b32参数名由scalar统一为value

增强

  • asc_copy_gm2ub_alignasc_copy_gm2ub_align_syncasc_copy_ub2gm_alignasc_copy_ub2gm_align_sync新增仅传入dstsrcsize的简化重载。
  • asc_copy_l0c2l1新增asc_copy_l0c2l1_sync,并新增int16_t目的数据与int32_t源数据、bfloat16_t目的数据与float源数据的组合,以及目的参数为__cbuf__ void*、源参数分别为__cc__ int32_t*__cc__ float*的通用重载。
  • asc_copy_l12l0a_mx新增asc_copy_l12l0a_mx_sync
  • asc_set_atomic_add_int8asc_set_atomic_add_int16asc_set_atomic_add_int:设置后续从Unified Buffer、L0C Buffer到Global Memory的数据搬运开启原子累加,累加的数据类型分别为int8_tint16_tint32_t
  • asc_gatherint16_tuint16_thalfbfloat16_t数据新增使用vector_uint32_t索引的重载。
  • asc_gather_datablock新增int4b_t重载和无需传入掩码参数的uint64_t重载。
  • asc_loadalignasc_loadalign_brcasc_loadalign_brc_v2asc_loadalign_upsampleasc_loadalign_downsampleasc_loadalign_unpackasc_loadalign_unpack_v2asc_loadalign_deintlv新增int4b_tvector_int4x2_t重载。
  • asc_loadalignasc_loadalign_upsampleasc_loadalign_downsampleasc_loadalign_postupdate新增vector_bool重载。
  • asc_storealignasc_storealign_1stasc_storealign_intlvasc_storeunalignasc_storeunalign_postupdateasc_storeunalign_postasc_storeunalign_post_postupdateasc_store新增int4b_tvector_int4x2_t数据重载。
  • asc_storealignasc_storealign_packasc_storealign_postupdateasc_storealign_pack_postupdateasc_storeunalign_postupdate新增vector_bool输出重载。
  • asc_scatter新增9组目的Unified Buffer地址在前、源矢量寄存器在后的重载,根据索引将源矢量寄存器元素分散写入Unified Buffer。支持的数据类型为int8_tuint8_tint16_tuint16_thalfbfloat16_tint32_tuint32_tfloat
  • asc_create_iter_reg_b8asc_create_iter_reg_b16asc_create_iter_reg_b32从单个偏移扩展为支持1至4个偏移。
  • asc_copy新增将vector_uint16_tvector_uint32_t矢量数据寄存器复制到vector_bool掩码寄存器的重载。
  • asc_duplicate_scalar新增无需传入掩码参数的重载。

接口废弃

本版本标记以下接口或特定重载为deprecated

数据搬运

废弃接口或重载替代接口说明
asc_set_gm2ub_padasc_set_copy_pad_val使用通用搬运填充值配置接口。
asc_get_store_atomic_config(Ascend 950PR/Ascend 950DT)asc_atomic_add标量原子加无需预先配置和查询数据搬运原子状态。
asc_set_store_atomic_config_v2asc_atomic_add标量原子加改为直接调用原子接口。
源矢量寄存器在前、目的Unified Buffer地址在后的asc_scatter重载目的Unified Buffer地址在前、源矢量寄存器在后的asc_scatter重载支持的数据类型不变,仅调整参数顺序。
asc_exp_sub_v2(vector_float&, vector_float, vector_float, vector_bool)asc_exp_subhalf输入的asc_exp_sub_v2仍保留,用于读取源操作数的奇数索引元素;仅float输入的该重载废弃。

注: 详情可参考废弃接口

免责声明:本站内容由 asc-devkit 仓 master 分支自动编译生成,属于持续开发版本,可能存在缺陷,仅供预览与参考。如需稳定及商用资料,请查阅官方 昇腾社区