ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp File Reference
#include <luci/ImporterEx.h>
#include <luci/CircleQuantizer.h>
#include <luci/Service/Validate.h>
#include <luci/CircleExporter.h>
#include <luci/CircleFileExpContract.h>
#include <luci/UserSettings.h>
#include <arser/arser.h>
#include "QImplant.h"
#include <iostream>
#include <string>

Go to the source code of this file.

Functions

int entry (int argc, char **argv)
 Dump IR for given arguments.
 

Function Documentation

◆ entry()

int entry ( int  argc,
char **  argv 
)

Dump IR for given arguments.

Call example: $ ./build/compiler/encodump/encodump \ –frontend build/compiler/enco/frontend/caffe/libenco_caffe_frontend.so \ –frontend-arg build/compiler/enco/test/caffe/Convolution_003.prototxt \ –frontend-arg build/compiler/enco/test/caffe/Convolution_003.caffemodel

HDF5 layout is like below

GROUP "/" ㄴGROUP "name" ㄴATTRIBUTE "0" ㄴDATA (0): "input_01:0" ㄴATTRIBUTE "1" ㄴDATA (0): "input_02:0" ㄴGROUP "value" ㄴDATASET "0" ㄴDATA ... ㄴDATASET "1" ㄴDATA ...

Definition at line 33 of file Driver.cpp.

34{
35 arser::Arser arser("q-implant provides circle model quantization");
36
38
39 arser.add_argument("input").help("Input circle model");
40 arser.add_argument("qparam").help("Quantization parameter file (.json)");
41 arser.add_argument("output").help("Output circle model");
42
43 try
44 {
45 arser.parse(argc, argv);
46 }
47 catch (const std::runtime_error &err)
48 {
49 std::cerr << err.what() << std::endl;
50 std::cout << arser;
51 return EXIT_FAILURE;
52 }
53
54 if (arser.get<bool>("--verbose"))
55 {
56 // The third parameter of setenv means REPLACE.
57 // If REPLACE is zero, it does not overwrite an existing value.
58 setenv("LUCI_LOG", "100", 0);
59 }
60
61 const std::string input_path = arser.get<std::string>("input");
62 const std::string qparam_path = arser.get<std::string>("qparam");
63 const std::string output_path = arser.get<std::string>("output");
64
65 // Load model from the file
66 luci::ImporterEx importerex;
67 auto module = importerex.importVerifyModule(input_path);
68 if (module.get() == nullptr)
69 return EXIT_FAILURE;
70
71 QImplant writer(qparam_path);
72
73 if (module->size() != 1)
74 {
75 std::cerr << "ERROR: Only a single subgraph is supported" << std::endl;
76 return EXIT_FAILURE;
77 }
78
79 for (size_t idx = 0; idx < module->size(); ++idx)
80 {
81 auto graph = module->graph(idx);
82
83 writer.write(graph);
84
85 if (!luci::validate(graph))
86 {
87 std::cerr << "ERROR: Quantized graph is invalid" << std::endl;
88 return EXIT_FAILURE;
89 }
90 }
91
92 // Export to output Circle file
93 luci::CircleExporter exporter;
94
95 luci::CircleFileExpContract contract(module.get(), output_path);
96
97 if (!exporter.invoke(&contract))
98 {
99 std::cerr << "ERROR: Failed to export '" << output_path << "'" << std::endl;
100 return EXIT_FAILURE;
101 }
102
103 return 0;
104}
static void add_verbose(Arser &arser)
Definition arser.h:765
bool invoke(Contract *) const
Definition arser.h:39
bool validate(luci::PartitionTable &partition)

References arser::Helper::add_verbose(), luci::CircleExporter::invoke(), luci::validate(), and q_implant::QImplant::write().