Mul
产品支持情况
功能说明
按元素求积,公式表达如下:

函数原型
-
整个tensor参与计算
dst = src0 * src1; -
tensor前n个数据计算
template <typename T> __aicore__ inline void Mul(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<T>& src1, const int32_t& count) -
tensor高维切分计算
-
mask逐bit模式
template <typename T, bool isSetMask = true> __aicore__ inline void Mul(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<T>& src1, uint64_t mask[], const uint8_t repeatTime, const BinaryRepeatParams& repeatParams) -
mask连续模式
template <typename T, bool isSetMask = true> __aicore__ inline void Mul(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<T>& src1, uint64_t mask, const uint8_t repeatTime, const BinaryRepeatParams& repeatParams)
-
参数说明
表 1 模板参数说明
|
Ascend 950PR/Ascend 950DT,支持的数据类型为:int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float、complex32、int64_t、uint64_t、complex64。 Atlas A3 训练系列产品/Atlas A3 推理系列产品,支持的数据类型为:half、int16_t、int32_t、float。 Atlas A2 训练系列产品/Atlas A2 推理系列产品,支持的数据类型为:half、int16_t、int32_t、float。 |
|
|
表 2 参数说明
|
类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 |
||
|
类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 |
||
|
||
重复迭代次数。矢量计算单元,每次读取连续的256Bytes数据进行计算,为完成对输入数据的处理,必须通过多次迭代(repeat)才能完成所有数据的读取与计算。repeatTime表示迭代的次数。 |
||
控制操作数地址步长的参数。BinaryRepeatParams类型,包含操作数相邻迭代间相同datablock的地址步长,操作数同一迭代内不同datablock的地址步长等参数。 |
返回值说明
无
约束说明
-
操作数地址对齐要求请参见通用地址对齐约束。
-
操作数地址重叠约束请参考通用地址重叠约束。
-
使用整个tensor参与计算接口符号重载时,运算量为目的LocalTensor的总长度。
-
针对Ascend 950PR/Ascend 950DT,uint64_t/int64_t/complex32/complex64数据类型仅支持tensor前n个数据计算接口和整个tensor参与计算的运算符重载。
调用示例
更多样例可参考LINK。
-
tensor高维切分计算样例-mask连续模式
uint64_t mask = 128; // repeatTime = 4,一次迭代计算128个数,共计算512个数 // dstBlkStride, src0BlkStride, src1BlkStride = 1,单次迭代内数据连续读取和写入 // dstRepStride, src0RepStride, src1RepStride = 8,相邻迭代间数据连续读取和写入 AscendC::Mul(dstLocal, src0Local, src1Local, mask, 4, { 1, 1, 1, 8, 8, 8 }); -
tensor高维切分计算样例-mask逐bit模式
uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // repeatTime = 4,一次迭代计算128个数,共计算512个数 // dstBlkStride, src0BlkStride, src1BlkStride = 1,单次迭代内数据连续读取和写入 // dstRepStride, src0RepStride, src1RepStride = 8,相邻迭代间数据连续读取和写入 AscendC::Mul(dstLocal, src0Local, src1Local, mask, 4, { 1, 1, 1, 8, 8, 8 }); -
tensor前n个数据计算样例
AscendC::Mul(dstLocal, src0Local, src1Local, 512); -
整个tensor参与计算样例
dstLocal = src0Local * src1Local;
结果示例如下:
输入数据src0Local:[1 2 3 ... 512]
输入数据src1Local:[2 2 2 ... 2]
输出数据dstLocal:[2 4 6... 1024]