GetLgammaTmpBufferFactorSize
Function Description
Obtains maxLiveNodeCnt and extraBuf to calculate the maximum number of elements that can be calculated by an operator at a time when the space is fixed. maxLiveNodeCnt indicates how many times the temporary space is the data volume computed per time. extraBuf indicates the size of the extra temporary space.
Example:
- The Lgamma API needs to be called for operator implementation. Developers need to reserve space of the currBuff size and use the GetLgammaTmpBufferFactorSize API to obtain the output values of maxLivedNodeCnt and extraBuf and calculate the maximum number of elements calculated by the operator at a time.
currentShapeSize = (currBuff - extraBuf) / maxLivedNodeCnt / typeSize
- To implement the operator, two kernel APIs KernelIntf1 and KernelIntf2 need to be called. Two output values (maxLivedNodeCnt and extraBuf) of two GetXxxTmpBufferFactorSize API functions (Xxx indicates the two high-level APIs to be called) and the existing temporary space are used to compute the maximum number of elements in a single computation (currentShapeSize).
currentShapeSize1 = (currBuff - extraBuf1) / maxLivedNodeCnt1 / typeSize
currentShapeSize2 = (currBuff - extraBuf2) / maxLivedNodeCnt2 / typeSize
currentShapeSize = min(currentShapeSize1, currentShapeSize2)
Note that currBuff indicates the available space for API computation. The space such as user input and output needs to be excluded. In addition, the value of maxLivedNodeCnt obtained by the API might be 0. During computation, ensure that the value is not 0 to avoid the division-by-zero error.
Prototype
1 | void GetLgammaTmpBufferFactorSize(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 active nodes, indicating how many times the temporary space is the data volume computed per time. |
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 | uint32_t maxLiveNodeCnt = 0; uint32_t extraBuf = 0; AscendC::GetLgammaTmpBufferFactorSize(typeSize, maxLiveNodeCnt, extraBuf); |