Partial redesign plugins system and add usage of new CLI (#1029)
authorРоман Михайлович Русяев/AI Tools Lab /SRR/Staff Engineer/삼성전자 <r.rusyaev@samsung.com>
Wed, 15 Aug 2018 16:53:16 +0000 (19:53 +0300)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Wed, 15 Aug 2018 16:53:16 +0000 (19:53 +0300)
* improve command line infrastructure:
  - add new parameter (checker) in Option class
* replace all uses by new CLI
* partial redesign plugins system

Signed-off-by: Roman Rusyaev <r.rusyaev@samsung.com>
64 files changed:
contrib/nnc/CMakeLists.txt
contrib/nnc/examples/plugin_example/samplePlugin.cpp
contrib/nnc/include/Options.h
contrib/nnc/include/module/AbstractModule.h
contrib/nnc/include/module/plugin/PluginData.h [deleted file]
contrib/nnc/include/module/plugin/PluginManager.h
contrib/nnc/include/module/plugin/PluginProxy.h
contrib/nnc/include/module/plugin/PluginSession.h [deleted file]
contrib/nnc/libs/backend/interpreter/plugin/include/interpreter_plugin.h
contrib/nnc/libs/backend/interpreter/plugin/src/interpreter_plugin.cpp
contrib/nnc/libs/backend/soft/include/base_generator.h
contrib/nnc/libs/backend/soft/include/c_generator.h
contrib/nnc/libs/backend/soft/include/cpp_generator.h
contrib/nnc/libs/backend/soft/include/soft_backend.h
contrib/nnc/libs/backend/soft/src/base_generator.cpp
contrib/nnc/libs/backend/soft/src/c_backend.cpp
contrib/nnc/libs/backend/soft/src/c_generator.cpp
contrib/nnc/libs/backend/soft/src/cpp_backend.cpp
contrib/nnc/libs/backend/soft/src/cpp_generator.cpp
contrib/nnc/libs/backend/soft/src/soft_backend.cpp
contrib/nnc/libs/frontend/caffe/CMakeLists.txt
contrib/nnc/libs/frontend/caffe/examples/model_dump.cpp
contrib/nnc/libs/frontend/caffe/src/caffe_plugin.cpp
contrib/nnc/libs/frontend/tflite/CMakeLists.txt
contrib/nnc/libs/frontend/tflite/examples/sanity_check.cpp
contrib/nnc/libs/frontend/tflite/src/tflite_plugin.cpp
contrib/nnc/libs/plugin/include/AbstractSession.h [deleted file]
contrib/nnc/libs/plugin/include/PluginInstance.h
contrib/nnc/libs/plugin/include/PluginParam.h [deleted file]
contrib/nnc/libs/plugin/include/PluginType.h [deleted file]
contrib/nnc/libs/plugin/src/AbstractSession.cpp [deleted file]
contrib/nnc/libs/plugin/src/PluginInstance.cpp [deleted file]
contrib/nnc/libs/plugin/src/PluginParam.cpp [deleted file]
contrib/nnc/libs/plugin/src/PluginType.cpp [deleted file]
contrib/nnc/src/Options.cpp
contrib/nnc/src/main.cpp
contrib/nnc/src/module/AbstractModule.cpp
contrib/nnc/src/module/BackendModule.cpp
contrib/nnc/src/module/FrontendModule.cpp
contrib/nnc/src/module/plugin/PluginData.cpp [deleted file]
contrib/nnc/src/module/plugin/PluginManager.cpp
contrib/nnc/src/module/plugin/PluginProxy.cpp
contrib/nnc/src/module/plugin/PluginSession.cpp [deleted file]
contrib/nnc/support/CMakeLists.txt
contrib/nnc/support/include/CommandLine.h
contrib/nnc/support/src/CLOptionChecker.cpp [new file with mode: 0644]
contrib/nnc/support/src/CommandLine.cpp
contrib/nnc/tests/import/CMakeLists.txt
contrib/nnc/tests/import/caffe.cpp
contrib/nnc/tests/import/tflite.cpp
contrib/nnc/unittests/module/AbstractModule.cpp [deleted file]
contrib/nnc/unittests/module/BackendModule.cpp
contrib/nnc/unittests/module/CMakeLists.txt
contrib/nnc/unittests/module/FrontendModule.cpp [deleted file]
contrib/nnc/unittests/module/PluginData.cpp [deleted file]
contrib/nnc/unittests/module/PluginManager.cpp
contrib/nnc/unittests/module/PluginProxy.cpp
contrib/nnc/unittests/module/PluginSession.cpp [deleted file]
contrib/nnc/unittests/plugin_core/AbstractSession.cpp [deleted file]
contrib/nnc/unittests/plugin_core/PluginInstance.cpp [deleted file]
contrib/nnc/unittests/plugin_core/PluginParam.cpp [deleted file]
contrib/nnc/unittests/soft_backend/CMakeLists.txt
contrib/nnc/unittests/soft_backend/generator.cpp
contrib/nnc/unittests/support/ComandLineTest.cpp

index 9c88137..9c51187 100644 (file)
@@ -5,9 +5,10 @@ include(soft_backend)
 
 file(GLOB_RECURSE HEADERS "include/*.h")
 file(GLOB_RECURSE SOURCES "src/*.cpp")
-file(GLOB_RECURSE TESTS "unittests/*.cpp")
-file(GLOB_RECURSE MAIN "src/main.cpp")
+set(MAIN "src/main.cpp")
+set(OPTIONS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/Options.cpp")
 list(REMOVE_ITEM SOURCES ${MAIN})
+list(REMOVE_ITEM SOURCES ${OPTIONS_SRC})
 
 include_directories(include)
 
@@ -19,12 +20,16 @@ set(NNC_SUPPORT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/support)
 
 # Plugin module library
 add_nncc_library(nnc_module SHARED ${HEADERS} ${SOURCES})
-target_link_libraries(nnc_module PRIVATE nncc_core nncc_foundation nnc_plugin_core dl)
+target_link_libraries(nnc_module PRIVATE nnc_support nncc_core nncc_foundation nnc_plugin_core dl)
 target_include_directories(nnc_module PUBLIC include)
 
+# add supprot header files
+include_directories(support/include)
+include_directories(include)
+
 # nnc executable
-add_executable(nnc ${MAIN})
-target_link_libraries(nnc PRIVATE nnc_module nncc_core nncc_foundation nnc_plugin_core dl)
+add_executable(nnc ${MAIN} ${OPTIONS_SRC})
+target_link_libraries(nnc PRIVATE nnc_support nnc_module nncc_core nncc_foundation nnc_plugin_core dl)
 target_include_directories(nnc PUBLIC include)
 
 add_subdirectory(support)
index 14b504e..6f295a3 100644 (file)
@@ -4,99 +4,42 @@
 #include "PluginInstance.h"
 #include "PluginException.h"
 #include "ConfigException.h"
-#include "PluginType.h"
 
-// Enable debugging
-#include "debug.h"
-#define DEBUG_AREA "examples"
-using nncc::contrib::dbgs;
-
-static const std::string pluginName = "Your plugin name here";
-static const std::string pluginVersion = "Your plugin version here";
-static const std::string pluginDesc = "Your plugin description here";
-static const auto pluginType = nncc::contrib::plugin::typeFrontEnd;
-
-using namespace nncc::contrib::config;
 using namespace nncc::contrib::plugin;
 
-class SamplePluginInstance : public AbstractPluginInstance
+class SamplePluginInstance : public FrontendPlugin
 {
 public:
   SamplePluginInstance &operator=(const SamplePluginInstance &) = delete;
   SamplePluginInstance(const SamplePluginInstance &) = delete;
 
-  static AbstractPluginInstance &getInstance();
-  void fillSession() override;
-  void checkConfig() override;
+  static FrontendPlugin &getInstance();
   void *execute(void *data) override;
 
-  void setParam(const std::string &name) override;
-  void setParam(const std::string &name, const std::string &value) override;
-
-private:
-  std::string _anotheroption;
-
 private:
   SamplePluginInstance() = default;
   ~SamplePluginInstance() override = default;
 };
 
-AbstractPluginInstance &SamplePluginInstance::getInstance()
+FrontendPlugin &SamplePluginInstance::getInstance()
 {
   static SamplePluginInstance instance;
-  NNC_DEBUG(dbgs() << std::endl << "!!! plugin (" << pluginName << ") " << __func__ << std::endl);
-
+  // FIXME: it's necessary to make this printing via debugging system (see issue #893)
+  //NNC_DEBUG(dbgs() << std::endl << "!!! plugin (" << pluginName << ") " << __func__ << std::endl);
   return instance;
 }
 
-void SamplePluginInstance::fillSession()
-{
-  static std::map<std::string, std::string> info = {{"module description", pluginDesc}};
-
-  static std::vector<PluginParam> moduleParams = {{"anotheroption", "[model file name]", false},
-                                                  {"someoption", "[Your <someoption> description here]", true}};
-
-  AbstractPluginInstance::fillSessionBase(pluginType, pluginVersion, pluginName);
-
-  for (auto &i : info)
-    getSession()->addInfo(i.first, i.second);
-
-  for (auto &p : moduleParams)
-    getSession()->registerParam(p);
-}
-
-void SamplePluginInstance::checkConfig()
-{
-  NNC_DEBUG(dbgs() << std::endl << "!!! plugin (" << pluginName << ") " << __func__ << std::endl);
-}
-
 void *SamplePluginInstance::execute(void *data)
 {
-  NNC_DEBUG(dbgs() << std::endl << "!!! plugin (" << pluginName << ") " << __func__ << std::endl);
+  // FIXME: it's necessary to make this printing via debugging system (see issue #893)
+  //std::cout << std::endl << "!!! plugin (" << pluginName << ") " << __func__ << std::endl;
   return data;
 }
 
-void SamplePluginInstance::setParam(const std::string &name)
-{
-  NNC_DEBUG(dbgs() << "bad parameter <" << name << ">");
-}
-
-void SamplePluginInstance::setParam(const std::string &name, const std::string &value)
-{
-  if (name == "anotheroption")
-  {
-    _anotheroption = value;
-  }
-  else
-  {
-    throw nncc::contrib::ConfigException("unsupported parameter <" + name + ">");
-  }
-  NNC_DEBUG(dbgs() << __func__ << " : " << name << " = " << value << std::endl);
-}
-
 extern "C" AbstractPluginInstance *get_instance()
 {
-  NNC_DEBUG(dbgs() << std::endl << "!!! plugin (" << pluginName << ") " << __func__ << std::endl);
+  // FIXME: it's necessary to make this printing via debugging system (see issue #893)
+  //std::cout << std::endl << "!!! plugin (" << pluginName << ") " << __func__ << std::endl;
   return &SamplePluginInstance::getInstance();
 }
 
index 8346eb8..2b8726e 100644 (file)
@@ -11,6 +11,29 @@ namespace contrib
 namespace clopt
 {
 
+/**
+ * @breif options for compiler driver
+ */
+extern Option<std::string> pluginsPath;
+extern Option<bool> pluginVerbose;
+
+/**
+ * @brief frontend options
+ */
+extern Option<std::string> inputFile;
+
+/**
+ * @brief options for backend
+ */
+// soft backend
+extern Option<std::string> artifactDir;
+extern Option<std::string> artifactName;
+
+// interpreter
+extern Option<std::string> interFileName;
+extern Option<std::string> interInNode;
+extern Option<std::string> interOutNode;
+
 } // namespace clopt
 } // namespace contrib
 } // namespace nncc
index ee2da85..c6ec51a 100644 (file)
@@ -3,7 +3,6 @@
 
 #include <vector>
 
-#include "module/plugin/PluginData.h"
 #include "module/plugin/PluginProxy.h"
 
 namespace nncc
@@ -21,20 +20,16 @@ public:
 
   void registerPlugin(std::shared_ptr<plugin::PluginProxy> &pl);
   virtual void *execute(void *data);
-  virtual void configure(std::shared_ptr<config::DataList> conf);
-  contrib::plugin::PluginType getModuleType() const;
 
   friend std::ostream &operator<<(std::ostream &st, const AbstractModule &m);
 
 protected:
   AbstractModule();
-  explicit AbstractModule(contrib::plugin::PluginType moduleType);
   virtual ~AbstractModule();
 
 private:
   std::shared_ptr<plugin::PluginProxy> _activePlugin;
   std::vector<std::shared_ptr<plugin::PluginProxy>> _plugins;
-  contrib::plugin::PluginType _moduleType;
 };
 
 } // namespace module
diff --git a/contrib/nnc/include/module/plugin/PluginData.h b/contrib/nnc/include/module/plugin/PluginData.h
deleted file mode 100644 (file)
index f640e78..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-#ifndef __PLUGIN_DATA_H__
-#define __PLUGIN_DATA_H__
-
-#include <string>
-#include <map>
-#include <vector>
-#include <memory>
-#include <exception>
-#include "PluginParam.h"
-#include "nncc/foundation/Exception.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace config
-{
-
-class DataException : public foundation::Exception
-{
-public:
-  explicit DataException(const std::string &info) : Exception(info) {}
-  explicit DataException(Exception &e, const std::string &info) : Exception(e, info) {}
-};
-
-class Data
-{
-public:
-  Data() = delete;
-  explicit Data(const std::string &name);
-  Data(const std::string &name, const std::string &value);
-
-  const std::string &getValue() const;
-  const std::string &getName() const;
-  bool hasValue() const;
-
-  void setValue(const std::string &value);
-
-private:
-  bool _hasValue;
-  std::string _name;
-  std::string _value;
-};
-
-bool operator==(const Data &elm, const char *cmp_value);
-
-std::ostream &operator<<(std::ostream &os, const Data &op);
-
-class DataList
-{
-public:
-  DataList() = delete;
-  explicit DataList(const std::string &name);
-
-  // factory method
-  static std::shared_ptr<DataList> parse(int argc, char *argv[]) noexcept(false);
-  static std::shared_ptr<DataList>
-  intersection(const DataList &common,
-               const std::map<std::string, PluginParam> &supported) noexcept(false);
-  static std::shared_ptr<DataList>
-  intersection(const DataList &common,
-               const std::vector<PluginParam> &supported) noexcept(false);
-
-  Data &createElement(const std::string &name);
-  Data &createElement(const std::string &name, const std::string &value);
-
-  const std::string &getName() const;
-  const Data &getElement(const std::string &name) const noexcept(false);
-  const std::map<std::string, Data> &getElements() const noexcept(false);
-
-  const Data &operator[](const std::string &key) const noexcept(false);
-
-private:
-  std::string _name;
-  std::map<std::string, Data> _items;
-};
-
-std::ostream &operator<<(std::ostream &os, const DataList &list);
-
-} // namespace config
-} // namespace contrib
-} // namespace nncc
-
-#endif /* __PLUGIN_DATA_H__ */
index 9b2eeb4..5a34758 100644 (file)
@@ -3,7 +3,6 @@
 
 #include <vector>
 
