WholeReduceMax
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
Function Usage
Computes the maximum value of all data and its index in each repeat. The returned index value is the internal index of each repeat.
Prototype
- Bitwise mask mode
1 2
template <typename T, bool isSetMask = true> __aicore__ inline void WholeReduceMax(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, ReduceOrder order = ReduceOrder::ORDER_VALUE_INDEX)
- Contiguous mask mode
1 2
template <typename T, bool isSetMask = true> __aicore__ inline void WholeReduceMax(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, ReduceOrder order = ReduceOrder::ORDER_VALUE_INDEX)
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Operand data type. 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 |
|
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 4-byte aligned (for data of the half type) or 8-byte aligned (for data of the float type). |
|
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. |
|
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. When the index and the maximum/minimum value are returned, the unit is twice the length of the data type of dst. For example, when dst is of the half type, the unit is 4 bytes. When only the maximum or minimum value is returned, the unit is the length of the data type of dst. When only the index is returned, the unit is the length of the data type of uint32_t. 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. |
|
order |
Input |
Storage order of the value and index in dst and the result return behavior. The value is of the ReduceOrder type and defaults to ORDER_VALUE_INDEX. The values are as follows:
For the Atlas 350 Accelerator Card, ORDER_VALUE_INDEX, ORDER_INDEX_VALUE, ORDER_ONLY_VALUE, and ORDER_ONLY_INDEX are supported. For the For the For the For the For the |
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.
- The storage order in dst is determined by the order parameter and defaults to the maximum or minimum value followed by its index. In the returned result, the index is stored using the data type specified by dst. For example, if dst is of type half, the index is stored as half and must be converted to an integer using reinterpret_cast when it is read. If the input type is half, reinterpret_cast<uint16_t*> is required. If the input type is float, reinterpret_cast<uint32_t*> is required. For
Atlas A2 training product /Atlas A2 inference product andAtlas A3 training product /Atlas A3 inference product , when ORDER_ONLY_INDEX (only the index of the maximum or minimum value is returned) is used, reinterpret_cast<uint32_t*> must be used to read the index.For the Atlas 350 Accelerator Card, when ORDER_ONLY_INDEX is used and the operand data type is uint16_t, int16_t, or half, reinterpret_cast<uint32_t*> must be used to read the index. - 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.
Examples
- Example of high-dimensional tensor sharding computation (contiguous mask mode)
1 2 3 4 5 6 7 8 9 10 11 12 13
// 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. // Based on the preceding information, repeatTime is 4, dstRepStride is 1, srcBlkStride is 1, and srcRepStride is 8. // To obtain the maximum value and index that is stored in the format of [value, index], you can use the default order. The following is an example: AscendC::WholeReduceMax<half>(dstLocal, srcLocal, 128, 4, 1, 1, 8); // To obtain the maximum value and index that is stored in the format of [index, value], you can use the following example API: AscendC::WholeReduceMax<half>(dstLocal, srcLocal, 128, 4, 1, 1, 8, AscendC::ReduceOrder::ORDER_INDEX_VALUE); // To obtain only the maximum value that is stored in the format of [value], you can use the following example API: AscendC::WholeReduceMax<half>(dstLocal, srcLocal, 128, 4, 1, 1, 8, AscendC::ReduceOrder::ORDER_ONLY_VALUE); // To obtain only the index that is stored in the format of [index], you can use the following example API: AscendC::WholeReduceMax<half>(dstLocal, srcLocal, 128, 4, 1, 1, 8, AscendC::ReduceOrder::ORDER_ONLY_INDEX);
- Example of high-dimensional tensor sharding computation (bitwise mask mode)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// 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. // To obtain the maximum value and index that is stored in the format of [value, index], you can use the default order. The following is an example: AscendC::WholeReduceMax<half>(dstLocal, srcLocal, mask, 4, 1, 1, 8); // To obtain the maximum value and index that is stored in the format of [index, value], you can use the following example API: AscendC::WholeReduceMax<half>(dstLocal, srcLocal, mask, 4, 1, 1, 8, AscendC::ReduceOrder::ORDER_INDEX_VALUE); // To obtain only the maximum value that is stored in the format of [value], you can use the following example API: AscendC::WholeReduceMax<half>(dstLocal, srcLocal, mask, 4, 1, 1, 8, AscendC::ReduceOrder::ORDER_ONLY_VALUE); // To obtain only the index that is stored in the format of [index], you can use the following example API: AscendC::WholeReduceMax<half>(dstLocal, srcLocal, mask, 4, 1, 1, 8, AscendC::ReduceOrder::ORDER_ONLY_INDEX);
The following is an example:
Input (src_gm): [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 12 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 13 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3] If the ReduceOrder type is ORDER_VALUE_INDEX or the default value, output the data to dst_gm. [11 3.09944e-06 12 5.96046e-06 ... 13 1.13249e-06] If the ReduceOrder type is ORDER_INDEX_VALUE, output the data to dst_gm. [3.09944e-06 11 5.96046e-06 12 ... 1.13249e-06 13] If the ReduceOrder type is ORDER_ONLY_VALUE, output the data to dst_gm. [11 12 ... 13 0 0 0 ...] If the ReduceOrder type is ORDER_ONLY_VALUE, output the data to dst_gm. [3.09944e-06 0 5.96046e-06 0 ... 1.13249e-06 0] The value of index represents the binary representation of an integer value expressed in the half format. Taking the above result as an example: Among the first 128 numbers, the position of 11 in the corresponding repeat is 52. The hexadecimal value is 0x3400, corresponding to a half-precision value of 3.09944e-06. Among the second 128 numbers, the position of 12 in the corresponding repeat is 100. The hexadecimal value is 0x6400, corresponding to a half-precision value of 5.96046e-06. In the last 128 numbers, the position of 13 in the corresponding repeat is 19. The hexadecimal value is 0x1300, corresponding to a half-precision value of 1.13249e-06.