GetDigammaTmpBufferFactorSize
Function Description
To perform Digamma 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 = maxLivedNodeCount * inputSize * typeSize + extraBuffer
maxLivedNodeCount 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 maxLivedNodeCount 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 maxLivedNodeCount 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 Digamma API needs to be called for operator implementation. Developers need to reserve space of the currBuff size and use the GetDigammaTmpBufferFactorSize API to obtain the output values of maxLivedNodeCount and extraBuffer and calculate the maximum number of elements calculated by the Digamma operator at a time.
currentShapeSize = (currBuff - extraBuffer) / maxLivedNodeCount / typeSize
Prototype
1 | void GetDigammaTmpBufferFactorSize(const uint32_t typeSize, uint32_t &maxLiveNodeCount, uint32_t &extraBuffer) |
Parameters
API |
Input/Output |
Description |
|---|---|---|
typeSize |
Input |
Data type size of operator inputs. The unit is byte. For example, if the data type of operator inputs 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. |
extraBuffer |
Output |
Size of the used extra temporary space. The unit is byte. |
Returns
None
Availability
Constraints
If currentShapeSize × typeSize < 256B is obtained based on maxLiveNodeCount and extraBuffer, currentShapeSize should be rounded up based on the value of 256B/typeSize.
Example
1 2 3 4 5 6 | // Obtain maxLiveNodeCount and extraBuffer of Digamma whose input type is half. uint32_t typeSize = sizeof(half); uint32_t maxLiveNodeCount = 0; uint32_t extraBuffer = 0; AscendC::GetDigammaTmpBufferFactorSize(typeSize, maxLiveNodeCount, extraBuffer); |