2 * Copyright (c) 2020 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.
17 #include <foder/FileLoader.h>
19 #include <luci/Importer.h>
20 #include <luci/Service/Validate.h>
21 #include <luci/Pass/ShapeInferencePass.h>
22 #include <luci/Pass/TypeInferencePass.h>
24 // Following passes will be removed after refactoring is finished
25 #include <luci/Pass/MigrateLegacyShapeDtypePass.h>
34 void show_help_message(const char *progname, std::ostream &os)
36 os << "USAGE: " << progname << " circlefile" << std::endl << std::endl;
39 void show_error_message(const char *progname, std::ostream &os, const std::string &msg)
41 os << "ERROR: " << msg << std::endl;
44 show_help_message(progname, os);
50 * @brief ReadTest main
52 * Give one Circle file as an argument
54 * This will use luci_import to read the file and get loco graph
55 * In luci_import, LUCI_LOG environment will be checked and will
56 * dump graph to console if set.
57 * i.e. "LUCI_LOG=1 luci_readtester mymodel.circle"
59 int entry(int argc, char **argv)
63 show_error_message(argv[0], std::cerr, "Circle file is not specified");
67 std::string input_path = argv[1];
69 std::cout << "[INFO] Circle is '" << input_path << "'" << std::endl;
71 // Load model from the file
72 foder::FileLoader file_loader{input_path};
73 std::vector<char> model_data = file_loader.load();
74 const circle::Model *circle_model = circle::GetModel(model_data.data());
75 if (circle_model == nullptr)
77 std::cerr << "ERROR: Failed to load circle '" << input_path << "'" << std::endl;
81 luci::Importer importer;
82 auto module = importer.importModule(circle_model);
83 assert(module->size() > 0);
85 for (size_t g = 0; g < module->size(); ++g)
87 auto graph = module->graph(g);
92 luci::ShapeInferencePass pass;
93 while (pass.run(graph) == true)
97 luci::TypeInferencePass pass;
98 while (pass.run(graph) == true)
102 // This pass will be removed after refactoring is finished
103 luci::MigrateLegacyShapeDtypePass pass;
104 while (pass.run(graph) == true)
108 if (!luci::validate(graph))