ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp File Reference
#include "OMInterpreter.h"
#include <stdexcept>
#include <cstdlib>
#include <fstream>
#include <vector>
#include <string>
#include <iostream>

Go to the source code of this file.

Functions

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

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 59 of file Driver.cpp.

60{
61 if (argc != 5)
62 {
63 std::cerr
64 << "Usage: " << argv[0]
65 << " <path/to/circle/model> <num_inputs> <path/to/input/prefix> <path/to/output/file>\n";
66 return EXIT_FAILURE;
67 }
68
69 const char *filename = argv[1];
70 const int32_t num_inputs = atoi(argv[2]);
71 const char *input_prefix = argv[3];
72 const char *output_file = argv[4];
73
74 std::ifstream file(filename, std::ios::binary | std::ios::in);
75 if (!file.good())
76 {
77 std::string errmsg = "Failed to open file";
78 throw std::runtime_error(errmsg.c_str());
79 }
80
81 file.seekg(0, std::ios::end);
82 auto fileSize = file.tellg();
83 file.seekg(0, std::ios::beg);
84
85 // reserve capacity
86 DataBuffer model_data(fileSize);
87
88 // read the data
89 file.read(model_data.data(), fileSize);
90 if (file.fail())
91 {
92 std::string errmsg = "Failed to read file";
93 throw std::runtime_error(errmsg.c_str());
94 }
95
96 // Create interpreter.
99 interpreter.importModel(model_data.data(), config);
100
101 // Set input.
102 // Data for n'th input is read from ${input_prefix}n
103 // (ex: Add.circle.input0, Add.circle.input1 ..)
104 int num_inference = 1;
105 for (int j = 0; j < num_inference; ++j)
106 {
107 interpreter.reset();
108 interpreter.allocateInputs();
109 for (int32_t i = 0; i < num_inputs; i++)
110 {
111 auto input_data = reinterpret_cast<char *>(interpreter.getInputDataAt(i));
112 readDataFromFile(std::string(input_prefix) + std::to_string(i), input_data,
113 interpreter.getInputSizeAt(i) * sizeof(float));
114 }
115
116 // Do inference.
117 interpreter.run(config);
118 }
119
120 // Get output.
121 int num_outputs = 1;
122 for (int i = 0; i < num_outputs; i++)
123 {
124 auto data = interpreter.getOutputDataAt(i);
125
126 // Output data is written in ${output_file}
127 // (ex: Add.circle.output0)
128 writeDataToFile(std::string(output_file) + std::to_string(i), reinterpret_cast<char *>(data),
129 interpreter.getOutputSizeAt(i) * sizeof(float));
130 }
131 interpreter.reset();
132 return EXIT_SUCCESS;
133}
list input_data
Definition infer.py:29
model_data
Definition infer.py:82
void writeDataToFile(const std::string &file_path, const std::string &data)
write data to file_path
void readDataFromFile(const std::string &filename, std::vector< char > &data, size_t data_size)
Definition Utils.cpp:65
std::vector< char > DataBuffer

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 152 of file Driver.cpp.

153{
154 // NOTE main does not catch internal exceptions for debug build to make it easy to
155 // check the stacktrace with a debugger
156 return entry(argc, argv);
157}
int entry(int argc, char **argv)
Definition Driver.cpp:29

References entry().