ModelLoadOptV2

Description

Functions as a data structure that allows users to select one of the supported input modes for inputting data to inference models.

Select a configuration based on the actual requirements. If the configuration differs from the actual inputs, an exception will be thrown at Model. If the catch operation is not performed on the exception, a core dump error will occur in the program.

Structure Definition

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
struct ModelLoadOptV2 {
    enum ModelLoadType {
        LOAD_MODEL_FROM_FILE = 1,
        LOAD_MODEL_FROM_FILE_WITH_MEM,
        LOAD_MODEL_FROM_MEM,
        LOAD_MODEL_FROM_MEM_WITH_MEM
    };
    enum ModelType {
        MODEL_TYPE_OM = 0,
        MODEL_TYPE_MINDIR
    };
    ModelType modelType = MODEL_TYPE_OM;
    ModelLoadType loadType = LOAD_MODEL_FROM_FILE;
    std::string modelPath = "";
    void* modelPtr = nullptr;
    void* modelWorkPtr = nullptr;
    void* modelWeightPtr = nullptr;
    size_t modelSize = 0;
    size_t workSize = 0;
    size_t weightSize = 0;
};

Parameters

Parameter

Input/Output

Description

modelType

Input

Inference model type. The options are as follows:

  • MODEL_TYPE_OM (default)
  • MODEL_TYPE_MINDIR (For MindIR models, only static shapes and dynamic batches are supported.)

loadType

Input

Input type of the inference model. You can select an input mode by setting the following parameters:

  • LOAD_MODEL_FROM_FILE (default): loads offline model data from a file. The memory is managed by the system.
  • LOAD_MODEL_FROM_FILE_WITH_MEM: loads offline model data from a file. The memory (including the workspace for storing temporary data during model execution and weight memory for storing the model weight data) is managed by the user.
  • LOAD_MODEL_FROM_MEM: loads offline model data from the memory. The memory is managed by the system.
  • LOAD_MODEL_FROM_MEM_WITH_MEM: loads offline model data from the memory. The memory (including the workspace and weight memory) is managed by the user.
  • When modelType is set to MODEL_TYPE_MINDIR, only the LOAD_MODEL_FROM_FILE and LOAD_MODEL_FROM_MEM input types are supported.

modelPath

Input

Path of the inference model file. This parameter takes effect only in the following modes. The default value is "". A model with a maximum size of 4 GB is supported, and it is recommended that the model owner be the current user. The permission on the model file must be less than or equal to 640.

  • LOAD_MODEL_FROM_FILE
  • LOAD_MODEL_FROM_FILE_WITH_MEM

modelPtr

Input

Pointer to the memory address of the inference model. This parameter takes effect only in the following modes. The default value is nullptr. Enter the memory address as required.

  • LOAD_MODEL_FROM_MEM
  • LOAD_MODEL_FROM_MEM_WITH_MEM

modelWorkPtr

Input

Pointer to the workspace address of the inference model. This parameter takes effect only in the following modes. The default value is nullptr, indicating that the system manages the memory.

  • LOAD_MODEL_FROM_FILE_WITH_MEM
  • LOAD_MODEL_FROM_MEM_WITH_MEM

modelWeightPtr

Input

Pointer to the weight memory address of the inference model. This parameter takes effect only in the following modes. The default value is nullptr, indicating that the system manages the memory.

  • LOAD_MODEL_FROM_FILE_WITH_MEM
  • LOAD_MODEL_FROM_MEM_WITH_MEM

modelSize

Input

Data length of the inference model, in bytes. This parameter takes effect only in the following modes. The default value is 0. A model with a maximum size of 4 GB is supported.

  • LOAD_MODEL_FROM_MEM
  • LOAD_MODEL_FROM_MEM_WITH_MEM

workSize

Input

Workspace size of the inference model, in bytes. The default value is 0. This parameter is invalid when modelWorkPtr is nullptr.

weightSize

Input

Weight memory size of the inference model, in bytes. The default value is 0. This parameter is invalid when modelWeightPtr is nullptr.