aclmdlExecuteAsync
Applicable Products
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Function Usage
Executes model inference. This API is asynchronous.
Prototype
1
|
aclError aclmdlExecuteAsync(uint32_t modelId, const aclmdlDataset *input, aclmdlDataset *output, aclrtStream stream) |
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
modelId |
Input |
Model ID for inference. After a model loading API (such as aclmdlLoadFromFile or aclmdlLoadFromMem) is successfully called, the model ID is returned. This ID is used as the input of this API. |
|
input |
Input |
Pointer to the input data for model inference. For the type definition, see aclmdlDataset. |
|
output |
Output |
Pointer to the output data for model inference. For the type definition, see aclmdlDataset. |
|
stream |
Input |
Returns
0 on success; else, failure. For details, see aclError.
Restrictions
- For models with the same modelId, aclmdlExecuteAsync cannot be called to perform model inference in the multi-stream concurrency scenario. An incorrect example is shown below. In this example, aclmdlExecuteAsync is called twice and multiple streams are concurrently executed. As a result, an error is reported.
//...... aclmdlExecuteAsync(modelId1, input, output, stream1); aclmdlExecuteAsync(modelId1, input, output, stream2); aclrtSynchronizeStream(stream1); aclrtSynchronizeStream(stream2); //......
- If the same modelId is shared by multiple threads due to service requirements, locks must be added between user threads to ensure that operations of refreshing the input and output memory and executing inference are performed continuously. For example:
// API call sequence of thread A: lock(handle1) -> aclrtMemcpyAsync(stream1) (Refresh the input and output memory) -> aclmdlExecuteAsync(modelId1,stream1) (Execute inference) -> unlock(handle1) // API call sequence of thread B: lock(handle1) -> aclrtMemcpyAsync(stream1) (Refresh the input and output memory) -> aclmdlExecuteAsync(modelId1,stream1) (Execute inference) -> unlock(handle1)
- If an external allocator is required, the stream used during allocator registration must be consistent with the stream used during model execution.
- Device memory is used for storing model input and output data. It can be allocated by calling APIs such as aclrtMalloc and hi_mpi_dvpp_malloc. The hi_mpi_dvpp_malloc API is a dedicated memory allocation API for media data processing. To reduce copying, the output of media data processing is used as the input of model inference, implementing memory reuse. The address space accessible by media data processing is limited. To ensure sufficient memory during media data processing, you are advised to call other APIs (such as aclrtMalloc) to allocate memory for other functions (such as model loading).