Adds
功能说明
矢量内每个element与标量求和,计算公式如下,其中PAR表示矢量计算单元一个迭代能够处理的元素个数:

函数原型
- tensor前n个数据计算
      1 2 template <typename T, bool isSetMask = true> __aicore__ inline void Adds(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, const int32_t& calCount) 
- tensor高维切分计算
      - mask逐bit模式
        1 2 template <typename T, bool isSetMask = true> __aicore__ inline void Adds(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, uint64_t mask[], const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams) 
- mask连续模式
        1 2 template <typename T, bool isSetMask = true> __aicore__ inline void Adds(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, uint64_t mask, const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams) 
 
- mask逐bit模式
        
- tensor前n个数据计算
       1 2 template <typename T, typename U, bool isSetMask = true, typename std::enable_if<IsSameType<PrimT<T>, U>::value, bool>::type = true> __aicore__ inline void Adds(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const U& scalarValue, const int32_t& calCount) 
- tensor高维切分计算
       - mask逐bit模式
         1 2 template <typename T, typename U, bool isSetMask = true, typename std::enable_if<IsSameType<PrimT<T>, U>::value, bool>::type = true> __aicore__ inline void Adds(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const U& scalarValue, uint64_t mask[], const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams) 
- mask连续模式
         1 2 template <typename T, typename U, bool isSetMask = true, typename std::enable_if<IsSameType<PrimT<T>, U>::value, bool>::type = true> __aicore__ inline void Adds(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const U& scalarValue, uint64_t mask, const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams) 
 
- mask逐bit模式
         
参数说明
| 参数名 | 描述 | 
|---|---|
| T | 操作数数据类型。 | 
| U | scalarValue数据类型。 | 
| isSetMask | 是否在接口内部设置mask模式和mask值。 
 | 
| 参数名称 | 类型 | 说明 | 
|---|---|---|
| dstLocal | 输出 | 目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 Atlas 训练系列产品,支持的数据类型为:Tensor(half/float) Atlas推理系列产品AI Core,支持的数据类型为:Tensor(half/int16_t/float/int32_t) Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:Tensor(half/int16_t/float/int32_t) Atlas 200/500 A2推理产品,支持的数据类型为:Tensor(half/int16_t/float/int32_t) | 
| srcLocal | 输入 | 源操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 数据类型需要与目的操作数保持一致。 Atlas 训练系列产品,支持的数据类型为:Tensor(half/float) Atlas推理系列产品AI Core,支持的数据类型为:Tensor(half/int16_t/float/int32_t) Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:Tensor(half/int16_t/float/int32_t) Atlas 200/500 A2推理产品,支持的数据类型为:Tensor(half/int16_t/float/int32_t) | 
| scalarValue | 输入 | 源操作数,数据类型需要与目的操作数中的元素类型保持一致 Atlas 训练系列产品,支持的数据类型为:half/float Atlas推理系列产品AI Core,支持的数据类型为:half/int16_t/float/int32_t Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:half/int16_t/float/int32_t Atlas 200/500 A2推理产品,支持的数据类型为:half/int16_t/float/int32_t | 
| calCount | 输入 | 输入数据元素个数。 参数取值范围和操作数的数据类型有关,数据类型不同,能够处理的元素个数最大值不同。 矢量计算单元,每个迭代读取连续256 Bytes数据进行计算,通过多次迭代完成所有数据的读取与计算。所以当操作数为16位时,calCount∈[1,128*255],255表示迭代次数的最大值,128表示每次迭代内能够处理128个16位数据;当操作数为32位时,calCount∈[1,64*255],64表示每次迭代内能够处理64个32位数据。 | 
| mask | 输入 | 
 | 
| repeatTimes | 输入 | 重复迭代次数。 矢量计算单元,每次读取连续的256 Bytes数据进行计算,为完成对输入数据的处理,必须通过多次迭代(repeat)才能完成所有数据的读取与计算。repeatTimes表示迭代的次数。 | 
| repeatParams | 输入 | 元素操作控制结构信息,具体请参考UnaryRepeatParams。 | 
返回值
无
支持的型号
Atlas 训练系列产品
Atlas推理系列产品AI Core
Atlas A2训练系列产品/Atlas 800I A2推理产品
Atlas 200/500 A2推理产品
注意事项
- 使用tensor高维切分计算接口时,节省地址空间,开发者可以定义一个Tensor,供源操作数与目的操作数同时使用(即地址重叠),相关约束如下:
      - 对于单次repeat(repeatTimes=1),且源操作数与目的操作数之间要求100%完全重叠,不支持部分重叠。
- 对于多次repeat(repeatTimes>1),操作数与目的操作数之间存在依赖的情况下,即第N次迭代的目的操作数是第N+1次的源操作数,不支持地址重叠的。
 
- 操作数地址偏移对齐要求请参见通用约束。
调用示例
- tensor高维切分计算样例-mask连续模式
       1 2 3 4 5 6 uint64_t mask = 128; int16_t scalar = 2; // repeatTimes = 4, 单次迭代处理128个数,计算512个数需要迭代4次 // dstBlkStride, srcBlkStride = 1, 每个迭代内src0参与计算的数据地址间隔为1个datablock,表示单次迭代内数据连续读取和写入 // dstRepStride, srcRepStride = 8, 相邻迭代间的地址间隔为8个datablock,表示相邻迭代间数据连续读取和写入 AscendC::Adds(dstLocal, srcLocal, scalar, mask, 4, { 1, 1, 8, 8 }); 
- tensor高维切分计算样例-mask逐bit模式
      1 2 3 4 5 6 uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; int16_t scalar = 2; // repeatTimes = 4, 单次迭代处理128个数,计算512个数需要迭代4次 // dstBlkStride, srcBlkStride = 1, 每个迭代内src0参与计算的数据地址间隔为1个datablock,表示单次迭代内数据连续读取和写入 // dstRepStride, srcRepStride = 8, 相邻迭代间的地址间隔为8个datablock,表示相邻迭代间数据连续读取和写入 AscendC::Adds(dstLocal, srcLocal, scalar, mask, 4, {1, 1, 8, 8}); 
- tensor前n个数据计算样例
      1 2 int16_t scalar = 2; AscendC::Adds(dstLocal, srcLocal, scalar, 512); 
输入数据(src0Local): [1 2 3 ... 512] 输入数据(scalar): 2 输出数据(dstLocal): [3 4 5 ... 514]