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.

The function of this API is the same as that of the basic Axpy API. The difference is that this API performs computation based on the combination of Muls and Add.
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
Parameter |
Description |
|---|---|
T |
Data type of the destination operand. |
U |
Data type of the source operand. |
isReuseSource |
Whether the source operand can be modified. This parameter is reserved. Pass the default value false. |
Parameter |
Input/Output |
Description |
|---|---|---|
dstTensor |
Output |
Destination operand. The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT. |
srcTensor |
Input |
Source operand. The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT. The source operand must have the same data type as the destination operand. |
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 the supported TPosition is VECIN, VECCALC, or VECOUT. Due to the complex mathematical computation involved in the internal implementation of this API, additional 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 actually computed data elements. The value range is [0, srcTensor.GetSize()]. |
Returns
None
Availability
Constraints
- The source operand address must not overlap the destination operand address.
- sharedTmpBuffer must not overlap the addresses of the source operand and destination operand.
- For details about the alignment requirements of the operand address offset, see General 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
Example
For details about the complete call example, see More Examples.
1 2 3 4 5 6 | AscendC::TPipe pipe; AscendC::TQue<AscendC::TPosition::VECCALC, 1> tmpQue; pipe.InitBuffer(tmpQue, 1, bufferSize); // bufferSize is obtained through the tiling parameter on the host. AscendC::LocalTensor<uint8_t> sharedTmpBuffer = tmpQue.AllocTensor<uint8_t>(); // The input shape is 1024, the input data type of the operator is half, and the actually computed data elements is 512. AscendC::Axpy(dstLocal, srcLocal, static_cast<half>(3.0), sharedTmpBuffer, 512); |
Input data (srcLocal): [104.875 107.4375 -62.59375 ... -242.875 15.8828125] Output data (dstLocal): [316.5 324.2 185.8 ... -726.5 49.66]