ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "ModuleIO.h"
18#include "OpSelector.h"
19
20#include <luci/ConnectNode.h>
21#include <luci/ImporterEx.h>
24
25#include <arser/arser.h>
26#include <vconone/vconone.h>
27
28#include <iostream>
29#include <string>
30#include <vector>
31#include <algorithm>
32#include <cctype>
33#include <numeric>
34#include <sstream>
35
36void print_version(void)
37{
38 std::cout << "circle-opselector version " << vconone::get_string() << std::endl;
39 std::cout << vconone::get_copyright() << std::endl;
40}
41
42int entry(int argc, char **argv)
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
int entry(int argc, char **argv)
Definition Driver.cpp:29
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
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