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>
31 void show_help_message(const char *progname, std::ostream &os)
33 os << "USAGE: " << progname << " circlefile" << std::endl << std::endl;
36 void show_error_message(const char *progname, std::ostream &os, const std::string &msg)
38 os << "ERROR: " << msg << std::endl;
41 show_help_message(progname, os);
47 * @brief ReadTest main
49 * Give one Circle file as an argument
51 * This will use luci_import to read the file and get loco graph
52 * In luci_import, LUCI_LOG environment will be checked and will
53 * dump graph to console if set.
54 * i.e. "LUCI_LOG=1 luci_readtester mymodel.circle"
56 int entry(int argc, char **argv)
60 show_error_message(argv[0], std::cerr, "Circle file is not specified");
64 std::string input_path = argv[1];
66 std::cout << "[INFO] Circle is '" << input_path << "'" << std::endl;
68 // Load model from the file
69 foder::FileLoader file_loader{input_path};
70 std::vector<char> model_data = file_loader.load();
71 const circle::Model *circle_model = circle::GetModel(model_data.data());
72 if (circle_model == nullptr)
74 std::cerr << "ERROR: Failed to load circle '" << input_path << "'" << std::endl;
78 luci::Importer importer;
79 auto module = importer.importModule(circle_model);
80 assert(module->size() > 0);
82 for (size_t g = 0; g < module->size(); ++g)
84 auto graph = module->graph(g);
89 luci::ShapeInferencePass pass;
90 while (pass.run(graph) == true)
94 luci::TypeInferencePass pass;
95 while (pass.run(graph) == true)
99 if (!luci::validate(graph))