Class QnnModel

Class Documentation

class QnnModel

Public Functions

~QnnModel() = default
ModelError_t initialize(const Qnn_BackendHandle_t &backendHandle, const QNN_INTERFACE_VER_TYPE &qnnInterface, const Qnn_ContextHandle_t &context, const char *graphName, bool debug, uint8_t doNodeValidations = 1, const QnnGraph_Config_t **graphConfigs = nullptr)

Creates a Qnn Graph within given context.

Parameters
  • backendHandle[in] A handle to the QNN backend handle which will be used to query the API symbols

  • qnnInterface[in] the QNN backend interface to use

  • context[in] A handler to the context where the model’s graph would be created.

  • graphName[in] The name to use for creating a graph in the context provided.

  • debug[in] If flag is true, sets all tensors created in model to be QNN_TENSOR_TYPE_APP_READ, essentially overwriting what is set in Qnn_TensorType.

  • doNodeValidations[in] If flag is set, all nodes added with addNode call will be validated by Backend

  • graphConfigs[in] Array of graph configurations to use for creating the QNN Graph. Default: nullptr

ModelError_t addTensor(const char *nodeName, Qnn_Tensor_t *tensor, bool saveTensor = true)

A wrapper function to create a tensor inside class’s context graph.

Parameters
  • nodeName[in] Lookup name for node/layer

  • tensor[in] A pointer to a struct containing information on the tensor

  • saveTensor[in] Flag to indicate if tensor should be saved in object for later retrieval with class getter functions.

Returns

Error code

ModelError_t addTensor(const char *nodeName, Qnn_Tensor_t tensor, bool saveTensor = true)

A wrapper function to create a tensor inside class’s context graph.

Parameters
  • nodeName[in] Lookup name for node/layer

  • tensor[in] A struct containing information on the tensor

  • saveTensor[in] Flag to indicate if tensor should be saved in object for later retrieval with class getter functions.

Returns

Error code

ModelError_t getQnnTensor(const char *&nodeName, const char *&tensorName, Qnn_Tensor_t &tensor)

function to be used to query tensors created within this QnnModel instance

Parameters
  • nodeName[in] Lookup name for node/layer

  • tensorName[in] Lookup name for tensor

  • tensor[out] The corresponding Qnn_Tensor_t object for given tensor name.

Returns

Error code

ModelError_t addNode(Qnn_OpConfigVersion_t version, const char *name, const char *packageName, const char *type, Qnn_Param_t *params, uint32_t numOfParams, const char **inputNames, uint32_t numOfInputs, Qnn_Tensor_t *outputTensors, uint32_t numOfOutputs)

A wrapper function to create a node in class’s graph.

Parameters
  • version[in] The QNN version for Op_Config_t structure to use (e.g. QNN_OPCONFIG_VERSION_1)

  • name[in] The node name to use (e.g. my_graph_conv_1)

  • packageName[in] The node package name (e.g. qti.aisw)

  • type[in] The QNN_OP_QNN_OP_H node type (e.g. QNN_OP_ARGMAX)

  • params[in] A struct object containing all the params for the node to be added. For tensorParam case. The tensor will be created within the function and the data will be retrieved from the binary blob to set the tensor data.

  • numOfParams[in] The number of elements in above params object

  • inputNames[in] List of tensor names for inputs to node. Note: the corresponding qnn tensor objects must be created within this instance prior to being listed as input to a node

  • numOfInputs[in] The number of elements in above inputNames object

  • outputTensors[in] List of Qnn_Tensor_t objects for outputs from node. Note1: the corresponding qnn tensor objects will be created in function and must not already exist. Note2: the output names must be unique per graph

  • numOfOutputs[in] The number of elements in above outputs object

Returns

Error code

inline Qnn_GraphHandle_t getQnnGraph()

A wrapper function to return model’s graph.

Returns

The Qnn graph object

inline std::string getQnnGraphName()

A wrapper function to return model’s graphName.

Returns

The Qnn graph object’s name

inline std::vector<Qnn_Tensor_t> getGraphInputTensors()

A wrapper function to return model’s graph input tensors.

Returns

vector of Qnn_Tensor_t objects

inline std::vector<Qnn_Tensor_t> getGraphOutputTensors()

A wrapper function to return model’s graph output tensors.

Returns

vector of Qnn_Tensor_t objects

inline std::map<std::string, std::vector<std::string>> getOutputTensorMap()

A wrapper function to return graph’s output tensors->op mapping.

Returns

map of std::string, std::vector<std::string>

ModelError_t finalize(Qnn_ProfileHandle_t profile = nullptr, Qnn_SignalHandle_t signal = nullptr)

A wrapper function to finalize model’s graph which includes calling backend finalize on graph.

Returns

Error code

ModelError_t freeCachedTensors()

Removes saved Qnn_Tensor_t objects and frees memory Note: Cleanup doesnt apply to input/output tensors as they are needed beyond this class finishes graph construction for the execute call. User of this API is expected to free those.

Returns

Error code