ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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
18
19#include <google/protobuf/io/coded_stream.h>
20#include <google/protobuf/io/zero_copy_stream_impl.h>
21#include <google/protobuf/text_format.h>
22
23#include <arser/arser.h>
24
25#include <fstream>
26#include <iostream>
27
28int entry(int argc, char **argv)
29{
31 arser.add_argument("recipe").help("Source recipe file path to convert");
32 arser.add_argument("circle").help("Target circle file path");
33
34 try
35 {
36 arser.parse(argc, argv);
37 }
38 catch (const std::runtime_error &err)
39 {
40 std::cout << err.what() << std::endl;
41 std::cout << arser;
42 return 255;
43 }
44
45 int32_t model_version = 1;
46
47 ::circlechef::ModelRecipe model_recipe;
48
49 std::string recipe_path = arser.get<std::string>("recipe");
50 // Load model recipe from a file
51 {
52 std::ifstream is{recipe_path};
53 google::protobuf::io::IstreamInputStream iis{&is};
54 if (!google::protobuf::TextFormat::Parse(&iis, &model_recipe))
55 {
56 std::cerr << "ERROR: Failed to parse recipe '" << recipe_path << "'" << std::endl;
57 return 255;
58 }
59
60 if (model_recipe.has_version())
61 {
62 model_version = model_recipe.version();
63 }
64 }
65
66 if (model_version > 1)
67 {
68 std::cerr << "ERROR: Unsupported recipe version: " << model_version << ", '" << recipe_path
69 << "'" << std::endl;
70 return 255;
71 }
72
73 auto generated_model = circlechef::cook(model_recipe);
74
75 std::string circle_path = arser.get<std::string>("circle");
76 // Dump generated model into a file
77 {
78 std::ofstream os{circle_path, std::ios::binary};
79 os.write(generated_model.base(), generated_model.size());
80 }
81
82 return 0;
83}
int entry(int argc, char **argv)
Definition Driver.cpp:29
Definition arser.h:39
GeneratedModel cook(const ModelRecipe &model_recipe)