GetReduceProdMaxMinTmpSize

Function

To perform ReduceProd computation on the kernel, you need to reserve or allocate the temporary space. This API is used to obtain the maximum and minimum temporary space sizes 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.

  • For correct functions, ensure that 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. To achieve better performance, reserve or allocate the space based on the actual buffer usage. The maximum temporary space of this API is currently equal to the minimum temporary space.

Prototype

1
void GetReduceProdMaxMinTmpSize(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

Parameter

Input/Output

Function

srcShape

Input

Shape size of the input data. The parameter value must be the same as that of the srcShape parameter of the ReduceProd 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 ReduceProd API.

pattern

Input

Computation axis of ReduceProd. The ReducePattern 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 ReduceProd 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

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

isReuseSource

Input

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

maxValue

Output

Maximum size of the temporary space required by ReduceProd 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 ReduceProd computation. For correct functions, ensure that the size of the temporary space to be reserved or allocated during API computation cannot be less 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
// The input shape is a 16 × 32 matrix. The data type of the operator input is float. The default value false is passed to isReuseSource.
uint32_t maxSize;
uint32_t minSize;
auto shape = ge::Shape({ 16, 32 });
AscendC::GetReduceProdMaxMinTmpSize(shape, ge::DataType::DT_FLOAT, AscendC::ReducePattern::AR, true, false, maxSize, minSize);