ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 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
19
20#include <arser/arser.h>
21#include <foder/FileLoader.h>
22#include <luci/CircleExporter.h>
24#include <luci/ImporterEx.h>
26
27#include <iostream>
28#include <string>
29
30using namespace fme_detect;
31
32int entry(int argc, char **argv)
33{
34 arser::Arser arser("fme-detect detects patterns to apply FM equalization in "
35 "the circle model");
36
38
39 arser.add_argument("--input").required().help("Input circle model");
40
41 arser.add_argument("--output")
42 .required()
43 .help("Output json file that describes equalization patterns");
44
45 arser.add_argument("--allow_dup_op")
46 .nargs(0)
47 .default_value(false)
48 .help("Allow to create duplicate operations when a feature map matches "
49 "with multiple equalization patterns. This can increase the size of "
50 "the model. Default is false.");
51
52 try
53 {
54 arser.parse(argc, argv);
55 }
56 catch (const std::runtime_error &err)
57 {
58 std::cerr << err.what() << std::endl;
59 std::cout << arser;
60 return EXIT_FAILURE;
61 }
62
63 if (arser.get<bool>("--verbose"))
64 {
65 // The third parameter of setenv means REPLACE.
66 // If REPLACE is zero, it does not overwrite an existing value.
67 setenv("LUCI_LOG", "100", 0);
68 }
69
70 const std::string input_path = arser.get<std::string>("--input");
71 const std::string output_path = arser.get<std::string>("--output");
72 const bool allow_dup_op = arser.get<bool>("--allow_dup_op");
73
75 {
76 ctx._allow_dup_op = allow_dup_op;
77 }
78 EqualizePatternFinder finder(ctx);
79
80 luci::ImporterEx importerex;
81 auto module = importerex.importVerifyModule(input_path);
82 assert(module != nullptr); // FIX_ME_UNLESS
83
84 std::vector<EqualizePattern> patterns;
85 for (size_t idx = 0; idx < module->size(); ++idx)
86 {
87 auto graph = module->graph(idx);
88
89 auto matched = finder.find(graph);
90 patterns.insert(patterns.end(), matched.begin(), matched.end());
91 }
92
93 fme_detect::write(patterns, output_path);
94
95 return EXIT_SUCCESS;
96}
static void add_verbose(Arser &arser)
Definition arser.h:765
std::vector< EqualizePattern > find(loco::Graph *) const
int entry(int argc, char **argv)
Dump IR for given arguments.
Definition Driver.cpp:32
Definition arser.h:39
void write(const std::vector< EqualizePattern > &patterns, const std::string &filename)