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

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