GetReduceRepeatMaxMinSpr(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 350 Accelerator Card

x

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

x

Atlas training product

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 GetReduceRepeatMaxMinSpr(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 GetReduceRepeatMaxMinSpr(T &maxMinValue)
    

Parameters

Table 1 Parameters in the template

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 product/Atlas A2 inference product, due to the internal implementation of ReduceMax or ReduceMin, the GetReduceRepeatMaxMinSpr 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 product/Atlas A3 inference product, due to the internal implementation of ReduceMax or ReduceMin, the GetReduceRepeatMaxMinSpr 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 350 Accelerator Card, due to the internal implementation of ReduceMax or ReduceMin, the GetReduceRepeatMaxMinSpr API cannot obtain the accurate index value. During verification, the WholeReduceMax or WholeReduceMin API needs to be used to obtain the accurate index value. In addition, the GetReduceRepeatMaxMinSpr API must be called immediately after the WholeReduceMax or WholeReduceMin API.
  • The maxMinIndex data is stored based on the data type of ReduceMax or ReduceMin. For example, if ReduceMax or 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.

Examples

  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 product/Atlas A2 inference product, you need to use the WholeReduceMax instruction to obtain the accurate index value, and then call the GetReduceRepeatMaxMinSpr 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 value
    float idx = 0; // Index value of the maximum value, which must match the result of ReduceMax. Ensure the calling order is the same as WholeReduceMax, and the operation is called in pairs.
    AscendC::GetReduceRepeatMaxMinSpr<float>(val, idx);
    
    For the Atlas A3 training product/Atlas A3 inference product, you need to use the WholeReduceMax instruction to obtain the accurate index value, and then call the GetReduceRepeatMaxMinSpr 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 value
    float idx = 0; // Index value of the maximum value, which must match the result of ReduceMax. Ensure the calling order is the same as WholeReduceMax, and the operation is called in pairs.
    AscendC::GetReduceRepeatMaxMinSpr<float>(val, idx);
    
    For the Atlas inference product AI Core, you can use the GetReduceRepeatMaxMinSpr instruction after calling ReduceMax 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 value
    AscendC::GetReduceRepeatMaxMinSpr<float>(val); // Ensure the calling order is the same as WholeReduceMax, and the operation is called in pairs.
    
    For the Atlas 350 Accelerator Card, you need to execute the WholeReduceMax instruction and then immediately call the GetReduceRepeatMaxMinSpr instruction.
    1
    2
    3
    4
    5
    6
    7
    AscendC::LocalTensor<float> src;
    AscendC::LocalTensor<float> dst;
    int32_t mask = 64;
    float val = 0;   // Maximum value
    float idx = 0;   // Index value of the maximum value, which is the same as the result of ReduceMax.
    AscendC::WholeReduceMax(dst, src, mask, 1, 1, 1, 8);
    AscendC::GetReduceRepeatMaxMinSpr<float>(val, idx); // Ensure the calling order is the same as WholeReduceMax, and the operation is called in pairs.