Function: get_output_size_by_index

C Prototype

size_t aclmdlGetOutputSizeByIndex(aclmdlDesc *modelDesc, size_t index)

Python Function

size = acl.mdl.get_output_size_by_index(model_desc, index)

Function Usage

Obtains the output size in bytes based on data of the aclmdlDesc type.

Input Description

model_desc: int, pointer address of the data of the aclmdlDesc type. Call acl.mdl.create_desc to create data of the aclmdlDesc type in advance.

index: int, sequence number of the output to be obtained, starting from 0.

Return Value

size: int, size of the output, in bytes.

  • 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.

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:

  • 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.

    When calling acl.create_data_buffer to create the aclDataBuffer type for storing output data of the corresponding index, you can pass 0 to the data parameter to create an empty aclDataBuffer type. During model execution, the system automatically calculates and allocates the index output buffer.

  • 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 app logs and view errors at the ERROR level. For details about how to obtain logs, see Log Reference.
    • Call Function: get_recent_err_msg in your app.