API Call Sequence

If network-wide model inference is involved, ensure that your app contains the code logic for model execution. For details about the API call sequence, see API Call Sequence.

This section describes the API call sequence for executing a model. For details about loading and executing a single-operator, see Single-Operator Execution.

Model Execution

Figure 1 Typical model inference workflow

The key APIs are described as follows:

  1. Call aclmdlCreateDesc to create data for describing the model.
  2. Call aclmdlGetDesc to obtain the model description using the model ID returned in API Call Sequence.
  3. Prepare the input and output data structures for model execution. For details, see Preparing Input/Output Data Structure for Model Execution.

    To configure dynamic batch size, dynamic image size, dynamic AIPP, or dynamic dimensions (ND format only) for your model input, see Model Inference with Dynamic-Shape Inputs and Dynamic AIPP Model Inference.

  4. Run model inference.

    In static batch size (greater than 1) scenarios, the input data is fed to your model for inference only when the input data reaches the given batch size. Design the processing logic for the remainder data that is less than the batch size as needed.

    Currently, synchronous model inference and asynchronous model inference are supported.

  5. Obtain the results of model inference for subsequent use.

    For synchronous inference, obtain the output data of model inference directly.

    For asynchronous inference with callback, obtain the model inference result from the callback function for subsequent use.

  6. Free the memory.

    Call aclrtFree to free the device memory.

  7. Destroy data of specific types.

    After the model inference is complete, call aclDestroyDataBuffer and aclmdlDestroyDataset in sequence to destroy the input data of the model. If the model takes multiple inputs or outputs, a separate call to aclDestroyDataBuffer is needed for each input or output.

Preparing Input/Output Data Structure for Model Execution

AscendCL provides the following data types to describe a model, model inputs, model outputs, and data buffers, as the input parameters of the model execution call.

Figure 2 Relationship between aclmdlDataset and aclDataBuffer

After learning related data types, you can use the operation APIs for these data types to prepare the input and output data structures of the model, as shown in the following figure.

Figure 3 Input and output data structure preparation workflow

The key points are described as follows: