Axpy

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Adds the product of each element of the source operand (srcTensor) and a scalar to the corresponding element in the destination operand (dstTensor). The formula is as follows.

This API has the same function as the basic API Axpy. The difference is that this API combines Muls and Add to provide higher precision.

Prototype

1
2
template <typename T, typename U, bool isReuseSource = false>
__aicore__ inline void Axpy(const LocalTensor<T>& dstTensor, const LocalTensor<U>& srcTensor, const U scalarValue, const LocalTensor<uint8_t>& sharedTmpBuffer, const uint32_t calCount)

Parameters

Table 1 Template parameters

Parameter

Description

T

Data type of the destination operand.

For the Atlas 350 Accelerator Card, the supported data types are half and float.

For the Atlas A3 training product/Atlas A3 inference product, the supported data types are half and float.

For the Atlas A2 training product/Atlas A2 inference product, the supported data types are half and float.

For the Atlas inference product AI Core, the supported data types are half and float.

U

Data type of the source operand.

For the Atlas 350 Accelerator Card, the supported data types are half and float.

For the Atlas A3 training product/Atlas A3 inference product, the supported data types are half and float.

For the Atlas A2 training product/Atlas A2 inference product, the supported data types are half and float.

For the Atlas inference product AI Core, the supported data types are half and float.

isReuseSource

Whether the source operand can be modified. This parameter is reserved. Pass the default value false.

Table 2 API parameters

Parameter

Input/Output

Description

dstTensor

Output

Destination operand.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

srcTensor

Input

Source operand.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

scalarValue

Input

Scalar. The supported data types are half and float. The type of the scalar operand must be the same as that of srcTensor.

sharedTmpBuffer

Input

Temporary buffer.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

Due to the complex mathematical computation involved in the internal implementation of this API, extra temporary space is required to store intermediate variables generated during computation. The temporary space needs to be passed through the sharedTmpBuffer input parameter by developers. For details about how to obtain the temporary space size (BufferSize), see GetAxpyMaxMinTmpSize.

calCount

Input

Number of elements involved in the computation.

Returns

None

Constraints

  • The source operand address must not overlap the destination operand address.
  • The address of sharedTmpBuffer cannot overlap that of the source or destination operand.
  • For details about the operand address alignment requirements, see General Address Alignment Restrictions.
  • The supported precision combinations are as follows.
    • half type: srcLocal data type = half; scalar data type = half; dstLocal data type = half; PAR=128
    • float type: srcLocal data type = float; scalar data type = float; dstLocal data type = float; PAR = 64
    • mix type: srcLocal data type = half; scalar data type = half; dstLocal data type = float; PAR = 64

Examples

1
2
3
4
5
6
// dstLocal: tensor for storing the Axpy computation result
// srcLocal: tensor for storing the Axpy computation input
// sharedTmpBuffer: tensor for storing the temporary buffer during Axpy computation

// The input data type of the operator is half, and the number of elements involved in the computation is 512.
AscendC::Axpy(dstLocal, srcLocal, static_cast<half>(3.0), sharedTmpBuffer, 512);

Result example:

Input (srcLocal):
[1. 2. 3. 4. 5. 6. ... 512.]
Input (scalarValue): 3.0
Initial output (dstLocal):
[0. 0. 0. 0. 0. 0. ... 0.]
Final output (dstLocal) after Axpy computation:
[3. 6. 9. 12. 15. 18. ... 1536.]