Loads an offline model adapted to the Ascend AI Processor from a file. The model workspace is managed by the user. This API is synchronous.
Returns the model ID after the model is loaded. The model ID is used for model identification in subsequent operations.
The operations of loading, executing, and unloading a model must be performed in the same context. For details about how to create a context, see aclrtCreateContext.
aclError aclmdlLoadFromFileWithMem(const char *modelPath, uint32_t *modelId, void *workPtr, size_t workSize, void *weightPtr, size_t weightSize)
Parameter |
Input/Output |
Description |
|---|---|---|
modelPath |
Input |
Pointer to the .om file path, including the file name. The user who runs the app must have enough permission to access the directory. The .om file is an offline model adapted to the Ascend AI Processor.
NOTE:
For details about how to obtain the .om file, see Building a Model. When you use ATC to generate an OM file whose size is limited, set --external_weight to 1, indicating that the weight of the Const/Constant node on the original network is saved in a separate file in the weight directory. Ensure that the weight directory is at the same level as the OM file so that AscendCL can automatically search for the weight file in the weight directory when you call this API to load the OM file. Otherwise, the weight file may fail to be loaded. |
modelId |
Output |
Pointer to the model ID. The model ID will be returned after a model is loaded to the system. |
workPtr |
Input |
Pointer to the address of the workspace (for storing temporary data during model execution) required by the model on the device. The workspace is managed by the user and cannot be freed during model execution. If a null pointer is passed to workPtr, the workspace is managed by the system.
NOTE:
In the event where the memory is managed by the user, if multiple models are executed in serial, the models can share a workspace. However, you need to guarantee the serial execution sequence of the models and the workspace size (the same as the total size of the workspaces needed by all the models). Refer to the following description to ensure serial execution:
|
workSize |
Input |
Workspace size required for model execution, in bytes. Invalid when workPtr is a null pointer. |
weightPtr |
Input |
Pointer to the address of the model weight memory (for storing weight data) on the device. The memory is managed by the user and cannot be freed during model execution. If a null pointer is passed, the memory is managed by the system.
NOTE:
In the multithreaded scenario where the weight memory is managed by the user, if a model is loaded once in each thread, weightPtr can be shared because the weight memory is read-only at inference time. Note that weightPtr cannot be freed when the sharing is in progress. |
weightSize |
Input |
Weight memory size required for model execution, in bytes. Invalid when weightPtr is a null pointer. |
0 on success; else, failure.
AscendCL also provides the aclmdlSetConfigOpt and aclmdlLoadWithConfig APIs for model loading. The caller needs to set the attributes in the configuration object passed to the API call to decide how the model will be loaded and who will manage the memory.