ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnc::CPPCodeGenerator Class Referencefinal

CPPCodeGenerator implements interfaces that provides BaseCodeGenerator for C++ language This includes header file generation, code file generation and variable renaming according to C++ naming requirements. More...

#include <CPPGenerator.h>

Public Member Functions

 CPPCodeGenerator (std::string output_dir, std::string artifact_name)
 
void run (mir::Graph *graph)
 Method represents base generation sequence: analysis, serialization, header/code generation, etc.
 

Detailed Description

CPPCodeGenerator implements interfaces that provides BaseCodeGenerator for C++ language This includes header file generation, code file generation and variable renaming according to C++ naming requirements.

Definition at line 47 of file CPPGenerator.h.

Constructor & Destructor Documentation

◆ CPPCodeGenerator()

nnc::CPPCodeGenerator::CPPCodeGenerator ( std::string  output_dir,
std::string  artifact_name 
)

Definition at line 81 of file CPPGenerator.cpp.

82 : _output_dir(std::move(output_dir)), _artifact_name(std::move(artifact_name))
83{
84}

Member Function Documentation

◆ run()

void nnc::CPPCodeGenerator::run ( mir::Graph graph)

Method represents base generation sequence: analysis, serialization, header/code generation, etc.

Parameters
graphMIR graph

Definition at line 109 of file CPPGenerator.cpp.

110{
111 assert(graph);
112
113 // visit and analyze graph
114 ModelAnalyzer ma;
115 ma.analyze(graph);
116 // serialize parameters
117 Serializer serializer;
118 serializer.serialize(ma.getInferenceSequence());
119 // rename tensors for specific backend language
120 formatTensorNames(ma);
121
122 fs::create_directory(_output_dir);
123
124 const string base_path = _output_dir + "/" + _artifact_name;
125 const string header_path = base_path + ".h";
126 const string code_path = base_path + ".cpp";
127 const string params_path = base_path + ".params";
128
129 // Print header
130 auto header_stream = getStream(header_path);
131 materializeHeader(*header_stream, ma);
132 header_stream.reset();
133
134 // Print code
135 auto code_stream = getStream(code_path);
136 materializeCode(*code_stream, ma, serializer);
137 code_stream.reset();
138
139 // Print model parameters
140 auto model_stream = getStream(params_path);
141 materializeModelParams(*model_stream, serializer);
142 model_stream.reset();
143}

References nnc::ModelAnalyzer::analyze(), nnc::ModelAnalyzer::getInferenceSequence(), and nnc::Serializer::serialize().

Referenced by package.infer.session::inference(), and TEST().


The documentation for this class was generated from the following files: