If the dynamic dimensions (ND format only) feature is involved during model inference, call the AscendCL API to set the dimensions. The dimensions supported by the model have been configured during model building (by using the dynamic_dims parameter of ATC).
For details about the ATC parameter, see ATC Instructions.
Following the API calls, add exception handling branches and specify log printing of error and information levels. The following is a code snippet of key steps only, which is not ready to be built or run.
//1. Load the model and then set the runtime dimensions.
// ......
//2. Prepare the model description modelDesc_, and the model inputs input_ and model outputs output_.
// ......
//3. Customize a function to set the runtime dimensions.
int ModelSetDynamicInfo()
{
size_t index;
//3.1 Obtain the indexes of the inputs with dynamic dimensions. The input name is fixed to ACL_DYNAMIC_TENSOR_NAME.
aclError ret = aclmdlGetInputIndexByName(modelDesc_, ACL_DYNAMIC_TENSOR_NAME, &index);
//3.2 Set the runtime dimensions, including the dimension count (dimCount) and the size of each dimension. modelId_ indicates the ID of a successfully loaded model, input_ indicates data of type aclmdlDataset, and index indicates the index of the input with dynamic dimensions.
aclmdlIODims currentDims;
currentDims.dimCount = 4;
currentDims.dims[0] = 8;
currentDims.dims[1] = 3;
currentDims.dims[2] = 224;
currentDims.dims[3] = 224;
ret = aclmdlSetInputDynamicDims(modelId_, input_, index, ¤tDims);
// ......
}
//4. Customize a function to execute the model.
int ModelExecute(int index)
{
aclError ret;
//4.1 Call the user-defined function to set the runtime dimensions.
ret = ModelSetDynamicInfo();
//4.2 Execute the model. modelId_ indicates the ID of a successfully loaded model, input_ indicates the model inputs, and output_ indicates the model outputs.
ret = aclmdlExecute(modelId_, input_, output_);
// ......
}
//5. Process the model inference result.
// TODO