set(GEN_OUT "")
foreach(file IN LISTS DEF_SOURCES)
get_filename_component(file_name ${file} NAME_WE)
- set(out_file "${OUT_DIR}/${file_name}.h")
+ set(out_file "${OUT_DIR}/${file_name}.generated.h")
list(APPEND GEN_OUT "${out_file}")
add_custom_command(
OUTPUT ${out_file}
-set(SOFT_BACKEND_COMMON_SOURCES soft_backend.cpp base_generator.cpp model_analyzer.cpp serializer.cpp)
-set(SOFT_BACKEND_CPP_SOURCES cpp_backend.cpp cpp_generator.cpp)
-set(SOFT_BACKEND_C_SOURCES c_backend.cpp c_generator.cpp)
+set(SOFT_BACKEND_COMMON_SOURCES base_generator.cpp model_analyzer.cpp serializer.cpp)
+set(SOFT_BACKEND_CPP_SOURCES cpp_generator.cpp)
+set(SOFT_BACKEND_C_SOURCES c_generator.cpp)
set(DEF_CONV ${NNC_ROOT_SRC_DIR}/utils/def2src.cpp)
file(GLOB_RECURSE SOFT_DEF_SOURCES "*.def")
}
}
-void BaseCodeGenerator::generate(Graph *g)
+void *BaseCodeGenerator::execute(void *data)
{
+ Graph *g = reinterpret_cast<Graph *>(data);
// inference shapes
core::IR::model::ShapeInference si;
g->accept(&si);
auto modelStream = getStream(_paramsPath);
materializeModelParams(*modelStream, serializer);
modelStream.reset();
+
+ return nullptr;
}
} // namespace soft
#define _NNC_SOFT_BACKEND_BASE_GENERATOR_H_
#include "core/modelIR/graph.h"
+#include "support/PluginInstance.h"
#include <string>
#include <ostream>
class Serializer;
-class BaseCodeGenerator
+class BaseCodeGenerator: public nncc::contrib::plugin::BackendPlugin
{
public:
- void generate(nncc::contrib::core::IR::model::Graph *g);
+ void *execute(void *data) override;
protected:
virtual void formatTensorNames(const ModelAnalyzer &ma) = 0;
+++ /dev/null
-#include "soft_backend.h"
-#include "c_generator.h"
-
-using namespace nncc::contrib::plugin;
-using namespace nncc::contrib::backend::soft;
-
-namespace nncc
-{
-namespace contrib
-{
-namespace backend
-{
-namespace soft
-{
-
-class CSoftBackend final: public BaseSoftBackend
-{
-public:
- CSoftBackend &operator=(const CSoftBackend &) = delete;
-
- CSoftBackend(const CSoftBackend &) = delete;
-
- void generate(nncc::contrib::core::IR::model::Graph *g) override
- {
- CCodeGenerator gen;
- gen.generate(g);
- }
-
- static CSoftBackend &getInstance()
- {
- static CSoftBackend instance;
- return instance;
- }
-
-private:
- CSoftBackend() = default;
-};
-
-} // namespace soft
-} // namespace backend
-} // namespace contrib
-} // namespace nncc
-
-
-extern "C" Plugin *get_instance()
-{
- return &CSoftBackend::getInstance();
-}
} // namespace contrib
} // namespace nncc
+extern "C" nncc::contrib::plugin::Plugin *get_instance()
+{
+ static nncc::contrib::backend::soft::CCodeGenerator cCodeGenerator;
+ return &cCodeGenerator;
+}
+++ /dev/null
-#include "soft_backend.h"
-#include "cpp_generator.h"
-
-using namespace nncc::contrib::plugin;
-using namespace nncc::contrib::backend::soft;
-
-namespace nncc
-{
-namespace contrib
-{
-namespace backend
-{
-namespace soft
-{
-
-class CPPSoftBackend final: public BaseSoftBackend
-{
-public:
- CPPSoftBackend &operator=(const CPPSoftBackend &) = delete;
-
- CPPSoftBackend(const CPPSoftBackend &) = delete;
-
- void generate(nncc::contrib::core::IR::model::Graph *g) override
- {
- CPPCodeGenerator gen;
- gen.generate(g);
- }
-
- static CPPSoftBackend &getInstance()
- {
- static CPPSoftBackend instance;
- return instance;
- }
-
-private:
- CPPSoftBackend() = default;
-};
-
-} // namespace soft
-} // namespace backend
-} // namespace contrib
-} // namespace nncc
-
-
-extern "C" Plugin *get_instance()
-{
- return &CPPSoftBackend::getInstance();
-}
using namespace nncc::contrib;
using namespace nncc::contrib::core::IR::model;
-#include "cpp_header_types.h"
-#include "cpp_operations.h"
-
#include "param_constants.def"
-#include "param_constants.h"
-#include "eigen.h"
-#include "cpp_common_funcs.h"
-#include "cpp_add_bias.h"
-#include "cpp_capped_relu.h"
-#include "cpp_concat.h"
-#include "cpp_conv.h"
-#include "cpp_depthwise_conv.h"
-#include "cpp_fully_connected.h"
-#include "cpp_pool.h"
-#include "cpp_relu.h"
-#include "cpp_softmax.h"
+#include "cpp_header_types.generated.h"
+#include "cpp_operations.generated.h"
+#include "param_constants.generated.h"
+#include "eigen.generated.h"
+#include "cpp_common_funcs.generated.h"
+#include "cpp_add_bias.generated.h"
+#include "cpp_capped_relu.generated.h"
+#include "cpp_concat.generated.h"
+#include "cpp_conv.generated.h"
+#include "cpp_depthwise_conv.generated.h"
+#include "cpp_fully_connected.generated.h"
+#include "cpp_pool.generated.h"
+#include "cpp_relu.generated.h"
+#include "cpp_softmax.generated.h"
namespace nncc
{
} // namespace contrib
} // namespace nncc
+extern "C" nncc::contrib::plugin::Plugin *get_instance()
+{
+ static nncc::contrib::backend::soft::CPPCodeGenerator cppCodeGenerator;
+ return &cppCodeGenerator;
+}
+++ /dev/null
-#include <map>
-#include <vector>
-#include <iostream>
-#include <cassert>
-
-#include "soft_backend.h"
-#include "support/PluginException.h"
-#include "core/modelIR/graph.h"
-
-#include "support/Debug.h"
-#define DEBUG_AREA "soft_backend"
-
-using namespace std;
-using namespace nncc::contrib;
-using namespace nncc::contrib::plugin;
-using namespace nncc::contrib::core::IR::model;
-using namespace nncc::contrib::backend::soft;
-
-namespace nncc
-{
-namespace contrib
-{
-namespace backend
-{
-namespace soft
-{
-
-void *BaseSoftBackend::execute(void *data)
-{
- assert(data);
- Graph *graph = static_cast<Graph*>(data);
- generate(graph);
- return data;
-}
-
-} // namespace soft
-} // namespace backend
-} // namespace contrib
-} // namespace nncc
+++ /dev/null
-#ifndef _NNC_SOFT_BACKEND_PLUGIN_H_
-#define _NNC_SOFT_BACKEND_PLUGIN_H_
-
-#include "support/PluginInstance.h"
-#include "core/modelIR/graph.h"
-#include "base_generator.h"
-
-#include <string>
-#include <map>
-
-namespace nncc
-{
-namespace contrib
-{
-namespace backend
-{
-namespace soft
-{
-
-enum class OPT_ID;
-
-class BaseSoftBackend : public nncc::contrib::plugin::BackendPlugin
-{
-public:
- BaseSoftBackend &operator=(const BaseSoftBackend &) = delete;
-
- BaseSoftBackend(const BaseSoftBackend &) = delete;
-
- void *execute(void *data) override;
-
-protected:
- BaseSoftBackend() = default;
-
- ~BaseSoftBackend() override = default;
-
- virtual void generate(nncc::contrib::core::IR::model::Graph *g) = 0;
-};
-
-} // namespace soft
-} // namespace backend
-} // namespace contrib
-} // namespace nncc
-
-#endif //_NNC_SOFT_BACKEND_PLUGIN_H_
#include "cpp_generator.h"
// This header generated and contains array with test_main.def contents
-#include "test_main.h"
+#include "test_main.generated.h"
using namespace std;
Graph g;
fillGraph(g);
- nncc::contrib::backend::soft::CPPCodeGenerator().generate(&g);
+ nncc::contrib::backend::soft::CPPCodeGenerator().execute(&g);
string basePath = outputDir + "/" + artifactName;
-set(SOFT_BACKEND_CPP_SOURCES ${NNC_SOFT_BACKEND_DIR}/cpp_backend.cpp
- ${NNC_SOFT_BACKEND_DIR}/cpp_generator.cpp)
+set(SOFT_BACKEND_CPP_SOURCES ${NNC_SOFT_BACKEND_DIR}/cpp_generator.cpp)
file(GLOB_RECURSE SOFT_DEF_SOURCES "${NNC_SOFT_BACKEND_DIR}/*.def")
file(GLOB_RECURSE TESTS "*.cpp")
#include <functional>
#include <numeric>
-#include "cpp_header_types.def"
+#include "code_snippets/cpp_header_types.def"
#include "gtest/gtest.h"
#include <functional>
// artifact part
-#include "cpp_ops/eigen.def"
+#include "code_snippets/eigen.def"
-#include "cpp_ops/cpp_common_funcs.def"
+#include "code_snippets/cpp_common_funcs.def"
-#include "cpp_ops/cpp_add_bias.def"
-#include "cpp_ops/cpp_capped_relu.def"
-#include "cpp_ops/cpp_concat.def"
-#include "cpp_ops/cpp_conv.def"
-#include "cpp_ops/cpp_depthwise_conv.def"
-#include "cpp_ops/cpp_fully_connected.def"
-#include "cpp_ops/cpp_pool.def"
-#include "cpp_ops/cpp_relu.def"
-#include "cpp_ops/cpp_softmax.def"
+#include "code_snippets/cpp_add_bias.def"
+#include "code_snippets/cpp_capped_relu.def"
+#include "code_snippets/cpp_concat.def"
+#include "code_snippets/cpp_conv.def"
+#include "code_snippets/cpp_depthwise_conv.def"
+#include "code_snippets/cpp_fully_connected.def"
+#include "code_snippets/cpp_pool.def"
+#include "code_snippets/cpp_relu.def"
+#include "code_snippets/cpp_softmax.def"
#include "param_constants.def"
-#include "cpp_header_types.def"
-#include "cpp_operations.def"
+#include "code_snippets/cpp_header_types.def"
+#include "code_snippets/cpp_operations.def"
// soft backend part
assert(!isFileExists(TEST_DIR) && "remove output dir");
{
CPPCodeGenerator gen;
- gen.generate(&g);
+ gen.execute(&g);
}
checkOutputExists(BASE_NAME);
deleteFile(BASE_NAME ".params");
{
CPPCodeGenerator gen;
- gen.generate(&g);
+ gen.execute(&g);
}
checkOutputExists(BASE_NAME);
assert(sBefore.st_size == 0);
{
CPPCodeGenerator gen;
- gen.generate(&g);
+ gen.execute(&g);
}
res = stat(BASE_NAME ".h", &sAfter);
assert(res == 0);
for (int i = 2; i < argc; i++) {
std::string sourceFullFileName = argv[i];
std::string filename = extractFileName(sourceFullFileName);
- std::string outputFileName = OutPutDir + "/" + filename + ".h";
+ std::string outputFileName = OutPutDir + "/" + filename + ".generated.h";
if (fileToArray(sourceFullFileName, outputFileName, filename) != 0)
return -1;