ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 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
17#include "Dalgona.h"
18
19#include <arser/arser.h>
20#include <pybind11/embed.h>
21
22namespace py = pybind11;
23
24using namespace dalgona;
25
26int entry(const int argc, char **argv)
27{
28 arser::Arser arser("Dalgona: Dynamic analysis tool for DNN");
29
30 arser.add_argument("--input_model")
31 .nargs(1)
32 .type(arser::DataType::STR)
33 .required(true)
34 .help("Input model filepath (.circle)");
35
36 arser.add_argument("--input_data")
37 .nargs(1)
38 .type(arser::DataType::STR)
39 .help("Input data filepath (.h5) (if not given, random data will be used)");
40
41 arser.add_argument("--analysis")
42 .nargs(1)
43 .type(arser::DataType::STR)
44 .required(true)
45 .help("Analysis code filepath (.py)");
46
47 arser.add_argument("--analysis_args")
48 .nargs(1)
49 .type(arser::DataType::STR)
50 .help("String argument passed to the analysis code");
51
52 try
53 {
54 arser.parse(argc, argv);
55 }
56 catch (const std::runtime_error &err)
57 {
58 std::cout << err.what() << std::endl;
59 std::cout << arser;
60 return EXIT_FAILURE;
61 }
62
63 auto input_model_path = arser.get<std::string>("--input_model");
64 auto analysis_path = arser.get<std::string>("--analysis");
65 std::string analysis_args = "";
66 if (arser["--analysis_args"])
67 analysis_args = arser.get<std::string>("--analysis_args");
68
69 // Initialize python interpreter
70 py::scoped_interpreter guard{};
71
73
74 // Initialize interpreter and operator hooks
75 dalgona.initialize(input_model_path);
76
77 // Run analysis
78 if (arser["--input_data"])
79 {
80 const auto input_data_path = arser.get<std::string>("--input_data");
81 dalgona.runAnalysisWithH5Input(input_data_path, analysis_path, analysis_args);
82 }
83 else
84 {
85 std::cout << "--input_data was not specified. Run with a random input." << std::endl;
86 dalgona.runAnalysisWithRandomInput(analysis_path, analysis_args);
87 }
88
89 return EXIT_SUCCESS;
90}
int entry(const int argc, char **argv)
Definition Driver.cpp:26
Definition arser.h:39