File QnnModel.hpp

Parent directory (share/converter/jni)

Definition (share/converter/jni/QnnModel.hpp)

Includes

Full File Listing

namespace qnn_wrapper_api

Functions

ModelError_t getGraphInfoFromModels(QnnModel *models, uint32_t numModels, GraphInfoPtr_t **graphsInfo)

A helper function to convert QnnModel objects to Graph struct for qnn_model c interface.

Parameters
  • models[in] List of QnnModel objects

  • numModels[in] The number of elements in above models object

  • graphsInfo[out] The corresponding array of Graph object for each of the above model objects(note: this function will malloc memory needed to store the struct objects. Following free shall be invoked when objects are no longer needed.

Returns

Error code

ModelError_t freeGraphsInfo(GraphInfoPtr_t **graphsInfo, uint32_t numGraphs)

A helper function to free memory malloced for communicating the Graph for a model(s)

Parameters
  • graphsInfo[in] Pointer pointing to location of graph objects

  • numGraphs[in] The number of graph objects the above pointer is pointing to

Returns

Error code

class QnnModel
#include <QnnModel.hpp>

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

Private Members

Qnn_GraphHandle_t m_graph = nullptr
std::string m_graphName
bool m_debug = false
bool m_doNodeValidations = true
std::vector<Qnn_Tensor_t> m_modelInputTensors
std::vector<Qnn_Tensor_t> m_modelOutputTensors
std::map<std::string, Qnn_Tensor_t> m_modelTensorsMap
std::map<std::string, std::vector<std::string>> m_modelOutputTensorMap
QNN_INTERFACE_VER_TYPE m_qnnInterface
Qnn_BackendHandle_t m_backendHandle