namespace parameters_format
{
- const int MAGIC_LEN = 4;
- const int VERSION_LEN = 4;
- const int HASH_LEN = 4;
- const int HEADER_LEN = MAGIC_LEN + VERSION_LEN + HASH_LEN;
+const int MAGIC_LEN = 4;
+const int VERSION_LEN = 4;
+const int HASH_LEN = 4;
+const int HEADER_LEN = MAGIC_LEN + VERSION_LEN + HASH_LEN;
- const char MAGIC[MAGIC_LEN + 1] = "NNMP"; // Neural Network Model Parameters
+const char MAGIC[MAGIC_LEN + 1] = "NNMP"; // Neural Network Model Parameters
}
namespace
out << "class " << className << "\n"
"{\n"
"public:\n"
- " " << className << "(const std::string ¶metersPath);\n";
+ " " << className << "(const std::string ¶metersPath);\n"
+ " ~" << className << "();\n";
// generate input setters
for (const size_t inId: ma.getInputs())
{
const string &tName = _formattedTensors[outId];
out << " std::shared_ptr<Tensor> " << tName << ";\n";
}
+ // pointer to NN parameters
+ out << " char * _parameters;\n";
+ out << " size_t _paramSize;\n";
out << "};\n";
}
// gather output arguments
gatherOperationArguments(ma, op._outputs, args);
// parameters offset
- args.push_back(to_string(op._paramStartOffset));
+ args.push_back("_parameters + " + to_string(parameters_format::HEADER_LEN + op._paramStartOffset));
// gather input arguments
gatherOperationArguments(ma, op._inputs, args);
// put arguments into stream
void CPPCodeGenerator::materializeCode(ostream &out, const ModelAnalyzer &ma)
{
string className = ma.getModelName() + "Model";
+
+ out << "#include \"" << _headerFile << "\"\n";
+
out << cpp_operations;
// gen NN constructor
out << className << "::" << className << "(const string ¶metersPath)\n"
"{\n"
- " readParameters(_parameters, parametersPath, " <<
- ma.getFormatVersion() << ", " << ma.getModelHash() << ");\n"
+ " readParameters(_parameters, _paramSize, parametersPath, "
+ << ma.getFormatVersion() << ", " << ma.getModelHash() << ");\n"
+ "}\n\n";
+ // gen NN destructor
+ out << className << "::~" << className << "()\n"
+ "{\n"
+ " releaseParameters(_parameters, _paramSize);\n"
"}\n\n";
-
// gen input setters
for (size_t inId: ma.getInputs())
{