File QnnMem.h

Parent directory (include/QNN)

Memory registration component API.

Definition (include/QNN/QnnMem.h)

Detailed Description

Requires Backend to be initialized. Provides means to register externally allocated memory with a backend.

Includes

Full File Listing

Memory registration component API.

    Requires Backend to be initialized.
    Provides means to register externally allocated memory with a backend.

Defines

QNN_MEM_INVALID_FD -1

Invalid memory file descriptor value.

SHAPE_CONFIG_DATA_FORMAT_UBWC_RGBA8888 "DATA_FORMAT_UBWC_RGBA8888"
SHAPE_CONFIG_DATA_FORMAT_UBWC_NV12 "DATA_FORMAT_UBWC_NV12"
SHAPE_CONFIG_DATA_FORMAT_UBWC_NV12_Y "DATA_FORMAT_UBWC_NV12_Y"
SHAPE_CONFIG_DATA_FORMAT_UBWC_NV12_UV "DATA_FORMAT_UBWC_NV12_UV"
QNN_MEM_SHAPE_INIT

{                           \

0u,       /*numDim*/      \

NULL,     /*dimSize*/     \

NULL      /*shapeConfig*/ \

}


Qnn_MemShape_t initializer macro.

QNN_MEM_ION_INFO_INIT   { QNN_MEM_INVALID_FD /*fd*/ }

Qnn_MemIonInfo_t initializer macro.

QNN_MEM_DMA_BUF_INFO_INIT   {                               \     QNN_MEM_INVALID_FD

, /*fd*/    \

NULL            /*data*/  \

}


Qnn_MemDmaBufInfo_t initializer macro.

QNN_MEM_DESCRIPTOR_INIT   {                                      \     QNN_MEM_SHAPE_INIT,     /*memShape*/ \     QNN_DATATYPE_UNDEFINED, /*dataType*/ \     QNN_MEM_TYPE_UNDEFINED

, /*memType*/  \

{                                    \

QNN_MEM_ION_INFO_INIT

/*ionInfo*/  \

}                                    \

}


Qnn_MemDescriptor_t initializer macro.

Typedefs

typedef void *Qnn_MemInfoCustom_t

Definition of custom mem info opaque object. This object type is managed by backend specific APIs obtained by a custom backend mechanism.

Enums

enum QnnMem_Error_t

QNN Mem(ory) API result / error codes.

Values:

enumerator QNN_MEM_MIN_ERROR = 8000
enumerator QNN_MEM_NO_ERROR = 0

Qnn Memory success.

enumerator QNN_MEM_ERROR_NOT_SUPPORTED = QNN_COMMON_ERROR_NOT_SUPPORTED

Backend does not support requested functionality.

enumerator QNN_MEM_ERROR_INVALID_ARGUMENT = 8000 + 0

Invalid function argument.

enumerator QNN_MEM_ERROR_INVALID_HANDLE = 8000 + 1

Invalid memory handle.

enumerator QNN_MEM_ERROR_ALREADY_REGISTERED = 8000 + 2

Provided memory has already been registered.

enumerator QNN_MEM_ERROR_MAPPING = 8000 + 3

Error in memory mapping.

enumerator QNN_MEM_ERROR_INVALID_SHAPE = 8000 + 4

Invalid memory shape based on a backend’s memory restrictions (e.g. alignment incompatibility)

enumerator QNN_MEM_ERROR_UNSUPPORTED_MEMTYPE = 8000 + 5

Backend does not support requested memory type.

enumerator QNN_MEM_MAX_ERROR = 8999
enumerator QNN_MEM_ERROR_UNDEFINED = 0x7FFFFFFF
enum Qnn_MemType_t

An enumeration of memory types which may be used to provide data for a QNN tensor.

Values:

enumerator QNN_MEM_TYPE_ION = 1

Memory allocated by ION manager. ION memory can only be registered with Backend libraries when a device supports ION manager.

enumerator QNN_MEM_TYPE_CUSTOM = 2

Memory allocated by a custom backend mechanism.

