WholeReduceSum
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
Function Usage
Sums all data in each repeat. 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 WholeReduceSum(const LocalTensor<T>& dst, const LocalTensor<T>& src, const uint64_t mask[], const int32_t repeatTime, 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 WholeReduceSum(const LocalTensor<T>& dst, const LocalTensor<T>& src, const int32_t mask, const int32_t repeatTime, const int32_t dstRepStride, const int32_t srcBlkStride, const int32_t srcRepStride)
- Bitwise mask mode
1 2
template <typename T, bool isSetMask = true, typename U = T> __aicore__ inline void WholeReduceSum(const LocalTensor<U>& dst, const LocalTensor<T>& src, const uint64_t mask[], const int32_t repeatTime, const int32_t dstRepStride, const int32_t srcBlkStride, const int32_t srcRepStride)
- Contiguous mask mode
1 2
template <typename T, bool isSetMask = true, typename U = T> __aicore__ inline void WholeReduceSum(const LocalTensor<U>& dst, const LocalTensor<T>& src, const int32_t mask, const int32_t repeatTime, const int32_t dstRepStride, const int32_t srcBlkStride, const int32_t srcRepStride)
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Data type of the source operand. |
|
U |
Data type of the destination operand. |
|
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 the LocalTensor must be 2-byte aligned (for data of the half type) or 4-byte aligned (for data of the float type). For the Atlas 350 Accelerator Card, the supported data types are uint32_t, int32_t, half, and float. For the For the For the For the For the |
|
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. The source operand must have the same data type as the destination operand. For the Atlas 350 Accelerator Card, when the data type of src is uint16_t or int16_t, the data type of dst is uint32_t or int32_t. In other cases, the data type of dst is the same as that of src. For the Atlas 350 Accelerator Card, the supported data types are uint16_t, int16_t, uint32_t, int32_t, half, and float. For the For the For the For the For the |
|
mask/mask[] |
Input |
mask controls the elements that participate in computation in each iteration.
|
|
repeatTime |
Input |
Number of iteration repeats. The value range is [0, 255]. For details about this parameter, see High-dimensional Sharding APIs. |
|
dstRepStride |
Input |
Address stride between adjacent iterations of the destination operand. The unit is the length after reduction of a repeat. The unit is the byte length of the dst data type. For example, when dst is of the half type, the unit is 2 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.
- For details about the constraints on operand address overlapping, see General Address Overlapping Restrictions.
- WholeReduceSum uses the binary tree mode to implement internal adding.
Assume that the source operand is 128 data elements of the half type [data0, data1, data2, ..., data127], the computation can be completed in one repeat. The computation process is as follows:
- Add data0 and data1 to obtain data00, add data2 and data3 to obtain data01, ..., add data124 and data125 to obtain data62, and add data126 and data127 to obtain data63.
- Add data00 and data01 to obtain data000, add data02 and data03 to obtain data001, ..., and add data62 and data63 to obtain data031.
- By analogy, the destination operand is one data element of the half type ([data]).
When being greater than 65504, the computation result is truncated to 65504. For example, the source operand is [60000, 60000, –30000, 100], 60000 + 60000 > 65504, meaning that the result overflows. In this case, the maximum value 65504 will be used as the result. Similarly, –30000 + 100 = –29900, 65504 – 29900 = 35604.
Examples
- Example of high-dimensional tensor sharding computation (contiguous mask mode)
1 2 3
// Both dstLocal and srcLocal are of the half type. The computation data volume of srcLocal is set to 512. The data is continuously arranged, and so is the computation result. The high-dimensional tensor sharding computation API is used. mask indicates that a maximum of 128 elements are involved for computation. // Based on the preceding information, repeatTime is 4, dstRepStride is 1, srcBlkStride is 1, and srcRepStride is 8. AscendC::WholeReduceSum<half>(dstLocal, srcLocal, 128, 4, 1, 1, 8);
- Example of high-dimensional tensor sharding computation (bitwise mask mode)
1 2 3 4 5
// Both dstLocal and srcLocal are of the half type. For srcLocal, the computation data is of size 512 and is continuously arranged. Its computation result is also continuously arranged. It uses the high-dimensional tensor sharding computation API. mask is set to 128, indicating that all elements are involved in the computation. uint64_t mask[2] = { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF }; // Based on the preceding information, repeatTime is 4, dstRepStride is 1, srcBlkStride is 1, and srcRepStride is 8. AscendC::WholeReduceSum<half>(dstLocal, srcLocal, mask, 4, 1, 1, 8);
- Proper use of the reduction instruction in different scenarios can improve performance. For details about the introduction, see Selecting Low-Latency Instructions to Optimize Reduction Operation Performance. For details about examples, see ReduceCustom.