Unloading a Model
After model execution is complete, unload the model and deallocate model resources.
After model inference is complete, call aclmdlUnload to unload the model, destroy the model description of the aclmdlDesc type, and free the working memory and weight memory for model running.
The following is a code snippet of key steps only, which is not ready to be built or run. After APIs are called, you need to add exception handling branches and record error logs and info logs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //1. Unload the model. aclError ret = aclmdlUnload(modelId_); //2. Destroy the model description. if (modelDesc_ != nullptr) { (void)aclmdlDestroyDesc(modelDesc_); modelDesc_ = nullptr; } //3. Free the workspace for model execution. if (modelWorkPtr_ != nullptr) { (void)aclrtFree(modelWorkPtr_); modelWorkPtr_ = nullptr; modelWorkSize_ = 0; } //4. Free the weight memory for model execution. if (modelWeightPtr_ != nullptr) { (void)aclrtFree(modelWeightPtr_); modelWeightPtr_ = nullptr; modelWeightSize_ = 0; } |
Parent topic: Model Inference with Static-Shape Inputs