-#include "PluginData.h"
 #include "PluginProxy.h"
 #include "module/AbstractModule.h"
 
@@ -27,32 +26,19 @@ public:
 class PluginManager
 {
 public:
-  static const std::string paramPluginPath;
-  static const std::string paramVerboseLoading;
-  static const std::string paramPluginHelp;
-
-  PluginManager();
-
-  void setConfig(std::shared_ptr<config::DataList> conf);
-  void loadPlugins(std::vector<AbstractModule *> &modules);
+  void loadPlugins();
   static PluginManager &getInstance();
-  void help() const;
 
   friend std::ostream &operator<<(std::ostream &st, const PluginManager &mod);
 
 private:
-  std::vector<std::string> getPluginPathList();
+  // only for singleton
+  PluginManager() = default;
 
-  void applyParam(const std::string &name);
-  void applyParam(const std::string &name, const std::string &value);
+  std::vector<std::string> getPluginPathList();
 
   std::vector<AbstractModule *> _modules;
-
   std::vector<std::shared_ptr<PluginProxy>> _plugins;
-  std::shared_ptr<config::DataList> _config;
-  std::string _pluginsPath;
-  std::vector<config::PluginParam> _supportedParams;
-  bool _showPluginInfo;
 };
 
 } // namespace plugin
index 19b7e02..bfbd1e9 100644 (file)
@@ -28,7 +28,11 @@ public:
   const std::string &getPluginPath() const;
   const std::string &getPluginName() const;
 
-  contrib::plugin::AbstractPluginInstance &getPluginInstance();
+  /**
+   * @breif singleton method to get plugin instance
+   * @return pointer to plugin instance (this pointer mustn't be freed)
+   */
+  contrib::plugin::AbstractPluginInstance *getPluginInstance();
 
 public:
   static const std::string getInstanceFuncName;
diff --git a/contrib/nnc/include/module/plugin/PluginSession.h b/contrib/nnc/include/module/plugin/PluginSession.h
deleted file mode 100644 (file)
index b6d2a28..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef __PLUGIN_SESSION_H__
-#define __PLUGIN_SESSION_H__
-
-#include <string>
-#include "AbstractSession.h"
-#include "PluginParam.h"
-#include "PluginData.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace config
-{
-
-class PluginSession : public AbstractSession
-{
-public:
-  PluginSession();
-
-  void addInfo(const std::string &name, const std::string &value) override;
-  void registerParam(const PluginParam &param) override;
-
-  const DataList &getInfo() const;
-  const std::string &getInfo(const std::string &name) const;
-  const std::map<std::string, PluginParam> &getSupportedParams() const;
-
-private:
-  DataList _info;
-  std::map<std::string, PluginParam> _supported_params_map;
-};
-
-std::ostream &operator<<(std::ostream &os, const PluginSession &op);
-
-} // namespace config
-} // namespace contrib
-} // namespace nncc
-
-#endif /*__PLUGIN_SESSION_H__ */
index 4f9c67c..b65184e 100644 (file)
@@ -6,7 +6,6 @@
 #include "PluginInstance.h"
 #include "PluginException.h"
 #include "ConfigException.h"
-#include "PluginType.h"
 
 #include "nnc/core/linalg/TensorVariant.h"
 #include "nncc/core/ADT/tensor/Shape.h"
