[neurun] Auto-generate Config strings (#4515)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 27 Feb 2019 07:22:27 +0000 (16:22 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 27 Feb 2019 07:22:27 +0000 (16:22 +0900)
With macro expansion, this commit generates variables for config
strings. It is recommended to use auto-generated Config string rather
than raw strings.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/backend/BackendManager.cc
runtimes/neurun/src/compiler/BackendResolver.h
runtimes/neurun/src/compiler/Compiler.cc
runtimes/neurun/src/dumper/dot/DotDumper.h
runtimes/neurun/src/util/config/ConfigManager.cc
runtimes/neurun/src/util/config/ConfigManager.h
runtimes/neurun/src/util/logging.h

index 5d19d40..eb8772c 100644 (file)
@@ -96,7 +96,7 @@ void BackendManager::loadBackend(const std::string &backend,
 
 BackendManager::BackendManager(const neurun::model::operand::Set &operands)
 {
-  const auto backends = config::ConfigManager::instance().get<std::string>("BACKENDS");
+  const auto backends = config::ConfigManager::instance().get<std::string>(config::BACKENDS);
   size_t prev_pos = 0;
   auto pos = backends.find(";");
   while (pos != std::string::npos)
index 4742b2d..07c5fc5 100644 (file)
@@ -39,7 +39,7 @@ public:
     _backend_manager = std::make_shared<backend::BackendManager>(operands);
 
     const auto backend_all_str =
-        config::ConfigManager::instance().get<std::string>("OP_BACKEND_ALLOPS");
+        config::ConfigManager::instance().get<std::string>(config::OP_BACKEND_ALLOPS);
     if (backend_all_str.compare("none") != 0)
     {
       VERBOSE(BackendResolver) << "Use backend for all ops: " << backend_all_str << std::endl;
@@ -58,7 +58,7 @@ public:
   if (IsNnApi)                                                                                    \
   {                                                                                               \
     const auto &backend_str =                                                                     \
-        config::ConfigManager::instance().get<std::string>("OP_BACKEND_" #NnApiName);             \
+        config::ConfigManager::instance().get<std::string>(config::OP_BACKEND_##NnApiName);       \
     auto backend = _backend_manager->get(backend_str);                                            \
     VERBOSE(BackendResolver) << "backend for " << #NnApiName << ": " << backend_str << std::endl; \
     _gen_map[typeid(model::operation::InternalName)] = backend;                                   \
index 82a9b90..73f8fa5 100644 (file)
@@ -127,7 +127,8 @@ bool Compiler::checkCompilable()
 {
   // Disable compile phase
   // When ready to use interpreter backend, remove this config and use backend setting
-  const auto env_disable_compile = config::ConfigManager::instance().get<bool>("DISABLE_COMPILE");
+  const auto env_disable_compile =
+      config::ConfigManager::instance().get<bool>(config::DISABLE_COMPILE);
   if (env_disable_compile)
   {
     return false;
index 0c0a9b8..040f434 100644 (file)
@@ -39,7 +39,7 @@ class DotDumper
 public:
   DotDumper(const neurun::graph::Graph &graph) : _graph(graph)
   {
-    _option = config::ConfigManager::instance().get<int>("GRAPH_DOT_DUMP");
+    _option = config::ConfigManager::instance().get<int>(config::GRAPH_DOT_DUMP);
   }
 
 public:
index 46b8031..588f440 100644 (file)
@@ -23,6 +23,12 @@ namespace neurun
 namespace config
 {
 
+#define CONFIG(Name, Type, Default) const char *Name = #Name;
+
+#include "Config.lst"
+
+#undef CONFIG
+
 ConfigManager &ConfigManager::instance()
 {
   static ConfigManager manager;
index 78db03d..2dd5a79 100644 (file)
@@ -31,6 +31,12 @@ namespace neurun
 namespace config
 {
 
+#define CONFIG(Name, Type, Default) extern const char *Name;
+
+#include "Config.lst"
+
+#undef CONFIG
+
 /**
  * @brief Class that manages configurations
  */
index 9a56326..2d90d66 100644 (file)
@@ -33,7 +33,7 @@ class Context
 public:
   Context() : _enabled{false}
   {
-    const auto env = config::ConfigManager::instance().get<bool>("NEURUN_LOG_ENABLE");
+    const auto env = config::ConfigManager::instance().get<bool>(config::NEURUN_LOG_ENABLE);
 
     if (env)
     {