GetReduceMaxMinCount (ISASI)
Applicability
Product |
Supported (Only the prototype of obtaining the maximum/minimum value is supported.) |
Supported (The prototype of obtaining the maximum/minimum value and index is supported.) |
|---|---|---|
x |
√ |
|
x |
√ |
|
x |
x |
|
√ |
x |
|
x |
x |
|
x |
x |
Function Usage
Obtains the maximum/minimum values and the corresponding index values in the scenario where the ReduceMax and ReduceMin are consecutive.
Prototype
- Obtain the maximum value, minimum value, and corresponding index value in the scenario where the ReduceMax and ReduceMin are consecutive.
1 2
template <typename T> __aicore__ inline void GetReduceMaxMinCount(T &maxMinValue, T &maxMinIndex)
- Obtains the maximum and minimum values in the scenario where the ReduceMax and ReduceMin values are consecutive.
1 2
template <typename T> __aicore__ inline void GetReduceMaxMinCount(T &maxMinValue)
Parameters
Parameter |
Description |
|---|---|
T |
Data type of the ReduceMax/ReduceMin instruction. The value can be half or float. |
Parameter |
Input/Output |
Description |
|---|---|---|
maxMinValue |
Output |
Maximum/Minimum value of the ReduceMax/ReduceMin instruction. |
maxMinIndex |
Output |
Index value corresponding to the maximum/minimum value of the ReduceMax/ReduceMin instruction. |
Returns
None
Constraints
- For the
Atlas A2 training products /Atlas A2 inference products , due to the internal implementation of ReduceMax/ReduceMin, the GetReduceMaxMinCount API cannot obtain the accurate index value. During verification, the WholeReduceMax or WholeReduceMin API needs to be used to obtain the accurate index value. - For the
Atlas A3 training products /Atlas A3 inference products , due to the internal implementation of ReduceMax/ReduceMin, the GetReduceMaxMinCount API cannot obtain the accurate index value. During verification, the WholeReduceMax or WholeReduceMin API needs to be used to obtain the accurate index value. - The maxMinIndex data is stored based on the ReduceMax/ReduceMin data type. For example, when ReduceMax/ReduceMin uses the half type, the maxMinIndex data is stored based on the half type. If the data is read in the half format, the value of maxMinIndex is incorrect, therefore, to read maxMinIndex, you need to use the reinterpret_cast method to convert it to the integer type. If the input type is half, reinterpret_cast<uint16_t*> is required. If the input type is float, reinterpret_cast<uint32_t*> is required.
Examples
- Execute the ReduceMax instruction.
1 2 3 4 5
AscendC::LocalTensor<float> src; AscendC::LocalTensor<float> work; AscendC::LocalTensor<float> dst; int32_t mask = 64; AscendC::ReduceMax(dst, src, work, mask, 1, 8, true); // Continuous scenario, srcRepStride = 8 and calIndex = true
- Obtain the maximum/minimum value and the index value of the ReduceMax instruction.For the
Atlas A2 training products /Atlas A2 inference products , you need to use the WholeReduceMax instruction to obtain the accurate index value, and then call the GetReduceMaxMinCount instruction.1 2 3 4 5 6 7
AscendC::LocalTensor<float> src; AscendC::LocalTensor<float> dst; int32_t mask = 64; AscendC::WholeReduceMax(dst, src, mask, 1, 1, 1, 8); float val = 0; // Maximum/Minimum value float idx = 0; // Index value of the maximum/minimum value, which is the same as the result of ReduceMax. AscendC::GetReduceMaxMinCount<float>(val, idx);
For theAtlas A3 training products /Atlas A3 inference products , you need to use the WholeReduceMax instruction to obtain the accurate index value, and then call the GetReduceMaxMinCount instruction.1 2 3 4 5 6 7
AscendC::LocalTensor<float> src; AscendC::LocalTensor<float> dst; int32_t mask = 64; AscendC::WholeReduceMax(dst, src, mask, 1, 1, 1, 8); float val = 0; // Maximum/Minimum value float idx = 0; // Index value of the maximum/minimum value, which is the same as the result of ReduceMax. AscendC::GetReduceMaxMinCount<float>(val, idx);
For theAtlas inference product 's AI Core, you can run the GetReduceMaxMinCount command after the ReduceMax command to obtain the maximum and minimum values.1 2 3 4 5 6 7
AscendC::LocalTensor<float> src; AscendC::LocalTensor<float> work; AscendC::LocalTensor<float> dst; int32_t mask = 64; AscendC::ReduceMax(dst, src, work, mask, 1, 8, true); float val = 0; // Maximum/Minimum value AscendC::GetReduceMaxMinCount<float>(val);