@@ -23,24 +22,16 @@ namespace plugin
 {
 
 using namespace nncc::contrib;
-using namespace config;
-using nncc::contrib::plugin::AbstractPluginInstance;
+using namespace nncc::contrib::plugin;
 
-class InterpreterPlugin : public AbstractPluginInstance {
+class InterpreterPlugin : public BackendPlugin {
  public:
-  static AbstractPluginInstance &getInstance();
-  void fillSession() override;
-  void checkConfig() override;
+  static BackendPlugin &getInstance();
   void *execute(void *data) override;
 
-  void setParam(const std::string &name) override;
-  void setParam(const std::string &name, const std::string &value) override;
-
   virtual ~InterpreterPlugin();
 
 private:
-  std::unordered_map<std::string, std::string> params;
-
   nncc::contrib::core::ADT::TensorVariant loadInput(const nncc::core::ADT::tensor::Shape &);
   nncc::contrib::core::ADT::TensorVariant *_out;
 };
index 73e8055..e4ac7c0 100644 (file)
@@ -2,8 +2,8 @@
 #include <vector>
 #include <fstream>
 #include <sstream>
+#include <Options.h>
 
-#include "PluginParam.h"
 #include "PluginInstance.h"
 
 #include "nncc/core/ADT/tensor/Shape.h"
@@ -29,42 +29,17 @@ namespace interpreter
 namespace plugin
 {
 
+using namespace nncc::contrib;
 using nncc::core::ADT::tensor::Shape;
 using namespace nncc::contrib::core::IR::model;
 using nncc::contrib::backend::interpreter::core::NNInterpreter;
-using nncc::contrib::plugin::AbstractPluginInstance;
-using nncc::contrib::config::PluginParam;
+using nncc::contrib::plugin::BackendPlugin;
 
-static const std::string pluginName = "NNInterpreterPlugin";
-static const std::string pluginVersion = "0.1";
-static const std::string pluginDesc = "NN Interpreter Plugin";
-static const auto pluginType = nncc::contrib::plugin::typeBackEnd;
-
-AbstractPluginInstance &InterpreterPlugin::getInstance() {
+BackendPlugin &InterpreterPlugin::getInstance() {
   static InterpreterPlugin instance;
   return instance;
 }
 
-void InterpreterPlugin::fillSession() {
-  static std::map<std::string, std::string> info = {{"module description", pluginDesc}};
-  static std::vector<PluginParam> moduleParams = {
-      {"filename", "Input file path", false},
-      {"input", "Input node name", false},
-      {"output", "Output node name", false}
-  };
-  AbstractPluginInstance::fillSessionBase(pluginType, pluginVersion, pluginName);
-
-  for (auto &i : info)
-    getSession()->addInfo(i.first, i.second);
-
-  for (auto &p : moduleParams)
-    getSession()->registerParam(p);
-}
-
-void InterpreterPlugin::checkConfig() {
-  //Nothing to configure
-}
-
 void *InterpreterPlugin::execute(void *data) {
   auto g = static_cast<Graph *>(data);
   ShapeInference shapeInference;
@@ -74,36 +49,27 @@ void *InterpreterPlugin::execute(void *data) {
   g->accept(&shapeInference);
 
   // Check nodes
-  auto inputNode = g->getInput(params["input"]);
+  auto inputNode = g->getInput(clopt::interInNode);
   if (inputNode == nullptr) {
-    throw PluginException("input node <" + params["input"] +"> not found" );
+    throw PluginException("input node <" + clopt::interInNode +"> not found" );
   }
 
-  auto outputNode = g->getOutput(params["output"]);
+  auto outputNode = g->getOutput(clopt::interOutNode);
   if (outputNode == nullptr) {
-    throw PluginException("output node <" + params["output"] +"> not found" );
+    throw PluginException("output node <" + clopt::interOutNode +"> not found" );
   }
 
   auto input = loadInput(inputNode->getOperation()->getOutputShape(0));
-  interpreter.setInput(params["input"], input);
+  interpreter.setInput(clopt::interInNode, input);
   g->accept(&interpreter);
 
   _out = new TensorVariant(interpreter.getResult(outputNode)[0]);
   return _out;
 }
 
-void InterpreterPlugin::setParam(const std::string &name) {
-  //No known options
-  (void) name;
-}
-
-void InterpreterPlugin::setParam(const std::string &name, const std::string &value) {
-  params[name] = value;
-}
-
 TensorVariant InterpreterPlugin::loadInput(const Shape &shape)
 {
-  auto f = fopen(params["filename"].c_str(), "rb");
+  auto f = fopen(clopt::interFileName.c_str(), "rb");
   fseek(f, 0L, SEEK_END);
   auto len = ftell(f);
   auto tensorSize = num_elements(shape) * sizeof(float);
@@ -111,7 +77,7 @@ TensorVariant InterpreterPlugin::loadInput(const Shape &shape)
   // Check size
   if (len != tensorSize) {
     std::stringstream info;
-    info << "Wrong input file size <" << params["filename"] << "> = " << len << ". Should be :" << tensorSize;
+    info << "Wrong input file size <" << clopt::interFileName << "> = " << len << ". Should be :" << tensorSize;
     throw PluginException(info.str());
   }
 
index 9825c4e..9b91db6 100644 (file)
@@ -22,15 +22,6 @@ class Serializer;
 class BaseCodeGenerator
 {
 public:
-
-  struct Parameters
-  {
-    // directory for output files
-    std::string _outDir;
-    // common name for output files
-    std::string _outName;
-  };
-
   void generate(nncc::contrib::core::IR::model::Graph *g);
 
 protected:
@@ -39,15 +30,10 @@ protected:
   virtual void materializeCode(std::ostream &out, const ModelAnalyzer &ma, const Serializer &s) = 0;
   void materializeModelParams(std::ostream &out, const Serializer &s);
 
-  BaseCodeGenerator(BaseCodeGenerator &g) = default;
-
-  BaseCodeGenerator(const Parameters &opt);
+  BaseCodeGenerator();
 
   std::vector<std::string> _formattedTensors;
 
-  // set of options
-  Parameters _params;
-
   std::string _headerPath;
   std::string _codePath;
   std::string _paramsPath;
index 5bff59a..1fbde6d 100644 (file)
@@ -15,13 +15,8 @@ namespace soft
 // C generator
 class CCodeGenerator: public BaseCodeGenerator
 {
-  CCodeGenerator(const Parameters &params): BaseCodeGenerator(params)
-  {
-    // EMPTY
-  }
-
 public:
-  static CCodeGenerator create(const Parameters &params);
+  CCodeGenerator() = default;
 
 protected:
   void formatTensorNames(const ModelAnalyzer &ma) override;
index eb21e76..0143102 100644 (file)
@@ -15,13 +15,8 @@ namespace soft
 // C++ generator
 class CPPCodeGenerator: public BaseCodeGenerator
 {
-  CPPCodeGenerator(const Parameters &params): BaseCodeGenerator(params)
-  {
-    // EMPTY
-  }
-
 public:
-  static CPPCodeGenerator create(const Parameters &params);
+  CPPCodeGenerator(): BaseCodeGenerator() {}
 
 protected:
   void formatTensorNames(const ModelAnalyzer &ma) override;
index 4dfdaa9..d101c0e 100644 (file)
@@ -19,35 +19,17 @@ namespace soft
 
 enum class OPT_ID;
 
-class BaseSoftBackend : public nncc::contrib::plugin::AbstractPluginInstance
+class BaseSoftBackend : public nncc::contrib::plugin::BackendPlugin
 {
 public:
   BaseSoftBackend &operator=(const BaseSoftBackend &) = delete;
 
   BaseSoftBackend(const BaseSoftBackend &) = delete;
 
-  void fillSession() override;
-
-  void checkConfig() override;
-
   void *execute(void *data) override;
 
-  void setParam(const std::string &name) override;
-
-  void setParam(const std::string &name, const std::string &value) override;
-
 protected:
-  const std::string _pluginName;
-
-  BaseCodeGenerator::Parameters _params;
-
-  // general options with some expected value
-  std::map<std::string, OPT_ID> _opts;
-
-  // flag options
-  std::map<std::string, OPT_ID> _flags;
-
-  BaseSoftBackend(const std::string &name, const std::string &target_opt);
+  BaseSoftBackend() = default;
 
   ~BaseSoftBackend() override = default;
 
index 79785e9..46b1e82 100644 (file)
@@ -3,6 +3,7 @@
 #include "serializer.h"
 #include "PluginException.h"
 #include "nnc/core/IR/model/actions/ShapeInference.h"
+#include "Options.h"
 
 #include "param_constants.def"
 
@@ -53,9 +54,9 @@ void createDir(const string &path)
 
 } // unnamed namespace
 
-BaseCodeGenerator::BaseCodeGenerator(const Parameters &params): _params(params)
+BaseCodeGenerator::BaseCodeGenerator()
 {
-  string basePath = _params._outDir + "/" + _params._outName;
+  string basePath = clopt::artifactDir + "/" + clopt::artifactName;
   _headerPath = basePath + ".h";
   _codePath = basePath + ".cpp";
   _paramsPath = basePath + ".params";
@@ -102,7 +103,7 @@ void BaseCodeGenerator::generate(Graph *g)
   // rename tensors for specific backend language
   formatTensorNames(ma);
 
-  createDir(_params._outDir);
+  createDir(clopt::artifactDir);
 
   // Print header
   auto headerStream = getStream(_headerPath);
index 6bc40fa..e4bb7f5 100644 (file)
@@ -3,7 +3,6 @@
 
 #include "ConfigException.h"
 
-using namespace nncc::contrib::config;
 using namespace nncc::contrib::plugin;
 using namespace nncc::contrib::backend::soft;
 
@@ -16,12 +15,6 @@ namespace backend
 namespace soft
 {
 
-namespace
-{
-const char *target_opt = "emit-c";
-const char *backend_name = "C soft backend";
-} // unnamed namespace
-
 class CSoftBackend final: public BaseSoftBackend
 {
 public:
@@ -29,15 +22,10 @@ public:
 
   CSoftBackend(const CSoftBackend &) = delete;
 
-  void fillSession() override
-  {
-    BaseSoftBackend::fillSession();
-    getSession()->registerParam(PluginParam(target_opt, "option enables C backend", false));
-  }
-
   void generate(nncc::contrib::core::IR::model::Graph *g) override
   {
-    CCodeGenerator::create(_params).generate(g);
+    CCodeGenerator gen;
+    gen.generate(g);
   }
 
   static CSoftBackend &getInstance()
@@ -47,7 +35,7 @@ public:
   }
 
 private:
-  CSoftBackend(): BaseSoftBackend(backend_name, target_opt) {}
+  CSoftBackend() = default;
 };
 
 } // namespace soft
index 122de00..89e394e 100644 (file)
@@ -14,12 +14,6 @@ namespace backend
 namespace soft
 {
 
-CCodeGenerator CCodeGenerator::create(const Parameters &params)
-{
-  CCodeGenerator gen(params);
-  return gen;
-}
-
 void CCodeGenerator::formatTensorNames(const ModelAnalyzer &ma)
 {
   // TODO format tensor names according to c backend requirements
index 8d3e5d9..d4927b1 100644 (file)
@@ -3,7 +3,6 @@
 
 #include "ConfigException.h"
 
-using namespace nncc::contrib::config;
 using namespace nncc::contrib::plugin;
 using namespace nncc::contrib::backend::soft;
 
@@ -16,12 +15,6 @@ namespace backend
 namespace soft
 {
 
-namespace
-{
-const char *target_opt = "emit-c++";
-const char *backend_name = "C++ soft backend";
-} // unnamed namespace
-
 class CPPSoftBackend final: public BaseSoftBackend
 {
 public:
@@ -29,15 +22,10 @@ public:
 
   CPPSoftBackend(const CPPSoftBackend &) = delete;
 
-  void fillSession() override
-  {
-    BaseSoftBackend::fillSession();
-    getSession()->registerParam(PluginParam(target_opt, "option enables C++ backend", false));
-  }
-
   void generate(nncc::contrib::core::IR::model::Graph *g) override
   {
-    CPPCodeGenerator::create(_params).generate(g);
+    CPPCodeGenerator gen;
+    gen.generate(g);
   }
 
   static CPPSoftBackend &getInstance()
@@ -47,7 +35,7 @@ public:
   }
 
 private:
-  CPPSoftBackend(): BaseSoftBackend(backend_name, target_opt) {}
+  CPPSoftBackend() = default;
 };
 
 } // namespace soft
index 3435329..c371195 100644 (file)
@@ -2,6 +2,7 @@
 #include "model_analyzer.h"
 #include "serializer.h"
 #include "PluginException.h"
+#include "Options.h"
 
 using namespace std;
 using namespace nncc::contrib;
@@ -34,12 +35,6 @@ namespace backend
 namespace soft
 {
 
-CPPCodeGenerator CPPCodeGenerator::create(const Parameters &params)
-{
-  CPPCodeGenerator gen(params);
-  return gen;
-}
-
 void CPPCodeGenerator::formatTensorNames(const ModelAnalyzer &ma)
 {
   int tmpTensors = 0;
@@ -195,7 +190,7 @@ void CPPCodeGenerator::materializeCode(ostream &out, const ModelAnalyzer &ma, co
 {
   string className = ma.getModelName() + "Model";
 
-  out << "#include \"" << _params._outName << ".h\"\n";
+  out << "#include \"" << clopt::artifactName << ".h\"\n";
 
   // put operations from tflite
   out.write(eigen, sizeof(eigen));
index a796fc9..cd4b56f 100644 (file)
@@ -6,18 +6,14 @@
 #include "soft_backend.h"
 #include "PluginException.h"
 #include "ConfigException.h"
-#include "PluginType.h"
 #include "nnc/core/IR/model/graph/graph.h"
-
-#include <sys/types.h>
-#include <dirent.h>
+#include "Options.h"
 
 #include "debug.h"
 #define DEBUG_AREA "soft_backend"
 
 using namespace std;
 using namespace nncc::contrib;
-using namespace nncc::contrib::config;
 using namespace nncc::contrib::plugin;
 using namespace nncc::contrib::core::IR::model;
 using namespace nncc::contrib::backend::soft;
@@ -31,116 +27,14 @@ namespace backend
 namespace soft
 {
 
-namespace
-{
-const string pluginVersion = "0.01";
-const string pluginDesc = "Generates source code for selected programming language from IR";
-const PluginType pluginType = typeBackEnd;
-
-const char *outDir = "out-dir";
-const char *outName = "out-name";
-} // unnamed namespace
-
-// Helpers
-enum class OPT_ID
-{
-  INVALID,
-  TARGET,
-  OUT_DIR,
-  OUT_NAME
-};
-
-void BaseSoftBackend::fillSession()
-{
-  const static map<string, string> info = {{"module description", pluginDesc}};
-  const static vector<PluginParam> moduleParams = {{outDir, "path to output directory", true},
-                                                   {outName, "common name for generated files", true}};
-
-  AbstractPluginInstance::fillSessionBase(pluginType, pluginVersion, _pluginName);
-
-  for (auto &i : info)
-    getSession()->addInfo(i.first, i.second);
-
-  for (const auto &p: moduleParams)
-    getSession()->registerParam(p);
-}
-
-void BaseSoftBackend::checkConfig()
-{
-  if (_params._outName.empty())
-  {
-    throw PluginException("Output file name should not be empty");
-  }
-  if (_params._outDir.empty())
-  {
-    throw PluginException("Output directory should not be empty");
-  }
-  auto dir = opendir(_params._outDir.c_str());
-  if (dir)
-  {
-    closedir(dir);
-    return;
-  }
-  auto err = errno;
-  switch (err)
-  {
-    case ENOENT:
-      return;
-    case ENOTDIR:
-      throw PluginException("Output path is not directory");
-    case EACCES:
-      throw PluginException("Has no permission to open output directory");
-    default:
-      throw PluginException("Can not open output directory");
-  }
-
-}
-
 void *BaseSoftBackend::execute(void *data)
 {
   assert(data);
   Graph *graph = static_cast<Graph*>(data);
   generate(graph);
-  NNC_DEBUG(dbgs() << "[" << _pluginName << "] Plugin executed" << endl);
   return data;
 }
 
-void BaseSoftBackend::setParam(const string &name)
-{
-  auto optionIt = _flags.find(name);
-  switch (optionIt->second)
-  {
-    case OPT_ID::TARGET:
-      break;
-    default:
-      throw ConfigException("[" + _pluginName + "] Unsupported flag parameter <" + name + ">");
-  }
-}
-
-void BaseSoftBackend::setParam(const string &name, const string &value)
-{
-  auto optionIt = _opts.find(name);
-  switch (optionIt->second)
-  {
-    case OPT_ID::OUT_DIR:
-      _params._outDir = value;
-      break;
-    case OPT_ID::OUT_NAME:
-      _params._outName = value;
-      break;
-    default:
-      throw ConfigException("[" + _pluginName + "] Unsupported parameter with value <" + name + ">");
-  }
-}
-
-BaseSoftBackend::BaseSoftBackend(const std::string &name, const std::string &target_opt):
-        _pluginName(name), _params({"out", "nnmodel"})
-{
-  _flags[target_opt] = OPT_ID::TARGET;
-  _opts[outDir] = OPT_ID::OUT_DIR;
-  _opts[outName] = OPT_ID::OUT_NAME;
-}
-
 } // namespace soft
 } // namespace backend
 } // namespace contrib
index 50e6efb..312286c 100644 (file)
@@ -21,9 +21,10 @@ target_include_directories(caffe_importer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc
 
 target_link_libraries(caffe_importer PUBLIC caffeproto)
 target_link_libraries(caffe_importer PUBLIC ${nn_import_common})
+target_link_libraries(caffe_importer PRIVATE nnc_support)
 target_link_libraries(caffe_importer PRIVATE nnc_core)
 target_link_libraries(caffe_importer PRIVATE nncc_core)
 target_link_libraries(caffe_importer PRIVATE nnc_plugin_core)
 
-add_nncc_example_executable(caffe_model_dumper examples/model_dump.cpp)
-nncc_target_link_libraries(caffe_model_dumper caffe_importer)
+add_nncc_example_executable(caffe_model_dumper ${OPTIONS_SRC} examples/model_dump.cpp)
+nncc_target_link_libraries(caffe_model_dumper nnc_support caffe_importer)
index d0200bb..c659fae 100644 (file)
@@ -1,15 +1,17 @@
 #include <iostream>
 
+#include "CommandLine.h"
+#include "Options.h"
 #include "caffe_importer.h"
 
-int main(int argc, char** argv)
+using namespace nncc::contrib;
+
+int main(int argc, const char** argv)
 {
-    std::string modelName;
-    if (argc > 1)
-    {
-        modelName = argv[1];
-    }
-    else
+    clopt::CommandLine::getParser()->parseCommandLine(argc, argv);
+    std::string modelName = clopt::inputFile;
+
+    if ( modelName.empty() )
     {
         modelName = "mobilenet.caffemodel";
     }
index 5719f65..4a20855 100644 (file)
 #include <vector>
 #include <iostream>
 
-#include "PluginType.h"
 #include "PluginInstance.h"
 #include "PluginException.h"
 #include "ConfigException.h"
+#include "Options.h"
 
 #include "caffe_importer.h"
 
 namespace
 {
-
-const std::string pluginName = "Caffe importer";
-const std::string pluginVersion = "0.0.1";
-const std::string pluginDesc = "Converts Caffe model to Model IR";
-
-const auto pluginType = nncc::contrib::plugin::typeFrontEnd;
-
-const auto inputFilenameOption = "input-filename";
-
-using namespace nncc::contrib::config;
+using namespace nncc::contrib;
 using namespace nncc::contrib::plugin;
 
-class ImporterPlugin : public AbstractPluginInstance
+class ImporterPlugin : public FrontendPlugin
 {
 public:
     ImporterPlugin &operator=(const ImporterPlugin &) = delete;
     ImporterPlugin(const ImporterPlugin &) = delete;
 
-    static AbstractPluginInstance &getInstance();
-    void fillSession() override;
-    void checkConfig() override;
+    static FrontendPlugin &getInstance();
     void *execute(void *data) override;
 
-    void setParam(const std::string &name) override;
-    void setParam(const std::string &name, const std::string &value) override;
-
-private:
-    std::string _filename;
-
 private:
     ImporterPlugin() = default;
     ~ImporterPlugin() override = default;
 };
 
-AbstractPluginInstance &ImporterPlugin::getInstance()
+FrontendPlugin &ImporterPlugin::getInstance()
 {
   static ImporterPlugin instance;
   return instance;
 }
 
-void ImporterPlugin::fillSession()
-{
-  static std::map<std::string, std::string> info = {{"module description", pluginDesc}};
-
-  static std::vector<PluginParam> moduleParams =
-          {{inputFilenameOption, "path to Caffe model file", false}};
-
-  AbstractPluginInstance::fillSessionBase(pluginType, pluginVersion, pluginName);
-
-  for (auto &i : info)
-    getSession()->addInfo(i.first, i.second);
-
-  for (auto &p : moduleParams)
-    getSession()->registerParam(p);
-}
-
-void ImporterPlugin::checkConfig()
-{
-}
-
 void *ImporterPlugin::execute(void *)
 {
-  nncc::contrib::frontend::caffe::CaffeImporter importer{_filename};
+  nncc::contrib::frontend::caffe::CaffeImporter importer{clopt::inputFile};
 
   bool success = importer.import();
 
   if (!success)
   {
-    throw nncc::contrib::PluginException("Could not load model: " + _filename + "\n");
-  };
+    throw nncc::contrib::PluginException("Could not load model: " + clopt::inputFile + "\n");
+  }
 
   return importer.createIR();
 }
 
-void ImporterPlugin::setParam(const std::string &name)
-{
-  throw nncc::contrib::ConfigException("unsupported parameter <" + name + ">");
-}
-
-void ImporterPlugin::setParam(const std::string &name, const std::string &value)
-{
-  if (name == inputFilenameOption)
-  {
-    _filename = value;
-  }
-  else
-  {
-    throw nncc::contrib::ConfigException("unsupported parameter <" + name + ">");
-  }
-}
-
 } // anonymous namespace
 
 extern "C" AbstractPluginInstance *get_instance()
index 2ec8e55..2486323 100644 (file)
@@ -29,6 +29,7 @@ target_include_directories(${tflite_import} PUBLIC include)
 
 target_link_libraries(${tflite_import} PUBLIC flatbuffers)
 target_link_libraries(${tflite_import} PUBLIC ${nn_import_common})
+target_link_libraries(${tflite_import} PUBLIC nnc_support)
 target_link_libraries(${tflite_import} PRIVATE nnc_core)
 target_link_libraries(${tflite_import} PRIVATE nncc_core)
 target_link_libraries(${tflite_import} PRIVATE nnc_plugin_core)
@@ -40,6 +41,6 @@ target_link_libraries(${tflite_import} PRIVATE nnc_plugin_core)
 file(GLOB tflite_example_sources examples/*)
 
 set(tflite_import_example tflite_import_example)
-add_executable(${tflite_import_example} ${tflite_example_sources})
+add_executable(${tflite_import_example} ${tflite_example_sources} ${OPTIONS_SRC})
 
 target_link_libraries(${tflite_import_example} PRIVATE ${tflite_import})
index b01fcae..2254fea 100644 (file)
@@ -1,15 +1,17 @@
 #include <iostream>
 
+#include "CommandLine.h"
+#include "Options.h"
 #include "tflite_v3_importer.h"
 
-int main(int argc, char **argv)
+using namespace nncc::contrib;
+
+int main(int argc, const char **argv)
 {
-  std::string modelName;
-  if (argc > 1)
-  {
-    modelName = argv[1];
-  }
-  else
+  clopt::CommandLine::getParser()->parseCommandLine(argc, argv);
+  std::string modelName = clopt::inputFile;
+
+  if (modelName.empty())
   {
     modelName = "mobilenet_v1.0.tflite";
   }
index eaf36d7..ef8af71 100644 (file)
 #include <vector>
 #include <iostream>
 
-#include "PluginType.h"
 #include "PluginInstance.h"
 #include "PluginException.h"
 #include "ConfigException.h"
+#include "Options.h"
 
 #include "tflite_v3_importer.h"
 
 namespace
 {
-const std::string pluginName = "Tensorflow Lite importer";
-const std::string pluginVersion = "0.0.1";
-const std::string pluginDesc = "Converts Tensorflow Lite v3 model to Model IR";
-
-const auto pluginType = nncc::contrib::plugin::typeFrontEnd;
-
-const auto inputFilenameOption = "input-filename";
-
-using namespace nncc::contrib::config;
+using namespace nncc::contrib;
 using namespace nncc::contrib::plugin;
 
-class ImporterPlugin : public AbstractPluginInstance
+class ImporterPlugin : public FrontendPlugin
 {
 public:
     ImporterPlugin &operator=(const ImporterPlugin &) = delete;
     ImporterPlugin(const ImporterPlugin &) = delete;
 
-    static AbstractPluginInstance &getInstance();
-    void fillSession() override;
-    void checkConfig() override;
+    static FrontendPlugin &getInstance();
     void *execute(void *data) override;
 
-    void setParam(const std::string &name) override;
-    void setParam(const std::string &name, const std::string &value) override;
-
-private:
-    std::string _filename;
-
 private:
     ImporterPlugin() = default;
     ~ImporterPlugin() override = default;
 };
 
-AbstractPluginInstance &ImporterPlugin::getInstance()
+FrontendPlugin &ImporterPlugin::getInstance()
 {
   static ImporterPlugin instance;
   return instance;
 }
 
-void ImporterPlugin::fillSession()
-{
-  static std::map<std::string, std::string> info = {{"module description", pluginDesc}};
-
-  static std::vector<PluginParam> moduleParams =
-          {{inputFilenameOption, "path to Tensorflow Lite model file", false}};
-
-  AbstractPluginInstance::fillSessionBase(pluginType, pluginVersion, pluginName);
-
-  for (auto &i : info)
-    getSession()->addInfo(i.first, i.second);
-
-  for (auto &p : moduleParams)
-    getSession()->registerParam(p);
-}
-
-void ImporterPlugin::checkConfig()
-{
-}
-
 void *ImporterPlugin::execute(void *)
 {
-  nncc::contrib::frontend::tflite::v3::TfliteImporter importer{_filename};
+  nncc::contrib::frontend::tflite::v3::TfliteImporter importer{clopt::inputFile};
 
   bool success = importer.import();
 
   if (!success)
   {
-    throw nncc::contrib::PluginException("Could not load model: " + _filename + "\n");
+    throw nncc::contrib::PluginException("Could not load model: " + clopt::inputFile + "\n");
   };
 
   return importer.createIR();
 }
 
-void ImporterPlugin::setParam(const std::string &name)
-{
-  throw nncc::contrib::ConfigException("unsupported parameter <" + name + ">");
-}
-
-void ImporterPlugin::setParam(const std::string &name, const std::string &value)
-{
-  if (name == inputFilenameOption)
-  {
-    _filename = value;
-  }
-  else
-  {
-    throw nncc::contrib::ConfigException("unsupported parameter <" + name + ">");
-  }
-}
-
 } // anonymous namespace
 
 extern "C" AbstractPluginInstance *get_instance()
diff --git a/contrib/nnc/libs/plugin/include/AbstractSession.h b/contrib/nnc/libs/plugin/include/AbstractSession.h
deleted file mode 100644 (file)
index 2f5e796..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef __ABSTRACT_SESSION_H__
-#define __ABSTRACT_SESSION_H__
-
-#include <string>
-#include "PluginParam.h"
-#include "PluginType.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace config
-{
-
-class AbstractSession
-{
-public:
-  AbstractSession() = default;
-
-  virtual ~AbstractSession() = default;
-
-  virtual void addInfo(const std::string &name, const std::string &value) = 0;
-  virtual void registerParam(const PluginParam &param) = 0;
-
-  plugin::PluginType getPluginType();
-  void setPluginType(plugin::PluginType pluginType);
-
-private:
-  plugin::PluginType _pluginType;
-};
-
-} // namespace config
-} // namespace contrib
-} // namespace nncc
-
-#endif // __ABSTRACT_SESSION_H__
index 0952fbb..8c5b9ad 100644 (file)
@@ -3,7 +3,6 @@
 
 #include <string>
 #include <memory>
-#include "AbstractSession.h"
 
 namespace nncc
 {
@@ -18,32 +17,40 @@ namespace plugin
 class AbstractPluginInstance
 {
 public:
-  static const std::string paramPluginVersion;
-  static const std::string paramPluginName;
-
-public:
   AbstractPluginInstance &operator=(const AbstractPluginInstance &) = delete;
   AbstractPluginInstance(const AbstractPluginInstance &) = delete;
 
-  virtual void fillSessionBase(PluginType type, const std::string &ver,
-                               const std::string &pluginName);
-
-  virtual void fillSession() = 0;
-  virtual void setParam(const std::string &name) = 0;
-  virtual void setParam(const std::string &name, const std::string &value) = 0;
-  virtual void checkConfig() = 0;
   virtual void *execute(void *data) = 0;
 
-  virtual void setSession(std::shared_ptr<config::AbstractSession> &session);
-  virtual std::shared_ptr<config::AbstractSession> getSession() const;
+protected:
+  AbstractPluginInstance() = default;
+  virtual ~AbstractPluginInstance() = default;
+};
+
+class FrontendPlugin : public AbstractPluginInstance
+{
+public:
+  FrontendPlugin &operator=(const FrontendPlugin &) = delete;
+  FrontendPlugin(const FrontendPlugin &) = delete;
 
-private:
-  std::shared_ptr<config::AbstractSession> _session;
+  virtual void *execute(void *data) = 0;
 
 protected:
-  AbstractPluginInstance();
-  virtual ~AbstractPluginInstance();
+  FrontendPlugin() = default;
+  virtual ~FrontendPlugin() = default;
+};
+
+class BackendPlugin : public AbstractPluginInstance
+{
+public:
+  BackendPlugin &operator=(const BackendPlugin &) = delete;
+  BackendPlugin (const BackendPlugin &) = delete;
+
+  virtual void *execute(void *data) = 0;
 
+protected:
+  BackendPlugin() = default;
+  virtual ~BackendPlugin() = default;
 };
 
 } // namespace plugin
diff --git a/contrib/nnc/libs/plugin/include/PluginParam.h b/contrib/nnc/libs/plugin/include/PluginParam.h
deleted file mode 100644 (file)
index 58d9dea..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// Created by v.cherepanov@samsung.com on 09.04.18.
-//
-
-#ifndef __PLUGIN_PARAM_H__
-#define __PLUGIN_PARAM_H__
-
-#include <string>
-
-namespace nncc
-{
-namespace contrib
-{
-namespace config
-{
-
-class PluginParam
-{
-public:
-  PluginParam() = delete;
-  PluginParam(const std::string &name, const std::string &desc, bool isOptional);
-
-  const std::string & getName() const;
-  const std::string & getDesc() const;
-  bool isOptional() const;
-
-protected:
-  std::string _name;
-  std::string _desc;
-  bool _isOptional;
-};
-
-std::ostream &operator<<(std::ostream &os, const PluginParam &param);
-
-} // namespace config
-} // namespace contrib
-} // namespace nncc
-
-#endif // __PLUGIN_PARAM_H__
diff --git a/contrib/nnc/libs/plugin/include/PluginType.h b/contrib/nnc/libs/plugin/include/PluginType.h
deleted file mode 100644 (file)
index be9cebb..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-//
-// Created by v.cherepanov@samsung.com on 02.04.18.
-//
-
-#ifndef __PLUGIN_TYPE_H__
-#define __PLUGIN_TYPE_H__
-
-#include <string>
-
-namespace nncc
-{
-namespace contrib
-{
-namespace plugin
-{
-
-enum PluginType
-{
-  typeInvalid = 0,
-  typeFrontEnd,
-  typeBackEnd
-};
-
-std::string pluginTypeToStr(PluginType type);
-
-} // namespace plugin
-} // namespace contrib
-} // namespace nncc
-
-#endif // __PLUGIN_TYPE_H__
diff --git a/contrib/nnc/libs/plugin/src/AbstractSession.cpp b/contrib/nnc/libs/plugin/src/AbstractSession.cpp
deleted file mode 100644 (file)
index 571956e..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "AbstractSession.h"
-#include "PluginType.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace config
-{
-
-plugin::PluginType AbstractSession::getPluginType() { return _pluginType; }
-
-void AbstractSession::setPluginType(plugin::PluginType pluginType) { _pluginType = pluginType; }
-
-} // namespace config
-} // namespace contrib
-} // namespace nncc
diff --git a/contrib/nnc/libs/plugin/src/PluginInstance.cpp b/contrib/nnc/libs/plugin/src/PluginInstance.cpp
deleted file mode 100644 (file)
index f1688c3..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#include <memory>
-#include "PluginInstance.h"
-#include "PluginException.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace plugin
-{
-
-const std::string AbstractPluginInstance::paramPluginVersion = "version";
-const std::string AbstractPluginInstance::paramPluginName = "plugin name";
-
-void AbstractPluginInstance::fillSessionBase(PluginType type, const std::string &ver,
-                                             const std::string &pluginName)
-{
-  getSession()->setPluginType(type);
-  getSession()->addInfo(paramPluginVersion, ver);
-  getSession()->addInfo(paramPluginName, pluginName);
-}
-
-void AbstractPluginInstance::setSession(std::shared_ptr<config::AbstractSession> &session)
-{
-  _session = session;
-}
-
-std::shared_ptr<config::AbstractSession> AbstractPluginInstance::getSession() const
-{
-  if (_session == nullptr)
-    throw nncc::contrib::PluginException("session not set!");
-  return _session;
-}
-
-AbstractPluginInstance::AbstractPluginInstance() : _session(nullptr) {}
-AbstractPluginInstance::~AbstractPluginInstance() {}
-
-} // namespace plugin
-} // namespace contrib
-} // namespace nncc
diff --git a/contrib/nnc/libs/plugin/src/PluginParam.cpp b/contrib/nnc/libs/plugin/src/PluginParam.cpp
deleted file mode 100644 (file)
index b4efc36..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// Created by v.cherepanov@samsung.com on 09.04.18.
-//
-
-#include <ostream>
-#include <string>
-
-#include "PluginParam.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace config
-{
-
-PluginParam::PluginParam(const std::string &name, const std::string &desc, bool isOptional)
-    : _name(name), _desc(desc), _isOptional(isOptional)
-{
-}
-
-const std::string & PluginParam::getName() const { return _name; }
-
-const std::string & PluginParam::getDesc() const { return _desc; }
-
-bool PluginParam::isOptional() const { return _isOptional; }
-
-std::ostream &operator<<(std::ostream &os, const PluginParam &param)
-{
-  os << param.getName() << ": " << param.getDesc();
-  return os;
-}
-
-} // namespace config
-} // namespace contrib
-} // namespace nncc
diff --git a/contrib/nnc/libs/plugin/src/PluginType.cpp b/contrib/nnc/libs/plugin/src/PluginType.cpp
deleted file mode 100644 (file)
index b2d7ee8..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-//
-// Created by v.cherepanov@samsung.com on 02.04.18.
-//
-
-#include <string>
-
-#include "PluginType.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace plugin
-{
-
-std::string pluginTypeToStr(PluginType type)
-{
-  switch (type)
-  {
-  case typeFrontEnd:
-    return "FrontEnd";
-  case typeBackEnd:
-    return "BackEnd";
-  default:
-    return "Invalid";
-  }
-}
-
-} // namespace plugin
-} // namespace contrib
-} // namespace nncc
index 7e741fc..1369340 100644 (file)
@@ -1,5 +1,7 @@
 #include <string>
 
+#include "CommandLine.h"
+
 namespace nncc
 {
 namespace contrib
@@ -7,21 +9,59 @@ namespace contrib
 namespace clopt
 {
 
-// examples of how to declare new options
-#if 0
-Option<std::string> BackendName(optname("--target, -t"),
-                                overview("target for which code will be generated"),
+/**
+ * @breif Options for compiler driver
+ */
+Option<std::string> pluginsPath(optname("--plugins-path"),
+                                overview("path where plugins will be searched"),
                                 "",
-                                optional(false),
-                                optvalues("emit-c++, emit-c"),
-                                separators("="));
+                                optional(true),
+                                optvalues(""),
+                                checkPluginsPath);
+Option<bool> pluginVerbose(optname("--plugins-verbose"),
+                           overview("verbose printing when plugins will be being searched"),
+                           false,
+                           optional(true));
 
-Option<std::string> ModelInputFile(optname("--input,-i"),
-                                   overview("Model input file"));
+/**
+ * @breif Options for frontend
+ */
+Option<std::string> inputFile(optname("--input-filename"),
+                              overview("path to AI model file"),
+                              "",
+                              optional(true),
+                              optvalues(""),
+                              checkInFile);
 
-Option<std::string> ModelOutputFile(optname("--output,-o"),
-                                    overview("Model output file"));
-#endif // if 0
+/**
+ * @breif Options for backend
+ */
+// options for soft backend
+Option<std::string> artifactName(optname("--out-name"),
+                                 overview("artifact output file name"),
+                                 "nnmodel",
+                                 optional(true),
+                                 optvalues(""),
+                                 checkOutFile);
+Option<std::string> artifactDir(optname("--out-dir"),
+                                overview("directory contains artifact output files"),
+                                ".", // default is current directory
+                                optional(true),
+                                optvalues(""),
+                                checkOutDir);
+// options for interpreter
+Option<std::string> interFileName(optname("--filename"),
+                                  overview("input file for interpreter"),
+                                  "",
+                                  optional(true));
+Option<std::string> interInNode(optname("--input"),
+                                overview("interpreter option: sets input node in Computational Graph"),
+                                "",
+                                optional(true));
+Option<std::string> interOutNode(optname("--output"),
+                                 overview("interpreter option: sets output node in Computational Graph"),
+                                 "",
+                                 optional(true));
 
 } // namespace clopt
 } // namespace contrib
index 2507f8b..7429893 100644 (file)
@@ -1,37 +1,33 @@
 #include <iostream>
+#include <vector>
 
 #include "ConfigException.h"
 #include "module/AbstractModule.h"
 #include "module/FrontendModule.h"
 #include "module/BackendModule.h"
-#include "module/plugin/PluginData.h"
 #include "module/plugin/PluginManager.h"
+#include "CommandLine.h"
 
 using namespace nncc::contrib;
+using namespace nncc::contrib::clopt;
 
 int main(int argc, char *argv[])
 {
   try
   {
-    std::shared_ptr<config::DataList> config = config::DataList::parse(argc, argv);
     module::plugin::PluginManager &pluginManager = module::plugin::PluginManager::getInstance();
     std::vector<module::AbstractModule *> modules;
 
     modules.push_back(&module::FrontendModule::getInstance());
     modules.push_back(&module::BackendModule::getInstance());
 
-    // Parsing command line
+    // Parse command line
+    CommandLine::getParser()->parseCommandLine(argc, const_cast<const char **>(argv));
 
-    // FIXME: it's necessary to make this printing via debugging system (see issue #893)
-    //std::cout << "input config:" << std::endl << *config << std::endl;
-    pluginManager.setConfig(config);
-    pluginManager.loadPlugins(modules);
+    pluginManager.loadPlugins();
     // FIXME: it's necessary to make this printing via debugging system (see issue #893)
     //std::cout << "plugins found:"  << std::endl << pluginManager << std::endl;
 
-    for (auto m : modules)
-      m->configure(config);
-
     void *exRes = nullptr;
     for (auto m : modules)
       exRes = m->execute(exRes);
@@ -39,14 +35,9 @@ int main(int argc, char *argv[])
     // No errors
     return 0;
   }
-  catch (config::DataException &e)
-  {
-    std::cout << e.what() << std::endl;
-  }
   catch (module::plugin::PluginManagerException &e)
   {
     std::cout << e.what() << std::endl;
-    module::plugin::PluginManager::getInstance().help();
   }
   catch (ConfigException &e)
   {
index aea2658..eba01b9 100644 (file)
@@ -4,7 +4,6 @@
 
 #include "module/AbstractModule.h"
 #include "PluginInstance.h"
-#include "module/plugin/PluginSession.h"
 
 namespace nncc
 {
@@ -12,63 +11,21 @@ namespace contrib
 {
 namespace module
 {
-
-AbstractModule::AbstractModule() : _activePlugin(nullptr) , _moduleType(contrib::plugin::typeInvalid) {}
-
-AbstractModule::AbstractModule(contrib::plugin::PluginType moduleType)
-    : _activePlugin(nullptr), _moduleType(moduleType) {
-}
+AbstractModule::AbstractModule() : _activePlugin(nullptr)  {}
 
 AbstractModule::~AbstractModule() {}
 
 void AbstractModule::registerPlugin(std::shared_ptr<plugin::PluginProxy> &pl) { _plugins.push_back(pl); }
 
-void AbstractModule::configure(std::shared_ptr<config::DataList> conf) {
-  _activePlugin = nullptr;
-  for (auto &pl : _plugins) {
-    try {
-      auto &pluginInstance = pl->getPluginInstance();
-      auto *session = dynamic_cast<config::PluginSession *>(pluginInstance.getSession().get());
-      auto resParams = config::DataList::intersection(*conf, session->getSupportedParams());
-
-      for (auto param : resParams->getElements()) {
-        if (param.second.hasValue())
-          pluginInstance.setParam(param.second.getName(), param.second.getValue());
-        else
-          pluginInstance.setParam(param.second.getName());
-      }
-
-      pluginInstance.checkConfig();
-      _activePlugin = pl;
-      break;
-    }
-    catch (nncc::contrib::ConfigException &e) {
-      std::cout << e.what() << std::endl;
-    }
-    catch (contrib::config::DataException &e) {
-      std::cout << e.what() << std::endl;
-    }
-    catch (PluginException &e) {
-      std::cout << e.what() << std::endl;
-    }
-
-    std::cout << "plugin cannot be configured (" << pl->getPluginName() << ")" << std::endl;
-  }
-
-  if (_activePlugin == nullptr)
-    throw ConfigException("Module <" + pluginTypeToStr(_moduleType) +
-        "> cannot be configured");
-}
-
 void *AbstractModule::execute(void *data) {
   if (_activePlugin == nullptr)
-    throw ConfigException("Module <" + pluginTypeToStr(_moduleType) +
-        "> has not been configured!");
+    throw ConfigException("Module has not been configured!");
   void *result = nullptr;
 
   try {
-    std::cout << "Executing plugin <" << _activePlugin->getPluginName() << ">" << std::endl;
-    result = _activePlugin->getPluginInstance().execute(data);
+    // FIXME: it's necessary to make this printing via debugging system (see issue #893)
+    //std::cout << "Executing plugin <" << _activePlugin->getPluginName() << ">" << std::endl;
+    result = _activePlugin->getPluginInstance()->execute(data);
   } catch (nncc::foundation::Exception &e) {
     e.append("Plugin <" + _activePlugin->getPluginName() + "> execution failed!");
     throw;
@@ -76,10 +33,7 @@ void *AbstractModule::execute(void *data) {
   return result;
 }
 
-contrib::plugin::PluginType AbstractModule::getModuleType() const { return _moduleType; }
-
 std::ostream &operator<<(std::ostream &st, const AbstractModule &m) {
-  st << "=== MODULE " << pluginTypeToStr(m._moduleType) << " ===" << std::endl;
   st << "plugins {" << std::endl;
   for (const auto &p : m._plugins)
     st << "  " << *p << std::endl;
index dc1f582..cc455b6 100644 (file)
@@ -12,7 +12,7 @@ BackendModule &BackendModule::getInstance() {
   return instance;
 }
 
-BackendModule::BackendModule() : AbstractModule(contrib::plugin::PluginType::typeBackEnd) {}
+BackendModule::BackendModule() : AbstractModule() {}
 BackendModule::~BackendModule() {}
 
 } // namespace module
index aaa395b..904cee3 100644 (file)
@@ -12,7 +12,7 @@ FrontendModule &FrontendModule::getInstance() {
   return instance;
 }
 
-FrontendModule::FrontendModule() : AbstractModule(contrib::plugin::PluginType::typeFrontEnd) {}
+FrontendModule::FrontendModule() : AbstractModule() {}
 FrontendModule::~FrontendModule() {}
 
 } // namespace module
diff --git a/contrib/nnc/src/module/plugin/PluginData.cpp b/contrib/nnc/src/module/plugin/PluginData.cpp
deleted file mode 100644 (file)
index bb3aaaa..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-#include <cstring>
-#include <ostream>
-#include "module/plugin/PluginData.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace config
-{
-
-// Data class
-
-Data::Data(const std::string &name) : _hasValue(false), _name(name) {}
-
-Data::Data(const std::string &name, const std::string &value) : Data(name) { setValue(value); }
-
-const std::string &Data::getValue() const {
-  if (!_hasValue)
-    throw DataException("Option <" + _name + "> has no value");
-  return _value;
-}
-
-const std::string &Data::getName() const { return _name; }
-
-bool operator==(const Data &elm, const char *cmp_value) { return elm.getValue() == cmp_value; };
-
-void Data::setValue(const std::string &value) {
-  _hasValue = true;
-  _value = value;
-}
-
-bool Data::hasValue() const { return _hasValue; }
-
-std::ostream &operator<<(std::ostream &os, const Data &op) {
-  if (op.hasValue()) {
-    os << "<" << op.getName() << "> = " << op.getValue();
-  } else {
-    os << "<" << op.getName() << ">";
-  }
-
-  return os;
-}
-
-// DataList class
-enum paramType {paramShort = 0, paramLong, paramData, paramError};
-static enum paramType getParamType(const char *argv) {
-  enum paramType res = paramError;
-  size_t len;
-
-  len = strnlen(argv, 3);
-  if (len <= 0) {
-    // should never happen
-    res = paramError;
-  } else if (len <= 1) {
-    res = paramData;
-  } else if (len == 2) {
-    if (argv[0] == '-' && argv[1] != '-')
-      res = paramShort;
-    else
-      res = paramData;
-  } else {
-    if (argv[0] == '-' && argv[1] == '-' && argv[2] != '-')
-      res = paramLong;
-    else
-      res = paramData;
-  }
-
-  return res;
-}
-
-static bool nextParamIsData(int cur, int argc, char *argv[]) {
-  bool res = 0;
-
-  if (cur >= argc - 1) {
-    res = false;
-  } else {
-    res = (getParamType(argv[cur + 1]) == paramData);
-  }
-
-  return res;
-}
-
-DataList::DataList(const std::string &name) : _name(name) {}
-
-std::shared_ptr<DataList> DataList::parse(int argc, char *argv[]) noexcept(false) {
-  std::shared_ptr<DataList> params(new DataList("params"));
-
-  for (int i = 1; i < argc; i++) {
-    enum paramType type = getParamType(argv[i]);
-    const char *paramName = nullptr;
-
-    // Check param type
-    if (type == paramShort)
-      paramName = argv[i] + 1;
-    else if (type == paramLong)
-      paramName = argv[i] + 2;
-    else
-      throw DataException(std::string("bad parameter <") + argv[i] + ">");
-
-    // Get param data
-    if (nextParamIsData(i, argc, argv)) {
-      params->createElement(paramName, argv[i + 1]);
-      i++;
-    } else {
-      params->createElement(paramName);
-    }
-  }
-
-  return params;
-}
-
-// This function is used to intersect command line params
-// with params requested by plugins and modules
-std::shared_ptr<DataList>
-DataList::intersection(const DataList &common,
-                       const std::vector<PluginParam> &supported) noexcept(false) {
-  std::shared_ptr<DataList> params(new DataList("params"));
-  for (auto s : supported) {
-    try {
-      const Data &op = common.getElement(s.getName());
-      if (op.hasValue())
-        params->createElement(op.getName(), op.getValue());
-      else
-        params->createElement(op.getName());
-    }
-    catch (DataException &eOp) {
-      if (!s.isOptional()) {
-        std::string info = "option <" + s.getName() + "> should be set. " + s.getDesc();
-        throw DataException(eOp, info);
-      }
-    }
-  }
-
-  return params;
-}
-
-// This function is used to intersect command line params
-// with params requested by plugins and modules
-std::shared_ptr<DataList>
-DataList::intersection(const DataList &common,
-                       const std::map<std::string, PluginParam> &supported) noexcept(false) {
-  std::vector<PluginParam> supported_list;
-  for (auto &param : supported) {
-    supported_list.push_back(param.second);
-  }
-
-  return intersection(common, supported_list);
-}
-
-Data &DataList::createElement(const std::string &name) {
-  // TODO check emplace
-  auto res = _items.emplace(name, Data(name));
-  return res.first->second;
-}
-
-Data &DataList::createElement(const std::string &name, const std::string &value) {
-  // TODO check emplace
-  auto res = DataList::_items.emplace(name, Data(name, value));
-  return res.first->second;
-}
-
-const std::string &DataList::getName() const { return _name;}
-
-const Data &DataList::getElement(const std::string &name) const noexcept(false) {
-  auto it = _items.find(name);
-  if (it == _items.end()) {
-    throw DataException(std::string("option <") + name + "> not found");
-  }
-  return it->second;
-}
-
-const std::map<std::string, Data> &DataList::getElements() const noexcept(false) { return _items; }
-
-const Data &DataList::operator[](const std::string &key) const noexcept(false) { return getElement(key); }
-
-std::ostream &operator<<(std::ostream &os, const DataList &list) {
-  os << "<" << list.getName() << "> = {" << std::endl;
-
-  for (auto &f : list.getElements())
-    os << f.second << std::endl;
-
-  os << "}" << std::endl;
-
-  return os;
-}
-
-} // namespace config
-} // namespace contrib
-} // namespace nncc
index 79cb971..251631e 100644 (file)
@@ -2,10 +2,14 @@
 #include <dlfcn.h>
 #include <dirent.h>
 #include <cstring>
+#include <vector>
+#include <module/FrontendModule.h>
+#include <module/BackendModule.h>
 
 #include "module/plugin/PluginProxy.h"
-#include "module/plugin/PluginSession.h"
 #include "module/plugin/PluginManager.h"
+#include "PluginInstance.h"
+#include "Options.h"
 
 #include "PluginException.h"
 #include "ConfigException.h"
@@ -28,17 +32,13 @@ namespace module
 namespace plugin
 {
 
-const std::string PluginManager::paramPluginPath = "plugins-path";
-const std::string PluginManager::paramVerboseLoading = "plugins-verbose";
-const std::string PluginManager::paramPluginHelp = "plugins-help";
-
 std::vector<std::string> PluginManager::getPluginPathList() {
   std::vector<std::string> pluginPathList;
   std::vector<std::string> dirList;
 
   // Push first path
   dirList.clear();
-  dirList.push_back(_pluginsPath);
+  dirList.push_back(clopt::pluginsPath);
 
   while (!dirList.empty()) {
     const auto curPluginsPath = dirList.back();
@@ -66,54 +66,53 @@ std::vector<std::string> PluginManager::getPluginPathList() {
   return pluginPathList;
 }
 
-void PluginManager::loadPlugins(std::vector<AbstractModule *> &modules) {
-  NNC_DEBUG(dbgs() << "Current plugin path is <" << _pluginsPath << ">" << std::endl);
+void PluginManager::loadPlugins()
+{
+  NNC_DEBUG(dbgs() << "Current plugin path is <" << clopt::pluginsPath << ">" << std::endl);
   auto plugins = getPluginPathList();
 
-  for (const auto &pluginPath : plugins) {
-    try {
+  for (const auto &pluginPath : plugins)
+  {
+    try
+    {
       auto pl = PluginProxy::create(pluginPath);
-      auto &plInst = pl->getPluginInstance();
-      std::shared_ptr<config::AbstractSession> session = std::make_shared<config::PluginSession>();
-      plInst.setSession(session);
-      plInst.fillSession();
 
-      if (_showPluginInfo)
+      if (clopt::pluginVerbose)
         std::cout << "plugin <" + pluginPath + ">: {" << std::endl
                   << "name <" + pl->getPluginName() + "> " << std::endl
-                  << dynamic_cast<config::PluginSession &>(*session) << std::endl
                   << "}" << std::endl;
 
       _plugins.push_back(pl);
     }
-    catch (PluginException &e) {
-      if (_showPluginInfo)
+    catch (PluginException &e)
+    {
+      if (clopt::pluginVerbose)
         std::cout << "plugin <" + pluginPath << ">: {" << std::endl
                   << "bad plugin :" << e.what() << std::endl
                   << "}" << std::endl;
     }
-    catch (config::DataException &eOp) {
-      std::cout << "bad plugin info <" + pluginPath << ">:" << eOp.what() << std::endl;
-    }
   }
 
   if (_plugins.empty())
     throw PluginManagerException("No plugins found");
 
   // Fill modules by plugins
-  for (auto &pl : _plugins) {
-    for (auto m : modules) {
-      auto *session =
-          dynamic_cast<config::PluginSession *>(pl->getPluginInstance().getSession().get());
-      if (m->getModuleType() == session->getPluginType()) {
-        m->registerPlugin(pl);
-        break;
-      }
-    }
-  }
+  for (auto &pl : _plugins)
+  {
+    auto ptype = pl->getPluginInstance();
 
-  for (auto m : modules) {
-    std::cout << *m;
+    if ( dynamic_cast<contrib::plugin::FrontendPlugin *>(ptype) )
+    {
+      module::FrontendModule::getInstance().registerPlugin(pl);
+    }
+    else if ( dynamic_cast<contrib::plugin::BackendPlugin *>(ptype) )
+    {
+      module::BackendModule::getInstance().registerPlugin(pl);
+    }
+    else
+    {
+      throw PluginManagerException("Incorrect plugin type");
+    }
   }
 }
 
@@ -128,72 +127,6 @@ PluginManager &PluginManager::getInstance() {
   return instance;
 }
 
-void PluginManager::setConfig(std::shared_ptr<config::DataList> conf) {
-  try {
-    _config = conf;
-    auto plist = config::DataList::intersection(*conf, _supportedParams);
-
-    for (auto &p : plist->getElements()) {
-      if (p.second.hasValue())
-        applyParam(p.second.getName(), p.second.getValue());
-      else
-        applyParam(p.second.getName());
-    }
-  }
-  catch (ConfigException &e) {
-    throw PluginManagerException(e, "config error");
-  }
-  catch (PluginException &e) {
-    throw PluginManagerException(e, "plugin error");
-  }
-}
-
-void PluginManager::applyParam(const std::string &name) {
-  if (name == paramPluginHelp) {
-    help();
-  } else if (name == paramVerboseLoading) {
-    _showPluginInfo = true;
-  } else {
-    std::string info =
-        "[ERR]" + std::string(__func__) + " <" + name + ">" + " WRONG SINGLE PARAMETER";
-    throw ConfigException(info);
-  }
-}
-
-void PluginManager::applyParam(const std::string &name, const std::string &value) {
-  NNC_DEBUG(dbgs() << __func__ << " <" + name + "> = " + value << std::endl);
-  if (name == paramPluginPath) {
-    _pluginsPath = value;
-  } else {
-    help();
-    std::string info =
-        "[ERR]" + std::string(__func__) + " <" + name + "> = " + value + " WRONG PARAMETER";
-    throw ConfigException(info);
-  }
-}
-
-void PluginManager::help() const {
-  std::cout << "HELP" << std::endl;
-
-  for (auto &p : _supportedParams)
-    if (!p.isOptional())
-      std::cout << "--" << p.getName() << " ";
-
-  for (auto &p : _supportedParams)
-    if (p.isOptional())
-      std::cout << "[--" << p.getName() << "] ";
-  std::cout << std::endl;
-
-  for (auto &p : _supportedParams)
-    std::cout << p << std::endl;
-}
-
-PluginManager::PluginManager() : _config(nullptr), _showPluginInfo(false) {
-  _supportedParams = {{paramPluginPath, "[path]", true},
-                      {paramVerboseLoading, "[show found plugins info]", true},
-                      {paramPluginHelp, "[help]", true}};
-}
-
 PluginManagerException::PluginManagerException(const std::string &info) : Exception(info) {}
 
 PluginManagerException::PluginManagerException(Exception &e, const std::string &info)
index ace5970..d65bc3f 100644 (file)
@@ -64,10 +64,10 @@ const std::string &PluginProxy::getPluginPath() const { return _lib->getPath();
 
 const std::string &PluginProxy::getPluginName() const { return _pluginName; }
 
-contrib::plugin::AbstractPluginInstance &PluginProxy::getPluginInstance() {
+contrib::plugin::AbstractPluginInstance *PluginProxy::getPluginInstance() {
   if (_pluginInstance == nullptr)
     throw PluginException(std::string("bad plugin instance <") + getPluginPath() + ">");
-  return *_pluginInstance;
+  return _pluginInstance;
 }
 
 } // namespace plugins
diff --git a/contrib/nnc/src/module/plugin/PluginSession.cpp b/contrib/nnc/src/module/plugin/PluginSession.cpp
deleted file mode 100644 (file)
index e04d423..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <string>
-#include "PluginParam.h"
-#include "module/plugin/PluginSession.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace config
-{
-
-PluginSession::PluginSession() : _info("info") {}
-
-void PluginSession::addInfo(const std::string &name, const std::string &value)
-{
-  _info.createElement(name, value);
-}
-
-const std::string &PluginSession::getInfo(const std::string &name) const
-{
-  return _info.getElement(name).getValue();
-}
-
-const DataList &PluginSession::getInfo() const
-{
-  return _info;
-}
-
-void PluginSession::registerParam(const PluginParam &param)
-{
-  _supported_params_map.emplace(param.getName(), param);
-}
-
-const std::map<std::string, PluginParam> &PluginSession::getSupportedParams() const { return _supported_params_map; }
-
-std::ostream &operator<<(std::ostream &os, const PluginSession &session)
-{
-  os << session.getInfo();
-  os << "supported params:" << std::endl;
-  for (auto &el : session.getSupportedParams())
-  {
-    os << el.second << std::endl;
-  }
-  return os;
-}
-
-} // namespace config
-} // namespace core
-} // namespace nncc
index 3e49f4c..ab393f6 100644 (file)
@@ -1,6 +1,6 @@
-set(SUPPORT_SOURCES src/CommandLine.cpp)
+set(SUPPORT_SOURCES src/CommandLine.cpp src/CLOptionChecker.cpp)
 set(SUPPORT_HEADERS include/CommandLine.h)
 
-add_library(nnc_support STATIC ${SUPPORT_SOURCES} ${SUPPORT_HEADERS})
+add_library(nnc_support SHARED ${SUPPORT_SOURCES} ${SUPPORT_HEADERS})
 
 target_include_directories(nnc_support PUBLIC include)
\ No newline at end of file
index 922feff..63d2ec1 100644 (file)
@@ -23,11 +23,15 @@ class BaseOption;
 /**
  * @brief simple exception class for invalid options
  */
-class BadOption : public std::exception
+class BadOption
 {
 public:
   BadOption() = default;
-  explicit BadOption(std::string optname, std::string value = "") : _option_name(optname), _option_value(value)  {}
+
+  explicit BadOption(const std::string &optname, const std::string &value)
+      : _option_name(optname), _option_value(value)  {}
+
+  explicit BadOption(const std::string &msg) : _err_msg(msg)  {}
 
   /**
    * @brief get name for invalid option
@@ -39,9 +43,15 @@ public:
     */
     const std::string &getValue() const { return _option_value; }
 
+    /**
+     * @brief get message when exception is thrown
+     */
+    const std::string &getMessage() const { return _err_msg; }
+
 private:
   std::string _option_name;
   std::string _option_value;
+  std::string _err_msg;
 };
 
 /**
@@ -87,6 +97,12 @@ private:
   void checkRegisteredOptions(const std::set<std::string> &cmd_args);
 
   /**
+   * @breif call verification function, if present, for option
+   * @param cmd_args - arguments from command line
+   */
+  void checkOptions(const std::set<std::string> &cmd_args);
+
+  /**
    * @brief find option with `optname` and set `pos` to option value
    * @param optname - name of option
    * @return pointer to option
@@ -111,7 +127,7 @@ private:
   std::map<std::string, BaseOption *> _options_name; // map of name -> option
   std::vector<BaseOption *> _options; // options
   std::string _prog_name; // name of program
-  int _args_num; // number of command line arguments
+  int _args_num = 0; // number of command line arguments
 };
 
 /**
@@ -222,6 +238,18 @@ public:
    * @brief get separators for option
    */
   virtual const std::vector<char> &getSeparators() const = 0;
+
+  /**
+   * @brief function type for option verification
+   * @throw this function throws exception of BadOption
+   *        type if verification is not passed
+   */
+  using option_checker_t = void(*)(const BaseOption &);
+
+  /**
+   * @breif get function for verification of option
+   */
+  virtual option_checker_t getCheckerFunc() = 0;
 };
 
 /**
@@ -248,6 +276,7 @@ public:
                   const T &default_val = T(),
                   bool  is_optional = false,
                   const std::vector<std::string> &vals = std::vector<std::string>(),
+                  option_checker_t checker = nullptr,
                   const std::vector<char> &seps = std::vector<char>());
 
   // options must not be copyable and default constructable
@@ -274,6 +303,8 @@ public:
 
   const std::vector<std::string> &getValidVals() const override { return _valid_vals; }
 
+  option_checker_t getCheckerFunc() override { return _checker; }
+
   const std::vector<char> &getSeparators() const override { return _seps; }
   // end overridden methods
 
@@ -283,6 +314,7 @@ private:
   std::string _descr; // overview of option
   bool _is_optional;
   std::vector<std::string> _valid_vals; // option can be initialized only by these values
+  option_checker_t _checker; // function verifies option and its value
   std::vector<char> _seps; // these symbols separate option name and its value
 };
 
@@ -430,6 +462,7 @@ Option<T>::Option(const std::vector<std::string> &optnames,
                   const T &default_val,
                   bool is_optional,
                   const std::vector<std::string> &vals,
+                  option_checker_t checker,
                   const std::vector<char> &seps)
 {
   // save all names
@@ -454,12 +487,23 @@ Option<T>::Option(const std::vector<std::string> &optnames,
     assert((s == '=' || s == ':') && "invalid option separators");
   }
 
+  // save checker
+  _checker = checker;
+
   // register new option for parser
   CommandLine::getParser()->registerOption(this);
 
 } // Option
 
 
+//
+// prototypes of option checker functions
+//
+void checkInFile(const BaseOption &);
+void checkOutFile(const BaseOption &);
+void checkOutDir(const BaseOption &);
+void checkPluginsPath(const BaseOption &);
+
 } // namespace clopt
 } // namespace contrib
 } // namespace nncc
diff --git a/contrib/nnc/support/src/CLOptionChecker.cpp b/contrib/nnc/support/src/CLOptionChecker.cpp
new file mode 100644 (file)
index 0000000..62e4279
--- /dev/null
@@ -0,0 +1,101 @@
+//
+// Created by rrusyaev on 14.08.18.
+//
+#include "CommandLine.h"
+
+#include <sys/types.h>
+#include <dirent.h>
+
+using namespace nncc::contrib::clopt;
+
+namespace nncc
+{
+namespace contrib
+{
+namespace clopt
+{
+void checkPluginsPath(const BaseOption &option)
+{
+  auto &plugin_dir = dynamic_cast<const Option<std::string> &>(option);
+
+  auto dir = opendir(plugin_dir.c_str());
+
+  if (dir)
+  {
+    closedir(dir);
+    return;
+  }
+
+  auto err = errno;
+
+  switch (err)
+  {
+    case ENOENT:
+      throw BadOption("No such plugins directory");
+    case ENOTDIR:
+      throw BadOption("Value for plugins path is not directory");
+    case EACCES:
+      throw BadOption("Has no permission to open plugins directory");
+    default:
+      throw BadOption("Can not open plugins directory");
+  }
+
+} // checkPluginsPath
+
+void checkInFile(const BaseOption &option)
+{
+  auto &in_file = dynamic_cast<const Option<std::string> &>(option);
+
+  if ( in_file.empty() )
+  {
+    throw BadOption("Input file name should not be empty");
+  }
+
+  /// @todo: need to open file and check that it exists
+
+} // checkInFile
+
+void checkOutFile(const BaseOption &option)
+{
+  auto &out_file = dynamic_cast<const Option<std::string> &>(option);
+
+  if ( out_file.empty() )
+  {
+    throw BadOption("Output file name should not be empty");
+  }
+
+  /// @todo: if file already exists need to check accessibility
+
+} // checkOutFile
+
+void checkOutDir(const BaseOption &option)
+{
+  auto &out_dir = dynamic_cast<const Option<std::string> &>(option);
+
+  auto dir = opendir(out_dir.c_str());
+
+  if (dir)
+  {
+    closedir(dir);
+    return;
+  }
+
+  auto err = errno;
+
+  switch (err)
+  {
+    case ENOENT:
+      return;
+    case ENOTDIR:
+      throw BadOption("Output path is not directory");
+    case EACCES:
+      throw BadOption("Has no permission to open output directory");
+    default:
+      throw BadOption("Can not open output directory");
+  }
+
+} // checkOutDir
+
+} // clopt
+} // contirb
+} // nncc
index 61a56d7..b7a21b8 100644 (file)
@@ -146,7 +146,12 @@ void CommandLine::registerOption(BaseOption *opt)
   for (const auto &n : opt->getNames())
   {
     auto i = _options_name.emplace(n, opt);
-    assert(i.second && "option name must be unique");
+
+    if ( !i.second )
+    {
+      std::cerr << "option name must be unique: `" << n << "'" << std::endl;
+      exit(EXIT_FAILURE);
+    }
   }
 
   _options.push_back(opt);
@@ -170,7 +175,7 @@ BaseOption *CommandLine::findOption(const char *optname)
     if ( it == _options_name.end() )
     {
       // couldn't find option
-      throw BadOption(optname);
+      throw BadOption(optname, "");
     }
   }
 
@@ -289,6 +294,40 @@ void CommandLine::checkRegisteredOptions(const std::set<std::string> &cmd_args)
 
 } // checkRegisteredOptions
 
+void CommandLine::checkOptions(const std::set<std::string> &cmd_args)
+{
+  for ( const auto &o : _options )
+  {
+    // search option from command line
+    for ( const auto &n : o->getNames() )
+    {
+      if ( cmd_args.find(n) == cmd_args.end() )
+      {
+        // name isn't found
+        continue;
+      }
+
+      if ( !o->getCheckerFunc() )
+      {
+        // checker isn't declared
+        continue;
+      }
+
+      // check option
+      try
+      {
+        o->getCheckerFunc()(*o);
+      }
+      catch (BadOption &e)
+      {
+        usage(e.getMessage());
+      }
+
+    } // opt names
+  } // options
+
+} // checkOptions
+
 void CommandLine::parseCommandLine(int argc, const char **argv)
 {
   std::set<std::string> cmd_args;
@@ -341,6 +380,9 @@ void CommandLine::parseCommandLine(int argc, const char **argv)
   // check that all registered options are present in command line
   checkRegisteredOptions(cmd_args);
 
+  // verify options
+  checkOptions(cmd_args);
+
 } // parseCommandLine
 
 } // namespace clopt
index 312e73d..f0d4087 100644 (file)
@@ -10,8 +10,8 @@
 # how to store large files (in this case, files with models), and how to run all system tests.
 # As soon as it is decided, model files should be added, as well as the code that runs the tests.
 
-add_executable(system_test_import_tflite tflite.cpp)
-target_link_libraries(system_test_import_tflite PRIVATE tflite_import)
+add_executable(system_test_import_tflite tflite.cpp ${OPTIONS_SRC})
+target_link_libraries(system_test_import_tflite PRIVATE nnc_support tflite_import)
 
-add_executable(system_test_import_caffe caffe.cpp)
-target_link_libraries(system_test_import_caffe PRIVATE caffe_importer)
+add_executable(system_test_import_caffe caffe.cpp ${OPTIONS_SRC})
+target_link_libraries(system_test_import_caffe PRIVATE nnc_support caffe_importer)
index 23151d1..36d2950 100644 (file)
@@ -1,15 +1,20 @@
 #include <iostream>
+#include "CommandLine.h"
+#include "Options.h"
 
 #include "caffe_importer.h"
 
-int main(int argc, char **argv)
+using namespace nncc::contrib;
+
+int main(int argc, const char **argv)
 {
   if (argc != 2)
   {
     return 1;
   }
 
-  std::string modelName = argv[1];
+  clopt::CommandLine::getParser()->parseCommandLine(argc, argv);
+  std::string modelName = clopt::inputFile;
 
   nncc::contrib::frontend::caffe::CaffeImporter importer{modelName};
 
index cb18052..a140033 100644 (file)
@@ -1,15 +1,20 @@
 #include <iostream>
+#include "CommandLine.h"
+#include "Options.h"
 
 #include "tflite_v3_importer.h"
 
-int main(int argc, char **argv)
+using namespace nncc::contrib;
+
+int main(int argc, const char **argv)
 {
   if (argc != 2)
   {
     return 1;
   }
 
-  std::string modelName = argv[1];
+  clopt::CommandLine::getParser()->parseCommandLine(argc, argv);
+  std::string modelName = clopt::inputFile;
 
   nncc::contrib::frontend::tflite::v3::TfliteImporter importer{modelName};
 
diff --git a/contrib/nnc/unittests/module/AbstractModule.cpp b/contrib/nnc/unittests/module/AbstractModule.cpp
deleted file mode 100644 (file)
index a72acaf..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-#include "module/plugin/PluginSession.h"
-#include "module/AbstractModule.h"
-#include "ConfigException.h"
-
-#include "gtest/gtest.h"
-
-#define STRING(s) _STRING(s)
-#define _STRING(s) #s
-
-using namespace nncc::contrib;
-using namespace nncc::contrib::config;
-using namespace nncc::contrib::plugin;
-using namespace nncc::contrib::module;
-using namespace nncc::contrib::module::plugin;
-
-class ConcreteModule : public AbstractModule
-{
-public:
-  ConcreteModule():AbstractModule() {}
-  ConcreteModule(PluginType moduleType):AbstractModule(moduleType) {}
-};
-
-std::shared_ptr<PluginProxy> createPluginProxy()
-{
-  std::shared_ptr<PluginProxy> pp = PluginProxy::create(STRING(CMAKE_SAMPLE_PLUGIN_ABS_PATH));
-  std::shared_ptr<AbstractSession> session = std::make_shared<PluginSession>();
-  pp->getPluginInstance().setSession(session);
-  pp->getPluginInstance().fillSession();
-  return pp;
-}
-
-// Test AbstractModule with wrong config
-TEST(CONTRIB_NNC, AbstractModuleWrongConfig)
-{
-  // Default constructor
-  ConcreteModule pluginModuleDefault;
-  ASSERT_THROW(pluginModuleDefault.execute(nullptr), ConfigException);
-
-  // Constructor(PluginType)
-  ConcreteModule pluginModule(PluginType::typeFrontEnd);
-  ASSERT_EQ(pluginModule.getModuleType(), PluginType::typeFrontEnd);
-
-  // 'configure' method for Module without plugins
-  ASSERT_THROW(pluginModule.configure(std::make_shared<DataList>("DataListName")), ConfigException);
-
-  // Register PluginProxy
-  auto pp = createPluginProxy();
-  pluginModule.registerPlugin(pp);
-
-  // 'configure' method with missing required plugin paramether
-  std::shared_ptr<DataList> config = std::make_shared<DataList>("DataListName");
-  ASSERT_THROW(pluginModule.configure(config), ConfigException);
-}
-
-// Test AbstractModule with correct config
-TEST(CONTRIB_NNC, AbstractModule)
-{
-  ConcreteModule pluginModule(PluginType::typeFrontEnd);
-
-  // Register PluginProxy
-  auto pp1 = createPluginProxy();
-  auto pp2 = createPluginProxy();
-  pluginModule.registerPlugin(pp1);
-  pluginModule.registerPlugin(pp2);
-
-  // 'configure' method
-  std::shared_ptr<DataList> config = std::make_shared<DataList>("DataListName");
-  config->createElement("anotheroption", "samplePluginName");
-  config->createElement("someoption");
-  pluginModule.configure(config);
-  int x;
-  ASSERT_EQ(pluginModule.execute((void*)&x), (void*)&x);
-
-  // Operator '<<'
-  std::ostringstream os; 
-  os << pluginModule;
-  ASSERT_EQ(os.str(), "=== MODULE FrontEnd ===\nplugins {\n  "
-                      STRING(CMAKE_SAMPLE_PLUGIN_ABS_PATH) "\n  "
-                      STRING(CMAKE_SAMPLE_PLUGIN_ABS_PATH) "\n}\n");
-}
index 9aea8dd..94199f3 100644 (file)
@@ -1,5 +1,4 @@
 #include "module/BackendModule.h"
-#include "PluginType.h"
 
 #include "gtest/gtest.h"
 
@@ -9,7 +8,6 @@ using namespace nncc::contrib::plugin;
 TEST(CONTRIB_NNC, BackendModule)
 {
     AbstractModule *backendModule1 = &BackendModule::getInstance();
-    ASSERT_EQ(backendModule1->getModuleType(), PluginType::typeBackEnd);
     AbstractModule *backendModule2 = &BackendModule::getInstance();
     ASSERT_EQ(backendModule1, backendModule2);
 }
index 828bc70..7533698 100644 (file)
@@ -1,8 +1,8 @@
 file(GLOB_RECURSE TEST_SOURCES "*.cpp")
 
 # Plugin module tests
-add_nncc_test(nnc_module_test ${TEST_SOURCES} ${HEADERS})
-nncc_target_link_libraries(nnc_module_test nnc_module nncc_core nncc_foundation nnc_plugin_core)
+add_nncc_test(nnc_module_test ${OPTIONS_SRC} ${TEST_SOURCES} ${HEADERS})
+nncc_target_link_libraries(nnc_module_test nnc_support nnc_module nncc_core nncc_foundation nnc_plugin_core)
 # target_include_directories(nnc_module_test PUBLIC ../include)
 
 # Set macro in nnc_module_test with some_parser absolute path
diff --git a/contrib/nnc/unittests/module/FrontendModule.cpp b/contrib/nnc/unittests/module/FrontendModule.cpp
deleted file mode 100644 (file)
index fd3be15..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "module/FrontendModule.h"
-#include "PluginType.h"
-
-#include "gtest/gtest.h"
-
-using namespace nncc::contrib::module;
-using namespace nncc::contrib::plugin;
-
-TEST(CONTRIB_NNC, FrontendModule)
-{
-    AbstractModule *frontendModule1 = &FrontendModule::getInstance();
-    ASSERT_EQ(frontendModule1->getModuleType(), PluginType::typeFrontEnd);
-    AbstractModule *frontendModule2 = &FrontendModule::getInstance();
-    ASSERT_EQ(frontendModule1, frontendModule2);
-}
diff --git a/contrib/nnc/unittests/module/PluginData.cpp b/contrib/nnc/unittests/module/PluginData.cpp
deleted file mode 100644 (file)
index b4f8a15..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-#include "module/plugin/PluginData.h"
-
-#include "gtest/gtest.h"
-
-using namespace nncc::contrib::config;
-
-// DataException class
-
-std::string errorMsg1 = "error constructor";
-std::string errorMsg2 = "error second constructor";
-
-std::vector<std::string> msgs = {errorMsg1, errorMsg2};
-
-void err1() { throw DataException(errorMsg1); }
-
-void err2()
-{
-  try
-  {
-    err1();
-  }
-  catch (DataException &e)
-  {
-    throw DataException(e, errorMsg2);
-  }
-}
-
-TEST(CONTRIB_NNC, DataException)
-{
-  try
-  {
-    err2();
-  }
-  catch (DataException &e)
-  {
-    ASSERT_TRUE(msgs == e.getInfo());
-    return;
-  }
-
-  // should not happen
-  FAIL();
-}
-
-// PluginData class
-
-TEST(CONTRIB_NNC, PluginData)
-{
-  // Constructor(name, value)
-  Data d("some name", "some value");
-  ASSERT_EQ(d.getName(), "some name");
-  ASSERT_EQ(d.getValue(), "some value");
-  ASSERT_EQ(d.hasValue(), true);
-
-  // Constructor(name)
-  Data d2("name1");
-  ASSERT_EQ(d2.getName(), "name1");
-  ASSERT_EQ(d2.hasValue(), false);
-  ASSERT_THROW(d2.getValue(), DataException);
-
-  // 'setValue' method
-  d2.setValue("value1");
-  ASSERT_EQ(d2.getValue(), "value1");
-  ASSERT_EQ(d2.hasValue(), true);
-  d2.setValue("value2");
-  ASSERT_EQ(d2.getValue(), "value2");
-}
-
-TEST(CONTRIB_NNC, PluginDataOperators)
-{
-  Data d("some name", "some value");
-
-  // Operator '=='
-  ASSERT_TRUE(d == "some value");
-  ASSERT_FALSE(d == "wrong value");
-
-  // Operator '<<'
-  std::ostringstream os1;
-  os1 << d;
-  ASSERT_EQ(os1.str(), "<some name> = some value");
-  std::ostringstream os2;
-  os2 << Data("name2");
-  ASSERT_EQ(os2.str(), "<name2>");
-}
-
-// PluginDataList class
-
-// Test for PluginData 'parse()' method
-TEST(CONTRIB_NNC, PluginDataListParse)
-{
-  char *argv[] = {(char*)"./main", (char*)"--option1", (char*)"1",
-                  (char*)"-A", (char*)"vA", (char*)"--option2",
-                  (char*)"value2", (char*)"-B", (char*)"valueB",
-                  (char*)"-C", (char*)"-B", (char*)"valueThatWillBeIgnored"};
-  int argc = 12;
-  std::shared_ptr<DataList> dl = DataList::parse(argc, argv);
-  ASSERT_EQ(dl->getElement("option1").getValue(), "1");
-  ASSERT_EQ(dl->getElement("option2").getValue(), "value2");
-  ASSERT_EQ(dl->getElement("A").getValue(), "vA");
-  ASSERT_EQ(dl->getElement("B").getValue(), "valueB");
-  ASSERT_EQ(dl->getElement("C").getName(), "C");
-
-  argv[1] = (char*)"wrongKey";
-  ASSERT_THROW(DataList::parse(argc, argv), DataException);
-
-  argv[1] = (char*)"";
-  ASSERT_THROW(DataList::parse(argc, argv), DataException);
-}
-
-// Test for PluginData 'intersection()' methods
-TEST(CONTRIB_NNC, PluginDataListIntersection)
-{
-  DataList dl = DataList("data_list_name");
-  dl.createElement("param1");
-  dl.createElement("param2", "value2");
-  dl.createElement("param3", "value3");
-
-  // 'intersection()' with vector argument
-  std::vector<PluginParam> vParam;
-  vParam.push_back(PluginParam("param1", "desc1", false));
-  vParam.push_back(PluginParam("param2", "desc2", false));
-  vParam.push_back(PluginParam("optionalParam", "desc3", true));
-  std::shared_ptr<DataList> pdl = DataList::intersection(dl, vParam);
-  ASSERT_EQ(pdl->getElement("param1").getName(), "param1");
-  ASSERT_EQ(pdl->getElement("param2").getName(), "param2");
-  ASSERT_THROW(pdl->getElement("param3"), DataException);
-
-  // 'intersection()' with map argument
-  std::map<std::string, PluginParam> mParam;
-  mParam.insert(std::pair<std::string, PluginParam>("someString1", PluginParam("param1", "desc1", false)));
-  mParam.insert(std::pair<std::string, PluginParam>("someString2", PluginParam("param2", "desc2", false)));
-  mParam.insert(std::pair<std::string, PluginParam>("someString3", PluginParam("optionalParam", "desc3", true)));
-  pdl = DataList::intersection(dl, mParam);
-  ASSERT_EQ(pdl->getElement("param1").getName(), "param1");
-  ASSERT_EQ(pdl->getElement("param2").getName(), "param2");
-  ASSERT_THROW(pdl->getElement("param3"), DataException);
-
-  // 'intersection()' with missing required param
-  vParam.push_back(PluginParam("requiredParam", "desc4", false));
-  ASSERT_THROW(DataList::intersection(dl, vParam), DataException);
-}
-
-TEST(CONTRIB_NNC, PluginDataListCommon)
-{
-  // Constructor, 'getElement', 'createElement', 'getElements' methods
-  DataList dl("name1");
-  ASSERT_EQ(dl.getName(), "name1");
-  ASSERT_THROW(dl.getElement("missing element"), DataException);
-
-  dl.createElement("element name 1");
-  ASSERT_EQ(dl.getElement("element name 1").getName(), "element name 1");
-  ASSERT_THROW(dl.getElement("element name 1").getValue(), DataException);
-  dl.createElement("element name 2", "value2");
-  ASSERT_EQ(dl.getElement("element name 2").getValue(), "value2");
-  dl.createElement("element name 2", "value3");
-  ASSERT_EQ(dl.getElement("element name 2").getValue(), "value2");
-  std::map<std::string, Data> getElementsRes = dl.getElements();
-  ASSERT_EQ(getElementsRes.find("element name 1")->second.getName(), "element name 1");
-  ASSERT_EQ(getElementsRes.find("element name 2")->second.getValue(), "value2");
-}
-
-// Operators '[]' and '<<'
-TEST(CONTRIB_NNC, PluginDataListOperators)
-{
-  DataList dl("name1");
-  dl.createElement("element name 1");
-  dl.createElement("element name 2", "value2");
-
-  std::ostringstream os;
-  os << dl;
-  ASSERT_EQ(os.str(), "<name1> = {\n<element name 1>\n<element name 2> = value2\n}\n");
-}
index 8363195..3290962 100644 (file)
@@ -1,7 +1,7 @@
+#include <CommandLine.h>
 #include "module/AbstractModule.h"
 #include "module/FrontendModule.h"
 #include "module/BackendModule.h"
-#include "module/plugin/PluginData.h"
 #include "module/plugin/PluginManager.h"
 
 #include "gtest/gtest.h"
@@ -65,29 +65,22 @@ TEST(CONTRIB_NNC, PluginManagerMissingDir)
 {
   PluginManager &pluginManager = PluginManager::getInstance();
 
-  auto params = std::make_shared<config::DataList>(config::DataList("PluginManagerParams"));
-  params->createElement(PluginManager::paramPluginPath, "some very missing path");
-  pluginManager.setConfig(params);
-
-  std::vector<module::AbstractModule *> modules;
-  ASSERT_THROW(pluginManager.loadPlugins(modules), PluginManagerException);
+  ASSERT_THROW(pluginManager.loadPlugins(), PluginManagerException);
 }
 
 // Test PluginManager work with correct configuration
 TEST(CONTRIB_NNC, PluginManager)
 {
   PluginManager &pluginManager = PluginManager::getInstance();
+  const char *argv[] = {"PluginManager",
+                        "--plugins-path", STRING(CMAKE_SAMPLE_PLUGIN_DIR_ABS_PATH),
+                        nullptr};
+  std::cout << STRING(CMAKE_SAMPLE_PLUGIN_DIR_ABS_PATH);
+  int argc = (sizeof(argv) / sizeof(argv[0])) - 1;
 
-  auto params = std::make_shared<config::DataList>(config::DataList("PluginManagerParams"));
-  params->createElement(PluginManager::paramPluginPath, STRING(CMAKE_SAMPLE_PLUGIN_DIR_ABS_PATH));
-  params->createElement(PluginManager::paramVerboseLoading);
-  params->createElement(PluginManager::paramPluginHelp);
-  pluginManager.setConfig(params);
+  clopt::CommandLine::getParser()->parseCommandLine(argc, argv);
 
-  std::vector<module::AbstractModule *> modules;
-  modules.push_back(&module::FrontendModule::getInstance());
-  modules.push_back(&module::BackendModule::getInstance());
-  pluginManager.loadPlugins(modules);
+  pluginManager.loadPlugins();
 
   // Test operator '<<'
   std::ostringstream os;
index 9a5d305..13c3d17 100644 (file)
@@ -31,7 +31,7 @@ TEST(CONTRIB_NNC, PluginProxy)
 #else /* __APPLE__ */
   ASSERT_EQ(pp->getPluginName(), "libsome_parser.so");
 #endif /* __APPLE__ */
-  ASSERT_NE(&pp->getPluginInstance(), nullptr);
+  ASSERT_NE(pp->getPluginInstance(), nullptr);
 
   // Operator '<<'
   std::ostringstream os;
diff --git a/contrib/nnc/unittests/module/PluginSession.cpp b/contrib/nnc/unittests/module/PluginSession.cpp
deleted file mode 100644 (file)
index 93d666d..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "module/plugin/PluginSession.h"
-
-#include "gtest/gtest.h"
-
-using namespace nncc::contrib::config;
-
-TEST(CONTRIB_NNC, PluginSession)
-{
-  PluginSession ps;
-
-  // 'getInfo' 'addInfo' methods
-  ps.addInfo("name1", "value1");
-  ASSERT_EQ(ps.getInfo().getElement("name1").getValue(), "value1");
-  ASSERT_EQ(ps.getInfo("name1"), "value1");
-
-  // 'registerParam' 'getSupportedParams' methods
-  ps.registerParam(PluginParam("param1", "desc1", true));
-  ps.registerParam(PluginParam("param2", "desc2", false));
-  std::map<std::string, PluginParam> params = ps.getSupportedParams();
-  ASSERT_EQ(params.find("param1")->second.getDesc(), "desc1");
-  ASSERT_EQ(params.find("param2")->second.getDesc(), "desc2");
-
-  // Operator '<<'
-  std::ostringstream os;
-  os << ps;
-  ASSERT_EQ(os.str(), "<info> = {\n<name1> = value1\n}\nsupported "
-                      "params:\nparam1: desc1\nparam2: desc2\n");
-}
diff --git a/contrib/nnc/unittests/plugin_core/AbstractSession.cpp b/contrib/nnc/unittests/plugin_core/AbstractSession.cpp
deleted file mode 100644 (file)
index 625f3ab..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "AbstractSession.h"
-#include "PluginType.h"
-
-#include "gtest/gtest.h"
-
-using namespace nncc::contrib::config;
-using namespace nncc::contrib::plugin;
-
-class ConcreteSession : public AbstractSession
-{
-  public:
-    ConcreteSession() {}
-    void addInfo(const std::string &name, const std::string &value) override {}
-    void registerParam(const PluginParam &param) override {}
-};
-
-TEST(CONTRIB_PLUGIN, AbstractSession)
-{
-  std::string st1 = "Invalid";
-  std::string st2 = "FrontEnd";
-  std::string st3 = "BackEnd";
-  PluginType t1 = PluginType::typeInvalid;
-  PluginType t2 = PluginType::typeFrontEnd;
-  PluginType t3 = PluginType::typeBackEnd;
-
-  ConcreteSession s;
-
-  s.setPluginType(t1);
-  ASSERT_EQ(pluginTypeToStr(s.getPluginType()), st1);
-  s.setPluginType(t2);
-  ASSERT_EQ(pluginTypeToStr(s.getPluginType()), st2);
-  s.setPluginType(t3);
-  ASSERT_EQ(pluginTypeToStr(s.getPluginType()), st3);
-}
diff --git a/contrib/nnc/unittests/plugin_core/PluginInstance.cpp b/contrib/nnc/unittests/plugin_core/PluginInstance.cpp
deleted file mode 100644 (file)
index c6103e1..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "PluginInstance.h"
-#include "AbstractSession.h"
-#include "PluginType.h"
-#include "PluginException.h"
-
-#include "gtest/gtest.h"
-
-using namespace nncc::contrib::plugin;
-using namespace nncc::contrib::config;
-
-class ConcretePluginInstance : public AbstractPluginInstance
-{
-public:
-  void fillSession() override {}
-  void setParam(const std::string &name) override {}
-  void setParam(const std::string &name, const std::string &value) override {}
-  void checkConfig() override {}
-  void *execute(void *data) override {return nullptr;}
-};   
-
-class ConcreteSession : public AbstractSession
-{
-public:
-  ConcreteSession() {}
-  void addInfo(const std::string &name, const std::string &value) override {}
-  void registerParam(const PluginParam &param) override {}
-};
-
-TEST(CONTRIB_PLUGIN, PluginInstance)
-{
-  ConcretePluginInstance pluginInstance;
-
-  ASSERT_THROW(pluginInstance.getSession(), nncc::contrib::PluginException);
-
-  std::shared_ptr<AbstractSession> pSession = std::make_shared<ConcreteSession>();
-  pluginInstance.setSession(pSession);
-
-  pluginInstance.fillSessionBase(PluginType::typeFrontEnd, "verNum", "pluginName");
-
-  ASSERT_EQ(pluginInstance.getSession()->getPluginType(), PluginType::typeFrontEnd);
-}
diff --git a/contrib/nnc/unittests/plugin_core/PluginParam.cpp b/contrib/nnc/unittests/plugin_core/PluginParam.cpp
deleted file mode 100644 (file)
index 60e1928..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "PluginParam.h"
-
-#include "gtest/gtest.h"
-
-using namespace nncc::contrib::config;
-
-TEST(CONTRIB_PLUGIN, PluginParam)
-{
-  std::string name = "plugin name";
-  std::string desc = "plugin description";
-  std::string stream = "plugin name: plugin description";
-
-  // Constructor
-  PluginParam p = PluginParam(name, desc, true);
-
-  // Methods
-  ASSERT_EQ(p.getName(), name);
-  ASSERT_EQ(p.getDesc(), desc);
-  ASSERT_EQ(p.isOptional(), true);
-
-  // Operator '<<'
-  std::ostringstream os;
-  os << p;
-  ASSERT_EQ(os.str(), stream);
-}
index ed85aa5..1db93dc 100644 (file)
@@ -10,7 +10,7 @@ file(GLOB_RECURSE TESTS "*.cpp")
 
 make_generated_sources("${SOFT_DEF_SOURCES}" ${CMAKE_CURRENT_BINARY_DIR} SOFT_GENERATED_SOURCES)
 
-add_nncc_test(nnc_soft_backend_test ${TESTS} ${HEADERS} ${SOFT_BACKEND_COMMON_SOURCES} ${SOFT_BACKEND_CPP_SOURCES} ${SOFT_GENERATED_SOURCES})
-nncc_target_link_libraries(nnc_soft_backend_test nncc_core nnc_core nnc_plugin_core nncc_foundation soft_backend_common)
+add_nncc_test(nnc_soft_backend_test ${TESTS} ${HEADERS} ${OPTIONS_SRC} ${SOFT_BACKEND_COMMON_SOURCES} ${SOFT_BACKEND_CPP_SOURCES} ${SOFT_GENERATED_SOURCES})
+nncc_target_link_libraries(nnc_soft_backend_test nnc_support nncc_core nnc_core nnc_plugin_core nncc_foundation soft_backend_common)
 target_include_directories(nnc_soft_backend_test PUBLIC ${NNC_SOFT_BACKEND_DIR}/include)
 target_include_directories(nnc_soft_backend_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
\ No newline at end of file
index 62600b2..77dd02a 100644 (file)
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <cstdio>
 #include <ftw.h>
+#include <CommandLine.h>
 
 using namespace std;
 using namespace nncc::contrib;
@@ -57,9 +58,16 @@ TEST(Generator, check_generator_call)
 {
   // assume here that c++ and c code generators behave identically in terms of parameters check
   // test only c++ generator
-  #define TEST_DIR "out_dir"
+  #define TEST_DIR "output_dir"
   #define TEST_NAME "someName"
   #define BASE_NAME TEST_DIR "/" TEST_NAME
+  const char *argv[] = {"soft_backend_test",
+                        "--out-dir", TEST_DIR,
+                        "--out-name", TEST_NAME,
+                        nullptr};
+  int argc = (sizeof(argv) / sizeof(argv[0])) - 1;
+
+  clopt::CommandLine::getParser()->parseCommandLine(argc, argv);
 
   nncc::contrib::core::IR::model::Graph g;
   g.create<ops::VariableOp>("input");
@@ -70,14 +78,20 @@ TEST(Generator, check_generator_call)
     deleteDir(TEST_DIR);
   }
   assert(!isFileExists(TEST_DIR) && "remove output dir");
-  CPPCodeGenerator::create(BaseCodeGenerator::Parameters({TEST_DIR, TEST_NAME})).generate(&g);
+  {
+      CPPCodeGenerator gen;
+      gen.generate(&g);
+  }
   checkOutputExists(BASE_NAME);
 
   // test that generator creates output files in existing empty dir
   deleteFile(BASE_NAME ".h");
   deleteFile(BASE_NAME ".cpp");
   deleteFile(BASE_NAME ".params");
-  CPPCodeGenerator::create(BaseCodeGenerator::Parameters({TEST_DIR, TEST_NAME})).generate(&g);
+  {
+      CPPCodeGenerator gen;
+      gen.generate(&g);
+  }
   checkOutputExists(BASE_NAME);
 
   // test that generator rewrites existing files
@@ -86,9 +100,10 @@ TEST(Generator, check_generator_call)
   int res = stat(BASE_NAME ".h", &sBefore);
   assert(res == 0);
   assert(sBefore.st_size == 0);
-
-  CPPCodeGenerator::create(BaseCodeGenerator::Parameters({TEST_DIR, TEST_NAME})).generate(&g);
-
+  {
+      CPPCodeGenerator gen;
+      gen.generate(&g);
+  }
   res = stat(BASE_NAME ".h", &sAfter);
   assert(res == 0);
 
index 7a09d54..2b4d617 100644 (file)
@@ -4,6 +4,22 @@
 
 using namespace nncc::contrib::clopt;
 
+
+void soption_checker1(const BaseOption &opt)
+{
+  ASSERT_EQ(dynamic_cast<const Option<std::string> &>(opt), "SOME_VALUE1,SOME_VALUE2");
+}
+
+void soption_checker2(const BaseOption &opt)
+{
+  ASSERT_EQ(dynamic_cast<const Option<std::string> &>(opt), "AAA_VALUE");
+}
+
+void boption_checker(const BaseOption &opt)
+{
+  ASSERT_EQ(dynamic_cast<const Option<bool> &>(opt), false);
+}
+
 /**
  * declare command line options for testing
  */
@@ -22,6 +38,7 @@ Option<std::string> SSeveralSepOpt(optname("-several_separators"),
                                    "",
                                    optional(false),
                                    optvalues(""),
+                                   soption_checker1,
                                    separators("=, :"));
 // test option with one separator
 Option<std::string> SOneSepOpt(optname("--one_separarot"),
@@ -29,6 +46,7 @@ Option<std::string> SOneSepOpt(optname("--one_separarot"),
                                "",
                                optional(false),
                                optvalues(""),
+                               soption_checker2,
                                separators("="));
 // test option with defalut value
 Option<std::string> SDefaultOpt(optname("-default_val_opt"),
@@ -90,6 +108,7 @@ Option<bool> BoolOpt(optname("-bool_opt"),
                      true,
                      optional(false),
                      optvalues(""),
+                     boption_checker,
                      separators("="));
 Option<bool> BoolOpt2(optname("-bool-opt2"),
                       overview("description of bool option with value"));