You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
10 KiB

/**
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2020-2020. All rights reserved.
*
*/
#ifndef __AI_CONFIG_H__
#define __AI_CONFIG_H__
#include <list>
#include <string>
#include <vector>
#include <vendor/huanglong/hardware/hwhlai/1.0/types.h>
#ifndef UNUSED_PARAMETER
// to remove compile warning for unused parameter
#define UNUSED_PARAMETER(x) (void)(x)
#endif
// 定义相关宏,对相关函数符号进行屏蔽
#ifndef HLAI_AP_VISIBILITY
#if !(defined _WIN32) && !(defined __CYGWIN__)
#define HLAI_AP_VISIBILITY __attribute__ ((visibility ("default")))
#else
#define HLAI_AP_VISIBILITY
#endif
#endif
#define HLAI_API_EXPORT HLAI_AP_VISIBILITY
#define AI_DEFAULT_PRIORITY 2
#define AI_MAX_PRIORITY 3
#define AI_IMAGE_DEFAULT_WIDTH 3936
#define AI_IMAGE_DEFAULT_HEIGHT 2976
#define AI_IMAGE_MAX_WIDTH 3936
#define AI_IMAGE_MAX_HEIGHT 2976
#define AI_SPEECH_DEFAULT_SAMPLERATE 16
#define AI_SPEECH_DEFAULT_CHANNEL_NUM 2
#define AI_MAX_COMPUTING_DEV_NUM 4
#define RUN_MODEL_TIMEOUT 60000 // ms
#define AI_MODEL_MNG_ID_BASE (100)
#define AI_MODEL_MNG_ID_NUM (2012)
#define AI_SPEECH_QUICKCALL_PATH_GRAMMAR ("/data/vendor/hlai/speech/quickcall/contact.fst")
#define AI_SPEECH_QUICKCALL_PATH_VOCAB ("/data/vendor/hlai/speech/quickcall/contact.txt")
#define AI_SPEECH_QUICKCALL_PATH_W2P ("/data/vendor/hlai/speech/quickcall/contact.w2p")
#define AI_SPEECH_QUICKCALL_PATH_CFG ("/data/vendor/hlai/speech/quickcall/contact.cfg")
namespace ai {
using ::std::string;
using ::std::vector;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiDataType;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiFramework;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiInputFormat;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiPixelFormat;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiImageFormat;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiModelType;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiOutputFormat;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiOutputParam;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiOutputType;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiSpeechType;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiSpeechFormat;
using ::vendor::huanglong::hardware::hwhlai::V1_0::AiDevPerf;
enum {
AI_OK = 0,
AI_EPERM, /***************** 1. Permission denied ***************************/
AI_ENOENT, /***************** 2. No such file or directory **********************/
AI_ESRCH, /***************** 3. No such process ****************************/
AI_EINTR, /***************** 4. Interrupted system call ***********************/
AI_EIO, /***************** 5. Input/output error **************************/
AI_ENXIO, /***************** 6. Device not configured ************************/
AI_E2BIG, /***************** 7. Argument list too long ************************/
AI_ENOEXEC, /***************** 8. Exec format error ****************************/
AI_EBADF, /***************** 9. Bad file descriptor ****************************/
AI_ECHILD, /***************** 10. No child processes ***************************/
AI_EAGAIN, /***************** 11. was EAGAIN ********************************/
AI_ENOMEM, /***************** 12. Cannot allocate memory ***********************/
AI_EACCES, /***************** 13. Bad address ********************************/
AI_EFAULT, /***************** 14. Block device required **************************/
AI_EBUSY, /***************** 15. Device busy *********************************/
AI_EEXIST, /***************** 16. File exists ***********************************/
AI_EXDEV, /***************** 17. Cross-device link *****************************/
AI_ENODEV, /***************** 18. Operation not supported by device ***************/
AI_ENOTDIR, /***************** 19. Not a directory *******************************/
AI_EISDIR, /***************** 20. Is a directory ********************************/
AI_EINVAL, /***************** 21. Invalid argument *****************************/
AI_ENFILE, /***************** 22. Too many open files in system ******************/
AI_EMFILE, /***************** 23. Too many open files ***************************/
AI_ENOTTY, /***************** 24. Inappropriate ioctl for device ********************/
AI_EFBIG, /***************** 25. File too large *********************************/
AI_ENOSPC, /***************** 26. No space left on device *************************/
AI_ESPIPE, /***************** 27. Illegal seek **********************************/
AI_EROFS, /***************** 28. Read-only file system **************************/
AI_EMLINK, /***************** 29. Too many links *******************************/
AI_EPIPE, /***************** 30. Broken pipe **********************************/
AI_ETIMEOUT, /***************** 31. timeout **********************************/
AI_EINITCHECK, /*****************32. graphicBuffer initCheck error****************/
AI_ECONVERT, /*****************33. convert error****************/
AI_ENOMODEL, /********************34.no model**********************/
AI_ECROP, /*************************35. crop failed**************************/
AI_ENSPT, /*************************36. not support**************************/
AI_MODEL_TENSOR_SHAPE_NO_MATCH = 500,
};
typedef enum {
MODEL_MANAGER_OK = 0,
MODEL_NAME_LEN_ERROR = 1,
MODEL_DIR_ERROR = 2,
MODEL_SECRET_KEY_ERROR = 3,
MODEL_PARA_SECRET_KEY_ERROR = 4,
FRAMEWORK_TYPE_ERROR = 5,
MODEL_TYPE_ERROR = 6,
IPU_FREQUENCY_ERROR = 7,
MODEL_NUM_ERROR = 8,
MODEL_SIZE_ERROR = 9,
TIMEOUT_ERROR = 10,
INPUT_DATA_SHAPE_ERROR = 11,
OUTPUT_DATA_SHAPE_ERROR = 12,
INPUT_DATA_NUM_ERROR = 13,
OUTPUT_DATA_NUM_ERROR = 14,
MODEL_MANAGER_TOO_MANY_ERROR = 15,
MDOEL_BUILD_TYPE_INCONSISTENT = 16,
MDOEL_FRAMEWORK_TYPE_INCONSISTENT = 17,
MODEL_NAME_DUPLICATE_ERROR = 18,
HLAI_SERVER_CONNECT_ERROR = 19,
HLAI_SERVER_CONNECT_IRPT = 20,
DLOPEN_ERROR = 21,
DLSYM_ERROR = 22,
BUILD_MODEL_ERROR = 23,
MODEL_MULTI_SEG_ERROR = 24,
INPUT_PARA_ERROR = 25,
MODEL_TENSOR_SHAPE_NO_MATCH = 500,
EXPIRATION_FUCNTION = 999,
INTERNAL_ERROR = 1000,
} MODEL_MANAGER_ERRCODE;
typedef enum {
LOW_PRI = 1,
NORMAL_PRI,
HIGH_PRI,
} AiPriority;
typedef enum {
AI_IMAGE_ENGINE = 0,
AI_SPEECH_ENGINE,
AI_MODELMNGR_ENGINE,
AI_INVALID_ENGINE = 0xff
} AiCategory;
typedef enum {
SPARSE_DISABLE = 0,
SPARSE_ENABLE,
} AiModelSparse;
typedef enum {
MODE_1BIT = 0,
MODE_8BIT,
MODE_16BIT,
MODE_32BIT,
MODE_UNKNOW
} AiDataWidth;
typedef enum {
LAYER_MODE = 0,
FUSION_MODE,
INVALID_MODE
} AiBuildMode;
typedef enum {
IPU = 1,
GPU,
DSP,
CPU,
IP_INVALID = 0xff
} AiComputingDev;
struct AiComputingRes {
int devNum;
AiComputingDev devIp[AI_MAX_COMPUTING_DEV_NUM];
};
struct AiVectorFormat {
uint32_t vectorNum;
};
struct AiAddrFormat {
uint32_t inAddr;
uint32_t inSize;
uint32_t outAddr;
uint32_t outSize;
};
typedef struct AiModelConfig {
// model config
uint32_t id;
AiDevPerf devPerf;
string modelName;
AiModelType modelType;
AiModelSparse modelSparse = SPARSE_DISABLE;
AiDataType modelDataType;
AiDataWidth modelDataWidth = MODE_UNKNOW;
uint32_t modelSize;
AiInputFormat modelInFmt;
AiOutputParam modelOutFmt;
int32_t ModelRatio;
int32_t currentRatio;
bool isFromFile = true;
// from file
string modelNetPath;
bool isModelNetEncrypted = false;
string modelNetKey;
string modelNetParamPath;
bool isModelNetParamEncrypted = false;
string modelNetParamKey;
int32_t maxUsedMemory;
// from memory
void *modelBuffer = nullptr;
uint32_t modelBufSize = 0;
string modelMeanPath;
string modelResultPath;
// execute config
AiBuildMode buildMode = INVALID_MODE;
} AiModelConfig;
typedef struct AiConfig {
// category config
string name;
bool isValid = false;
AiCategory category = AI_INVALID_ENGINE;
uint32_t priority;
AiFramework frameworkType;
AiModelType modelType;
// model config
vector<AiModelConfig> modelConfig;
AiComputingRes cmpRes;
bool subMeanEnable = true;
// TFLite indicator for tensorflow framework
bool isTFLite = false;
} AiConfig;
typedef struct ModelIOStruct {
uint32_t n;
uint32_t c;
uint32_t h;
uint32_t w;
} ModelIOStruct;
enum AI_IMAGE_FORMAT : int32_t {
AI_IMG_FMT_NV21 = 0, // YUV420: yyyy....vuvuvu...
AI_IMG_FMT_NV12 = 1, // YUV420: yyyy....uvuvuv....
AI_IMG_FMT_YUV420 = 2, // YUV420: yyyy....uuuu....vvvv....
AI_IMG_FMT_Y8 = 3, // Y: yyyy, for uv cut
AI_IMG_FMT_YUV422 = 4, // YUV422:UYVY
AI_IMG_FMT_RAW10_COMPACT = 5,
AI_IMG_FMT_RAW16 = 6, // no compress
AI_IMG_FMT_Y16 = 7,
AI_IMG_FMT_RGBA_8888 = 8,
AI_IMG_FMT_RGBX_8888 = 9,
AI_IMG_FMT_RGB_888 = 10,
AI_IMG_FMT_BGR_888 = 11,
AI_IMG_FMT_UNKOWN,
};
};
#endif // __AI_CONFIG_H__