summaryrefslogtreecommitdiff
path: root/compiler/nnc/include/backends/soft_backend/CPPGenerator.h
diff options
context:
space:
mode:
authorСергей Баранников/AI Tools Lab /SRR/Engineer/삼성전자 <s.barannikov@samsung.com>2019-09-17 19:52:58 +0300
committerAlexander Efimov/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>2019-09-17 19:52:58 +0300
commit6601e7963fa4a356a7982e55eed79b751598921c (patch)
tree46963993c38ef92f83596e54681d4e599a9dcc02 /compiler/nnc/include/backends/soft_backend/CPPGenerator.h
parent0d47a522ac5014465cb42715ef65e8ed9ff7fe03 (diff)
downloadnnfw-6601e7963fa4a356a7982e55eed79b751598921c.tar.gz
nnfw-6601e7963fa4a356a7982e55eed79b751598921c.tar.bz2
nnfw-6601e7963fa4a356a7982e55eed79b751598921c.zip
[nnc] Remove C generating backend (#7545)
Remove C generating backend skeleton. Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
Diffstat (limited to 'compiler/nnc/include/backends/soft_backend/CPPGenerator.h')
-rw-r--r--compiler/nnc/include/backends/soft_backend/CPPGenerator.h67
1 files changed, 55 insertions, 12 deletions
diff --git a/compiler/nnc/include/backends/soft_backend/CPPGenerator.h b/compiler/nnc/include/backends/soft_backend/CPPGenerator.h
index 666a67046..8bb707c25 100644
--- a/compiler/nnc/include/backends/soft_backend/CPPGenerator.h
+++ b/compiler/nnc/include/backends/soft_backend/CPPGenerator.h
@@ -17,11 +17,18 @@
#ifndef _NNC_SOFT_BACKEND_CPP_GENERATOR_H_
#define _NNC_SOFT_BACKEND_CPP_GENERATOR_H_
-#include "BaseGenerator.h"
+#include "mir/Graph.h"
+
+#include <ostream>
+#include <string>
+#include <vector>
namespace nnc
{
+class ModelAnalyzer;
+class Serializer;
+
namespace sir
{
struct TensorDescriptor;
@@ -37,11 +44,29 @@ struct DestroyTmp;
* This includes header file generation, code file generation and variable renaming according to C++
* naming requirements
*/
-class CPPCodeGenerator final : public BaseCodeGenerator
+class CPPCodeGenerator final
{
-protected:
- void formatTensorNames(const ModelAnalyzer &ma) override;
- void materializeHeader(std::ostream &out, const ModelAnalyzer &ma) override;
+public:
+ /**
+ * @brief Method represents base generation sequence: analysis, serialization, header/code
+ * generation, etc
+ * @param graph MIR graph
+ */
+ void run(mir::Graph *graph);
+
+private:
+ /**
+ * @brief This function processes tensor names
+ * to transform them into valid identificators of target language
+ * @param ma Intermediate artifact information
+ */
+ void formatTensorNames(const ModelAnalyzer &ma);
+ /**
+ * @brief Derivative classes should override this function to generate header of artifact
+ * @param out Stream to write header text
+ * @param ma Intermediate artifact information
+ */
+ void materializeHeader(std::ostream &out, const ModelAnalyzer &ma);
/**
* @brief Form list of function call arguments
@@ -49,7 +74,7 @@ protected:
* @param argIds List of argument variable ids
* @param args Result list of arguments transformed in form of strings
*/
- void gatherOperationArguments(const ModelAnalyzer &ma, const std::vector<size_t> &arg_ids,
+ void gatherOperationArguments(const ModelAnalyzer &ma, const std::vector<std::size_t> &arg_ids,
std::vector<std::string> &args);
/**
* @brief Prints setter of artifact
@@ -75,8 +100,7 @@ protected:
* @param ma Intermediate model representation
* @param call Action to generate code from
*/
- void materializeCall(std::ostream &out, const ModelAnalyzer &ma,
- const nnc::sir::CallFunction *call);
+ void materializeCall(std::ostream &out, const ModelAnalyzer &ma, const sir::CallFunction *call);
/**
* @brief Generate code for transpose action
* @param out Output stream to print
@@ -84,7 +108,7 @@ protected:
* @param action Action to generate code from
*/
void materializeTranspose(std::ostream &out, const ModelAnalyzer &ma,
- const nnc::sir::TransposeTensor *transpose);
+ const sir::TransposeTensor *transpose);
/**
* @brief Generate code for constructor action
* @param out Output stream to print
@@ -92,7 +116,7 @@ protected:
* @param action Action to generate code from
*/
void materializeConstructor(std::ostream &out, const ModelAnalyzer &ma,
- const nnc::sir::CreateTmp *constructor);
+ const sir::CreateTmp *constructor);
/**
* @brief Generate code for destructor action
* @param out Output stream to print
@@ -100,14 +124,33 @@ protected:
* @param action Action to generate code from
*/
void materializeDestructor(std::ostream &out, const ModelAnalyzer &ma,
- const nnc::sir::DestroyTmp *destructor);
+ const sir::DestroyTmp *destructor);
/**
* @brief Prints inference sequence placed in doInference method of artifact
* @param out Output stream
* @param ma Intermediate model representation
*/
void materializeInferenceSequence(std::ostream &out, const ModelAnalyzer &ma);
- void materializeCode(std::ostream &out, const ModelAnalyzer &ma, const Serializer &s) override;
+ /**
+ * @brief Derivative classes should override this function to generate implementation of artifact
+ * @param out Stream to write header text
+ * @param ma Intermediate artifact information
+ * @param s Serializer holds parameters of network and various meta-information: serializer
+ * version, hashes, etc
+ */
+ void materializeCode(std::ostream &out, const ModelAnalyzer &ma, const Serializer &s);
+ /**
+ * @brief Writes serialized parameters to out stream
+ * @param out Stream to write serialized parameters
+ * @param s Serializer holds parameters of network
+ *
+ * Contents of generated file:
+ * + header(magic number to identify file type, protocol version, hashes of network and params)
+ * + array of serialized network parameters
+ */
+ void materializeModelParams(std::ostream &out, const Serializer &s);
+
+ std::vector<std::string> _formattedTensors;
};
} // namespace nnc