• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef _HI_NNIE_H_
17 #define _HI_NNIE_H_
18 
19 #include "hi_comm_svp.h"
20 #include "hi_common.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 /* SVP_NNIE Error Code */
29 typedef enum hiEN_SVP_NNIE_ERR_CODE_E {
30     ERR_SVP_NNIE_SYS_TIMEOUT = 0x40, /* SVP_NNIE process timeout */
31     ERR_SVP_NNIE_QUERY_TIMEOUT = 0x41, /* SVP_NNIE query timeout */
32     ERR_SVP_NNIE_CFG_ERR = 0x42, /* SVP_NNIE Configure error */
33     ERR_SVP_NNIE_OPEN_FILE = 0x43, /* SVP NNIE open file error */
34     ERR_SVP_NNIE_READ_FILE = 0x44, /* SVP NNIE read file error */
35     ERR_SVP_NNIE_WRITE_FILE = 0x45, /* SVP NNIE write file error */
36 
37     ERR_SVP_NNIE_BUTT
38 } EN_SVP_NNIE_ERR_CODE_E;
39 /* Invalid device ID */
40 #define HI_ERR_SVP_NNIE_INVALID_DEVID     HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_INVALID_DEVID)
41 /* Invalid channel ID */
42 #define HI_ERR_SVP_NNIE_INVALID_CHNID     HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_INVALID_CHNID)
43 /* At least one parameter is illegal. For example, an illegal enumeration value exists. */
44 #define HI_ERR_SVP_NNIE_ILLEGAL_PARAM     HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_ILLEGAL_PARAM)
45 /* The channel exists. */
46 #define HI_ERR_SVP_NNIE_EXIST             HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_EXIST)
47 /* The UN exists. */
48 #define HI_ERR_SVP_NNIE_UNEXIST           HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_UNEXIST)
49 /* A null point is used. */
50 #define HI_ERR_SVP_NNIE_NULL_PTR          HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_NULL_PTR)
51 /* Try to enable or initialize the system, device, or channel before configuring attributes. */
52 #define HI_ERR_SVP_NNIE_NOT_CONFIG        HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_CONFIG)
53 /* The operation is not supported currently. */
54 #define HI_ERR_SVP_NNIE_NOT_SURPPORT      HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_SUPPORT)
55 /* The operation, changing static attributes for example, is not permitted. */
56 #define HI_ERR_SVP_NNIE_NOT_PERM          HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_PERM)
57 /* A failure caused by the malloc memory occurs. */
58 #define HI_ERR_SVP_NNIE_NOMEM             HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_NOMEM)
59 /* A failure caused by the malloc buffer occurs. */
60 #define HI_ERR_SVP_NNIE_NOBUF             HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_NOBUF)
61 /* The buffer is empty. */
62 #define HI_ERR_SVP_NNIE_BUF_EMPTY         HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_BUF_EMPTY)
63 /* No buffer is provided for storing new data. */
64 #define HI_ERR_SVP_NNIE_BUF_FULL          HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_BUF_FULL)
65 /* The system is not ready because it may be not initialized or loaded. */
66 /* The error code is returned when a device file fails to be opened. */
67 #define HI_ERR_SVP_NNIE_NOTREADY          HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_SYS_NOTREADY)
68 /* The source address or target address is incorrect during the operations */
69 #define HI_ERR_SVP_NNIE_BADADDR           HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_BADADDR)
70 /* The resource is busy during the operations */
71 #define HI_ERR_SVP_NNIE_BUSY              HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, EN_ERR_BUSY)
72 /* SVP_NNIE process timeout */
73 #define HI_ERR_SVP_NNIE_SYS_TIMEOUT       HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, ERR_SVP_NNIE_SYS_TIMEOUT)
74 /* SVP_NNIE query timeout */
75 #define HI_ERR_SVP_NNIE_QUERY_TIMEOUT     HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, ERR_SVP_NNIE_QUERY_TIMEOUT)
76 /* SVP_NNIE configure error */
77 #define HI_ERR_SVP_NNIE_CFG_ERR           HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, ERR_SVP_NNIE_CFG_ERR)
78 #define HI_ERR_SVP_NNIE_OPEN_FILE         HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, ERR_SVP_NNIE_OPEN_FILE)
79 #define HI_ERR_SVP_NNIE_READ_FILE         HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, ERR_SVP_NNIE_READ_FILE)
80 #define HI_ERR_SVP_NNIE_WRITE_FILE        HI_DEF_ERR(HI_ID_SVP_NNIE, EN_ERR_LEVEL_ERROR, ERR_SVP_NNIE_WRITE_FILE)
81 
82 /* macro */
83 #define SVP_NNIE_MAX_NET_SEG_NUM          8 /* NNIE max segment num that the net being cut into */
84 #define SVP_NNIE_MAX_INPUT_NUM            16 /* NNIE max input num in each seg */
85 #define SVP_NNIE_MAX_OUTPUT_NUM           16 /* NNIE max output num in each seg */
86 #define SVP_NNIE_MAX_ROI_LAYER_NUM_OF_SEG 2 /* NNIE max roi layer num in each seg */
87 #define SVP_NNIE_MAX_ROI_LAYER_NUM        4 /* NNIE max roi layer num */
88 #define SVP_NNIE_NODE_NAME_LEN            32 /* NNIE node name length */
89 
90 /* NNIE core id */
91 typedef enum hiSVP_NNIE_ID_E {
92     SVP_NNIE_ID_0 = 0x0,
93 
94     SVP_NNIE_ID_BUTT
95 } SVP_NNIE_ID_E;
96 
97 /* Run Mode */
98 typedef enum hiSVP_NNIE_RUN_MODE_E {
99     SVP_NNIE_RUN_MODE_CHIP = 0x0, /* on SOC chip running */
100     SVP_NNIE_RUN_MODE_FUNC_SIM = 0x1, /* functional simultaion */
101 
102     SVP_NNIE_RUN_MODE_BUTT
103 } SVP_NNIE_RUN_MODE_E;
104 
105 /* Network type */
106 typedef enum hiSVP_NNIE_NET_TYPE_E {
107     SVP_NNIE_NET_TYPE_CNN = 0x0, /* Non-ROI input cnn net */
108     SVP_NNIE_NET_TYPE_ROI = 0x1, /* With ROI input cnn net */
109     SVP_NNIE_NET_TYPE_RECURRENT = 0x2, /* RNN or LSTM net */
110 
111     SVP_NNIE_NET_TYPE_BUTT
112 } SVP_NNIE_NET_TYPE_E;
113 
114 /* Node information */
115 typedef struct hiSVP_NNIE_NODE_S {
116     SVP_BLOB_TYPE_E enType;
117     union {
118         struct {
119             HI_U32 u32Width;
120             HI_U32 u32Height;
121             HI_U32 u32Chn;
122         } stWhc;
123         HI_U32 u32Dim;
124     } unShape;
125     HI_U32 u32NodeId;
126     HI_CHAR szName[SVP_NNIE_NODE_NAME_LEN]; /* Report layer bottom name or data layer bottom name */
127 } SVP_NNIE_NODE_S;
128 
129 /* Roi/Psroi Pooling type */
130 typedef enum hiSVP_NNIE_ROIPOOL_TYPE_E {
131     SVP_NNIE_ROIPOOL_TYPE_NORMAL = 0x0, /* Roipooling */
132     SVP_NNIE_ROIPOOL_TYPE_PS = 0x1, /* Position-Sensitive roipooling */
133 
134     SVP_NNIE_ROIPOOL_TYPE_BUTT
135 } SVP_NNIE_ROIPOOL_TYPE_E;
136 
137 /* RoiPooling information */
138 typedef struct hiSVP_NNIE_ROIPOOL_INFO_S {
139     HI_U32 u32SrcHeight; /* ROI/PSROI Pooling  src height */
140     HI_U32 u32SrcWidth; /* ROI/PSROI Pooling src width */
141     HI_U32 u32SrcMapNum; /* Input featrue map channel */
142 
143     HI_U32 u32DstHeight; /* ROI/PSROI Pooling dst height */
144     HI_U32 u32DstWidth; /* ROI/PSROI Pooling dst width */
145     HI_U32 u32DstMapNum; /* Output featrue map channel */
146 
147     HI_U32 u32DinWidthRamOffset;
148     HI_U32 u32DinHeightRamOffset;
149     HI_U32 u32TotalDinWidthRamOffset;
150     HI_U32 u32TotalDinHeightRamOffset;
151 
152     HI_U32 u32BlockMaxHeight; /* Block max height */
153     HI_U32 u32BlockNum; /* Block number */
154     HI_U32 u32BboxMaxNum; /* Bbox max number */
155     HI_U32 u32SpatialScale;
156 
157     HI_BOOL bNormPPMode; /* whether use PingPang mode */
158     HI_BOOL bTotalPPMode; /* whether use PingPang mode */
159     HI_BOOL bHighPrec; /* whether use high precision mode */
160     SVP_NNIE_ROIPOOL_TYPE_E enRoiPoolType; /* ROIPooling or PSROIPooling */
161     HI_CHAR szName[SVP_NNIE_NODE_NAME_LEN]; /* Report layer bottom name or data layer bottom name */
162 } SVP_NNIE_ROIPOOL_INFO_S;
163 
164 /* Segment information */
165 typedef struct hiSVP_NNIE_SEG_S {
166     SVP_NNIE_NET_TYPE_E enNetType;
167     HI_U16 u16SrcNum;
168     HI_U16 u16DstNum;
169     HI_U16 u16RoiPoolNum;
170     HI_U16 u16MaxStep;
171 
172     HI_U32 u32InstOffset;
173     HI_U32 u32InstLen;
174 
175     SVP_NNIE_NODE_S astSrcNode[SVP_NNIE_MAX_INPUT_NUM];
176     SVP_NNIE_NODE_S astDstNode[SVP_NNIE_MAX_OUTPUT_NUM];
177     HI_U32 au32RoiIdx[SVP_NNIE_MAX_ROI_LAYER_NUM_OF_SEG]; /* Roipooling info index */
178 } SVP_NNIE_SEG_S;
179 
180 /* NNIE model */
181 typedef struct hiSVP_NNIE_MODEL_S {
182     SVP_NNIE_RUN_MODE_E enRunMode;
183 
184     HI_U32 u32TmpBufSize; /* temp buffer size */
185     HI_U32 u32NetSegNum;
186     SVP_NNIE_SEG_S astSeg[SVP_NNIE_MAX_NET_SEG_NUM];
187     SVP_NNIE_ROIPOOL_INFO_S astRoiInfo[SVP_NNIE_MAX_ROI_LAYER_NUM]; /* ROIPooling info */
188 
189     SVP_MEM_INFO_S stBase;
190 } SVP_NNIE_MODEL_S;
191 
192 typedef struct hiSVP_NNIE_FORWARD_CTRL_S {
193     HI_U32 u32SrcNum; /* input node num, [1, 16] */
194     HI_U32 u32DstNum; /* output node num, [1, 16] */
195     HI_U32 u32NetSegId; /* net segment index running on NNIE */
196     SVP_NNIE_ID_E enNnieId; /* device target which running the seg */
197     SVP_MEM_INFO_S stTmpBuf; /* auxiliary temp mem */
198     SVP_MEM_INFO_S stTskBuf; /* auxiliary task mem */
199 } SVP_NNIE_FORWARD_CTRL_S;
200 
201 typedef struct hiSVP_NNIE_FORWARD_WITHBBOX_CTRL_S {
202     HI_U32 u32SrcNum; /* input node num, [1, 16] */
203     HI_U32 u32DstNum; /* output node num, [1, 16] */
204     HI_U32 u32ProposalNum; /* elment num of  roi array */
205     HI_U32 u32NetSegId; /* net segment index running on NNIE */
206     SVP_NNIE_ID_E enNnieId; /* device target which running the seg */
207     SVP_MEM_INFO_S stTmpBuf; /* auxiliary temp mem */
208     SVP_MEM_INFO_S stTskBuf; /* auxiliary task mem */
209 } SVP_NNIE_FORWARD_WITHBBOX_CTRL_S;
210 
211 #ifdef __cplusplus
212 #if __cplusplus
213 }
214 #endif
215 #endif
216 #endif /* _HI_NNIE_H_ */
217