ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp File Reference
#include "ModuleIO.h"
#include "OpSelector.h"
#include <luci/ConnectNode.h>
#include <luci/ImporterEx.h>
#include <luci/Profile/CircleNodeID.h>
#include <luci/Service/CircleNodeClone.h>
#include <arser/arser.h>
#include <vconone/vconone.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#include <numeric>
#include <sstream>

Go to the source code of this file.

Functions

void print_version (void)
 
int entry (int argc, char **argv)
 

Function Documentation

◆ entry()

int entry ( int  argc,
char **  argv 
)

Definition at line 42 of file Driver.cpp.

43{
44 // TODO Add new option names!
45
46 arser::Arser arser("circle-opselector provides selecting operations in circle model");
47
49
50 // TODO Add new options!
51
52 arser.add_argument("input").help("Input circle model");
53 arser.add_argument("output").help("Output circle model");
54
55 // select option
56 arser.add_argument("--by_id").help("Input operation id to select nodes.");
57 arser.add_argument("--by_name").help("Input operation name to select nodes.");
58
59 try
60 {
61 arser.parse(argc, argv);
62 }
63 catch (const std::runtime_error &err)
64 {
65 std::cerr << err.what() << std::endl;
66 std::cout << arser;
67 return EXIT_FAILURE;
68 }
69
70 std::string input_path = arser.get<std::string>("input");
71 std::string output_path = arser.get<std::string>("output");
72
73 if (!arser["--by_id"] && !arser["--by_name"] || arser["--by_id"] && arser["--by_name"])
74 {
75 std::cerr << "ERROR: Either option '--by_id' or '--by_name' must be specified" << std::endl;
76 std::cerr << arser;
77 return EXIT_FAILURE;
78 }
79
80 // Import original circle file.
81 luci::ImporterEx importerex;
82 auto module = importerex.importVerifyModule(input_path);
83
84 // TODO support two or more subgraphs
85 if (module.get()->size() > 1)
86 {
87 std::cout << "WARNING: Only first subgraph's operators will be selected" << std::endl;
88 }
89
90 opselector::OpSelector op_selector{module.get()};
91
92 std::unique_ptr<luci::Module> new_module;
93 std::string operator_input;
94
95 if (arser["--by_id"])
96 {
97 operator_input = arser.get<std::string>("--by_id");
98 new_module = op_selector.select_by<opselector::SelectType::ID>(operator_input);
99 }
100 if (arser["--by_name"])
101 {
102 operator_input = arser.get<std::string>("--by_name");
103 new_module = op_selector.select_by<opselector::SelectType::NAME>(operator_input);
104 }
105
106 if (not opselector::exportModule(new_module.get(), output_path))
107 {
108 std::cerr << "ERROR: Cannot export the module" << std::endl;
109 return EXIT_FAILURE;
110 }
111
112 return 0;
113}
static void add_version(Arser &arser, const std::function< void(void)> &func)
Definition arser.h:755
void print_version(void)
Definition Driver.cpp:36
Definition arser.h:39
bool exportModule(luci::Module *module, std::string &output_path)
Definition ModuleIO.cpp:29

References arser::Helper::add_version(), opselector::exportModule(), opselector::ID, opselector::NAME, and print_version().

◆ print_version()

void print_version ( void  )

Definition at line 36 of file Driver.cpp.

37{
38 std::cout << "circle-opselector version " << vconone::get_string() << std::endl;
39 std::cout << vconone::get_copyright() << std::endl;
40}
std::string get_copyright(void)
get_copyright will return copyright string
Definition version.cpp:54
std::string get_string(void)
get_string will return string of major.minor.patch (without build)
Definition version.cpp:44

References vconone::get_copyright(), and vconone::get_string().

Referenced by entry(), and entry().