LogSoftMax Tiling
Function Usage
To perform LogSoftMax computation in the kernel, developers 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. Developers can also call LogSoftMaxTilingFunc to obtain parameters such as reduceSize and splitSize and pass them as the tiling parameters 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
- APIs for obtaining the minimum and maximum temporary space required for kernel computation
1uint32_t GetLogSoftMaxMaxTmpSize(const ge::Shape srcShape, const uint32_t dataTypeSize, const bool isReuseSource)
1uint32_t GetLogSoftMaxMinTmpSize(const ge::Shape srcShape, const uint32_t dataTypeSize, const bool isReuseSource)
- Tiling computation APIs
1void LogSoftMaxTilingFunc(const ge::Shape srcShape, const uint32_t dataTypeSize, const uint32_t localWorkSpaceSize, optiling::LogSoftMaxTiling& softmaxTiling)
1void LogSoftMaxTilingFunc(const ge::Shape srcShape, const uint32_t dataTypeSize, const uint32_t localWorkSpaceSize, AscendC::tiling::LogSoftMaxTiling& softmaxTiling)
Parameters
API |
Input/Output |
Description |
|---|---|---|
srcShape |
Input |
Input shape. |
dataTypeSize |
Input |
Size of the input data type, in bytes. For example, if the input data type is half, set this parameter to 2. |
isReuseSource |
Input |
Whether to reuse the space of the source operand input, which must be the same as that of the LogSoftMax API. |
API |
Input/Output |
Description |
|---|---|---|
srcShape |
Input |
Input shape. |
dataTypeSize |
Input |
Size of the input data type, in bytes. For example, if the input data type is half, set this parameter to 2. |
localWorkSpaceSize |
Input |
Input temporary space. |
softmaxTiling |
Output |
Tiling parameters passed to the kernel. |
Returns
The GetLogSoftMaxMaxTmpSize API returns the maximum temporary space, and the GetLogSoftMaxMinTmpSize API returns the minimum temporary space.
The LogSoftMaxTilingFunc API does not return any value.
Constraints
None
Examples
1 2 3 4 5 6 7 8 9 10 11 12 | // shape: input shape. // dtypesize: size of the input data type, in bytes. // Defines the tiling parameter structure instance of the LogSoftMax operator. AscendC::tiling::LogSoftMaxTiling tilingData; // Whether to reuse the space of the source operand input, which must be the same as that of the LogSoftMax API. bool isReuseSource = false; // Obtains the maximum temporary space required for computation. const uint32_t tmpsize = AscendC::GetLogSoftMaxMaxTmpSize(shape, dtypesize, isReuseSource); // Computes the optimal fragmentation policy and fills it in the TilingData structure for the kernel. AscendC::LogSoftMaxTilingFunc(shape, dtypesize, tmpsize, tilingData); |