aclmdlExecuteV2

Description

Performs model inference based on the attributes configured by the aclmdlSetExecConfigOpt API until the inference result is returned. This API is enhanced based on aclmdlExecute. It can control the timeout interval of stream tasks and event tasks during model inference.

Restrictions

  • This API must be used together with other APIs to implement model execution. The API call sequence is as follows:
    1. Call aclmdlCreateExecConfigHandle to create a configuration object for model execution.
    2. Call aclmdlSetExecConfigOpt for multiple times to set the value of each attribute in the configuration object.
    3. Call aclmdlExecuteV2 to specify the configuration information required for model execution and execute the model.
    4. After the model is successfully executed, call the aclmdlDestroyExecConfigHandle API to destroy the model.
  • Other restrictions are the same as those of aclmdlExecute.

Prototype

aclError aclmdlExecuteV2(uint32_t modelId, const aclmdlDataset *input, aclmdlDataset *output, aclrtStream stream, const aclmdlExecConfigHandle *handle)

Parameters

Parameter

Input/Output

Description

modelId

Input

Model ID for inference.

A successful aclmdlLoadFromFile, aclmdlLoadFromMem, aclmdlLoadFromFileWithMem, or aclmdlLoadFromMemWithMem call returns a model ID.

input

Input

Pointer to the input data for model inference.

output

Output

Pointer to the output data for model inference.

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.

stream

Input

Stream.

If this parameter is set to NULL, the attribute value configured through the aclmdlSetExecConfigOpt interface does not take effect.

handle

Input

Pointer to the configuration object executed by the model. The value must be the same as that of handle in aclmdlSetExecConfigOpt.

Returns

The value 0 indicates success, and other values indicate failure. For details, see aclError.