ONE - On-device Neural Engine
Loading...
Searching...
No Matches
InterpreterWrapper Class Reference

Public Member Functions

 InterpreterWrapper (const uint8_t *data, const size_t data_size)
 
 ~InterpreterWrapper ()
 
void interpret (void)
 
void writeInputTensor (const int input_idx, const void *data, size_t input_size)
 
void readOutputTensor (const int output_idx, void *output, size_t output_size)
 

Detailed Description

Definition at line 116 of file CircleInterpreter_cffi.cpp.

Constructor & Destructor Documentation

◆ InterpreterWrapper()

InterpreterWrapper::InterpreterWrapper ( const uint8_t *  data,
const size_t  data_size 
)
inlineexplicit

Definition at line 119 of file CircleInterpreter_cffi.cpp.

120 {
121 luci::Importer importer;
122 _module = importer.importModule(data, data_size);
123 if (_module == nullptr)
124 {
125 throw std::runtime_error{"Cannot import module."};
126 }
127 _intp = new luci_interpreter::Interpreter(_module.get());
128 }

◆ ~InterpreterWrapper()

InterpreterWrapper::~InterpreterWrapper ( )
inline

Definition at line 130 of file CircleInterpreter_cffi.cpp.

130{ delete _intp; }

Member Function Documentation

◆ interpret()

void InterpreterWrapper::interpret ( void  )
inline

◆ readOutputTensor()

void InterpreterWrapper::readOutputTensor ( const int  output_idx,
void *  output,
size_t  output_size 
)
inline

Definition at line 149 of file CircleInterpreter_cffi.cpp.

150 {
151 const auto output_nodes = loco::output_nodes(_module->graph());
152 const auto output_node =
153 loco::must_cast<const luci::CircleOutput *>(output_nodes.at(output_idx));
154 const auto fb_output_size = ::getTensorSize(output_node);
155 if (fb_output_size != output_size)
156 {
157 const auto msg = "Invalid output size: " + std::to_string(fb_output_size) +
158 " != " + std::to_string(output_size);
159 throw std::runtime_error(msg);
160 }
161 _intp->readOutputTensor(output_node, output, fb_output_size);
162 }
void readOutputTensor(const luci::CircleOutput *output_node, void *data, size_t data_size)
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101
CircleOutput * output_node(loco::Graph *g, const loco::GraphOutputIndex &index)
Find a CircleOutput node with a given output index.

References loco::output_nodes(), and luci_interpreter::Interpreter::readOutputTensor().

◆ writeInputTensor()

void InterpreterWrapper::writeInputTensor ( const int  input_idx,
const void *  data,
size_t  input_size 
)
inline

Definition at line 134 of file CircleInterpreter_cffi.cpp.

135 {
136 const auto input_nodes = loco::input_nodes(_module->graph());
137 const auto input_node = loco::must_cast<const luci::CircleInput *>(input_nodes.at(input_idx));
138 // Input size from model binary
139 const auto fb_input_size = ::getTensorSize(input_node);
140 if (fb_input_size != input_size)
141 {
142 const auto msg = "Invalid input size: " + std::to_string(fb_input_size) +
143 " != " + std::to_string(input_size);
144 throw std::runtime_error(msg);
145 }
146 _intp->writeInputTensor(input_node, data, fb_input_size);
147 }
void writeInputTensor(const luci::CircleInput *input_node, const void *data, size_t data_size)
std::vector< Node * > input_nodes(const Graph *)
Definition Graph.cpp:71
CircleInput * input_node(loco::Graph *g, const loco::GraphInputIndex &index)
Find a Pull node with a given input index.

References loco::input_nodes(), and luci_interpreter::Interpreter::writeInputTensor().


The documentation for this class was generated from the following file: