sample_comm_svp.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #ifndef __SAMPLE_COMM_SVP_H__
  2. #define __SAMPLE_COMM_SVP_H__
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <errno.h>
  7. #include <fcntl.h>
  8. #include <sys/mman.h>
  9. #include <sys/stat.h>
  10. #include <sys/types.h>
  11. #include <unistd.h>
  12. #include <signal.h>
  13. #include "hi_common.h"
  14. #include "hi_debug.h"
  15. #include "hi_dsp.h"
  16. #ifdef __cplusplus
  17. #if __cplusplus
  18. extern "C"{
  19. #endif
  20. #endif /* __cplusplus */
  21. //#########################add##########################
  22. //增加代码,补充SAMPLE_SVP_NNIE_Yolov3_SoftwareInit中缺少的定义
  23. #define SAMPLE_SVP_NNIE_YOLOV3_REPORT_BLOB_NUM 3 /*yolov3 report blob num*/
  24. //增加代码,补充SVP_NNIE_Yolov3_GetResult中缺少的定义
  25. typedef struct hiSAMPLE_SVP_NNIE_YOLOV2_BBOX
  26. {
  27. HI_FLOAT f32Xmin;
  28. HI_FLOAT f32Xmax;
  29. HI_FLOAT f32Ymin;
  30. HI_FLOAT f32Ymax;
  31. HI_S32 s32ClsScore;
  32. HI_U32 u32ClassIdx;
  33. HI_U32 u32Mask;
  34. }SAMPLE_SVP_NNIE_YOLOV2_BBOX_S;
  35. typedef SAMPLE_SVP_NNIE_YOLOV2_BBOX_S SAMPLE_SVP_NNIE_YOLOV3_BBOX_S;
  36. #define SAMPLE_SVP_NNIE_YOLOV3_EACH_GRID_BIAS_NUM 6 /*yolov3 bias num of each grid*/
  37. #define SAMPLE_SVP_NNIE_YOLOV3_EACH_BBOX_INFER_RESULT_NUM 7 /*yolov3 inference result num of each bbox*/ //4+1+2
  38. #define SAMPLE_SVP_NNIE_SIGMOID(x) (HI_FLOAT)(1.0f/(1+exp(-x)))
  39. //##########################add#########################
  40. typedef enum hiSAMPLE_SVP_ERR_LEVEL_E
  41. {
  42. SAMPLE_SVP_ERR_LEVEL_DEBUG = 0x0, /* debug-level */
  43. SAMPLE_SVP_ERR_LEVEL_INFO = 0x1, /* informational */
  44. SAMPLE_SVP_ERR_LEVEL_NOTICE = 0x2, /* normal but significant condition */
  45. SAMPLE_SVP_ERR_LEVEL_WARNING = 0x3, /* warning conditions */
  46. SAMPLE_SVP_ERR_LEVEL_ERROR = 0x4, /* error conditions */
  47. SAMPLE_SVP_ERR_LEVEL_CRIT = 0x5, /* critical conditions */
  48. SAMPLE_SVP_ERR_LEVEL_ALERT = 0x6, /* action must be taken immediately */
  49. SAMPLE_SVP_ERR_LEVEL_FATAL = 0x7, /* just for compatibility with previous version */
  50. SAMPLE_SVP_ERR_LEVEL_BUTT
  51. }SAMPLE_SVP_ERR_LEVEL_E;
  52. #define SAMPLE_SVP_PRINTF(LevelStr,Msg, ...) do { fprintf(stderr,"[Level]:%s,[Func]:%s [Line]:%d [Info]:"Msg,LevelStr, __FUNCTION__, __LINE__,## __VA_ARGS__); } while (0)
  53. #define SAMPLE_SVP_PRINTF_RED(LevelStr,Msg, ...) do { fprintf(stderr,"\033[0;31m [Level]:%s,[Func]:%s [Line]:%d [Info]:"Msg"\033[0;39m\n",LevelStr, __FUNCTION__, __LINE__,## __VA_ARGS__); } while (0)
  54. /* system is unusable */
  55. #define SAMPLE_SVP_TRACE_FATAL(Msg,...) SAMPLE_SVP_PRINTF_RED("Fatal",Msg,##__VA_ARGS__)
  56. /* action must be taken immediately */
  57. #define SAMPLE_SVP_TRACE_ALERT(Msg,...) SAMPLE_SVP_PRINTF_RED("Alert",Msg,##__VA_ARGS__)
  58. /* critical conditions */
  59. #define SAMPLE_SVP_TRACE_CRIT(Msg,...) SAMPLE_SVP_PRINTF_RED("Critical",Msg,##__VA_ARGS__)
  60. /* error conditions */
  61. #define SAMPLE_SVP_TRACE_ERR(Msg,...) SAMPLE_SVP_PRINTF_RED("Error",Msg,##__VA_ARGS__)
  62. /* warning conditions */
  63. #define SAMPLE_SVP_TRACE_WARN(Msg,...) SAMPLE_SVP_PRINTF("Warning",Msg,##__VA_ARGS__)
  64. /* normal but significant condition */
  65. #define SAMPLE_SVP_TRACE_NOTICE(Msg,...) SAMPLE_SVP_PRINTF("Notice",Msg,##__VA_ARGS__)
  66. /* informational */
  67. #define SAMPLE_SVP_TRACE_INFO(Msg,...) SAMPLE_SVP_PRINTF("Info",Msg,##__VA_ARGS__)
  68. /* debug-level messages */
  69. #define SAMPLE_SVP_TRACE_DEBUG(Msg, ...) SAMPLE_SVP_PRINTF("Debug",Msg,##__VA_ARGS__)
  70. #define SAMPLE_SVP_TRACE(Level,Msg, ...)\
  71. do\
  72. {\
  73. switch(Level){\
  74. case SAMPLE_SVP_ERR_LEVEL_DEBUG:\
  75. SAMPLE_SVP_TRACE_DEBUG(Msg,##__VA_ARGS__);\
  76. break;\
  77. case SAMPLE_SVP_ERR_LEVEL_INFO:\
  78. SAMPLE_SVP_TRACE_INFO(Msg,##__VA_ARGS__);\
  79. break;\
  80. case SAMPLE_SVP_ERR_LEVEL_NOTICE:\
  81. SAMPLE_SVP_TRACE_NOTICE(Msg,##__VA_ARGS__);\
  82. break;\
  83. case SAMPLE_SVP_ERR_LEVEL_WARNING:\
  84. SAMPLE_SVP_TRACE_WARN(Msg,##__VA_ARGS__);\
  85. break;\
  86. case SAMPLE_SVP_ERR_LEVEL_ERROR:\
  87. SAMPLE_SVP_TRACE_ERR(Msg,##__VA_ARGS__);\
  88. break;\
  89. case SAMPLE_SVP_ERR_LEVEL_CRIT:\
  90. SAMPLE_SVP_TRACE_CRIT(Msg,##__VA_ARGS__);\
  91. break;\
  92. case SAMPLE_SVP_ERR_LEVEL_ALERT:\
  93. SAMPLE_SVP_TRACE_ALERT(Msg,##__VA_ARGS__);\
  94. break;\
  95. case SAMPLE_SVP_ERR_LEVEL_FATAL:\
  96. SAMPLE_SVP_TRACE_FATAL(Msg,##__VA_ARGS__);\
  97. break;\
  98. default:\
  99. break;\
  100. }\
  101. }while(0)
  102. /****
  103. *Expr is true,goto
  104. */
  105. #define SAMPLE_SVP_CHECK_EXPR_GOTO(Expr, Label,Level,Msg, ...) \
  106. do{ \
  107. if(Expr) \
  108. { \
  109. SAMPLE_SVP_TRACE(Level,Msg,## __VA_ARGS__); \
  110. goto Label; \
  111. } \
  112. }while(0)
  113. /****
  114. *Expr is true,return void
  115. */
  116. #define SAMPLE_SVP_CHECK_EXPR_RET_VOID(Expr,Level,Msg, ...) \
  117. do{ \
  118. if(Expr) \
  119. { \
  120. SAMPLE_SVP_TRACE(Level,Msg, ##__VA_ARGS__); \
  121. return; \
  122. } \
  123. }while(0)
  124. /****
  125. *Expr is true,return Ret
  126. */
  127. #define SAMPLE_SVP_CHECK_EXPR_RET(Expr,Ret,Level,Msg, ...) \
  128. do{ \
  129. if(Expr) \
  130. { \
  131. SAMPLE_SVP_TRACE(Level,Msg, ##__VA_ARGS__); \
  132. return Ret; \
  133. } \
  134. }while(0)
  135. /****
  136. *Expr is true,trace
  137. */
  138. #define SAMPLE_SVP_CHECK_EXPR_TRACE(Expr,Level,Msg, ...) \
  139. do{ \
  140. if(Expr) \
  141. { \
  142. SAMPLE_SVP_TRACE(Level,Msg, ##__VA_ARGS__); \
  143. } \
  144. }while(0)
  145. #define SAMPLE_SVP_ALIGN_16 16
  146. #define SAMPLE_SVP_ALIGN_32 32
  147. #define SAMPLE_SVP_D1_PAL_HEIGHT 576
  148. #define SAMPLE_SVP_D1_PAL_WIDTH 704
  149. //free mmz
  150. #define SAMPLE_SVP_MMZ_FREE(phy,vir)\
  151. do{\
  152. if ((0 != (phy)) && (0 != (vir)))\
  153. {\
  154. HI_MPI_SYS_MmzFree((phy),(void*)(vir));\
  155. (phy) = 0;\
  156. (vir) = 0;\
  157. }\
  158. }while(0)
  159. #define SAMPLE_SVP_CLOSE_FILE(fp)\
  160. do{\
  161. if (NULL != (fp))\
  162. {\
  163. fclose((fp));\
  164. (fp) = NULL;\
  165. }\
  166. }while(0)
  167. /*
  168. *System init
  169. */
  170. void SAMPLE_COMM_SVP_CheckSysInit(void);
  171. /*
  172. *System exit
  173. */
  174. void SAMPLE_COMM_SVP_CheckSysExit(void);
  175. /*
  176. *Load bin
  177. */
  178. HI_S32 SAMPLE_COMM_SVP_LoadCoreBinary(SVP_DSP_ID_E enCoreId);
  179. /*
  180. *UnLoad bin
  181. */
  182. void SAMPLE_COMM_SVP_UnLoadCoreBinary(SVP_DSP_ID_E enCoreId);
  183. /*
  184. *Align
  185. */
  186. HI_U32 SAMPLE_COMM_SVP_Align(HI_U32 u32Size, HI_U16 u16Align);
  187. /*
  188. *Create Image memory
  189. */
  190. HI_S32 SAMPLE_COMM_SVP_CreateImage(SVP_IMAGE_S *pstImg,SVP_IMAGE_TYPE_E enType,HI_U32 u32Width,
  191. HI_U32 u32Height,HI_U32 u32AddrOffset);
  192. /*
  193. *Destory image memory
  194. */
  195. HI_VOID SAMPLE_COMM_SVP_DestroyImage(SVP_IMAGE_S *pstImg,HI_U32 u32AddrOffset);
  196. /*
  197. *Create mem info
  198. */
  199. HI_S32 SAMPLE_COMM_SVP_CreateMemInfo(SVP_MEM_INFO_S *pstMemInfo,HI_U32 u32Size,HI_U32 u32AddrOffset);
  200. /*
  201. Destory mem info
  202. */
  203. HI_VOID SAMPLE_COMM_SVP_DestroyMemInfo(SVP_MEM_INFO_S *pstMemInfo,HI_U32 u32AddrOffset);
  204. /*
  205. *Malloc memory
  206. */
  207. HI_S32 SAMPLE_COMM_SVP_MallocMem(HI_CHAR *pszMmb, HI_CHAR *pszZone, HI_U64 *pu64PhyAddr, HI_VOID **ppvVirAddr, HI_U32 u32Size);
  208. /*
  209. *Malloc memory with cached
  210. */
  211. HI_S32 SAMPLE_COMM_SVP_MallocCached(HI_CHAR *pszMmb, HI_CHAR *pszZone,HI_U64 *pu64PhyAddr, HI_VOID **ppvVirAddr, HI_U32 u32Size);
  212. /*
  213. *Fulsh cached
  214. */
  215. HI_S32 SAMPLE_COMM_SVP_FlushCache(HI_U64 u64PhyAddr, HI_VOID *pvVirAddr, HI_U32 u32Size);
  216. /*
  217. *Gen rand data
  218. */
  219. HI_S32 SAMPLE_COMM_SVP_GenRandS32(HI_S32 s32Max,HI_S32 s32Min);
  220. /*
  221. *Gen image
  222. */
  223. HI_VOID SAMPLE_COMM_SVP_GenImage(HI_U64 au64Buff[3],HI_U32 au32Stride[3],SVP_IMAGE_TYPE_E enType,HI_U32 u32Width,HI_U32 u32Height);
  224. #ifdef __cplusplus
  225. #if __cplusplus
  226. }
  227. #endif
  228. #endif /* __cplusplus */
  229. #endif /* __SAMPLE_COMM_SVP_H__ */