From 5e2047ab345c801e1e2ffbfb2e6c9ce6e753186c Mon Sep 17 00:00:00 2001
From: "Efimov Alexander/AI Tools Lab/./Samsung Electronics"
Date: Mon, 13 Aug 2018 18:33:43 +0300
Subject: [PATCH] Generalize options for soft backend (#923)
Replace specific file paths with output directory and common name
Signed-off-by: Efimov Alexander
---
contrib/nnc/README.md | 11 +--
.../nnc/libs/backend/soft/include/base_generator.h | 27 ++---
.../nnc/libs/backend/soft/include/c_generator.h | 7 +-
.../nnc/libs/backend/soft/include/cpp_generator.h | 7 +-
.../nnc/libs/backend/soft/include/soft_backend.h | 7 +-
.../nnc/libs/backend/soft/src/base_generator.cpp | 97 +++++-------------
contrib/nnc/libs/backend/soft/src/c_backend.cpp | 2 +-
contrib/nnc/libs/backend/soft/src/c_generator.cpp | 7 +-
contrib/nnc/libs/backend/soft/src/cpp_backend.cpp | 2 +-
.../nnc/libs/backend/soft/src/cpp_generator.cpp | 16 ++-
contrib/nnc/libs/backend/soft/src/serializer.cpp | 2 +-
contrib/nnc/libs/backend/soft/src/soft_backend.cpp | 72 ++++++++------
contrib/nnc/unittests/soft_backend/generator.cpp | 110 +++++++++++----------
13 files changed, 161 insertions(+), 206 deletions(-)
diff --git a/contrib/nnc/README.md b/contrib/nnc/README.md
index 42e9825..ee23a80 100644
--- a/contrib/nnc/README.md
+++ b/contrib/nnc/README.md
@@ -59,16 +59,13 @@ Assuming that current directory is a build root and we have tflite model(for exa
./nnc --plugins-path . \
--input-filename inceptionv3.tflite \
--emit-c++ \
---out-code nn.cpp \
---out-header nn.h \
---out-model param.file
+--out-dir output \
+--out-name inception
```
``--emit-c++`` is a _soft backend_ option that selects target language to emit(for now supported ``--emit-c++`` and ``--emit-c``)
-``--out-code nn.cpp`` is a _soft backend_ option, it sets path to source code file
+``--out-dir output`` is a _soft backend_ option, it sets path for output files, parameter is optional with default value ``out``
-``--out-header nn.h`` is a _soft backend_ option, it sets path to header file
-
-``--out-model param.file`` is a _soft backend_ option, it sets path to file with model parameters
+``--out-name inception`` is a _soft backend_ option, it sets name for output files(in case of c++ it is ``inception.cpp``, ``inception.h``, ``inception.params``)
diff --git a/contrib/nnc/libs/backend/soft/include/base_generator.h b/contrib/nnc/libs/backend/soft/include/base_generator.h
index 17a3ca1..9825c4e 100644
--- a/contrib/nnc/libs/backend/soft/include/base_generator.h
+++ b/contrib/nnc/libs/backend/soft/include/base_generator.h
@@ -22,6 +22,15 @@ 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:
@@ -32,20 +41,16 @@ protected:
BaseCodeGenerator(BaseCodeGenerator &g) = default;
- // check validity of selected output files, throws appropriate exception on error
- void checkCorrectness();
-
- BaseCodeGenerator(const std::string &headerFile,
- const std::string &codeFile, const std::string &modelFile);
+ BaseCodeGenerator(const Parameters &opt);
std::vector _formattedTensors;
- // Code output file
- std::string _headerFile;
- // Code output file
- std::string _codeFile;
- // Model output file
- std::string _modelFile;
+ // set of options
+ Parameters _params;
+
+ std::string _headerPath;
+ std::string _codePath;
+ std::string _paramsPath;
};
} // namespace soft
diff --git a/contrib/nnc/libs/backend/soft/include/c_generator.h b/contrib/nnc/libs/backend/soft/include/c_generator.h
index a19afc8..5bff59a 100644
--- a/contrib/nnc/libs/backend/soft/include/c_generator.h
+++ b/contrib/nnc/libs/backend/soft/include/c_generator.h
@@ -15,16 +15,13 @@ namespace soft
// C generator
class CCodeGenerator: public BaseCodeGenerator
{
- CCodeGenerator(const std::string &headerFile, const std::string &codeFile, const std::string &modelFile):
- BaseCodeGenerator(headerFile, codeFile, modelFile)
+ CCodeGenerator(const Parameters ¶ms): BaseCodeGenerator(params)
{
// EMPTY
}
public:
- static CCodeGenerator create(const std::string &headerFile,
- const std::string &codeFile,
- const std::string &modelFile);
+ static CCodeGenerator create(const Parameters ¶ms);
protected:
void formatTensorNames(const ModelAnalyzer &ma) override;
diff --git a/contrib/nnc/libs/backend/soft/include/cpp_generator.h b/contrib/nnc/libs/backend/soft/include/cpp_generator.h
index 46ff6f7..eb21e76 100644
--- a/contrib/nnc/libs/backend/soft/include/cpp_generator.h
+++ b/contrib/nnc/libs/backend/soft/include/cpp_generator.h
@@ -15,16 +15,13 @@ namespace soft
// C++ generator
class CPPCodeGenerator: public BaseCodeGenerator
{
- CPPCodeGenerator(const std::string &headerFile, const std::string &codeFile, const std::string &modelFile):
- BaseCodeGenerator(headerFile, codeFile, modelFile)
+ CPPCodeGenerator(const Parameters ¶ms): BaseCodeGenerator(params)
{
// EMPTY
}
public:
- static CPPCodeGenerator create(const std::string &headerFile,
- const std::string &codeFile,
- const std::string &modelFile);
+ static CPPCodeGenerator create(const Parameters ¶ms);
protected:
void formatTensorNames(const ModelAnalyzer &ma) override;
diff --git a/contrib/nnc/libs/backend/soft/include/soft_backend.h b/contrib/nnc/libs/backend/soft/include/soft_backend.h
index 679f8d2..4dfdaa9 100644
--- a/contrib/nnc/libs/backend/soft/include/soft_backend.h
+++ b/contrib/nnc/libs/backend/soft/include/soft_backend.h
@@ -3,6 +3,7 @@
#include "PluginInstance.h"
#include "nnc/core/IR/model/graph/graph.h"
+#include "base_generator.h"
#include
#include