2 * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "OpSelector.h"
20 #include <luci/ConnectNode.h>
21 #include <luci/Profile/CircleNodeID.h>
22 #include <luci/Service/CircleNodeClone.h>
24 #include <arser/arser.h>
25 #include <vconone/vconone.h>
35 void print_version(void)
37 std::cout << "circle-opselector version " << vconone::get_string() << std::endl;
38 std::cout << vconone::get_copyright() << std::endl;
41 int entry(int argc, char **argv)
43 // TODO Add new option names!
45 arser::Arser arser("circle-opselector provides selecting operations in circle model");
47 arser::Helper::add_version(arser, print_version);
49 // TODO Add new options!
51 arser.add_argument("input").help("Input circle model");
52 arser.add_argument("output").help("Output circle model");
55 arser.add_argument("--by_id").help("Input operation id to select nodes.");
56 arser.add_argument("--by_name").help("Input operation name to select nodes.");
60 arser.parse(argc, argv);
62 catch (const std::runtime_error &err)
64 std::cerr << err.what() << std::endl;
69 std::string input_path = arser.get<std::string>("input");
70 std::string output_path = arser.get<std::string>("output");
72 if (!arser["--by_id"] && !arser["--by_name"] || arser["--by_id"] && arser["--by_name"])
74 std::cerr << "ERROR: Either option '--by_id' or '--by_name' must be specified" << std::endl;
79 // Import original circle file.
80 auto module = opselector::getModule(input_path);
82 // TODO support two or more subgraphs
83 if (module.get()->size() != 1)
85 std::cerr << "ERROR: Not support two or more subgraphs" << std::endl;
89 opselector::OpSelector op_selector{module.get()};
91 std::unique_ptr<luci::Module> new_module;
92 std::string operator_input;
96 operator_input = arser.get<std::string>("--by_id");
97 new_module = op_selector.select_by<opselector::SelectType::ID>(operator_input);
99 if (arser["--by_name"])
101 operator_input = arser.get<std::string>("--by_name");
102 new_module = op_selector.select_by<opselector::SelectType::NAME>(operator_input);
105 assert(opselector::exportModule(new_module.get(), output_path));