ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp File Reference
#include "circlechef/ModelChef.h"
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
#include <arser/arser.h>
#include <fstream>
#include <iostream>

Go to the source code of this file.

Functions

int entry (int argc, char **argv)
 

Function Documentation

◆ entry()

int entry ( int  argc,
char **  argv 
)

Definition at line 28 of file Driver.cpp.

29{
31 arser.add_argument("recipe").help("Source recipe file path to convert");
32 arser.add_argument("circle").help("Target circle file path");
33
34 try
35 {
36 arser.parse(argc, argv);
37 }
38 catch (const std::runtime_error &err)
39 {
40 std::cout << err.what() << std::endl;
41 std::cout << arser;
42 return 255;
43 }
44
45 int32_t model_version = 1;
46
47 ::circlechef::ModelRecipe model_recipe;
48
49 std::string recipe_path = arser.get<std::string>("recipe");
50 // Load model recipe from a file
51 {
52 std::ifstream is{recipe_path};
53 google::protobuf::io::IstreamInputStream iis{&is};
54 if (!google::protobuf::TextFormat::Parse(&iis, &model_recipe))
55 {
56 std::cerr << "ERROR: Failed to parse recipe '" << recipe_path << "'" << std::endl;
57 return 255;
58 }
59
60 if (model_recipe.has_version())
61 {
62 model_version = model_recipe.version();
63 }
64 }
65
66 if (model_version > 1)
67 {
68 std::cerr << "ERROR: Unsupported recipe version: " << model_version << ", '" << recipe_path
69 << "'" << std::endl;
70 return 255;
71 }
72
73 auto generated_model = circlechef::cook(model_recipe);
74
75 std::string circle_path = arser.get<std::string>("circle");
76 // Dump generated model into a file
77 {
78 std::ofstream os{circle_path, std::ios::binary};
79 os.write(generated_model.base(), generated_model.size());
80 }
81
82 return 0;
83}
Definition arser.h:39
GeneratedModel cook(const ModelRecipe &model_recipe)

References circlechef::cook().