tensor前n个数据计算:
template <typename T, typename U> __aicore__ inline void Axpy(const LocalTensor<T>& dstLocal, const LocalTensor<U>& srcLocal, const U& scalarValue, const int32_t& calCount)
表1 模板参数说明
| 参数名 | 描述 |
|---|---|
| T | 目的操作数数据类型。 |
| U | 源操作数数据类型。 |
表2 参数说明
| 参数名称 | 类型 | 说明 |
|---|---|---|
| dstLocal | 输出 | 目的操作数。 类型为LocalTensor,支持的TPosition为VECIN、VECCALC、VECOUT。 LocalTensor的起始地址需要32字节对齐。 Kirin9020系列处理器、Kirin9030系列处理器、KirinX90系列处理器,支持的数据类型为:half、float | 支持mixed精度类型:dst为float,src为half |
| srcLocal | 输入 | 源操作数。 类型为LocalTensor,支持的TPosition为VECIN、VECCALC、VECOUT。 LocalTensor的起始地址需要32字节对齐。 Kirin9020系列处理器、Kirin9030系列处理器、KirinX90系列处理器,支持的数据类型为:half、float | 支持mixed精度类型:dst为float,src为half |
| scalarValue | 输入 | 源操作数,scalar标量。支持的数据类型为:half/float。scalarValue的数据类型需要和srcLocal保持一致。 |
| calCount | 输入 | 输入数据元素个数。 |
该接口支持的精度组合如下。
half精度组合:srcLocal数据类型=half;scalar数据类型=half;dstLocal数据类型=half;PAR=128。
float精度组合:srcLocal数据类型=float;scalar数据类型=float;dstLocal数据类型=float;PAR=64。
mixed精度组合:srcLocal数据类型=half;scalar数据类型=half;dstLocal数据类型=float;PAR=64。
本样例中只展示Compute流程中的部分代码。如果开发者需要运行样例代码,请将该代码段拷贝并替换更多样例完整样例模板中Compute函数的部分代码即可。
tensor前n个数据计算样例:
AscendC::Axpy(dstLocal, src0Local, (half)2.0, 512);// half精度组合