PairReduceSum
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
Function Usage
PairReduceSum: sums up two adjacent (odd and even) elements, for example, (a1, a2, a3, a4, a5, a6, ...). The result is (a1+a2, a3+a4, a5+a6, ...). For details about reduction instructions, see How to Use Reduction Compute APIs.
Prototype
- Bitwise mask mode
1 2
template <typename T, bool isSetMask = true> __aicore__ inline void PairReduceSum(const LocalTensor<T>& dst, const LocalTensor<T>& src, const int32_t repeatTime, const uint64_t mask[], const int32_t dstRepStride, const int32_t srcBlkStride, const int32_t srcRepStride)
- Contiguous mask mode
1 2
template <typename T, bool isSetMask = true> __aicore__ inline void PairReduceSum(const LocalTensor<T>& dst, const LocalTensor<T>& src, const int32_t repeatTime, const int32_t mask, const int32_t dstRepStride, const int32_t srcBlkStride, const int32_t srcRepStride)
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are half and float. For the For the For the For the For the |
|
isSetMask |
Indicates whether to set mask inside the API.
|
|
Parameter |
Input/Output |
Meaning |
|---|---|---|
|
dst |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. |
|
src |
Input |
Source operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. |
|
repeatTime |
Input |
Number of iteration repeats. The value range is [0, 255]. For details about this parameter, see High-dimensional Sharding APIs. |
|
mask/mask[] |
Input |
mask controls the elements that participate in computation in each iteration.
|
|
dstRepStride |
Input |
Address stride between adjacent iterations of the destination operand. The unit is the length after reduction of a repeat. After PairReduce is complete, the length of a repeat is halved. That is, the unit is 128 bytes. Note that this parameter cannot be set to 0 for the |
|
srcBlkStride |
Input |
Address stride of data blocks in a single iteration. For details, see dataBlockStride. |
|
srcRepStride |
Input |
Address stride between adjacent iterations of the source operand, that is, the number of data blocks skipped from the source operand in each iteration. For details, see repeatStride. |
Returns
None
Restrictions
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
- If the mask bits of every two elements are not configured (that is, the current two elements do not participate in the operation), the value in the corresponding destination operand is set to 0 for
Atlas 200I/500 A2 inference product , and the value in the corresponding destination operand does not change for other product models. For example, if the current instruction is used for 64 elements of the float type and mask is set to 62, the last two elements are not involved in the computation. For theAtlas 200I/500 A2 inference product , the last value in the destination operand is 0. For other product models, the last value in the destination operand remains unchanged.
Examples
These examples show only part of the code used in the computation.
- Example of PairReduceSum – high-dimensional tensor sharding computation (contiguous mask mode)
1 2 3 4 5 6 7 8 9
// Set mask to 128, which indicates that a maximum of 128 elements are involved for computation. int32_t mask = 256/sizeof(half); // Each repeat contains 128 elements, and there are 128 elements in total. int repeat = 1; // dstLocal: destination operand tensor // srcLocal: source operand tensor // srcBlkStride = 1. Within a repeat, there are no gaps between blocks. // dstRepStride = 1, srcRepStride = 8. There are no gaps between repeats. AscendC::PairReduceSum<half>(dstLocal, srcLocal, repeat, mask, 1, 1, 8);
- Example of PairReduceSum – high-dimensional tensor sharding computation (bitwise mask mode)
1 2 3 4 5 6 7 8 9
// Set mask to 128, which indicates that a maximum of 128 elements are involved for computation. uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // Each repeat contains 128 elements, and there are 128 elements in total. int repeat = 1; // dstLocal: destination operand tensor // srcLocal: source operand tensor // srcBlkStride = 1. Within a repeat, there are no gaps between blocks. // dstRepStride = 1, srcRepStride = 8. There are no gaps between repeats. AscendC::PairReduceSum<half>(dstLocal, srcLocal, repeat, mask, 1, 1, 8);
- Result example:
Input (src_gm): [1, 1, 1, -1, 2, 2, -1, 2, 3, 3, 3, -1, 4, 4, -2, 4, .... ] Output (dst_gm): [2, 0, 4, 1, 6, 2, 8, 2, .... ]