GetGeluMaxMinTmpSize

Function Usage

To perform Gelu, FasterGelu, and FasterGeluV2 computations 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. Developers 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 from the minimum to the maximum, as the temporary space increases, the API compute performance in the kernel can be optimized to some extent. To achieve better performance, reserve or allocate the space based on the actual buffer usage.

Prototype

  • API for obtaining the maximum temporary space required for kernel computation
    1
    uint32_t GetGeluMaxTmpSize(const ge::Shape& srcShape, const uint32_t typeSize)
    
  • API for obtaining the minimum temporary space required for kernel computation
    1
    uint32_t GetGeluMinTmpSize(const ge::Shape& srcShape, const uint32_t typeSize)
    
  • APIs for obtaining the minimum and maximum temporary space required for kernel computation
    1
    void GetGeluMaxMinTmpSize(const ge::Shape& srcShape, const uint32_t typeSize, uint32_t& maxValue, uint32_t& minValue)
    

Parameters

Table 1 Parameters

API

Input/Output

Description

srcShape

Input

Input shape.

typeSize

Input

Size of the input data type, in bytes. For example, if the input data type is half, set this parameter to 2.

maxValue

Output

Maximum size of the temporary space required by Gelu, FasterGelu, and FasterGeluV2 computations. Any space exceeding this value will not be utilized by the API. Within the range from the minimum to the maximum, as the temporary space increases, the API compute performance in the kernel can be optimized to some extent. To achieve better performance, reserve or allocate the space based on the actual buffer usage. If the maximum space size is 0, no temporary space is required.

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 Gelu, FasterGelu, and FasterGeluV2 computations. To ensure correct functions, the size of the temporary space to be reserved or allocated during API computation cannot be less than the value of this parameter. If the minimum space size is 0, no temporary space is required.

Returns

GetGeluMaxTmpSize returns the maximum temporary space required by APIs on the kernel.

GetGeluMinTmpSize returns the minimum temporary space required by APIs on the kernel.

No value is returned for GetGeluMaxMinTmpSize.

Constraints

None

Examples

1
2
3
4
5
6
7
// The input shape information is 1024, and the input data type of the operator is half.
std::vector<int64_t> shape_vec = {1024};
ge::Shape srcShape(shape_vec);
uint32_t typeSize = 2;
uint32_t maxValue = 0;
uint32_t minValue = 0;
AscendC::GetGeluMaxMinTmpSize(srcShape, typeSize, maxValue, minValue);