目录

Axpy

Function Description

Adds the product of each element in srcLocal and a scalar to the corresponding element in dstLocal using the following formula, where PAR indicates the number of elements that can be processed by the Vector Unit in one iteration.

Function Prototype

Computation of the first n data elements of a tensor:

template <typename T, typename U> 
__aicore__ inline void Axpy(const LocalTensor<T>& dstLocal, const LocalTensor<U>& srcLocal, const U& scalarValue, const int32_t& calCount)

Parameters

Table 1 Template parameters

Parameter Description
T Data type of the destination operand.
U Data type of the source operands.

Table 2 Parameters

Parameter Type Description
dstLocal Output

Destination operand.

The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT.

The start address of the LocalTensor must be 32-byte aligned.

For Kirin 9020, Kirin 9030, and Kirin X90 series processors, the supported data types include half and float. The supported mixed precision type is float for dst and half for src.

srcLocal Input

Source operand

The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT.

The start address of the LocalTensor must be 32-byte aligned.

For Kirin 9020, Kirin 9030, and Kirin X90 series processors, the supported data types include half and float. The supported mixed precision type is float for dst and half for src.

scalarValue Input Source operand (scalar). The supported data types are half and float. The data type of scalarValue must be the same as that of srcLocal.
calCount Input Number of elements of the input data.

Return Value

None

Supported Models

Kirin 9020 series processors

Kirin 9030 series processors

Kirin X90 series processors

Restrictions

The supported precision combinations are as follows.

Calling Example

This example shows only part of the code used in the computation process (Compute). To run the sample code, copy the code snippet and replace parts of code of the Compute function in the complete sample template in More Samples.

Example of computing the first n data elements of a tensor:

AscendC::Axpy(dstLocal, src0Local, (half)2.0, 512);// half type