Files
DroidDeck/tools/upscale/layer/fsr4_qnn.h
T
The412Banner 74ece6c854 upscale: port Winlator-NeuralScale r5 (non-root parts)
Layer and bridges updated from Winlator-NeuralScale 71c140d9 (michaelisomer-cyber, GPL-3.0):
- full FSR 4.1 on the NPU (S8 graph, U8 fallback), compiled on the device per HTP arch
- ghosting fix: blank far depth when a game sends none, binding 11 bound with 62
- FSR 4.1.2 Lite S8/U8 zero-copy graphs
- Snapdragon GSR 2 on the GPU (new engine sgsr2_gpu)
- D3D11 DLSS through DXVK's interop (nvngx D3D11 entry points)

Left out on purpose: upstream's root-only performance/thermal manager, GPU clock floor and
bypass charging. Kept from DroidDeck: NPU detection by the app (DROIDDECK_UPSCALE_NPU, any HTP
generation incl. the phone's own QNN libraries) instead of upstream's SoC list, DD env names and
log tags, Intel XeSS 3 (runtime still fetched from a0ab6b0f, upstream dropped it in cb3ae04e).

FSR 4.0 on the NPU is gone upstream; the engine id becomes fsr4_1_full_npu and saved
fsr4_0_npu choices map to it. The full-FSR-4-on-Turnip guard is now opt-in
(DROIDDECK_UPSCALE_FULL_OFF_ON_TURNIP=1), since upstream's binding-11 fix targets that black frame.
Data files re-pinned to 71c140d9 (81 core + 8 NPU, sha256 checked).
2026-12-04 18:52:36 -05:00

558 lines
24 KiB
C

// Clean-room C declaration of the Qualcomm QNN HTP (v79/v81) interface subset and shared-buffer
// helpers for the DroidDeck upscaler layer (ported from Winlator-NeuralScale).
// Struct layouts match the QAIRT 2.47+ C ABI so builds need zero external QNN headers.
#pragma once
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
enum {
WL_FSR4_TENSOR_BYTES = 8294400u,
WL_FSR4_AHB_BYTES = 4u * WL_FSR4_TENSOR_BYTES,
WL_FSR4_PRESET_PERF = 0,
WL_FSR4_PRESET_ULTRAPERF = 1,
// Built-in self-contained AMD FSR 4.0.2 INT8 (fsr4_model_v07_i8_quality) AHB layout:
// slot 0 in : [0, 8294400) UFIXED_POINT_8 [1, 540, 960, 16]
// slot 1 in : [8294400, 16588800) UFIXED_POINT_8 [1, 540, 960, 16]
// slot 0 out : [16588800, 33177600) UFIXED_POINT_8 [1, 1080, 1920, 8]
// slot 1 out : [33177600, 49766400) UFIXED_POINT_8 [1, 1080, 1920, 8]
WL_FSR4_BUILTIN_IN_BYTES = 8294400u,
WL_FSR4_BUILTIN_OUT_BYTES = 16588800u,
WL_FSR4_BUILTIN_AHB_BYTES = 49766400u,
WL_FSR4_PASS0_WB_BYTES = 1056u,
// AMD FSR 4.1.2 Lite INT8 zero-copy AHB-backed scratch layout (4096-byte page-aligned!):
// slot 0 scratch: [0, 25030656) -> in at +0 (8342464 B), out at +16687104 (8342464 B)
// slot 1 scratch: [25030656, 50061312) -> in at +25030656, out at +41717760
WL_FSR4_LITE_IN_BYTES = 8342464u,
WL_FSR4_LITE_OUT_BYTES = 8342464u,
WL_FSR4_LITE_OUT_OFFSET = 16687104u,
WL_FSR4_LITE_SLOT_STRIDE = 25030656u,
WL_FSR4_LITE_AHB_BYTES = 2u * WL_FSR4_LITE_SLOT_STRIDE,
// AMD FSR 4.1.1 Full INT8 zero-copy AHB layout (4096-byte page-aligned!):
// slot 0: in at +0 (8342464 B), out at +8343552 (8342464 B)
// slot 1: in at +16687104, out at +25030656
WL_FSR411_FULL_IN_BYTES = 8342464u,
WL_FSR411_FULL_OUT_BYTES = 8342464u,
WL_FSR411_FULL_OUT_OFFSET = 8343552u,
WL_FSR411_FULL_SLOT_STRIDE = 16687104u,
WL_FSR411_FULL_AHB_BYTES = 2u * WL_FSR411_FULL_SLOT_STRIDE,
};
typedef struct wl_fsr4_qnn wl_fsr4_qnn;
wl_fsr4_qnn *wl_fsr4_qnn_init(const char *fsr4_dir, int preset, const char *power_mode);
wl_fsr4_qnn *wl_fsr4_qnn_init_builtin(const char *fsr4_dir, const char *power_mode,
uint8_t out_pass0_wb[WL_FSR4_PASS0_WB_BYTES]);
// The compiled context lives in <fsr4_dir>/<this device's htp arch>/<file>; a "<arch>/" prefix the caller
// writes (upstream writes v81/) is replaced by this device's arch.
wl_fsr4_qnn *wl_fsr4_qnn_init_wpack(const char *fsr4_dir, const char *wpack_rel,
const char *cache_name, const char *graph_name,
const char *power_mode,
uint32_t in_bytes, uint32_t out_bytes);
wl_fsr4_qnn *wl_fsr4_qnn_init_wpack_layout(const char *fsr4_dir, const char *wpack_rel,
const char *cache_rel, const char *graph_name,
const char *power_mode,
size_t total_ahb_bytes,
const uint64_t in_offs[2], const uint64_t out_offs[2]);
int wl_fsr4_qnn_load_preset(wl_fsr4_qnn *q, int preset);
void *wl_fsr4_qnn_ahb(const wl_fsr4_qnn *q);
void *wl_fsr4_qnn_mapped(const wl_fsr4_qnn *q);
int wl_fsr4_qnn_dmabuf_fd(const wl_fsr4_qnn *q);
int wl_fsr4_qnn_exec(wl_fsr4_qnn *q, int preset, int slot, double *out_ms);
int wl_fsr4_qnn_exec_builtin(wl_fsr4_qnn *q, int slot, double *out_ms);
int wl_fsr4_qnn_exec_custom(wl_fsr4_qnn *q, int slot, uint32_t in_bytes, uint32_t out_bytes, double *out_ms);
int wl_fsr4_qnn_exec_offsets(wl_fsr4_qnn *q, int slot,
uint64_t in_off, uint32_t in_bytes,
uint64_t out_off, uint32_t out_bytes,
double *out_ms);
int wl_fsr4_qnn_exec_offsets_zc(wl_fsr4_qnn *q, int slot,
uint64_t in_off, uint32_t in_bytes,
uint64_t out_off, uint32_t out_bytes,
int zero_copy, double *out_ms);
int wl_fsr4_qnn_set_power_mode(const char *power_mode);
const char *wl_fsr4_qnn_get_power_mode(void);
void wl_fsr4_pin_worker_non_prime(const char *worker_name);
const char *wl_fsr4_qnn_last_error(void);
void wl_fsr4_qnn_free(wl_fsr4_qnn *q);
// Writes <fsr4_dir>/<htp arch>/<name>; returns 0 when it does not fit or an argument is missing.
int wl_fsr4_qnn_cache_path(const char *fsr4_dir, const char *name, char *out, size_t out_sz);
// ---- Clean-room QNN C ABI definitions (QAIRT 2.47+ / HTP v81) ----
typedef uint64_t Qnn_ErrorHandle_t;
typedef void *Qnn_Handle_t;
typedef Qnn_Handle_t Qnn_BackendHandle_t;
typedef Qnn_Handle_t Qnn_ContextHandle_t;
typedef Qnn_Handle_t Qnn_DeviceHandle_t;
typedef Qnn_Handle_t Qnn_GraphHandle_t;
typedef Qnn_Handle_t Qnn_LogHandle_t;
typedef Qnn_Handle_t Qnn_MemHandle_t;
typedef Qnn_Handle_t Qnn_ProfileHandle_t;
typedef Qnn_Handle_t Qnn_SignalHandle_t;
typedef void *QnnSystemContext_Handle_t;
typedef uint64_t Qnn_ContextBinarySize_t;
enum {
QNN_SUCCESS_CODE = 0,
QNN_DEFINITION_IMPL_GENERATED = 0,
QNN_DEFINITION_DEFINED = 1,
QNN_DEFINITION_UNDEFINED = 0x7FFFFFFF,
QNN_LOG_LEVEL_ERROR = 1,
QNN_LOG_LEVEL_WARN = 2,
QNN_LOG_LEVEL_INFO = 3,
QNN_TENSOR_VERSION_1 = 1,
QNN_TENSOR_VERSION_2 = 2,
QNN_TENSOR_TYPE_APP_WRITE = 0,
QNN_TENSOR_TYPE_APP_READ = 1,
QNN_TENSOR_TYPE_APP_READWRITE = 2,
QNN_TENSOR_TYPE_NATIVE = 3,
QNN_TENSOR_TYPE_STATIC = 4,
QNN_TENSORMEMTYPE_RAW = 0,
QNN_TENSORMEMTYPE_MEMHANDLE = 1,
QNN_TENSOR_DATA_FORMAT_FLAT_BUFFER = 0,
QNN_DATATYPE_INT_8 = 0x0008,
QNN_DATATYPE_INT_32 = 0x0032,
QNN_DATATYPE_UINT_8 = 0x0108,
QNN_DATATYPE_UINT_32 = 0x0132,
QNN_DATATYPE_FLOAT_16 = 0x0216,
QNN_DATATYPE_FLOAT_32 = 0x0232,
QNN_DATATYPE_SFIXED_POINT_8 = 0x0308,
QNN_DATATYPE_SFIXED_POINT_32 = 0x0332,
QNN_DATATYPE_UFIXED_POINT_8 = 0x0408,
QNN_DATATYPE_BOOL_8 = 0x0508,
QNN_PARAMTYPE_SCALAR = 0,
QNN_PARAMTYPE_TENSOR = 1,
QNN_OPCONFIG_VERSION_1 = 1,
QNN_MEM_TYPE_CUSTOM = 2,
QNN_HTP_MEM_SHARED_BUFFER = 1,
QNN_DEVICE_CONFIG_OPTION_CUSTOM = 0,
QNN_HTP_DEVICE_CONFIG_OPTION_SIGNEDPD = 2,
QNN_HTP_DEVICE_INFRA_TYPE_PERF = 0,
QNN_QUANT_ENC_SCALE_OFFSET = 0,
QNN_QUANT_ENC_AXIS_SCALE_OFFSET = 1,
QNN_QUANT_ENC_BW_AXIS_SCALE_OFFSET = 3,
QNN_QUANT_ENC_UNDEFINED = 0x7FFFFFFF,
QNN_GRAPH_CONFIG_OPTION_CUSTOM = 0,
QNN_HTP_GRAPH_CONFIG_OPTION_OPTIMIZATION = 1,
QNN_HTP_GRAPH_CONFIG_OPTION_VTCM_SIZE = 3,
QNN_HTP_GRAPH_OPT_FINALIZE_FLAG = 3,
};
typedef struct { uint32_t major, minor, patch; } Qnn_Version_t;
typedef struct { Qnn_Version_t coreApiVersion; Qnn_Version_t backendApiVersion; } Qnn_ApiVersion_t;
typedef struct { float scale; int32_t offset; } Qnn_ScaleOffset_t;
typedef struct { uint32_t bitwidth; float scale; int32_t offset; } Qnn_BwScaleOffset_t;
typedef struct { int32_t axis; uint32_t numScaleOffsets; Qnn_ScaleOffset_t *scaleOffset; } Qnn_AxisScaleOffset_t;
typedef struct { uint32_t bitwidth; int32_t axis; uint32_t numElements; float *scales; int32_t *offsets; } Qnn_BwAxisScaleOffset_t;
typedef struct { uint32_t *blockSize; Qnn_ScaleOffset_t *scaleOffset; } Qnn_BlockEncoding_t;
typedef struct { float scale; float offset; } Qnn_FloatScaleOffset_t;
typedef struct { uint32_t *blockSize; Qnn_FloatScaleOffset_t *floatScaleOffset; } Qnn_FloatBlockEncoding_t;
typedef struct { uint32_t bitwidth; uint32_t *blockSize; Qnn_FloatScaleOffset_t *floatScaleOffset; } Qnn_BwFloatBlockEncoding_t;
typedef struct {
uint32_t encodingDefinition;
uint32_t quantizationEncoding;
union {
Qnn_ScaleOffset_t scaleOffsetEncoding;
Qnn_AxisScaleOffset_t axisScaleOffsetEncoding;
Qnn_BwScaleOffset_t bwScaleOffsetEncoding;
Qnn_BwAxisScaleOffset_t bwAxisScaleOffsetEncoding;
Qnn_BlockEncoding_t blockEncoding;
void *blockwiseExpansion;
void *vectorEncoding;
Qnn_FloatBlockEncoding_t floatBlockEncoding;
void *bwAxisScaleOffsetMappedEncoding;
void *bwBlockMappedEncoding;
void *bwBlockwiseExpansionMappedEncoding;
Qnn_BwFloatBlockEncoding_t bwFloatBlockEncoding;
void *microScalingEncoding;
void *arrayOfEncoding;
};
} Qnn_QuantizeParams_t;
typedef struct { void *data; uint32_t dataSize; } Qnn_ClientBuffer_t;
typedef struct {
uint32_t type;
struct { uint32_t numSpecifiedElements; uint32_t numSparseDimensions; } hybridCoo;
} Qnn_SparseParams_t;
typedef struct {
uint32_t id;
const char *name;
uint32_t type;
uint32_t dataFormat;
uint32_t dataType;
Qnn_QuantizeParams_t quantizeParams;
uint32_t rank;
uint32_t *dimensions;
uint32_t memType;
union { Qnn_ClientBuffer_t clientBuf; Qnn_MemHandle_t memHandle; };
} Qnn_TensorV1_t;
typedef struct {
uint32_t id;
const char *name;
uint32_t type;
uint32_t dataFormat;
uint32_t dataType;
Qnn_QuantizeParams_t quantizeParams;
uint32_t rank;
uint32_t *dimensions;
uint32_t memType;
union { Qnn_ClientBuffer_t clientBuf; Qnn_MemHandle_t memHandle; void *retrieveRaw; };
uint8_t *isDynamicDimensions;
Qnn_SparseParams_t sparseParams;
uint8_t isProduced;
} Qnn_TensorV2_t;
typedef struct {
uint32_t version;
union { Qnn_TensorV1_t v1; Qnn_TensorV2_t v2; };
} Qnn_Tensor_t;
typedef struct { uint32_t numDim; uint32_t *dimSize; const char *shapeConfig; } Qnn_MemShape_t;
typedef struct {
Qnn_MemShape_t memShape;
uint32_t dataType;
uint32_t memType;
union {
struct { int32_t fd; } ionInfo;
void *customInfo;
struct { int32_t fd; void *data; } dmaBufInfo;
void *dx12BufInfo;
};
} Qnn_MemDescriptor_t;
typedef struct {
uint32_t type;
uint64_t size;
union {
uint32_t qurtAddress;
struct { int32_t fd; uint64_t offset; } sharedBufferConfig;
uint8_t raw[16];
};
} QnnMemHtp_Descriptor_t;
typedef struct {
uint32_t option;
union {
uint32_t socModel;
struct { uint32_t deviceId, arch; } arch;
struct { uint32_t deviceId; bool useSignedProcessDomain; } useSignedProcessDomain;
struct { uint32_t deviceId; bool useSecureProcessDomain; } useSecureProcessDomain;
struct { uint32_t deviceId; bool enableAsyncExecute; } asyncExecute;
void *htpExtension;
};
} QnnHtpDevice_CustomConfig_t;
typedef struct {
uint32_t option;
union { void *customConfig; void *hardwareInfo; };
} QnnDevice_Config_t;
typedef struct {
uint32_t contextId;
uint32_t setDcvsEnable, dcvsEnable;
uint32_t powerMode;
uint32_t setSleepLatency, sleepLatency;
uint32_t setSleepDisable, sleepDisable;
uint32_t setBusParams, busVoltageCornerMin, busVoltageCornerTarget, busVoltageCornerMax;
uint32_t setCoreParams, coreVoltageCornerMin, coreVoltageCornerTarget, coreVoltageCornerMax;
} QnnHtpPerfInfrastructure_DcvsV3_t;
typedef struct {
uint32_t hmxPickDefault;
uint32_t hmxVoltageCornerMin, hmxVoltageCornerTarget, hmxVoltageCornerMax;
uint32_t hmxPerfMode;
} QnnHtpPerfInfrastructure_HmxV2_t;
typedef struct {
uint32_t option;
union {
QnnHtpPerfInfrastructure_DcvsV3_t dcvsV3Config;
uint32_t rpcControlLatencyConfig;
uint32_t rpcPollingTimeConfig;
uint32_t hmxTimeoutIntervalUsConfig;
QnnHtpPerfInfrastructure_HmxV2_t hmxV2Config;
uint32_t raw[16];
};
} QnnHtpPerfInfrastructure_PowerConfig_t;
enum {
QNN_HTP_POWER_OPT_DCVS_V3 = 1,
QNN_HTP_POWER_OPT_RPC_CONTROL_LATENCY = 2,
QNN_HTP_POWER_OPT_RPC_POLLING_TIME = 3,
QNN_HTP_POWER_OPT_HMX_TIMEOUT_INTERVAL_US = 4,
QNN_HTP_POWER_OPT_HMX_V2 = 5,
QNN_HTP_POWERMODE_ADJUST_UPDOWN = 0x01,
QNN_HTP_POWERMODE_POWER_SAVER = 0x04,
QNN_HTP_POWERMODE_PERF = 0x10,
QNN_HTP_CLK_PERF_HIGH = 0,
QNN_HTP_CLK_PERF_LOW = 1,
QNN_HTP_VCORNER_DISABLE = 0x10,
QNN_HTP_VCORNER_MIN = 0x20,
QNN_HTP_VCORNER_SVS2 = 0x30,
QNN_HTP_VCORNER_SVS = 0x40,
QNN_HTP_VCORNER_NOM = 0x60,
QNN_HTP_VCORNER_TURBO = 0x80,
QNN_HTP_VCORNER_MAX = 0xA0,
QNN_HTP_EXP_VCORNER_DISABLE = 0,
QNN_HTP_EXP_VCORNER_MIN = 0x100,
QNN_HTP_EXP_VCORNER_LOW_SVS = 0x140,
QNN_HTP_EXP_VCORNER_SVS = 0x180,
QNN_HTP_EXP_VCORNER_NOM = 0x200,
QNN_HTP_EXP_VCORNER_TUR = 0x280,
QNN_HTP_EXP_VCORNER_MAX = 0xFFFF,
};
typedef Qnn_ErrorHandle_t (*QnnHtpPerf_CreatePowerConfigIdFn_t)(uint32_t deviceId, uint32_t coreId, uint32_t *powerConfigId);
typedef Qnn_ErrorHandle_t (*QnnHtpPerf_DestroyPowerConfigIdFn_t)(uint32_t powerConfigId);
typedef Qnn_ErrorHandle_t (*QnnHtpPerf_SetPowerConfigFn_t)(uint32_t powerConfigId, const QnnHtpPerfInfrastructure_PowerConfig_t **config);
typedef Qnn_ErrorHandle_t (*QnnHtpPerf_SetMemoryConfigFn_t)(uint32_t deviceId, uint32_t coreId, const void **config);
typedef struct {
QnnHtpPerf_CreatePowerConfigIdFn_t createPowerConfigId;
QnnHtpPerf_DestroyPowerConfigIdFn_t destroyPowerConfigId;
QnnHtpPerf_SetPowerConfigFn_t setPowerConfig;
QnnHtpPerf_SetMemoryConfigFn_t setMemoryConfig;
} QnnHtpDevice_PerfInfrastructure_t;
typedef struct {
uint32_t infraType;
union { QnnHtpDevice_PerfInfrastructure_t perfInfra; };
} QnnHtpDevice_Infrastructure_t;
typedef void (*QnnLog_Callback_t)(const char *fmt, uint32_t level, uint64_t timestamp, va_list args);
typedef struct {
const char *graphName;
uint32_t numGraphInputs; Qnn_Tensor_t *graphInputs;
uint32_t numGraphOutputs; Qnn_Tensor_t *graphOutputs;
} QnnSystemContext_GraphInfoV1_t;
typedef struct {
const char *graphName;
uint32_t numGraphInputs; Qnn_Tensor_t *graphInputs;
uint32_t numGraphOutputs; Qnn_Tensor_t *graphOutputs;
uint32_t numUpdateableTensors; Qnn_Tensor_t *updateableTensors;
} QnnSystemContext_GraphInfoV2_t;
typedef struct {
const char *graphName;
uint32_t numGraphInputs; Qnn_Tensor_t *graphInputs;
uint32_t numGraphOutputs; Qnn_Tensor_t *graphOutputs;
uint32_t numUpdateableTensors; Qnn_Tensor_t *updateableTensors;
uint32_t graphBlobInfoSize; void *graphBlobInfo;
uint32_t startOpIndex; uint32_t endOpIndex;
} QnnSystemContext_GraphInfoV3_t;
typedef struct {
uint32_t version;
union {
QnnSystemContext_GraphInfoV1_t graphInfoV1;
QnnSystemContext_GraphInfoV2_t graphInfoV2;
QnnSystemContext_GraphInfoV3_t graphInfoV3;
};
} QnnSystemContext_GraphInfo_t;
typedef struct {
uint32_t backendId; const char *buildId;
Qnn_Version_t coreApiVersion; Qnn_Version_t backendApiVersion;
const char *socVersion;
Qnn_Version_t hwInfoBlobVersion; Qnn_Version_t contextBlobVersion;
uint32_t hwInfoBlobSize; void *hwInfoBlob;
uint64_t contextBlobSize;
uint32_t numContextTensors; Qnn_Tensor_t *contextTensors;
uint32_t numGraphs; QnnSystemContext_GraphInfo_t *graphs;
} QnnSystemContext_BinaryInfoV1_t;
typedef struct {
uint32_t backendId; const char *buildId;
Qnn_Version_t coreApiVersion; Qnn_Version_t backendApiVersion;
const char *socVersion;
Qnn_Version_t hwInfoBlobVersion; Qnn_Version_t contextBlobVersion;
uint32_t hwInfoBlobSize; void *hwInfoBlob;
uint64_t contextBlobSize;
uint32_t numContextTensors; Qnn_Tensor_t *contextTensors;
uint32_t numGraphs; QnnSystemContext_GraphInfo_t *graphs;
void *platformInfo;
} QnnSystemContext_BinaryInfoV2_t;
typedef struct {
uint32_t backendId; const char *buildId;
Qnn_Version_t coreApiVersion; Qnn_Version_t backendApiVersion;
const char *socVersion;
Qnn_Version_t contextBlobVersion;
uint64_t contextBlobSize;
uint32_t numContextTensors; Qnn_Tensor_t *contextTensors;
uint32_t numGraphs; QnnSystemContext_GraphInfo_t *graphs;
void *platformInfo;
uint32_t contextMetadataSize; void *contextMetadata;
uint32_t socModel;
} QnnSystemContext_BinaryInfoV3_t;
typedef struct {
uint32_t version;
union {
QnnSystemContext_BinaryInfoV1_t contextBinaryInfoV1;
QnnSystemContext_BinaryInfoV2_t contextBinaryInfoV2;
QnnSystemContext_BinaryInfoV3_t contextBinaryInfoV3;
};
} QnnSystemContext_BinaryInfo_t;
typedef struct {
Qnn_ErrorHandle_t (*systemContextCreate)(QnnSystemContext_Handle_t *sysCtxHandle);
Qnn_ErrorHandle_t (*systemContextGetBinaryInfo)(QnnSystemContext_Handle_t sysCtxHandle, void *binaryBuffer, uint64_t binaryBufferSize,
const QnnSystemContext_BinaryInfo_t **binaryInfo, Qnn_ContextBinarySize_t *binaryInfoSize);
Qnn_ErrorHandle_t (*systemContextGetMetaData)(QnnSystemContext_Handle_t sysCtxHandle, const void *binaryBuffer, uint64_t binaryBufferSize,
const QnnSystemContext_BinaryInfo_t **binaryInfo);
Qnn_ErrorHandle_t (*systemContextFree)(QnnSystemContext_Handle_t sysCtxHandle);
void (*reserved_slot[22])(void);
} QnnSystemInterface_ImplV1_11_t;
typedef struct {
uint32_t backendId;
const char *providerName;
Qnn_Version_t systemApiVersion;
union { QnnSystemInterface_ImplV1_11_t v1_11; };
} QnnSystemInterface_t;
typedef struct {
uint32_t dataType;
union {
float floatValue;
double doubleValue;
uint64_t uint64Value;
int64_t int64Value;
uint32_t uint32Value;
int32_t int32Value;
uint16_t uint16Value;
int16_t int16Value;
uint8_t uint8Value;
int8_t int8Value;
uint8_t bool8Value;
const char *stringValue;
};
} Qnn_Scalar_t;
typedef struct {
uint32_t paramType;
const char *name;
union {
Qnn_Scalar_t scalarParam;
Qnn_Tensor_t tensorParam;
};
} Qnn_Param_t;
typedef struct {
const char *name;
const char *packageName;
const char *typeName;
uint32_t numOfParams;
Qnn_Param_t *params;
uint32_t numOfInputs;
Qnn_Tensor_t *inputTensors;
uint32_t numOfOutputs;
Qnn_Tensor_t *outputTensors;
} Qnn_OpConfigV1_t;
typedef struct {
uint32_t version;
union {
Qnn_OpConfigV1_t v1;
};
} Qnn_OpConfig_t;
typedef struct {
uint32_t option;
union {
struct { uint32_t type; float floatValue; } optimizationOption;
uint32_t precision;
uint32_t vtcmSizeInMB;
uint64_t raw[4];
};
} QnnHtpGraph_CustomConfig_t;
typedef struct {
uint32_t option;
union {
void *customConfig;
uint32_t priority;
};
} QnnGraph_Config_t;
typedef struct {
void (*propertyHasCapability)(void);
Qnn_ErrorHandle_t (*backendCreate)(Qnn_LogHandle_t logger, const void **config, Qnn_BackendHandle_t *backend);
void (*backendSetConfig)(void);
void (*backendGetApiVersion)(void);
void (*backendGetBuildId)(void);
void (*backendRegisterOpPackage)(void);
void (*backendGetSupportedOperations)(void);
void (*backendValidateOpConfig)(void);
Qnn_ErrorHandle_t (*backendFree)(Qnn_BackendHandle_t backend);
Qnn_ErrorHandle_t (*contextCreate)(Qnn_BackendHandle_t backend, Qnn_DeviceHandle_t device, const void **config, Qnn_ContextHandle_t *context);
void (*contextSetConfig)(void);
Qnn_ErrorHandle_t (*contextGetBinarySize)(Qnn_ContextHandle_t context, Qnn_ContextBinarySize_t *binaryBufferSize);
Qnn_ErrorHandle_t (*contextGetBinary)(Qnn_ContextHandle_t context, void *binaryBuffer, Qnn_ContextBinarySize_t binaryBufferSize, Qnn_ContextBinarySize_t *writtenBufferSize);
Qnn_ErrorHandle_t (*contextCreateFromBinary)(Qnn_BackendHandle_t backend, Qnn_DeviceHandle_t device, const void **config, const void *binaryBuffer,
Qnn_ContextBinarySize_t binaryBufferSize, Qnn_ContextHandle_t *context, Qnn_ProfileHandle_t profile);
Qnn_ErrorHandle_t (*contextFree)(Qnn_ContextHandle_t context, Qnn_ProfileHandle_t profile);
Qnn_ErrorHandle_t (*graphCreate)(Qnn_ContextHandle_t contextHandle, const char *graphName, const QnnGraph_Config_t **config, Qnn_GraphHandle_t *graphHandle);
void (*graphCreateSubgraph)(void);
void (*graphSetConfig)(void);
Qnn_ErrorHandle_t (*graphAddNode)(Qnn_GraphHandle_t graphHandle, Qnn_OpConfig_t opConfig);
Qnn_ErrorHandle_t (*graphFinalize)(Qnn_GraphHandle_t graphHandle, Qnn_ProfileHandle_t profileHandle, Qnn_SignalHandle_t signalHandle);
Qnn_ErrorHandle_t (*graphRetrieve)(Qnn_ContextHandle_t contextHandle, const char *graphName, Qnn_GraphHandle_t *graphHandle);
Qnn_ErrorHandle_t (*graphExecute)(Qnn_GraphHandle_t graphHandle, const Qnn_Tensor_t *inputs, uint32_t numInputs,
Qnn_Tensor_t *outputs, uint32_t numOutputs, Qnn_ProfileHandle_t profileHandle, Qnn_SignalHandle_t signalHandle);
void (*graphExecuteAsync)(void);
void (*tensorCreateContextTensor)(void);
Qnn_ErrorHandle_t (*tensorCreateGraphTensor)(Qnn_GraphHandle_t graph, Qnn_Tensor_t *tensor);
Qnn_ErrorHandle_t (*logCreate)(QnnLog_Callback_t callback, uint32_t maxLogLevel, Qnn_LogHandle_t *logger);
void (*logSetLogLevel)(void);
Qnn_ErrorHandle_t (*logFree)(Qnn_LogHandle_t logger);
void (*profile_slots[7])(void);
Qnn_ErrorHandle_t (*memRegister)(Qnn_ContextHandle_t context, const Qnn_MemDescriptor_t *memDescriptors, uint32_t numDescriptors, Qnn_MemHandle_t *memHandles);
Qnn_ErrorHandle_t (*memDeRegister)(const Qnn_MemHandle_t *memHandles, uint32_t numHandles);
void (*deviceGetPlatformInfo)(void);
void (*deviceFreePlatformInfo)(void);
Qnn_ErrorHandle_t (*deviceGetInfrastructure)(const QnnHtpDevice_Infrastructure_t **deviceInfra);
Qnn_ErrorHandle_t (*deviceCreate)(Qnn_LogHandle_t logger, const QnnDevice_Config_t **config, Qnn_DeviceHandle_t *device);
void (*deviceSetConfig)(void);
void (*deviceGetInfo)(void);
Qnn_ErrorHandle_t (*deviceFree)(Qnn_DeviceHandle_t device);
void (*tail_slots[28])(void);
} QnnInterface_ImplV2_36_t;
typedef struct {
uint32_t backendId;
const char *providerName;
Qnn_ApiVersion_t apiVersion;
union { QnnInterface_ImplV2_36_t v2_36; };
} QnnInterface_t;
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
_Static_assert(sizeof(Qnn_ScaleOffset_t) == 8, "Qnn_ScaleOffset_t size");
_Static_assert(sizeof(Qnn_QuantizeParams_t) == 40, "Qnn_QuantizeParams_t size");
_Static_assert(sizeof(Qnn_SparseParams_t) == 12, "Qnn_SparseParams_t size");
_Static_assert(sizeof(QnnMemHtp_Descriptor_t) == 32, "QnnMemHtp_Descriptor_t size");
_Static_assert(sizeof(QnnHtpPerfInfrastructure_PowerConfig_t) == 68, "QnnHtpPerfInfrastructure_PowerConfig_t size");
_Static_assert(sizeof(QnnSystemInterface_ImplV1_11_t) == 26 * sizeof(void *), "QnnSystemInterface_ImplV1_11_t size");
_Static_assert(sizeof(QnnInterface_ImplV2_36_t) == 72 * sizeof(void *), "QnnInterface_ImplV2_36_t size");
#endif
#ifdef __cplusplus
}
#endif