[Misc] Change the default loglevel to 2
[platform/adaptation/npu/trix-engine.git] / src / core / utils / ne-conf.h
1 /**
2  * Proprietary
3  * Copyright (C) 2019 Samsung Electronics
4  * Copyright (C) 2019 MyungJoo Ham <myungjoo.ham@samsung.com>
5  * Copyright (C) 2019 Dongju Chae <dongju.chae@samsung.com>
6  */
7 /**
8  * @file ne-conf.h
9  * @date 15 Apr 2019
10  * @brief Internal API to access global configuration of NPU Engine.
11  * @see https://code.sec.samsung.net/confluence/display/ODLC/2020+Overall+Software+Stack
12  * @author MyungJoo Ham <myungjoo.ham@samsung.com>
13  * @author Dongju Chae <dongju.chae@samsung.com>
14  * @bug No known bugs except for NYI items
15  */
16
17 #ifndef __NE_CONF_H__
18 #define __NE_CONF_H__
19
20 #include <stdint.h>
21 #include <iniparser.h>
22
23 #include <memory>
24 #include <mutex>
25
26 #define MAX_DIR_LEN 256
27
28 #define ENV_NUM_THREADS "NE_NUM_THREADS"
29 #define ENV_RESV_MEM_SIZE "NE_RESV_MEM_SIZE"
30 #define ENV_LOG_DIR "NE_LOG_DIR"
31 #define ENV_LOG_LEVEL "NE_LOG_LEVEL"
32
33 #define ENV_PREFIX_SHARE "NE_PREFIX_SHARE"
34 #define ENV_PREFIX_PROFILE "NE_PREFIX_PROFILE"
35
36 #define ENV_MUTE_STDOUT "NE_MUTE_STDOUT"
37
38 /** @brief Configuration for NPU-Engine components */
39 class Conf {
40  public:
41   static Conf &getInstance (const char *inipath = nullptr);
42
43   uint32_t getNumThreads (bool is_default = false) const;
44   size_t getResvMemSize (bool is_default = false) const;
45   const char *getLogDir (bool is_default = false) const;
46   uint32_t getLogLevel (bool is_default = false) const;
47   const char *getPrefixShare (bool is_default = false) const;
48   const char *getPrefixProfile (bool is_default = false) const;
49   bool getMuteStdout (bool is_default = false) const;
50
51   void reset ();
52
53  private:
54   static std::unique_ptr<Conf> instance_;
55   static std::once_flag once_flag_;
56
57   Conf ();
58
59   void loadConf (const char *inipath);
60   void loadConfIni (dictionary *ini);
61   void loadConfDefault ();
62   void loadConfEnvvar ();
63
64   void setNumThreads (const char *str);
65   void setResvMemSize (const char *str);
66   void setPrefixShare (const char *str);
67   void setPrefixProfile (const char *str);
68   void setLogDir (const char *str);
69   void setLogLevel (const char *str);
70   void setLayerDump (const char *str);
71   void setMuteStdout (bool mute_stdout) { mute_stdout_ = mute_stdout; }
72
73   uint32_t num_threads_;
74   /**< NE_NUM_THREADS, [main] num_threads, the number of threads in thread pool */
75   size_t reserved_mem_size_;
76   /**< NE_RESV_MEM_SIZE, [main] resv_mem_size, the size of memory reserved */
77   char prefix_share_[MAX_DIR_LEN];
78   /**< NE_PREFIX_SHARE, [main] prefix_share, the path where share directory is located */
79   char prefix_profile_[MAX_DIR_LEN];
80   /**< NE_PREFIX_PROFILE, [main] prefix_profile, the path where profile data is created */
81   char log_dir_[MAX_DIR_LEN];
82   /**< NE_LOG_DIR, [debug] log_dir, the path where log files are created */
83   uint32_t log_level_;
84   /**< NE_LOG_LEVEL, [debug] log_level, maximum log level to print log messages to stderr */
85   bool mute_stdout_;
86   /**< NE_MUTE_STDOUT, [sim] mute_stdout, ignore any stdout messages from simulator */
87 };
88
89 #endif /* __NE_CONF_H__ */