hi_nnie.h 10 KB

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