aclmdlGetOutputSizeByIndex
Description
Obtains the size (in bytes) of an output based on the model description.
Restrictions
If the size obtained from this call is 0, the possible cause is that the range of the output shape is unknown. Currently, the following two processing methods are available:
- Method 1: The system internally allocates output buffer of the corresponding index to save the memory. However, after the buffer data is used, free it in a timely manner. In addition, memory copy is involved in allocation, which may cause performance loss. This method can be used only when the aclmdlExecute and aclmdlExecuteV2 inference APIs are used.
When calling aclCreateDataBuffer to create the aclDataBuffer type for storing output data of the corresponding index, you can pass nullptr to the data parameter and set size to 0 to create an empty aclDataBuffer type. During model execution, the system automatically calculates and allocates the index output buffer. This method saves memory. However, you need to free the memory and reset the aclDataBuffer after using the data. In addition, memory copy is involved when the system allocates memory, which may cause performance loss.
The sample code for freeing the memory and resetting the aclDataBuffer is as follows:1 2 3 4
aclDataBuffer *dataBuffer = aclmdlGetDatasetBuffer(output, 0); // Obtain the corresponding data buffer based on the index. void *data = aclGetDataBufferAddr(dataBuffer); // Obtain the device pointer to data. aclrtFree(data ); // Free the device memory. aclUpdateDataBuffer(dataBuffer, nullptr, 0); // Reset the content in the data buffer for next inference.
- Method 2: Estimate the size of the output buffer and allocate it. You can manage it by yourself. However, the buffer size may be insufficient or exceed the threshold. If the buffer size is insufficient, the system reports an error. If it exceeds the threshold, a waste is caused.You need to estimate a large output buffer as needed. During model execution, the system checks whether the specified output buffer size meets the requirement. If no, an error message is returned, with the size of the desired output buffer displayed. You can use either of the following methods to view the error message:
- Obtain application logs and view error logs. For details about how to obtain and view logs, see Log Reference.
- Call aclGetRecentErrMsg in your app.
Prototype
size_t aclmdlGetOutputSizeByIndex(aclmdlDesc *modelDesc, size_t index)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
modelDesc |
Input |
Pointer to data of the aclmdlDesc type. Call aclmdlCreateDesc to create data of the aclmdlDesc type in advance. |
index |
Input |
Sequence number of the output to obtain, indexed starting at 0. |
Returns
If dynamic batch/image size is enabled, the output size of the maximum profile is returned. In other cases, the size of the specified output is returned. The unit is byte.