254 lines
11 KiB
C
254 lines
11 KiB
C
/*
|
|
Copyright (c), 2001-2022, Shenshu Tech. Co., Ltd.
|
|
*/
|
|
|
|
#ifndef OT_COMMON_NNIE_H
|
|
#define OT_COMMON_NNIE_H
|
|
|
|
#include "ot_common_svp.h"
|
|
#include "ot_common.h"
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#endif
|
|
|
|
/* SVP NNIE Error Code */
|
|
typedef enum {
|
|
OT_SVP_NNIE_ERR_SYS_TIMEOUT = 0x40, /* SVP_NNIE process timeout */
|
|
OT_SVP_NNIE_ERR_QUERY_TIMEOUT = 0x41, /* SVP_NNIE query timeout */
|
|
OT_SVP_NNIE_ERR_CFG_ERR = 0x42, /* SVP_NNIE Configure error */
|
|
OT_SVP_NNIE_ERR_BUS_ERR = 0x43, /* SVP_NNIE Configure error */
|
|
OT_SVP_NNIE_ERR_OPEN_FILE = 0x44, /* SVP NNIE open file error */
|
|
OT_SVP_NNIE_ERR_READ_FILE = 0x45, /* SVP NNIE read file error */
|
|
|
|
OT_SVP_NNIE_ERR_BUTT
|
|
} ot_svp_nnie_err_code;
|
|
|
|
/* invlalid device ID */
|
|
#define OT_ERR_SVP_NNIE_INVALID_DEV_ID OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_INVALID_DEV_ID)
|
|
/* invlalid pipe ID */
|
|
#define OT_ERR_SVP_NNIE_INVALID_PIPE_ID OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_INVALID_PIPE_ID)
|
|
/* invlalid channel ID */
|
|
#define OT_ERR_SVP_NNIE_INVALID_CHN_ID OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_INVALID_CHN_ID)
|
|
#define OT_ERR_SVP_NNIE_INVALID_LAYER_ID OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_INVALID_LAYER_ID)
|
|
|
|
/* at lease one parameter is illagal */
|
|
#define OT_ERR_SVP_NNIE_ILLEGAL_PARAM OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_ILLEGAL_PARAM)
|
|
/* resource exists */
|
|
#define OT_ERR_SVP_NNIE_EXIST OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_EXIST)
|
|
/* resource unexists */
|
|
#define OT_ERR_SVP_NNIE_UNEXIST OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_UNEXIST)
|
|
/* using a TD_NULL pointer */
|
|
#define OT_ERR_SVP_NNIE_NULL_PTR OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NULL_PTR)
|
|
/* try to enable or initialize the system, device, or channel before configuring attributes. */
|
|
#define OT_ERR_SVP_NNIE_NOT_CFG OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_CFG)
|
|
/* operation or type is not supported by NOW */
|
|
#define OT_ERR_SVP_NNIE_NOT_SUPPORT OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_SUPPORT)
|
|
/* operation is not permitted. */
|
|
#define OT_ERR_SVP_NNIE_NOT_PERM OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_PERM)
|
|
|
|
#define OT_ERR_SVP_NNIE_NOT_ENABLE OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_ENABLE)
|
|
#define OT_ERR_SVP_NNIE_NOT_DISABLE OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_DISABLE)
|
|
#define OT_ERR_SVP_NNIE_NOT_START OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_START)
|
|
#define OT_ERR_SVP_NNIE_NOT_STOP OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_STOP)
|
|
/* failure caused by malloc memory */
|
|
#define OT_ERR_SVP_NNIE_NO_MEM OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NO_MEM)
|
|
/* failure caused by malloc buffer */
|
|
#define OT_ERR_SVP_NNIE_NO_BUF OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NO_BUF)
|
|
/* no data in buffer */
|
|
#define OT_ERR_SVP_NNIE_BUF_EMPTY OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_BUF_EMPTY)
|
|
/* no buffer for new data */
|
|
#define OT_ERR_SVP_NNIE_BUF_FULL OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_BUF_FULL)
|
|
/* The system is not ready because it may be not initialized or loaded. */
|
|
/* The error code is returned when a device file fails to be opened. */
|
|
#define OT_ERR_SVP_NNIE_NOT_READY OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_READY)
|
|
|
|
#define OT_ERR_SVP_NNIE_TIMEOUT OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_TIMEOUT)
|
|
/* bad address eg. used for copy_from_user & copy_to_user */
|
|
#define OT_ERR_SVP_NNIE_BAD_ADDR OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_BAD_ADDR)
|
|
/* resource is busy */
|
|
#define OT_ERR_SVP_NNIE_BUSY OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_BUSY)
|
|
/* buffer size is smaller than the actual size required */
|
|
#define OT_ERR_SVP_NNIE_SIZE_NOT_ENOUGH OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_SIZE_NOT_ENOUGH)
|
|
#define OT_ERR_SVP_NNIE_NOT_BINDED OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_NOT_BINDED)
|
|
#define OT_ERR_SVP_NNIE_BINDED OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_ERR_BINDED)
|
|
|
|
/* SVP process timeout */
|
|
#define OT_ERR_SVP_NNIE_SYS_TIMEOUT OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_SVP_NNIE_ERR_SYS_TIMEOUT)
|
|
/* SVP query timeout */
|
|
#define OT_ERR_SVP_NNIE_QUERY_TIMEOUT OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_SVP_NNIE_ERR_QUERY_TIMEOUT)
|
|
/* SVP configure error */
|
|
#define OT_ERR_SVP_NNIE_CFG_ERR OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_SVP_NNIE_ERR_CFG_ERR)
|
|
#define OT_ERR_SVP_NNIE_BUS_ERR OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_SVP_NNIE_ERR_BUS_ERR)
|
|
|
|
#define OT_ERR_SVP_NNIE_OPEN_FILE OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_SVP_NNIE_ERR_OPEN_FILE)
|
|
#define OT_ERR_SVP_NNIE_READ_FILE OT_DEFINE_ERR(OT_ID_SVP_NNIE, OT_ERR_LEVEL_ERROR, OT_SVP_NNIE_ERR_READ_FILE)
|
|
|
|
/* macro */
|
|
#define OT_SVP_NNIE_MAX_NET_SEG_NUM 8 /* NNIE max segment num that the net being cut into */
|
|
#define OT_SVP_NNIE_MAX_IN_NUM 16 /* NNIE max input num in each seg */
|
|
#define OT_SVP_NNIE_MAX_OUT_NUM 16 /* NNIE max output num in each seg */
|
|
#define OT_SVP_NNIE_MAX_ROI_LAYER_NUM_OF_SEG 2 /* NNIE max roi layer num in each seg */
|
|
#define OT_SVP_NNIE_MAX_ROI_LAYER_NUM 4 /* NNIE max roi layer num */
|
|
#define OT_SVP_NNIE_NODE_NAME_LEN 32 /* NNIE node name length */
|
|
#define OT_SVP_NNIE_MAX_THRESHOLD_NUM 2 /* NNIE max threshold num */
|
|
|
|
/* NNIE core id */
|
|
typedef enum {
|
|
OT_SVP_NNIE_ID_0 = 0x0,
|
|
|
|
OT_SVP_NNIE_ID_BUTT
|
|
} ot_svp_nnie_id;
|
|
|
|
/* Run Mode */
|
|
typedef enum {
|
|
OT_SVP_NNIE_RUN_MODE_CHIP = 0x0, /* on SOC chip running */
|
|
OT_SVP_NNIE_RUN_MODE_FUNC_SIM = 0x1, /* functional simulation */
|
|
|
|
OT_SVP_NNIE_RUN_MODE_BUTT
|
|
} ot_svp_nnie_run_mode;
|
|
|
|
/* Network type */
|
|
typedef enum {
|
|
OT_SVP_NNIE_NET_TYPE_CNN = 0x0, /* Non-ROI input cnn net */
|
|
OT_SVP_NNIE_NET_TYPE_ROI = 0x1, /* With ROI input cnn net */
|
|
OT_SVP_NNIE_NET_TYPE_RECURRENT = 0x2, /* RNN or LSTM net */
|
|
|
|
OT_SVP_NNIE_NET_TYPE_BUTT
|
|
} ot_svp_nnie_net_type;
|
|
|
|
/* Roi/Psroi Pooling type */
|
|
typedef enum {
|
|
OT_SVP_NNIE_ROI_POOL_TYPE_NORM = 0x0, /* roipooling */
|
|
OT_SVP_NNIE_ROI_POOL_TYPE_PS = 0x1, /* Position-Sensitive roipooling */
|
|
|
|
OT_SVP_NNIE_ROI_POOL_TYPE_BUTT
|
|
} ot_svp_nnie_roi_pool_type;
|
|
|
|
/* Proposal flag mask */
|
|
typedef enum {
|
|
OT_SVP_NNIE_PROPOSAL_FLAG_MASK_DECODE_BBOX = 0x1,
|
|
OT_SVP_NNIE_PROPOSAL_FLAG_MASK_NMS = 0x2,
|
|
OT_SVP_NNIE_PROPOSAL_FLAG_MASK_FILTER = 0x4,
|
|
OT_SVP_NNIE_PROPOSAL_FLAG_MASK_SORT = 0x8,
|
|
OT_SVP_NNIE_PROPOSAL_FLAG_MASK_PRIOR_BOX = 0x10,
|
|
OT_SVP_NNIE_PROPOSAL_FLAG_MASK_VAR = 0x20,
|
|
OT_SVP_NNIE_PROPOSAL_FLAG_MASK_CLASS_BBOX_NUM = 0x40,
|
|
|
|
OT_SVP_NNIE_PROPOSAL_FLAG_MASK_BUTT
|
|
} ot_svp_nnie_proposal_flag_mask;
|
|
|
|
/* Node information */
|
|
typedef struct {
|
|
ot_svp_blob_type type;
|
|
union {
|
|
struct {
|
|
td_u32 width;
|
|
td_u32 height;
|
|
td_u32 chn;
|
|
} whc; /* AUTO:ot_svp_blob_type:other; */
|
|
td_u32 dim; /* AUTO:ot_svp_blob_type:OT_SVP_BLOB_TYPE_SEQ_S20Q12; */
|
|
} shape;
|
|
td_u32 node_id;
|
|
td_char name[OT_SVP_NNIE_NODE_NAME_LEN]; /* Report layer bottom name or data layer bottom name */
|
|
} ot_svp_nnie_node;
|
|
|
|
/* RoiPooling information */
|
|
typedef struct {
|
|
td_u32 src_height; /* ROI/PSROI Pooling src height */
|
|
td_u32 src_width; /* ROI/PSROI Pooling src width */
|
|
td_u32 src_map_num; /* Input feature map channel */
|
|
|
|
td_u32 dst_height; /* ROI/PSROI Pooling dst height */
|
|
td_u32 dst_width; /* ROI/PSROI Pooling dst width */
|
|
td_u32 dst_map_num; /* Output feature map channel */
|
|
|
|
td_u32 norm_width_ram_offset;
|
|
td_u32 norm_height_ram_offset;
|
|
td_u32 total_width_ram_offset;
|
|
td_u32 total_height_ram_offset;
|
|
|
|
td_u32 blk_max_height; /* Block max height */
|
|
td_u32 blk_num; /* Block number */
|
|
td_u32 bbox_max_num; /* Bbox max number */
|
|
td_u32 spatial_scale;
|
|
|
|
td_bool norm_ping_pong_mode_en; /* whether use PingPong mode */
|
|
td_bool total_ping_pong_mode_en; /* whether use PingPong mode */
|
|
td_bool high_precision_en; /* whether use high precision mode */
|
|
ot_svp_nnie_roi_pool_type roi_pool_type; /* ROIPooling or PSROIPooling */
|
|
td_char name[OT_SVP_NNIE_NODE_NAME_LEN]; /* Report layer bottom name or data layer bottom name */
|
|
} ot_svp_nnie_roi_pool_info;
|
|
|
|
/* Segment information */
|
|
typedef struct {
|
|
ot_svp_nnie_net_type net_type;
|
|
td_u16 src_num;
|
|
td_u16 dst_num;
|
|
td_u16 roi_pool_num;
|
|
td_u16 max_step;
|
|
|
|
td_u32 instr_offset;
|
|
td_u32 instr_len;
|
|
|
|
td_u32 proposal_flag;
|
|
td_u32 prior_box_num;
|
|
td_u32 var_num;
|
|
|
|
ot_svp_nnie_node src_node[OT_SVP_NNIE_MAX_IN_NUM];
|
|
ot_svp_nnie_node dst_node[OT_SVP_NNIE_MAX_OUT_NUM];
|
|
td_u32 roi_idx[OT_SVP_NNIE_MAX_ROI_LAYER_NUM_OF_SEG]; /* Roipooling info index */
|
|
} ot_svp_nnie_seg;
|
|
|
|
/* NNIE model */
|
|
typedef struct {
|
|
ot_svp_nnie_run_mode run_mode;
|
|
|
|
td_u32 model_version; /* model version */
|
|
td_u32 arch_version; /* arch version */
|
|
|
|
td_u32 tmp_buf_size; /* temp buffer size */
|
|
td_u32 net_seg_num;
|
|
ot_svp_nnie_seg seg[OT_SVP_NNIE_MAX_NET_SEG_NUM];
|
|
ot_svp_nnie_roi_pool_info roi_info[OT_SVP_NNIE_MAX_ROI_LAYER_NUM];
|
|
|
|
ot_svp_mem_info base;
|
|
ot_svp_blob prior_box[OT_SVP_NNIE_MAX_NET_SEG_NUM];
|
|
} ot_svp_nnie_model;
|
|
|
|
/* Thresh */
|
|
typedef struct {
|
|
td_u32 min_width; /* min width */
|
|
td_u32 min_height; /* min height */
|
|
td_u32 nms_threshold; /* nms threshold */
|
|
td_u32 score_threshold; /* score threshold */
|
|
} ot_svp_nnie_threshold;
|
|
|
|
/* Forward ctrl */
|
|
typedef struct {
|
|
td_u32 src_num; /* input node num, [1, 16] */
|
|
td_u32 dst_num; /* output node num, [1, 16] */
|
|
td_u32 threshold_num; /* thresh num, [0, 2] */
|
|
td_u32 net_seg_id; /* net segment index running on NNIE */
|
|
ot_svp_nnie_id nnie_id; /* device target which running the seg */
|
|
ot_svp_nnie_threshold threshold[OT_SVP_NNIE_MAX_THRESHOLD_NUM]; /* threshold */
|
|
ot_svp_mem_info tmp_buf; /* auxiliary temp mem */
|
|
ot_svp_mem_info task_buf; /* auxiliary task mem */
|
|
} ot_svp_nnie_forward_ctrl;
|
|
|
|
/* Task buf info */
|
|
typedef struct {
|
|
td_u32 task_buf_size; /* task buf size */
|
|
td_u32 prior_box_num; /* priorbox num */
|
|
td_u32 var_num; /* variance num */
|
|
} ot_svp_nnie_task_buf_info;
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|
|
#endif /* OT_COMMON_NNIE_H */
|