LogSoftMax Tiling
Function
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 between the minimum and maximum, as the temporary space increases, the API computing performance in the kernel can be optimized to some extent. For better performance, reserve or allocate the temporary space based on the actual memory 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
Parameter |
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. |
Parameter |
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.
Restrictions
None
Example
1 2 3 4 5 6 7 8 | static ge::graphStatus TilingFunc(gert::TilingContext* context) { std::vector<int64_t> srcDims = {outter, inner}; ge::Shape shape(srcDims); const uint32_t tmpsize = AscendC::GetLogSoftMaxMaxTmpSize(shape, dtypesize, false); AscendC::LogSoftMaxTilingFunc(shape, dtypesize, tmpsize, tiling.logSoftmaxTilingData); ... } |