| 29 | #include <vector> |
| 30 | |
| 31 | std::unique_ptr<luci::Module> ReadModule(std::string &input_path) |
| 32 | { |
| 33 | // Load model from the file |
| 34 | foder::FileLoader file_loader{input_path}; |
| 35 | std::vector<char> model_data = file_loader.load(); |
| 36 | |
| 37 | auto *data_data = reinterpret_cast<uint8_t *>(model_data.data()); |
| 38 | luci::Importer importer; |
| 39 | auto module = importer.importModule(data_data, model_data.size()); |
| 40 | if (module == nullptr) |
| 41 | { |
| 42 | std::cerr << "ERROR: Failed to load circle '" << input_path << "'" << std::endl; |
| 43 | return nullptr; |
| 44 | } |
| 45 | assert(module->size() > 0); |
| 46 | |
| 47 | for (size_t g = 0; g < module->size(); ++g) |
| 48 | { |
| 49 | auto graph = module->graph(g); |
| 50 | if (graph == nullptr) |
| 51 | return nullptr; |
| 52 | |
| 53 | { |
| 54 | logo::Phase phase; |
| 55 | |
| 56 | phase.emplace_back(std::make_unique<luci::CircleShapeInferencePass>()); |
| 57 | phase.emplace_back(std::make_unique<luci::CircleTypeInferencePass>()); |
| 58 | |
| 59 | logo::PhaseRunner<logo::PhaseStrategy::Saturate> phase_runner{graph}; |
| 60 | phase_runner.run(phase); |
| 61 | } |
| 62 | |
| 63 | if (!luci::validate(graph)) |
| 64 | return nullptr; |
| 65 | } |
| 66 | return module; |
| 67 | } |