GetTransDataMaxMinTmpSize
Function
To perform TransData computation in the kernel, you 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. You can select a proper size within this range as the tiling parameters and pass it 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. To achieve better performance, reserve or allocate the space based on the actual buffer usage. The maximum temporary space of this API is currently equal to the minimum temporary space.
Prototype
1
|
bool GetTransDataMaxMinTmpSize(const platform_ascendc::PlatformAscendC& platform, const ge::Shape& srcShape, const ge::Shape& dstShape,const ge::DataType dataType, const TransDataConfig &config, uint32_t& maxValue, uint32_t& minValue) |
Parameters
|
API |
Input/Output |
Function |
||
|---|---|---|---|---|
|
platform |
Input |
Hardware platform information that is passed. For details about the definition of PlatformAscendC, see Constructor and Destructor. |
||
|
srcShape |
Input |
Shape size of the input source operand. The value of this parameter must be the same as the Shape information in the params.srcLayout parameter of the TransData API. |
||
|
dstShape |
Input |
Shape size of the output destination operand. The value of this parameter must be the same as the Shape information in the params.dstLayout parameter of the TransData API. |
||
|
dataType |
Input |
Input data type, which is of the ge::DataType type. For details about this type, see DataType. Currently, only the half, float, uint16_t, and int16_t data types are supported. |
||
|
config |
Input |
Data format conversion scenario. The value of the parameter must be the same as that of the config parameter of the TransData API. Currently, the following conversion scenarios are supported: NCDHW -> NDC1HWC0, NDC1HWC0 -> NCDHW, NCDHW -> FRACTAL_Z_3D, and FRACTAL_Z_3D -> NCDHW. TransDataConfig type. The specific definition is as follows:
|
||
|
maxValue |
Output |
Maximum size of the temporary space required by TransData computation. Any space exceeding this value will not be utilized by the API.
NOTE:
maxValue is for reference only and may be larger than the remaining space of the Unified Buffer. In this case, select a proper temporary space size based on the remaining space of the Unified Buffer. |
||
|
minValue |
Output |
Minimum size of the temporary space required by TransData computation. To ensure correct functions, the temporary space to be reserved or applied for during API computation cannot be less than the parameter value. |
Returns
The return value of GetTransDataMaxMinTmpSize is either true or false. true indicates that the maximum and minimum temporary space sizes required for TransData internal computation are successfully obtained. false indicates that the sizes fail to be obtained.
Restrictions
None
Example
For details about the complete call example, see More Examples.
1 2 3 4 5 6 7 8 9 |
// Convert the input shape (1,16,2,4,4)NCDHW to the output shape (1,2,1,4,4,16)NDC1HWC0. The input data type of the operator is half. uint32_t maxSize; uint32_t minSize; int32_t n = 1, c = 16, d = 2, h = 4, w = 4, c1 = 1, c0 = 16; auto ncdhwShape = ge::Shape({ n, c, d, h, w }); auto ndc1hwc0Shape = ge::Shape({ n, d, c1, h, w, c0}); auto plat = platform_ascendc::PlatformAscendC(context->GetPlatformInfo()); TransDataConfig config = {DataFormat::NCDHW, DataFormat::NDC1HWC0}; bool ret = GetTransDataMaxMinTmpSize(plat, ncdhwShape, ndc1hwc0Shape, ge::DataType::DT_FLOAT16, config, maxSize, minSize); |