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 <iostream>
24
25int entry_stream(std::istream &is)
26{
27 int32_t model_version = 1;
28
29 ::circlechef::ModelRecipe model_recipe;
30
31 // Read a model recipe from standard input
32 {
33 google::protobuf::io::IstreamInputStream iis{&is};
34 if (!google::protobuf::TextFormat::Parse(&iis, &model_recipe))
35 {
36 std::cerr << "ERROR: Failed to parse recipe" << std::endl;
37 return 255;
38 }
39
40 if (model_recipe.has_version())
41 {
42 model_version = model_recipe.version();
43 }
44 }
45
46 if (model_version > 1)
47 {
48 std::cerr << "ERROR: Unsupported recipe version: " << model_version << std::endl;
49 return 255;
50 }
51
52 auto generated_model = circlechef::cook(model_recipe);
53
54 // Write a generated model into standard output
55 std::cout.write(generated_model.base(), generated_model.size());
56
57 return 0;
58}
59
60int entry(int, char **)
61{
62 // forward to entry_stream
63 return entry_stream(std::cin);
64}
int entry(int argc, char **argv)
Definition Driver.cpp:29
int entry_stream(std::istream &is)
Definition Driver.cpp:25
GeneratedModel cook(const ModelRecipe &model_recipe)