跳到主要内容

Mul

功能说明

按元素求积,公式表达如下,其中PAR表示矢量计算单元一个迭代能够处理的元素个数:

函数原型

tensor前n个数据计算:

template <typename T>
__aicore__ inline void Mul(const LocalTensor<T>& dstLocal, const LocalTensor<T>& src0Local, const LocalTensor<T>& src1Local, const int32_t& calCount)

参数说明

表1 模板参数说明

参数名描述
T操作数数据类型。

表2 参数说明

参数名输入/输出描述
dstLocal输出目的操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 Kirin9020系列处理器,支持的数据类型为: 前n个tensor:int16_t、int32_t、half、float32_t KirinX90系列处理器,支持的数据类型为: 前n个tensor:int16_t、int32_t、half、float32_t
src0Local、src1Local输入源操作数。 类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。 LocalTensor的起始地址需要32字节对齐。 两个源操作数的数据类型需要与目的操作数保持一致。 Kirin9020系列处理器,支持的数据类型为: 前n个tensor:int16_t、int32_t、half、float32_t KirinX90系列处理器,支持的数据类型为: 前n个tensor:int16_t、int32_t、half、float32_t
calCount输入输入数据元素个数。

返回值

支持的型号

Kirin9020系列处理器

KirinX90系列处理器

注意事项

操作数地址偏移对齐要求请参见通用约束

调用示例

本样例中只展示Compute流程中的部分代码。如果开发者需要运行样例代码,请将该代码段拷贝并替换双目指令样例模板更多样例中的Compute函数即可。

tensor前n个数据计算样例:

AscendC::Mul(dstLocal, src0Local, src1Local, 512);

结果示例如下。

输入数据(src0Local): [1 2 3 ... 512]
输入数据(src1Local): [2 2 2 ... 2]
输出数据(dstLocal): [2 4 6... 1024]