GetReduceMaxMinCount (ISASI)

Applicability

Product

Supported (Prototype for Obtaining Only the Maximum/Minimum Value)

Supported (Prototype for Obtaining Both the Maximum/Minimum Value and Its Index)

Atlas A3 training products/Atlas A3 inference products

x

Atlas A2 training products/Atlas A2 inference products

x

Atlas 200I/500 A2 inference products

x

x

Atlas inference product's AI Core

x

Atlas inference product's Vector Core

x

x

Atlas training products

x

x

Function

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

Table 1 Template parameters

Parameter

Description

T

Data type of the ReduceMax/ReduceMin instruction. The value can be half or float.

Table 2 Parameters

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

Restrictions

  • 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 data type of ReduceMax/ReduceMin. For example, if ReduceMax/ReduceMin uses the half type, maxMinIndex is stored in half format. Reading the data directly as half will yield incorrect values. For this reason, maxMinIndex must be converted to an integer using reinterpret_cast. If the input data type is half, reinterpret_cast<uint16_t*> is used; if the input data type is float, reinterpret_cast<uint32_t*> is used.

Example

  1. 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
    
  2. 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 the Atlas 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 the Atlas 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);