enumerator QNN_MEM_TYPE_DMA_BUF = 3

Memory allocated by DMA-BUF subsystem.

enumerator QNN_MEM_TYPE_UNDEFINED = 0x7FFFFFFF

Functions

Qnn_ErrorHandle_t QnnMem_register(Qnn_ContextHandle_t context, const Qnn_MemDescriptor_t *memDescriptors, uint32_t numDescriptors, Qnn_MemHandle_t *memHandles)

Register existing memory to memory handle. Used to instruct QNN to use this memory directly.

Parameters
  • context[in] A context handle.

  • memDescriptors[in] Array of memory descriptors to be registered.

  • numDescriptors[in] Number of memory descriptors in the array.

  • memHandles[out] Array of allocated memory handles, length is numDescriptors. Same shape as memDescriptors (i.e. memHandles[n] corresponds to memDescriptors[n]).

Returns

Error code:

  • QNN_SUCCESS: memory was successfully registered

  • QNN_MEM_ERROR_NOT_SUPPORTED: backend does not support this API

  • QNN_MEM_ERROR_ALREADY_REGISTERED: memory has already been registered

  • QNN_MEM_ERROR_UNSUPPORTED_MEMTYPE: backend does not support a memType specified within memDescriptors

  • QNN_MEM_ERROR_MAPPING: failed to map between memory file descriptor and memory address

  • QNN_MEM_ERROR_INVALID_ARGUMENT: NULL array ptr or invalid memory descriptor

  • QNN_MEM_ERROR_INVALID_SHAPE: backend does not support a memShape specified within memDescriptors

  • QNN_MEM_ERROR_INVALID_HANDLE: context is not a valid handle

Note

memHandles parameter: Array memory is owned by the client. Array size must be at least numDescriptors*sizeof(Qnn_MemHandle_t). The array will be initialized to NULL by the backend. Upon failure, no memory will be registered and the memHandles array will remain NULL.

Qnn_ErrorHandle_t QnnMem_deRegister(const Qnn_MemHandle_t *memHandles, uint32_t numHandles)

Deregister a memory handle which was registered via QnnMem_register and invalidates memHandle for the given backend handle.

Parameters
  • memHandles[in] Array of memory handles to be deregistered.

  • numHandles[in] Number of memory handles in the array.

Returns

Error code:

  • QNN_SUCCESS: memory was successfully de-registered

  • QNN_MEM_ERROR_NOT_SUPPORTED: backend does not support this API

  • QNN_MEM_ERROR_INVALID_ARGUMENT: memHandles is NULL

  • QNN_MEM_ERROR_INVALID_HANDLE: a handle within memHandles is NULL/invalid

Note

memHandles parameter: Upon failure, all valid handles within memHandles will still be de-registered.

struct Qnn_MemShape_t
#include <QnnMem.h>

A struct which describes the shape of memory.

Public Members

uint32_t numDim

Number of dimensions.

uint32_t *dimSize

Array holding size of each dimension. Size of array is = numDim.

const char *shapeConfig

Additional configuration in string, for extensibility. Allowed to be NULL.

struct Qnn_MemIonInfo_t
#include <QnnMem.h>

a struct which includes ION related information

Public Members

int32_t fd

file descriptor for memory, must be set to QNN_MEM_INVALID_FD if not applicable

struct Qnn_MemDmaBufInfo_t
#include <QnnMem.h>

a struct which includes DMA-BUF related information

Public Members

int32_t fd

file descriptor for memory, must be set to QNN_MEM_INVALID_FD if not applicable

void *data

data pointer, created by app, using mmap on above file descriptor.

struct Qnn_MemDescriptor_t
#include <QnnMem.h>

A struct which describes memory params.

Public Members

Qnn_MemShape_t memShape

memory shape

Qnn_DataType_t dataType

memory data type

Qnn_MemType_t memType

memory type

union unnamed
#include <QnnMem.h>

Public Members

Qnn_MemIonInfo_t ionInfo
Qnn_MemInfoCustom_t customInfo
Qnn_MemDmaBufInfo_t dmaBufInfo