TAXPY
Introduction
Performs an in-place scaled accumulation (AXPY, ) on a tile: scales src0 by scalar and accumulates the result onto dst.
dst serves as both the accumulation input () and the output, and must be initialized before the call; src0 () is read-only; scalar () is a scalar.
Mathematical Semantics
For each element (i, j) in the valid region:
dst: read-modify-write (RMW). Reads the old value as the accumulation base , and writes back .src0: read-only. Participates in the operation element by element ().scalar: scalar scaling factor (), of typeTileDataSrc::DType.
Unless otherwise specified, the semantics are defined within the valid region, and target-dependent behavior is marked as implementation-defined.
C++ Built-in APIs
Declared in include/pto/common/pto_instr.hpp.
The public include header is
<pto/pto-inst.hpp>, and the internal declaration is located inpto/common/pto_instr.hpp.
template <typename TileDataDst, typename TileDataSrc, typename... WaitEvents>
PTO_INST RecordEvent TAXPY(TileDataDst &dst, TileDataSrc &src0, typename TileDataSrc::DType scalar,
WaitEvents &...events);| Parameter | Direction | Meaning |
|---|---|---|
dst | Input/Output | Accumulation base and result tile (), read-modify-write, Vec |
src0 | Input | Scaling source tile (), read-only, Vec, with the same valid shape as dst |
scalar | Input | Scalar scaling coefficient (), of type TileDataSrc::DType |
events... | Input | Wait events (WaitEvents), implicit TSYNC before the instruction |
Tile Size and Data Type
For a valid shape of :
| Tile | Dtype | Valid Shape | TileType | Description |
|---|---|---|---|---|
dst | half or float | Vec (UB) | Accumulation base + result (RMW) | |
src0 | half or float | Vec (UB) | Scaling source, element-wise |
The valid rows and valid columns of
dstandsrc0must be exactly the same.
Supported Input Dtypes
dst Dtype | src0 Dtype | scalar Dtype | Description |
|---|---|---|---|
half | half | half | Same-type path, directly vaxpy |
float | float | float | Same-type path, directly vaxpy |
float | half | half | Difference path: src0 is widened to FP32 before accumulation |
dstandsrc0must have the same dtype, ordstisfloatandsrc0ishalf(allowing half-to-float widened accumulation). The combination wheredstishalfandsrc0isfloatis invalid (blocked bystatic_assertin the implementation).
Implementation Notes
TAXPY executes on the vector pipe (PIPE_V) using the built-in vaxpy () vector:
- Same type (
dstandsrc0have the same dtype): loadssrc0anddstrepeat by repeat, executesvaxpy(dst, src0, scalar), and writes back todst; the columns in the tail that are less than one repeat are masked by the predicate mask. - Different type (
dst=float,src0=half): the half data ofsrc0is widened to FP32 before participating in the accumulation (on Ascend 950PR/Ascend 950DT, it is unpacked viaUNPK_B16and converted viavcvt; on Atlas A2/A3 training products/Atlas A2/A3 inference products, it is natively handled byvaxpyas 4-block src / 8-block dst). - On Atlas A2/A3 training products/Atlas A2/A3 inference products, the implementation selects between count mode and norm mode based on whether the repeat-stride overflows and on the relationship between the number of columns and the number of rows, to cover any valid shape.
Constraints
| Constraint | Scope | Reason |
|---|---|---|
dst and src0 must be TileType::Vec | All targets | Executes on UB (vector pipeline) |
dst and src0 have the same valid shape () | All targets | Element-wise one-to-one correspondence |
dst dtype ∈ {half, float} | All targets | Floating-point word width supported by vaxpy |
dst/src0 have the same dtype, or (float,half) | All targets | Only half→float widened accumulation is allowed |
dst must be initialized before the call | All targets | dst is read as the accumulation base |
Examples
// dst must be initialized first (as the accumulation base y); result: dst = scalar * src0 + dst
TAXPY(dstTile, srcTile, scalar);For complete ST examples, see tests/npu/a5/src/st/testcase/taxpy/ (A5), tests/npu/a2a3/src/st/testcase/taxpy/ (A2/A3), tests/npu/kirin9030/src/st/testcase/taxpy/ (Kirin9030), and tests/cpu/st/testcase/taxpy/ (CPU reference implementation).