35#include "Definitions.h"
39#ifdef NNC_FRONTEND_CAFFE2_ENABLED
42#ifdef NNC_FRONTEND_CAFFE_ENABLED
45#ifdef NNC_FRONTEND_TFLITE_ENABLED
48#ifdef NNC_FRONTEND_ONNX_ENABLED
57static std::string getFrontendOptionsString()
76static std::unique_ptr<mir::Graph> importModel()
80 throw DriverException(
"One and only one of the following options are allowed and have to be set"
81 "in the same time: " +
82 getFrontendOptionsString());
86#ifdef NNC_FRONTEND_CAFFE_ENABLED
92#ifdef NNC_FRONTEND_CAFFE2_ENABLED
101#ifdef NNC_FRONTEND_ONNX_ENABLED
107#ifdef NNC_FRONTEND_TFLITE_ENABLED
132 assert(
false &&
"invalid option value");
140void Driver::runPasses()
142 auto graph = importModel();
143 PassData pass_data(
graph.get());
145 for (
const auto &pass : _passManager.getPasses())
147 pass_data = pass->run(pass_data);
150 DumperPass d(pass->getName());
166void Driver::registerBackendSpecificPasses()
168 std::unique_ptr<Pass> data_format_pass;
172 _passManager.
registerPass(std::make_unique<LowerConv2D>());
177 _passManager.
registerPass(std::make_unique<LowerConv2D>());
178 _passManager.
registerPass(std::make_unique<ConstantFoldTranspose>());
188 assert(
false &&
"invalid option value");
192void Driver::registerOptimizationPass()
197 _passManager.
registerPass(std::unique_ptr<Pass>(
new CombineTransposes()));
198 _passManager.
registerPass(std::unique_ptr<Pass>(
new SinkTranspose()));
199 _passManager.
registerPass(std::unique_ptr<Pass>(
new SinkRelu()));
202 _passManager.
registerPass(std::unique_ptr<Pass>(
new FuseArithmeticOps()));
204 _passManager.
registerPass(std::unique_ptr<Pass>(
new DeadCodeElimination()));
210 registerOptimizationPass();
211 registerBackendSpecificPasses();
#define NNC_TARGET_ARM_CPP
#define NNC_TARGET_ARM_GPU_CPP
#define NNC_TARGET_INTERPRETER
#define NNC_TARGET_X86_CPP
void runDriver()
main method to run compiler driver
void registerPass(std::unique_ptr< Pass > pass)
register pass in pass manager
std::unique_ptr< mir::Graph > loadModel(std::string predict_net, std::string init_net, const std::vector< std::vector< int > > &input_shapes)
std::unique_ptr< mir::Graph > loadModel(const std::string &filename)
std::unique_ptr< mir::Graph > loadModel(const std::string &filename)
std::unique_ptr< mir::Graph > loadModel(std::string filename)
Option< bool > onnxFrontend(optname("--onnx"), overview("treat input file as ONNX model"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(false))
Option< std::string > artifactName(optname("--output, -o"), overview("specify name for output files"), "nnmodel", optional(true), optvalues(""), checkOutFile)
Option< std::string > inputFile(optname("--nnmodel, -m"), overview("specify input file with serialized NN models"), std::string(), optional(false), optvalues(""), checkInFile)
Option< std::vector< int > > inputShapes(optname("--input-shape"), overview("Shape of caffe2 input"), std::vector< int >{}, optional(false), optvalues(""), nullptr, separators(""), showopt(false), IOption::Group::caffe2)
Option< bool > caffe2Frontend(optname("--caffe2"), overview("treat input file as Caffe2 model (predict_net.pb)"), false, optional(false), optvalues(""), nullptr, separators(""), showopt(false), IOption::Group::caffe2)
Option< bool > doOptimizationPass(optname("-O"), overview("whether to optimize model or not"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(true))
Option< std::string > artifactDir(optname("--output-dir, -d"), overview("specify directory for output files"), ".", optional(true), optvalues(""), checkOutDir, separators("="))
Option< bool > caffeFrontend(optname("--caffe"), overview("treat input file as Caffe model"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(false))
Option< bool > tflFrontend(optname("--tflite"), overview("treat input file as Tensor Flow Lite model"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(false))
Option< bool > dumpGraph(optname("--dump, -D"), overview("dump graph to dot files after optimization passes"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(true))
Option< std::string > initNet(optname("--init-net"), overview("path to Caffe2 model weights (init_net.pb)"), std::string(), optional(false), optvalues(""), checkInFile, separators(""), showopt(false), IOption::Group::caffe2)
Option< std::string > interInputDataDir(optname("--input-data-dir"), overview("specify directory with binary files " "containing the input data for the model " "(one file for each input with the same name)"), ".", optional(true), optvalues(""), checkInDir)
Option< std::string > target(optname("--target"), overview("select target language to emit for given architecture." "Valid values are '" NNC_TARGET_ARM_CPP "', '" NNC_TARGET_X86_CPP "', '" NNC_TARGET_ARM_GPU_CPP "', '" NNC_TARGET_INTERPRETER "'"), std::string(), optional(false), optvalues(NNC_TARGET_ARM_CPP "," NNC_TARGET_X86_CPP "," NNC_TARGET_ARM_GPU_CPP "," NNC_TARGET_INTERPRETER), nullptr, separators("="))