AddDeqRelu
功能说明
依次计算按元素求和、结果进行deq量化后再进行relu计算(结果和0对比取较大值)。计算公式如下,其中dstType表示目的操作数的数据类型,PAR表示矢量计算单元一个迭代能够处理的元素个数:

Deq的计算公式如下:

其中DeqScale需要通过SetDeqScale进行设置。具体可参考SetDeqScale。
函数原型
- tensor前n个数据计算
      1__aicore__ inline void AddDeqRelu(const LocalTensor<half> &dstLocal, const LocalTensor<int32_t> &src0Local, const LocalTensor<int32_t> &src1Local, const int32_t &calCount) 
- tensor高维切分计算
      - mask逐bit模式
        1 2 template <bool isSetMask = true> __aicore__ inline void AddDeqRelu(const LocalTensor<half> &dstLocal, const LocalTensor<int32_t> &src0Local, const LocalTensor<int32_t> &src1Local, uint64_t mask[], const uint8_t repeatTimes, const BinaryRepeatParams &repeatParams) 
- mask连续模式
        1 2 template <bool isSetMask = true> __aicore__ inline void AddDeqRelu(const LocalTensor<half> &dstLocal, const LocalTensor<int32_t> &src0Local, const LocalTensor<int32_t> &src1Local, uint64_t mask, const uint8_t repeatTimes, const BinaryRepeatParams &repeatParams) 
 
- mask逐bit模式
        
- tensor前n个数据计算
       1 2 template <typename T, typename U> __aicore__ inline void AddDeqRelu(const LocalTensor<T>& dstLocal, const LocalTensor<U>& src0Local, const LocalTensor<U>& src1Local, const int32_t& calCount) 
- tensor高维切分计算
       - mask逐bit模式
         1 2 template <typename T, typename U, bool isSetMask = true> __aicore__ inline void AddDeqRelu(const LocalTensor<T>& dstLocal, const LocalTensor<U>& src0Local, const LocalTensor<U>& src1Local, uint64_t mask[], const uint8_t repeatTimes, const BinaryRepeatParams& repeatParams) 
- mask连续模式
         1 2 template <typename T, typename U, bool isSetMask = true> __aicore__ inline void AddDeqRelu(const LocalTensor<T> &dstLocal, const LocalTensor<U> &src0Local, const LocalTensor<U> &src1Local, uint64_t mask, const uint8_t repeatTimes, const BinaryRepeatParams &repeatParams) 
 
- mask逐bit模式
         
参数说明
| 参数名 | 描述 | 
|---|---|
| isSetMask | 是否在接口内部设置mask。 
 | 
| T | 目的操作数的数据类型。 | 
| U | 源操作数的数据类型。 | 
| 参数名 | 输入/输出 | 描述 | 
|---|---|---|
| dstLocal | 输出 | 目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 Atlas推理系列产品AI Core,支持的数据类型为:half Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:half | 
| src0Local、src1Local | 输入 | 源操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 Atlas推理系列产品AI Core,支持的数据类型为:int32_t Atlas A2训练系列产品/Atlas 800I A2推理产品,支持的数据类型为:int32_t | 
| calCount | 输入 | 输入数据元素个数。 | 
| mask | 输入 | 
 
 当源操作数和目的操作数位数不同时,以数据类型的字节较大的为准。 | 
| repeatTimes | 输入 | 重复迭代次数。矢量计算单元,每次读取连续的256 Bytes数据进行计算,为完成对输入数据的处理,必须通过多次迭代(repeat)才能完成所有数据的读取与计算。repeatTimes表示迭代的次数。 | 
| repeatParams | 输入 | 控制操作数地址步长的参数。BinaryRepeatParams类型,包含操作数相邻迭代间相同datablock的地址步长,操作数同一迭代内不同datablock的地址步长等参数。 相邻迭代间的地址步长参数说明请参考repeatStride(相邻迭代间相同datablock的地址步长);同一迭代内datablock的地址步长参数说明请参考dataBlockStride(同一迭代内不同datablock的地址步长)。 | 
返回值
无
支持的型号
Atlas推理系列产品AI Core
Atlas A2训练系列产品/Atlas 800I A2推理产品
约束说明
接口目的地址和源地址不能复用。
调用示例
本样例中只展示Compute流程中的部分代码。本样例的srcLocal为int32_t类型,dstLocal为half类型,计算mask时以int32_t为准。如果您需要运行样例代码,请将该代码段拷贝并替换双目指令样例模板更多样例中的Compute函数即可。
- tensor高维切分计算样例-mask连续模式
      1 2 3 4 5 6 7 uint64_t mask = 256 / sizeof(int32_t); // 64 // repeatTimes = 4, 一次迭代计算64个数, 共计算256个数 // dstBlkStride, src0BlkStride, src1BlkStride = 1, 单次迭代内数据连续读取和写入 // dstRepStride = 4, src0RepStride, src1RepStride = 8, 相邻迭代间数据连续读取和写入 half scale = 0.1; AscendC::SetDeqScale(scale); AscendC::AddDeqRelu(dstLocal, src0Local, src1Local, mask, 4, { 1, 1, 1, 4, 8, 8 }); 
- tensor高维切分计算样例-mask逐bit模式
      1 2 3 4 5 6 7 uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // repeatTimes = 4, 一次迭代计算64个数, 共计算256个数 // dstBlkStride, src0BlkStride, src1BlkStride = 1, 单次迭代内数据连续读取和写入 // dstRepStride = 4, src0RepStride, src1RepStride = 8, 相邻迭代间数据连续读取和写入 half scale = 0.1; AscendC::SetDeqScale(scale); AscendC::AddDeqRelu(dstLocal, src0Local, src1Local, mask, 4, { 1, 1, 1, 4, 8, 8 }); 
- tensor前n个数据计算样例
      1 2 3 half scale = 0.1; AscendC::SetDeqScale(scale); AscendC::AddDeqRelu(dstLocal, src0Local, src1Local, 512); 
输入数据(src0Local): [70 36 43 54 28 49 27 82 95 ...] 输入数据(src1Local): [19 33 34 50 42 2 97 93 99 ...] 输出数据(dstLocal): [8.9 6.9 7.7 10.4 7.0 5.1 12.4 17.5 19.4 ...]