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

slog.h 17 kB

5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef D_SYSLOG_H_
  17. #define D_SYSLOG_H_
  18. static const int TMP_LOG = 0;
  19. #ifdef __cplusplus
  20. #ifndef LOG_CPP
  21. extern "C" {
  22. #endif
  23. #endif // __cplusplus
  24. #ifndef LINUX
  25. #define LINUX 0
  26. #endif // LINUX
  27. #ifndef WIN
  28. #define WIN 1
  29. #endif
  30. #ifndef OS_TYPE
  31. #define OS_TYPE 0
  32. #endif // OS_TYPE
  33. #if (OS_TYPE == LINUX)
  34. #define DLL_EXPORT __attribute__((visibility("default")))
  35. #else
  36. #define DLL_EXPORT _declspec(dllexport)
  37. #endif
  38. /**
  39. * @ingroup slog
  40. *
  41. * debug level id
  42. */
  43. #define DLOG_DEBUG 0
  44. /**
  45. * @ingroup slog
  46. *
  47. * info level id
  48. */
  49. #define DLOG_INFO 1
  50. /**
  51. * @ingroup slog
  52. *
  53. * warning level id
  54. */
  55. #define DLOG_WARN 2
  56. /**
  57. * @ingroup slog
  58. *
  59. * error level id
  60. */
  61. #define DLOG_ERROR 3
  62. /**
  63. * @ingroup slog
  64. *
  65. * don't print log
  66. */
  67. #define DLOG_NULL 4
  68. /**
  69. * @ingroup slog
  70. *
  71. * trace log print level id
  72. */
  73. #define DLOG_TRACE 5
  74. /**
  75. * @ingroup slog
  76. *
  77. * oplog log print level id
  78. */
  79. #define DLOG_OPLOG 6
  80. /**
  81. * @ingroup slog
  82. *
  83. * event log print level id
  84. */
  85. #define DLOG_EVENT 0x10
  86. /**
  87. * @ingroup slog
  88. *
  89. * max log length
  90. */
  91. #define MSG_LENGTH 1024
  92. #define DEBUG_LOG_MASK (0x00010000)
  93. #define SECURITY_LOG_MASK (0x00100000)
  94. #define RUN_LOG_MASK (0x01000000)
  95. #define OPERATION_LOG_MASK (0x10000000)
  96. #define RESERVERD_LENGTH 52
  97. typedef struct tagDCODE {
  98. const char *cName;
  99. int cVal;
  100. } DCODE;
  101. typedef struct tagKV {
  102. char *kname;
  103. char *value;
  104. } KeyValue;
  105. typedef enum {
  106. APPLICATION = 0,
  107. SYSTEM
  108. } ProcessType;
  109. typedef struct {
  110. ProcessType type;
  111. unsigned int pid;
  112. unsigned int deviceId;
  113. char reserved[RESERVERD_LENGTH];
  114. } LogAttr;
  115. /**
  116. * @ingroup slog
  117. *
  118. * module id
  119. */
  120. enum {
  121. SLOG, /**< Slog */
  122. IDEDD, /**< IDE daemon device */
  123. IDEDH, /**< IDE daemon host */
  124. HCCL, /**< HCCL */
  125. FMK, /**< Adapter */
  126. HIAIENGINE, /**< Matrix */
  127. DVPP, /**< DVPP */
  128. RUNTIME, /**< Runtime */
  129. CCE, /**< CCE */
  130. #if (OS_TYPE == LINUX)
  131. HDC, /**< HDC */
  132. #else
  133. HDCL,
  134. #endif // OS_TYPE
  135. DRV, /**< Driver */
  136. MDCFUSION, /**< Mdc fusion */
  137. MDCLOCATION, /**< Mdc location */
  138. MDCPERCEPTION, /**< Mdc perception */
  139. MDCFSM,
  140. MDCCOMMON,
  141. MDCMONITOR,
  142. MDCBSWP, /**< MDC base software platform */
  143. MDCDEFAULT, /**< MDC undefine */
  144. MDCSC, /**< MDC spatial cognition */
  145. MDCPNC,
  146. MLL, /**< abandon */
  147. DEVMM, /**< Dlog memory managent */
  148. KERNEL, /**< Kernel */
  149. LIBMEDIA, /**< Libmedia */
  150. CCECPU, /**< aicpu shedule */
  151. ASCENDDK, /**< AscendDK */
  152. ROS, /**< ROS */
  153. HCCP,
  154. ROCE,
  155. TEFUSION,
  156. PROFILING, /**< Profiling */
  157. DP, /**< Data Preprocess */
  158. APP, /**< User Application */
  159. TS, /**< TS module */
  160. TSDUMP, /**< TSDUMP module */
  161. AICPU, /**< AICPU module */
  162. LP, /**< LP module */
  163. TDT, /**< tsdaemon or aicpu shedule */
  164. FE,
  165. MD,
  166. MB,
  167. ME,
  168. IMU,
  169. IMP,
  170. GE, /**< Fmk */
  171. MDCFUSA,
  172. CAMERA,
  173. ASCENDCL,
  174. TEEOS,
  175. ISP,
  176. SIS,
  177. HSM,
  178. DSS,
  179. PROCMGR, // Process Manager, Base Platform
  180. BBOX,
  181. AIVECTOR,
  182. TBE,
  183. FV,
  184. MDCMAP,
  185. TUNE,
  186. HSS, /**< helper */
  187. INVLID_MOUDLE_ID
  188. };
  189. /**
  190. * @ingroup slog
  191. * @brief External log interface, which called by modules
  192. */
  193. DLL_EXPORT void dlog_init(void);
  194. /**
  195. * @ingroup slog
  196. * @brief dlog_getlevel: get module loglevel and enableEvent
  197. *
  198. * @param [in]moduleId: moudule id(see slog.h, eg: CCE), others: invalid
  199. * @param [out]enableEvent: 1: enable; 0: disable
  200. * @return: module level(0: debug, 1: info, 2: warning, 3: error, 4: null output)
  201. */
  202. DLL_EXPORT int dlog_getlevel(int moduleId, int *enableEvent);
  203. /**
  204. * @ingroup slog
  205. * @brief dlog_setlevel: set module loglevel and enableEvent
  206. *
  207. * @param [in]moduleId: moudule id(see slog.h, eg: CCE), -1: all modules, others: invalid
  208. * @param [in]level: log level(0: debug, 1: info, 2: warning, 3: error, 4: null output)
  209. * @param [in]enableEvent: 1: enable; 0: disable, others:invalid
  210. * @return: 0: SUCCEED, others: FAILED
  211. */
  212. DLL_EXPORT int dlog_setlevel(int moduleId, int level, int enableEvent);
  213. /**
  214. * @ingroup slog
  215. * @brief CheckLogLevel: check module level enable or not
  216. * users no need to call it because all dlog interface(include inner interface) has already called
  217. *
  218. * @param [in]moduleId: module id, eg: CCE
  219. * @param [in]logLevel: eg: DLOG_EVENT/DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
  220. * @return: 1:enable, 0:disable
  221. */
  222. DLL_EXPORT int CheckLogLevel(int moduleId, int logLevel);
  223. /**
  224. * @ingroup slog
  225. * @brief DlogSetAttr: set log attr, default pid is 0, default device id is 0, default process type is APPLICATION
  226. * @param [in]logAttr: attr info, include pid(must be larger than 0), process type and device id(chip ID)
  227. * @return: 0: SUCCEED, others: FAILED
  228. */
  229. DLL_EXPORT int DlogSetAttr(LogAttr logAttr);
  230. /**
  231. * @ingroup slog
  232. * @brief dlog_error: print error log
  233. *
  234. * @param [in]moduleId: module id, eg: CCE
  235. * @param [in]fmt: log content
  236. */
  237. #define dlog_error(moduleId, fmt, ...) \
  238. do { \
  239. DlogErrorInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  240. } while (TMP_LOG != 0)
  241. /**
  242. * @ingroup slog
  243. * @brief dlog_warn: print warning log
  244. * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
  245. *
  246. * @param [in]moduleId: module id, eg: CCE
  247. * @param [in]fmt: log content
  248. */
  249. #define dlog_warn(moduleId, fmt, ...) \
  250. do { \
  251. if(CheckLogLevel(moduleId, DLOG_WARN) == 1) { \
  252. DlogWarnInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  253. } \
  254. } while (TMP_LOG != 0)
  255. /**
  256. * @ingroup slog
  257. * @brief dlog_info: print info log
  258. * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
  259. *
  260. * @param [in]moduleId: module id, eg: CCE
  261. * @param [in]fmt: log content
  262. */
  263. #define dlog_info(moduleId, fmt, ...) \
  264. do { \
  265. if(CheckLogLevel(moduleId, DLOG_INFO) == 1) { \
  266. DlogInfoInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  267. } \
  268. } while (TMP_LOG != 0)
  269. /**
  270. * @ingroup slog
  271. * @brief dlog_debug: print debug log
  272. * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
  273. *
  274. * @param [in]moduleId: module id, eg: CCE
  275. * @param [in]fmt: log content
  276. */
  277. #define dlog_debug(moduleId, fmt, ...) \
  278. do { \
  279. if(CheckLogLevel(moduleId, DLOG_DEBUG) == 1) { \
  280. DlogDebugInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  281. } \
  282. } while (TMP_LOG != 0)
  283. /**
  284. * @ingroup slog
  285. * @brief dlog_event: print event log
  286. *
  287. * @param [in]moduleId: module id, eg: CCE
  288. * @param [in]fmt: log content
  289. */
  290. #define dlog_event(moduleId, fmt, ...) \
  291. do { \
  292. DlogEventInner(moduleId, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  293. } while (TMP_LOG != 0)
  294. /**
  295. * @ingroup slog
  296. * @brief Dlog: print log, need caller to specify level
  297. * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
  298. *
  299. * @param [in]moduleId: module id, eg: CCE
  300. * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 5: trace, 6: oplog, 16: event)
  301. * @param [in]fmt: log content
  302. */
  303. #define Dlog(moduleId, level, fmt, ...) \
  304. do { \
  305. if(CheckLogLevel(moduleId, level) == 1) { \
  306. DlogInner(moduleId, level, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  307. } \
  308. } while (TMP_LOG != 0)
  309. /**
  310. * @ingroup slog
  311. * @brief DlogSub: print log, need caller to specify level and submodule
  312. * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
  313. *
  314. * @param [in]moduleId: module id, eg: CCE
  315. * @param [in]submodule: eg: engine
  316. * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 5: trace, 6: oplog, 16: event)
  317. * @param [in]fmt: log content
  318. */
  319. #define DlogSub(moduleId, submodule, level, fmt, ...) \
  320. do { \
  321. if(CheckLogLevel(moduleId, level) == 1) { \
  322. DlogInner(moduleId, level, "[%s:%d][%s]" fmt, __FILE__, __LINE__, submodule, ##__VA_ARGS__); \
  323. } \
  324. } while (TMP_LOG != 0)
  325. /**
  326. * @ingroup slog
  327. * @brief DlogWithKV: print log, need caller to specify level and other paramters
  328. * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
  329. *
  330. * @param [in]moduleId: module id, eg: CCE
  331. * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 5: trace, 6: oplog, 16: event)
  332. * @param [in]pstKVArray: key-value array
  333. * @param [in]kvNum: key-value element num in array
  334. * @param [in]fmt: log content
  335. */
  336. #define DlogWithKV(moduleId, level, pstKVArray, kvNum, fmt, ...) \
  337. do { \
  338. if(CheckLogLevel(moduleId, level) == 1) { \
  339. DlogWithKVInner(moduleId, level, pstKVArray, kvNum, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  340. } \
  341. } while (TMP_LOG != 0)
  342. /**
  343. * @ingroup slog
  344. * @brief DlogFlush: flush log buffer to file
  345. */
  346. DLL_EXPORT void DlogFlush(void);
  347. /**
  348. * @ingroup slog
  349. * @brief Internal log interface, other modules are not allowed to call this interface
  350. */
  351. void DlogErrorInner(int moduleId, const char *fmt, ...);
  352. void DlogWarnInner(int moduleId, const char *fmt, ...);
  353. void DlogInfoInner(int moduleId, const char *fmt, ...);
  354. void DlogDebugInner(int moduleId, const char *fmt, ...);
  355. void DlogEventInner(int moduleId, const char *fmt, ...);
  356. void DlogInner(int moduleId, int level, const char *fmt, ...);
  357. void DlogWithKVInner(int moduleId, int level, KeyValue *pstKVArray, int kvNum, const char *fmt, ...);
  358. #ifdef __cplusplus
  359. #ifndef LOG_CPP
  360. }
  361. #endif // LOG_CPP
  362. #endif // __cplusplus
  363. #ifdef LOG_CPP
  364. #ifdef __cplusplus
  365. extern "C" {
  366. #endif
  367. /**
  368. * @ingroup slog
  369. * @brief DlogGetlevelForC: get module loglevel and enableEvent
  370. *
  371. * @param [in]moduleId: moudule id(see slog.h, eg: CCE), others: invalid
  372. * @param [out]enableEvent: 1: enable; 0: disable
  373. * @return: module level(0: debug, 1: info, 2: warning, 3: error, 4: null output)
  374. */
  375. DLL_EXPORT int DlogGetlevelForC(int moduleId, int *enableEvent);
  376. /**
  377. * @ingroup slog
  378. * @brief DlogSetlevelForC: set module loglevel and enableEvent
  379. *
  380. * @param [in]moduleId: moudule id(see slog.h, eg: CCE), -1: all modules, others: invalid
  381. * @param [in]level: log level(0: debug, 1: info, 2: warning, 3: error, 4: null output)
  382. * @param [in]enableEvent: 1: enable; 0: disable, others:invalid
  383. * @return: 0: SUCCEED, others: FAILED
  384. */
  385. DLL_EXPORT int DlogSetlevelForC(int moduleId, int level, int enableEvent);
  386. /**
  387. * @ingroup slog
  388. * @brief CheckLogLevelForC: check module level enable or not
  389. * users no need to call it because all dlog interface(include inner interface) has already called
  390. *
  391. * @param [in]moduleId: module id, eg: CCE
  392. * @param [in]logLevel: eg: DLOG_EVENT/DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
  393. * @return: 1:enable, 0:disable
  394. */
  395. DLL_EXPORT int CheckLogLevelForC(int moduleId, int logLevel);
  396. /**
  397. * @ingroup slog
  398. * @brief DlogSetAttrForC: set log attr, default pid is 0, default device id is 0, default process type is APPLICATION
  399. * @param [in]logAttr: attr info, include pid(must be larger than 0), process type and device id(chip ID)
  400. * @return: 0: SUCCEED, others: FAILED
  401. */
  402. DLL_EXPORT int DlogSetAttrForC(LogAttr logAttr);
  403. /**
  404. * @ingroup slog
  405. * @brief DlogForC: print log, need caller to specify level
  406. * call CheckLogLevelForC in advance to optimize performance, call interface with fmt input take time
  407. *
  408. * @param [in]moduleId: module id, eg: CCE
  409. * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 5: trace, 6: oplog, 16: event)
  410. * @param [in]fmt: log content
  411. */
  412. #define DlogForC(moduleId, level, fmt, ...) \
  413. do { \
  414. if(CheckLogLevelForC(moduleId, level) == 1) { \
  415. DlogInnerForC(moduleId, level, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  416. } \
  417. } while (TMP_LOG != 0)
  418. /**
  419. * @ingroup slog
  420. * @brief DlogSubForC: print log, need caller to specify level and submodule
  421. * call CheckLogLevelForC in advance to optimize performance, call interface with fmt input take time
  422. *
  423. * @param [in]moduleId: module id, eg: CCE
  424. * @param [in]submodule: eg: engine
  425. * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 5: trace, 6: oplog, 16: event)
  426. * @param [in]fmt: log content
  427. */
  428. #define DlogSubForC(moduleId, submodule, level, fmt, ...) \
  429. do { \
  430. if(CheckLogLevelForC(moduleId, level) == 1) { \
  431. DlogInnerForC(moduleId, level, "[%s:%d][%s]" fmt, __FILE__, __LINE__, submodule, ##__VA_ARGS__); \
  432. } \
  433. } while (TMP_LOG != 0)
  434. /**
  435. * @ingroup slog
  436. * @brief DlogWithKVForC: print log, need caller to specify level and other paramters
  437. * call CheckLogLevelForC in advance to optimize performance, call interface with fmt input take time
  438. *
  439. * @param [in]moduleId: module id, eg: CCE
  440. * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 5: trace, 6: oplog, 16: event)
  441. * @param [in]pstKVArray: key-value array
  442. * @param [in]kvNum: key-value element num in array
  443. * @param [in]fmt: log content
  444. */
  445. #define DlogWithKVForC(moduleId, level, pstKVArray, kvNum, fmt, ...) \
  446. do { \
  447. if(CheckLogLevelForC(moduleId, level) == 1) { \
  448. DlogWithKVInnerForC(moduleId, level, pstKVArray, kvNum, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
  449. } \
  450. } while (TMP_LOG != 0)
  451. /**
  452. * @ingroup slog
  453. * @brief DlogFlushForC: flush log buffer to file
  454. */
  455. DLL_EXPORT void DlogFlushForC(void);
  456. /**
  457. * @ingroup slog
  458. * @brief Internal log interface, other modules are not allowed to call this interface
  459. */
  460. void DlogInnerForC(int moduleId, int level, const char *fmt, ...);
  461. void DlogWithKVInnerForC(int moduleId, int level, KeyValue *pstKVArray, int kvNum, const char *fmt, ...);
  462. #ifdef __cplusplus
  463. }
  464. #endif
  465. #endif // LOG_CPP
  466. #endif // D_SYSLOG_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示