目录

Add

Function Description

Performs addition based on elements 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> 
__aicore__ inline void Add(const LocalTensor<T>& dstLocal, const LocalTensor<T>& src0Local, const LocalTensor<T>& src1Local, const int32_t& calCount)

Parameters

Table 1 Template parameters

Parameter Description
T Operand data type.

Table 2 Parameters

Parameter Input/Output 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, float, int16_t, and int32_t.

src0Local and src1Local 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.

Both source operands must have the same data type as the destination operand.

For Kirin 9020, Kirin 9030, and Kirin X90 series processors, the supported data types include: half, float, int16_t, and int32_t.

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

For details about the alignment requirements of the operand address offset, see General Constraints.

Calling Example

This example shows only part of the code used in the computation process (Compute). If you need to run the sample code, copy the code snippet and replace the Compute function in the binary instruction template provided in More Examples.

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

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

An example of the result is as follows:

Input (src0Local): [1 2 3 ... 512]
Input (src1Local): [513 514 515 ... 1024]
Output (dstLocal): [514 516 518 ... 1536]