Skip to content

okftype: reference.api description: "按内置固定模式或用户自定义gather mask从源操作数选取元素写入目的地址的数据收集接口,内置模式取值1至7、取0时用src1自定义掩码,支持uint16_t与uint32_t。" tag:

  • roles: [compute]
  • operations: [selection] dependencies:
  • path: docs/zh/api/SIMD-API/c_api/general_description_and_constraints.md kind: constrained_by condition: "操作数地址重叠约束见该页通用地址重叠约束节"
  • path: docs/zh/api/SIMD-API/c_api/vector_compute/vector_mask_config/asc_set_vector_mask.md kind: related condition: "本接口不支持通过该接口配置掩码" version: ">=9.0.0" version_changes: []

asc_reduce

产品支持情况​

  • Ascend 950PR&950DT系列产品:不支持
  • Atlas A3系列产品:支持
  • Atlas A2系列产品:支持
  • Atlas 200I/500 A2推理产品:不支持
  • Atlas推理系列产品AI Core:不支持
  • Atlas推理系列产品Vector Core:不支持
  • Atlas训练系列产品:不支持

功能说明​

头文件路径为:"c_api/vector_compute/compute/vector_reduce.h"。

以内置固定模式对应的二进制或者用户自定义输入的数值对应的gather mask(数据收集的掩码),从源操作数中选取元素写入目的操作数中。

函数原型​

  • 前n个数据计算

    C++
    __aicore__ inline void asc_reduce(__ubuf__ uint16_t* dst, __ubuf__ uint16_t* src0, __ubuf__ uint16_t* src1, uint32_t count)
    __aicore__ inline void asc_reduce(__ubuf__ uint32_t* dst, __ubuf__ uint32_t* src0, __ubuf__ uint32_t* src1, uint32_t count)
    
  • 高维切分计算

    C++
    __aicore__ inline void asc_reduce(__ubuf__ uint16_t* dst, __ubuf__ uint16_t* src0, __ubuf__ uint16_t* src1,
      uint16_t repeat, uint8_t src0_block_stride, uint8_t pattern_mode, uint16_t src0_repeat_stride, uint8_t src1_repeat_stride)
    __aicore__ inline void asc_reduce(__ubuf__ uint32_t* dst, __ubuf__ uint32_t* src0, __ubuf__ uint32_t* src1,
      uint16_t repeat, uint8_t src0_block_stride, uint8_t pattern_mode, uint16_t src0_repeat_stride, uint8_t src1_repeat_stride)
    

参数说明​

表1 参数说明

参数名输入/输出描述
dst输出目的操作数(矢量)的起始地址。
src0输入源操作数(矢量)的起始地址。
src1输入在用户自定义模式下,由用户自定义的数据收集的掩码。
count输入参与计算的元素个数。
repeat输入迭代次数。
src0_block_stride输入源操作数0单次迭代内不同DataBlock间地址步长。
pattern_mode输入gather mask(数据收集的掩码),分为内置固定模式和用户自定义模式两种,根据内置固定模式对应的二进制或者用户自定义输入的数值对应的二进制从源操作数中选取元素写入目的操作数中。
•内置固定模式:pattern_mode数据类型为uint8_t,取值范围为[1, 7],所有迭代使用相同的gather mask。不支持配置src1。
  • 1:01010101...0101 # 每个repeat取偶数索引元素
  • 2:10101010...1010 # 每个repeat取奇数索引元素
  • 3:00010001...0001 # 每个repeat内每四个元素取第一个元素
  • 4:00100010...0010 # 每个repeat内每四个元素取第二个元素
  • 5:01000100...0100 # 每个repeat内每四个元素取第三个元素
  • 6:10001000...1000 # 每个repeat内每四个元素取第四个元素
  • 7:11111111...1111 # 每个repeat内取全部元素
•用户自定义模式:pattern_mode取值为0时为用户自定义模式,用户通过src1参数输入自定义的gather mask,迭代间隔由src1_repeat_stride决定。
src0_repeat_stride输入源操作数0相邻迭代间相同DataBlock的地址步长。
src1_repeat_stride输入源操作数1相邻迭代间相同DataBlock的地址步长。

返回值说明​

无

流水类型​

PIPE_V

约束说明​

调用示例​

C++
//total_length指参与计算的数据总长度
constexpr uint64_t total_length = 128;
__ubuf__ uint16_t src0[total_length];
__ubuf__ uint16_t src1[total_length/16];
__ubuf__ uint16_t dst[total_length];
asc_reduce(dst, src0, src1, total_length);

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