GetAsinhTmpBufferFactorSize

Function

To perform Asinh computation in the kernel, developers need to reserve or allocate the temporary space. The relationship between the maximum temporary space (maxTmpBuffer) and the space occupied by the input (inputSize × typeSize) is as follows:

maxTmpBuffer = maxLiveNodeCount × inputSize × typeSize + extraBuffer

maxLiveNodeCount indicates how many times the maximum temporary space is the space occupied by the input. extraBuffer indicates the size of the extra temporary space.

This API can be used to obtain maxLiveNodeCount and extraBuffer to calculate the maximum number of elements that can be calculated by an operator at a time when the space is fixed. In addition, the value of maxLiveNodeCount obtained by the API might be 0. During computation, ensure that the value is not 0 to avoid the division-by-zero error.

The following is an example:

The Asinh API needs to be called for operator implementation. Developers need to reserve space of the currBuff size and use the GetAsinhTmpBufferFactorSize API to obtain the output values of maxLiveNodeCount and extraBuffer, to calculate the maximum number of elements in a single computation of an Asinh operator.

currentShapeSize = (currBuff – extraBuffer)/maxLiveNodeCount/typeSize

Prototype

1
void GetAsinhTmpBufferFactorSize(const uint32_t typeSize, uint32_t& maxLiveNodeCount, uint32_t& extraBuf)

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

typeSize

Input

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

maxLiveNodeCount

Output

Maximum number of live nodes, indicating how many times the maximum temporary space is the space occupied by the input.

extraBuf

Output

Size of the used extra temporary space. The unit is byte.

Returns

None

Restrictions

If currentShapeSize × typeSize < 256B is obtained based on maxLiveNodeCount and extraBuf, currentShapeSize should be rounded up based on the value of 256B/typeSize.

Example

1
2
3
4
5
6
// Obtain maxLiveNodeCount and extraBuffer of Asinh whose input type is half.
uint32_t typeSize = sizeof(half);
uint32_t maxLiveNodeCount = 0;
uint32_t extraBuffer = 0;

AscendC::GetAsinhTmpBufferFactorSize(typeSize, maxLiveNodeCount, extraBuffer);