Function QnnTensor_createContextTensor

Function Documentation

Qnn_ErrorHandle_t QnnTensor_createContextTensor(Qnn_ContextHandle_t context, Qnn_Tensor_t *tensor)

A function to create a new tensor on Qnn_ContextHandle_t.

   This call may or may not allocate memory, depending on the Qnn_TensorType_t
   value specified in tensor and the accelerator implementation.
   Optionally it may be initialized with data provided in the tensor if present.

Parameters
  • context[in] The context in which the tensor would be created.

  • tensor[inout] Pointer to a user-allocated struct containing information on the tensor (type, name, data format, dimensions, data, etc). For tensors containing static data (such as weights or biases), the tensor type is expected to be QNN_TENSOR_TYPE_STATIC. Valid data must be presented in the tensor object at creation. This data will be copied, and may be safely de-allocated after this call returns. Other tensor types (e.g: APP_READ, APP_WRITE, APP_READWRITE, NULL) must have the data pointer set to NULL at the time of creation. Any preset value in id will be overwritten by the backend as part of this call. Subsequent usage of the tensor must reference this id. Creating a tensor with a name that duplicates a previously created tensor name in the context and all child graphs results in undefined behaviour. The dimensions are treated as the maximum dimensions during tensor creation.

Returns

Error code:

  • QNN_SUCCESS: Successfully created a context tensor

  • QNN_TENSOR_ERROR_INVALID_HANDLE: Provided context handle is invalid

  • QNN_TENSOR_ERROR_INVALID_TENSOR_PARAM: One or more tensor parameters is invalid

  • QNN_TENSOR_ERROR_UNSUPPORTED_TENSOR_PARAM: One or more tensor parameters are unsupported

  • QNN_COMMON_ERROR_MEM_ALLOC: Failure in creating tensor due to issues with memory allocation

  • QNN_TENSOR_ERROR_UNSUPPORTED_FEATURE: some API feature is not supported yet

Note

Use corresponding API through QnnInterface_t.

Warning

Context tensors cannot be of type QNN_TENSOR_TYPE_NATIVE. Native tensors connect nodes within a single graph.

Warning

Context tensors cannot be of datatype QNN_DATATYPE_STRING.