GetReduceSumMaxMinTmpSize

Function

To perform ReduceSum computation on the kernel, developers need to reserve or allocate the temporary space. This API is used to obtain the maximum and minimum sizes of the temporary space to be reserved or allocated on the host. You can select a proper size within this range as the tiling parameter and pass it to the kernel.

  • To ensure correct functions, the temporary space to be reserved or allocated cannot be less than the minimum temporary space.
  • Within the range between the minimum and maximum, as the temporary space increases, the API computing performance in the kernel is optimized to some extent. For better performance, reserve or allocate the temporary space based on the actual memory usage. The maximum temporary space of this API is currently equal to the minimum temporary space.

Prototype

1
void GetReduceSumMaxMinTmpSize(const ge::Shape& srcShape, const ge::DataType dataType, ReducePattern pattern, bool isSrcInnerPad, bool isReuseSource, uint32_t& maxValue, uint32_t& minValue)

Parameters

Table 1 API parameters

API

Input/Output

Function

srcShape

Input

Input shape information. The parameter value must be the same as that of the srcShape parameter of the ReduceSum API.

dataType

Input

Input data type, which is of the ge::DataType type. For details about the definition of this type, see DataType. Currently, the supported data types are consistent with the template parameter T of the ReduceSum API.

pattern

Input

Specifies the computation axis of ReduceSum. ReducePattern type. This type is defined as follows, including the Reduce axis and Normal axis. pattern is a string composed of letters A (standing for Normal axis) and R (standing for Reduced axis), with the number of letters equal to the number of dimensions in the input vector. The value of this parameter must be the same as that of the pattern parameter of the ReduceSum API. Currently, only AscendC::ReducePattern::AR and AscendC::ReducePattern::RA are supported.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
enum class ReducePattern : uint32_t {
    AR = 0,
    RA = 1,
    R,
    ARA,
    ARAR,
    ARARA,
    ARARAR,
    ARARARA,
    ARARARAR,
    ARARARARA,
    RAR,
    RARA,
    RARAR,
    RARARA,
    RARARAR,
    RARARARA,
};

isSrcInnerPad

Input

Indicates whether the innermost axis data to be computed is 32-byte aligned. The value of this parameter must be the same as that of the isSrcInnerPad parameter of the ReduceSum API.

isReuseSource

Input

Indicates whether to reuse the space of the source operand input. The value of this parameter must be the same as that of the isReuseSource parameter of the ReduceSum API.

maxValue

Output

Maximum size of the temporary space required by ReduceSum computation. Any space exceeding this value will not be utilized by the API.

NOTE:

maxValue is for reference only and may be larger than the remaining space of the Unified Buffer. In this case, select a proper temporary space size based on the remaining space of the Unified Buffer.

minValue

Output

Minimum size of the temporary space required by ReduceSum computation. To ensure correct functions, the size of the temporary space to be reserved or allocated during API computation cannot be smaller than the value of this parameter.

Returns

None

Restrictions

None

Example

For details about the complete call example, see More Examples.

1
2
3
4
5
6
7
// The input shape is 1024. The operator input data is of the float type. The source operand cannot be modified.
auto shape = ge::Shape({ 16, 32 });
uint32_t maxValue = 0;
uint32_t minValue = 0;
bool isSrcInnerPad = true;
bool isReuseSource = false;
AscendC::GetReduceSumMaxMinTmpSize(shape, ge::DataType::DT_FLOAT, AscendC::ReducePattern::AR, isSrcInnerPad, isReuseSource, maxValue, minValue);