ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
luci_interpreter::RuntimeGraph Class Reference

#include <RuntimeGraph.h>

Data Structures

class  TensorAllocPlan
 

Public Member Functions

 RuntimeGraph (RuntimeModule *owning_module, IMemoryManager *memory_manager)
 
 ~RuntimeGraph ()
 
TensoraddTensor (std::unique_ptr< Tensor > &&tensor)
 
void setInputTensors (const std::vector< Tensor * > &input_tensors)
 
void setOutputTensors (const std::vector< Tensor * > &output_tensors)
 
void configureAllocations (Tensor *tensor)
 
const std::vector< Tensor * > & getInputTensors () const
 
const std::vector< Tensor * > & getOutputTensors () const
 
void addKernel (std::unique_ptr< Kernel > &&kernel)
 
void execute () const
 
 RuntimeGraph ()=delete
 
 RuntimeGraph (SimpleMemoryManager *memory_manager, CircleReader *circle_reader, RuntimeModule *runtime_module, uint32_t subgraph_index)
 
 ~RuntimeGraph ()
 
TensoraddTensor (const circle::Tensor *raw_tensor, std::unique_ptr< Tensor > &&tensor)
 
const circle::Tensor * getCircleTensorByIndex (int32_t index)
 
void makeInplaceOperation (const circle::Tensor *src_tensor, const circle::Tensor *dst_tensor)
 
uint8_t * getDataByTensor (const circle::Tensor *raw_tensor)
 
uint8_t * getConstDataByTensor (const circle::Tensor *raw_tensor)
 
uint8_t * configureGraphInput (int32_t input_index)
 
void configureGraphInput (int32_t input_index, uint8_t *data)
 
int32_t getInputDataSizeByIndex (int32_t input_index)
 
int32_t getOutputDataSizeByIndex (int32_t output_index)
 
int32_t getNumOfInputTensors ()
 
int32_t getNumOfOutputTensors ()
 
const circle::Tensor * getInputTensorByIndex (int32_t input_index)
 
const circle::Tensor * getOutputTensorByIndex (int32_t input_index)
 
uint8_t * getOutputDataByIndex (int32_t output_index)
 
void addInplaceOpIndex (const circle::Operator *op)
 
void execute ()
 
void configure (bool dealloc_input)
 
void invalidate ()
 
bool isValid () const
 
void selectOwnSubgraph ()
 
void resetOutputTensorsData ()
 
void clearTensors ()
 
void setDataToTensor (const circle::Tensor *tensor, uint8_t *data)
 
void resetTensorData (uint8_t *new_data, const circle::Tensor *tensor)
 
RuntimeModulegetRuntimeModule ()
 
bool is_inplace_op (const circle::Operator *op)
 
void addDynamicShapeTensor (const circle::Tensor *tensor, luci_interpreter::RuntimeShape &&shapes)
 
luci_interpreter::RuntimeShapegetDynamicShapeTensor (const circle::Tensor *tensor)
 
void removeDynamicShapeTensor (const circle::Tensor *tensor)
 

Friends

class TensorAllocPlan
 

Detailed Description

Definition at line 32 of file RuntimeGraph.h.

Constructor & Destructor Documentation

◆ RuntimeGraph() [1/3]

luci_interpreter::RuntimeGraph::RuntimeGraph ( RuntimeModule owning_module,
IMemoryManager memory_manager 
)
explicit

Definition at line 103 of file RuntimeGraph.cpp.

104 : _owning_module(owning_module), _memory_manager(memory_manager),
105 _tensor_alloc_plan(std::make_unique<TensorAllocPlan>(memory_manager))
106{
107}

◆ ~RuntimeGraph() [1/2]

luci_interpreter::RuntimeGraph::~RuntimeGraph ( )

Definition at line 109 of file RuntimeGraph.cpp.

110{
111 for (auto &tensor : _tensors)
112 {
113 if (tensor->is_data_allocated())
114 _memory_manager->release_memory(*tensor);
115 }
116}
virtual void release_memory(luci_interpreter::Tensor &tensor)=0

References luci_interpreter::IMemoryManager::release_memory().

◆ RuntimeGraph() [2/3]

luci_interpreter::RuntimeGraph::RuntimeGraph ( )
delete

◆ RuntimeGraph() [3/3]

luci_interpreter::RuntimeGraph::RuntimeGraph ( SimpleMemoryManager memory_manager,
CircleReader circle_reader,
RuntimeModule runtime_module,
uint32_t  subgraph_index 
)
explicit

Definition at line 27 of file RuntimeGraph.cpp.

29 : _memory_manager(memory_manager),
30 _tensor_to_data(std::unordered_map<const circle::Tensor *, uint8_t *>{}),
31 _runtime_module(runtime_module), _reader(circle_reader),
32 _inplace_op_indexes(std::unordered_set<const circle::Operator *>{}),
33 _subgraph_index(subgraph_index)
34{
35}

◆ ~RuntimeGraph() [2/2]

luci_interpreter::RuntimeGraph::~RuntimeGraph ( )

Member Function Documentation

◆ addDynamicShapeTensor()

void luci_interpreter::RuntimeGraph::addDynamicShapeTensor ( const circle::Tensor *  tensor,
luci_interpreter::RuntimeShape &&  shapes 
)

Definition at line 144 of file RuntimeGraph.cpp.

146{
147 assert(_reader->get_current_subgraph_index() == _subgraph_index);
148 _dynamic_tensor_shapes[tensor] = std::move(shapes);
149}

Referenced by luci_interpreter::execute_kernel_CircleAdd(), luci_interpreter::execute_kernel_CircleReshape(), and luci_interpreter::execute_kernel_CircleSlice().

◆ addInplaceOpIndex()

void luci_interpreter::RuntimeGraph::addInplaceOpIndex ( const circle::Operator *  op)
inline

Definition at line 94 of file RuntimeGraph.h.

94{ _inplace_op_indexes.insert(op); }

Referenced by luci_interpreter::GraphLoader::checkInplaceOps().

◆ addKernel()

void luci_interpreter::RuntimeGraph::addKernel ( std::unique_ptr< Kernel > &&  kernel)

Definition at line 144 of file RuntimeGraph.cpp.

145{
146 assert(kernel != nullptr);
147 _kernels.push_back(std::move(kernel));
148 _tensor_alloc_plan->invalidate();
149}

Referenced by luci_interpreter::GraphLoader::loadOperators().

◆ addTensor() [1/2]

Tensor * luci_interpreter::RuntimeGraph::addTensor ( const circle::Tensor *  raw_tensor,
std::unique_ptr< Tensor > &&  tensor 
)

◆ addTensor() [2/2]

◆ clearTensors()

void luci_interpreter::RuntimeGraph::clearTensors ( )

Definition at line 370 of file RuntimeGraph.cpp.

370{ _tensor_to_data.clear(); }

Referenced by luci_interpreter::execute_kernel_CircleIf().

◆ configure()

void luci_interpreter::RuntimeGraph::configure ( bool  dealloc_input)

Definition at line 435 of file RuntimeGraph.cpp.

436{
438
439 for (uint32_t i = 0; i < _reader->operators().size(); ++i)
440 {
441 const auto op = _reader->operators().at(i);
442 assert(op != nullptr);
443
444 const auto opcode = _reader->builtin_code(op);
445
446 kernel_configure.configure_kernel(op, opcode, this);
447 }
448
449 if (not _is_valid)
450 buildAllocDeallocPlan(dealloc_input);
451
452 _is_valid = true;
453}
CircleOperators operators() const
circle::BuiltinOperator builtin_code(const circle::Operator *op) const
value_type at(uint32_t i) const
void configure_kernel(const circle::Operator *cur_op, circle::BuiltinOperator opcode, BaseRuntimeGraph *runtime_graph) const
constexpr KernelConfigureRegistry kernel_configure
int32_t size[5]
Definition Slice.cpp:35

References luci::VectorWrapper< T >::at(), luci::CircleReader::builtin_code(), luci_interpreter::KernelConfigureRegistry::configure_kernel(), luci_interpreter::kernel_configure, luci::CircleReader::operators(), selectOwnSubgraph(), and size.

Referenced by execute(), and luci_interpreter::ModuleLoader::load().

◆ configureAllocations()

void luci_interpreter::RuntimeGraph::configureAllocations ( Tensor tensor)

Definition at line 139 of file RuntimeGraph.cpp.

140{
141 _memory_manager->allocate_memory(*tensor);
142}
virtual void allocate_memory(luci_interpreter::Tensor &tensor)=0

References luci_interpreter::IMemoryManager::allocate_memory().

Referenced by luci_interpreter::build_kernel_CircleFullyConnected().

◆ configureGraphInput() [1/2]

uint8_t * luci_interpreter::RuntimeGraph::configureGraphInput ( int32_t  input_index)

Definition at line 245 of file RuntimeGraph.cpp.

246{
247 assert(_reader->get_current_subgraph_index() == _subgraph_index);
248
249 const auto tensor_index = _reader->inputs()[input_index];
250 assert(tensor_index != -1);
251 const auto tensor = _reader->tensors()[tensor_index];
252 assert(tensor != nullptr);
253
254 auto *data = _memory_manager->allocate_memory(tensor);
255 configureGraphInput(input_index, data);
256
257 return data;
258}
CircleTensors tensors() const
VectorWrapper< int32_t > inputs() const
uint8_t * configureGraphInput(int32_t input_index)
const T * data(const std::vector< T, Alloc > &v)

References luci_interpreter::IMemoryManager::allocate_memory(), configureGraphInput(), flatbuffers::data(), luci::CircleReader::inputs(), and luci::CircleReader::tensors().

Referenced by configureGraphInput(), and luci_interpreter::execute_kernel_CircleIf().

◆ configureGraphInput() [2/2]

void luci_interpreter::RuntimeGraph::configureGraphInput ( int32_t  input_index,
uint8_t *  data 
)

Definition at line 260 of file RuntimeGraph.cpp.

261{
262 assert(_reader->get_current_subgraph_index() == _subgraph_index);
264
265 const auto tensor_index = _reader->inputs()[input_index];
266 assert(tensor_index != -1);
267 const auto tensor = _reader->tensors()[tensor_index];
268 assert(tensor != nullptr);
269
270 if (_tensor_to_data.find(tensor) != _tensor_to_data.end())
271 {
272 auto *data_prev = _tensor_to_data.at(tensor);
273 if (data_prev != data)
274 _memory_manager->release_memory(data_prev);
275 }
276 _tensor_to_data[tensor] = data;
277}

References flatbuffers::data(), luci::CircleReader::inputs(), luci_interpreter::IMemoryManager::release_memory(), resetOutputTensorsData(), and luci::CircleReader::tensors().

◆ execute() [1/2]

void luci_interpreter::RuntimeGraph::execute ( )

Definition at line 460 of file RuntimeGraph.cpp.

461{
463
464 if (not _is_valid)
465 configure(true);
466
467 const auto operators_size = _reader->operators().size();
468 const auto operators = _reader->operators();
469
470 for (uint32_t i = 0; i < operators_size; ++i)
471 {
472 const auto op = operators.at(i);
473 assert(op != nullptr);
474
475 const auto opcode = _reader->builtin_code(op);
476
477 allocate(i);
478
479 kernel_executor.execute_kernel(op, opcode, this);
480
481 deallocate(i);
482 }
483
484#ifdef ENABLE_TRAINING
485 if (_number_of_last_trainable_layers > 0)
486 {
487 const auto graph_output = _reader->outputs();
488
489 assert(graph_output.size() == 1);
490
491 const auto output_tensor = _reader->tensors()[graph_output[0]];
492 uint8_t *output_data = _tensor_to_data.at(output_tensor);
493 _gradient_calc_storage->saveDataToTensor(output_tensor, output_data);
494 _tensor_to_data.erase(output_tensor);
495 }
496#endif // ENABLE_TRAINING
497}
VectorWrapper< int32_t > outputs() const
uint32_t size() const
void execute_kernel(const circle::Operator *cur_op, circle::BuiltinOperator opcode, BaseRuntimeGraph *runtime_graph) const
void configure(bool dealloc_input)
constexpr KernelExecuteRegistry kernel_executor

References luci::VectorWrapper< T >::at(), luci::CircleReader::builtin_code(), configure(), luci_interpreter::KernelExecuteRegistry::execute_kernel(), luci_interpreter::kernel_executor, luci::CircleReader::operators(), luci::CircleReader::outputs(), selectOwnSubgraph(), luci::VectorWrapper< T >::size(), and luci::CircleReader::tensors().

◆ execute() [2/2]

void luci_interpreter::RuntimeGraph::execute ( ) const

Definition at line 151 of file RuntimeGraph.cpp.

152{
153 if (!_tensor_alloc_plan->isValid())
154 _tensor_alloc_plan->build(*this);
155
156 EventNotifier *event_notifier = _owning_module->getEventNotifier();
157
158 // Notify the observers that the input tensors have changed.
159 if (event_notifier != nullptr)
160 {
161 for (const Tensor *input_tensor : getInputTensors())
162 {
163 if (input_tensor->is_observable())
164 event_notifier->postTensorWrite(input_tensor);
165 }
166 }
167
168 for (size_t index = 0; index < _kernels.size(); ++index)
169 {
170 const auto &kernel = _kernels[index];
171 if (event_notifier != nullptr)
172 {
173 event_notifier->preOperatorExecute(kernel.get());
174 }
175
176 // TODO The `configure` method should only be called if the outputs of an operator need to be
177 // resized.
178 kernel->configure();
179
180 // Preallocate outputs in advance instead of relying on automatic allocation
181 _tensor_alloc_plan->allocate(index);
182
183 kernel->execute();
184
185 if (event_notifier != nullptr)
186 {
187 event_notifier->postOperatorExecute(kernel.get());
188 }
189
190 for (const Tensor *tensor : kernel->getOutputTensors())
191 {
192 if (event_notifier != nullptr && tensor->is_observable())
193 {
194 event_notifier->postTensorWrite(tensor);
195 }
196 }
197 _tensor_alloc_plan->deallocate(index);
198 }
199}
virtual void postTensorWrite(const Tensor *tensor)=0
const std::vector< Tensor * > & getOutputTensors() const
const std::vector< Tensor * > & getInputTensors() const
EventNotifier * getEventNotifier() const
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References luci_interpreter::RuntimeModule::getEventNotifier(), getInputTensors(), luci_interpreter::EventNotifier::postOperatorExecute(), luci_interpreter::EventNotifier::postTensorWrite(), and luci_interpreter::EventNotifier::preOperatorExecute().

Referenced by luci_interpreter::RuntimeModule::execute(), luci_interpreter::RuntimeModule::execute(), luci_interpreter::kernels::While::execute(), and luci_interpreter::execute_kernel_CircleIf().

◆ getCircleTensorByIndex()

const circle::Tensor * luci_interpreter::RuntimeGraph::getCircleTensorByIndex ( int32_t  index)

Definition at line 424 of file RuntimeGraph.cpp.

425{
426 assert(_reader->get_current_subgraph_index() == _subgraph_index);
427 if (index < 0)
428 return nullptr;
429
430 const auto raw_tensor = _reader->tensors()[index];
431
432 return raw_tensor;
433}

References luci::CircleReader::tensors().

Referenced by luci_interpreter::configure_kernel_CircleAddN(), luci_interpreter::configure_kernel_CircleConcatenation(), luci_interpreter::configure_kernel_CircleExpandDims(), luci_interpreter::configure_kernel_CircleFloor(), luci_interpreter::configure_kernel_CircleFullyConnected(), luci_interpreter::configure_kernel_CircleIf(), luci_interpreter::configure_kernel_CircleNeg(), luci_interpreter::configure_kernel_CircleResizeBilinear(), luci_interpreter::configure_kernel_CircleSelectV2(), luci_interpreter::configure_kernel_CircleSplit(), luci_interpreter::configure_kernel_CircleSplitV(), luci_interpreter::configure_kernel_CircleSVDF(), luci_interpreter::configure_kernel_CircleTransposeConv(), luci_interpreter::configure_kernel_CircleUnpack(), luci_interpreter::kernels::DownsamplingConv2DKernel::DownsamplingConv2DKernel(), luci_interpreter::execute_kernel_CircleAddN(), luci_interpreter::execute_kernel_CircleConcatenation(), luci_interpreter::execute_kernel_CircleExpandDims(), luci_interpreter::execute_kernel_CircleFloor(), luci_interpreter::execute_kernel_CircleFullyConnected(), luci_interpreter::execute_kernel_CircleIf(), luci_interpreter::execute_kernel_CircleNeg(), luci_interpreter::execute_kernel_CirclePack(), luci_interpreter::execute_kernel_CircleReshape(), luci_interpreter::execute_kernel_CircleResizeBilinear(), luci_interpreter::execute_kernel_CircleSelectV2(), luci_interpreter::execute_kernel_CircleSplit(), luci_interpreter::execute_kernel_CircleSplitV(), luci_interpreter::execute_kernel_CircleSVDF(), luci_interpreter::execute_kernel_CircleTransposeConv(), luci_interpreter::execute_kernel_CircleUnidirectionalSequenceLSTM(), luci_interpreter::execute_kernel_CircleUnpack(), luci_interpreter::lstm::LSTMStruct::LSTMStruct(), luci_interpreter::kernels::MISOKernel::MISOKernel(), luci_interpreter::kernels::SISOKernel::SISOKernel(), luci_interpreter::splitImpl(), and luci_interpreter::kernels::TISOKernel::TISOKernel().

◆ getConstDataByTensor()

uint8_t * luci_interpreter::RuntimeGraph::getConstDataByTensor ( const circle::Tensor *  raw_tensor)

Definition at line 398 of file RuntimeGraph.cpp.

399{
400 assert(_reader->get_current_subgraph_index() == _subgraph_index);
401 if (raw_tensor == nullptr)
402 return nullptr;
403
404#ifdef ENABLE_TRAINING
405 assert(_number_of_last_trainable_layers == 0 or
406 _storage != nullptr && "Storage should not be null here");
407
408 if (_storage != nullptr)
409 {
410 uint8_t *result = nullptr;
411 _storage->getTrainWeightDataByTensor(raw_tensor, &result);
412
413 if (result != nullptr)
414 return result;
415 }
416
417#endif // ENABLE_TRAINING
418
419 auto const &buffer = wrap(_reader->buffers()[raw_tensor->buffer()]->data());
420
421 return const_cast<uint8_t *>(buffer.data());
422}
CircleBuffers buffers() const
const T * data() const
result
Definition infer.py:103
VectorWrapper< T > wrap(const flatbuffers::Vector< T > *vec)

References luci::CircleReader::buffers(), luci::VectorWrapper< T >::data(), and luci::wrap().

Referenced by luci_interpreter_pal::lstm_internal::calculateLstmGate(), luci_interpreter::configure_kernel_CircleConv2D(), luci_interpreter::configure_kernel_CircleDepthwiseConv2D(), luci_interpreter::configure_kernel_CircleExpandDims(), luci_interpreter::configure_kernel_CircleMean(), luci_interpreter::configure_kernel_CirclePadCommon(), luci_interpreter::configure_kernel_CircleReduceMax(), luci_interpreter::configure_kernel_CircleSplitV(), luci_interpreter::configure_kernel_CircleSum(), luci_interpreter::configure_kernel_CircleTranspose(), luci_interpreter::configure_kernel_CircleTransposeConv(), luci_interpreter::kernels::evalComparisonGeneric(), luci_interpreter::execute_kernel_CircleBatchToSpaceND(), luci_interpreter::execute_kernel_CircleGatherND(), luci_interpreter::execute_kernel_CircleLogicalAnd(), luci_interpreter::execute_kernel_CircleLogicalNot(), luci_interpreter::execute_kernel_CircleLogicalOr(), luci_interpreter::execute_kernel_CirclePadCommon(), luci_interpreter::execute_kernel_CircleReshape(), luci_interpreter::execute_kernel_CircleResizeBilinear(), luci_interpreter::execute_kernel_CircleResizeNearestNeighbor(), luci_interpreter::execute_kernel_CircleSlice(), luci_interpreter::execute_kernel_CircleSpaceToBatchND(), luci_interpreter::execute_kernel_CircleSplit(), luci_interpreter::execute_kernel_CircleSplitV(), luci_interpreter::execute_kernel_CircleStridedSlice(), luci_interpreter::execute_kernel_CircleSVDF(), luci_interpreter::kernels::TISOKernel::readData(), and luci_interpreter::kernels::TISOKernel::readInplaceData().

◆ getDataByTensor()

uint8_t * luci_interpreter::RuntimeGraph::getDataByTensor ( const circle::Tensor *  raw_tensor)

Definition at line 355 of file RuntimeGraph.cpp.

356{
357 assert(_reader->get_current_subgraph_index() == _subgraph_index);
358
359 if (raw_tensor == nullptr)
360 return nullptr;
361
362 if (_tensor_to_data.find(raw_tensor) == _tensor_to_data.end())
363 {
364 return nullptr;
365 }
366
367 return _tensor_to_data.at(raw_tensor);
368}

Referenced by luci_interpreter::configure_kernel_CircleSqueeze(), luci_interpreter::kernels::evalComparisonGeneric(), luci_interpreter::evalInteger(), luci_interpreter::execute_kernel_CircleAbs(), luci_interpreter::execute_kernel_CircleAveragePool2D(), luci_interpreter::execute_kernel_CircleBatchToSpaceND(), luci_interpreter::execute_kernel_CircleBroadcastTo(), luci_interpreter::execute_kernel_CircleCast(), luci_interpreter::execute_kernel_CircleCeil(), luci_interpreter::execute_kernel_CircleCos(), luci_interpreter::execute_kernel_CircleDepthToSpace(), luci_interpreter::execute_kernel_CircleDequantize(), luci_interpreter::execute_kernel_CircleElu(), luci_interpreter::execute_kernel_CircleExp(), luci_interpreter::execute_kernel_CircleExpandDims(), luci_interpreter::execute_kernel_CircleFloor(), luci_interpreter::execute_kernel_CircleFloorDiv(), luci_interpreter::execute_kernel_CircleFloorMod(), luci_interpreter::execute_kernel_CircleGatherND(), luci_interpreter::execute_kernel_CircleIf(), luci_interpreter::execute_kernel_CircleL2Normalize(), luci_interpreter::execute_kernel_CircleL2Pool2D(), luci_interpreter::execute_kernel_CircleLeakyRelu(), luci_interpreter::execute_kernel_CircleLog(), luci_interpreter::execute_kernel_CircleLogicalAnd(), luci_interpreter::execute_kernel_CircleLogicalNot(), luci_interpreter::execute_kernel_CircleLogicalOr(), luci_interpreter::execute_kernel_CircleLogistic(), luci_interpreter::execute_kernel_CircleLogSoftmax(), luci_interpreter::execute_kernel_CircleMaximum(), luci_interpreter::execute_kernel_CircleMaxPool2D(), luci_interpreter::execute_kernel_CircleMinimum(), luci_interpreter::execute_kernel_CircleNeg(), luci_interpreter::execute_kernel_CirclePack(), luci_interpreter::execute_kernel_CirclePadCommon(), luci_interpreter::execute_kernel_CircleQuantize(), luci_interpreter::execute_kernel_CircleRelu(), luci_interpreter::execute_kernel_CircleRelu6(), luci_interpreter::execute_kernel_CircleReshape(), luci_interpreter::execute_kernel_CircleResizeBilinear(), luci_interpreter::execute_kernel_CircleResizeNearestNeighbor(), luci_interpreter::execute_kernel_CircleRound(), luci_interpreter::execute_kernel_CircleRsqrt(), luci_interpreter::execute_kernel_CircleShape(), luci_interpreter::execute_kernel_CircleSin(), luci_interpreter::execute_kernel_CircleSlice(), luci_interpreter::execute_kernel_CircleSpaceToBatchND(), luci_interpreter::execute_kernel_CircleSpaceToDepth(), luci_interpreter::execute_kernel_CircleSplit(), luci_interpreter::execute_kernel_CircleSplitV(), luci_interpreter::execute_kernel_CircleSqrt(), luci_interpreter::execute_kernel_CircleSquare(), luci_interpreter::execute_kernel_CircleSquaredDifference(), luci_interpreter::execute_kernel_CircleSqueeze(), luci_interpreter::execute_kernel_CircleStridedSlice(), luci_interpreter::execute_kernel_CircleSVDF(), luci_interpreter::execute_kernel_CircleTanh(), luci_interpreter::execute_kernel_CircleZerosLike(), luci_interpreter_pal::lstm_internal::lstmStep(), luci_interpreter::kernels::TISOKernel::readData(), luci_interpreter::kernels::TISOKernel::readInplaceData(), and luci_interpreter::splitImpl().

◆ getDynamicShapeTensor()

luci_interpreter::RuntimeShape * luci_interpreter::RuntimeGraph::getDynamicShapeTensor ( const circle::Tensor *  tensor)

Definition at line 151 of file RuntimeGraph.cpp.

152{
153 assert(_reader->get_current_subgraph_index() == _subgraph_index);
154 auto it = _dynamic_tensor_shapes.find(tensor);
155
156 return it == _dynamic_tensor_shapes.end() ? nullptr : &_dynamic_tensor_shapes[tensor];
157}

Referenced by luci_interpreter::kernels::getTensorDims(), and luci_interpreter::kernels::getTensorRuntimeShape().

◆ getInputDataSizeByIndex()

int32_t luci_interpreter::RuntimeGraph::getInputDataSizeByIndex ( int32_t  input_index)

Definition at line 279 of file RuntimeGraph.cpp.

280{
281 assert(_reader->get_current_subgraph_index() == _subgraph_index);
282 const auto tensor_index = _reader->inputs()[input_index];
283 assert(tensor_index != -1);
284 const auto tensor = _reader->tensors()[tensor_index];
285 assert(tensor != nullptr);
286
287 return Tensor::num_elements(tensor) * size(Tensor::element_type(tensor));
288}

References luci::CircleReader::inputs(), size, and luci::CircleReader::tensors().

◆ getInputTensorByIndex()

const circle::Tensor * luci_interpreter::RuntimeGraph::getInputTensorByIndex ( int32_t  input_index)

Definition at line 302 of file RuntimeGraph.cpp.

303{
304 assert(_reader->get_current_subgraph_index() == _subgraph_index);
305
306 const auto tensor_index = _reader->inputs()[input_index];
307 const auto tensor = _reader->tensors()[tensor_index];
308 assert(tensor != nullptr);
309 return tensor;
310}

References luci::CircleReader::inputs(), and luci::CircleReader::tensors().

◆ getInputTensors()

const std::vector< Tensor * > & luci_interpreter::RuntimeGraph::getInputTensors ( ) const
inline

◆ getNumOfInputTensors()

int32_t luci_interpreter::RuntimeGraph::getNumOfInputTensors ( )

Definition at line 290 of file RuntimeGraph.cpp.

291{
292 assert(_reader->get_current_subgraph_index() == _subgraph_index);
293 return _reader->inputs().size();
294}

References luci::CircleReader::inputs().

◆ getNumOfOutputTensors()

int32_t luci_interpreter::RuntimeGraph::getNumOfOutputTensors ( )

Definition at line 296 of file RuntimeGraph.cpp.

297{
298 assert(_reader->get_current_subgraph_index() == _subgraph_index);
299 return _reader->outputs().size();
300}

References luci::CircleReader::outputs().

◆ getOutputDataByIndex()

uint8_t * luci_interpreter::RuntimeGraph::getOutputDataByIndex ( int32_t  output_index)

Definition at line 341 of file RuntimeGraph.cpp.

342{
343 assert(_reader->get_current_subgraph_index() == _subgraph_index);
344
345 const auto tensor_index = _reader->outputs()[output_index];
346 assert(tensor_index != -1);
347 const auto tensor = _reader->tensors()[tensor_index];
348 assert(tensor != nullptr);
349
350 assert(_tensor_to_data.find(tensor) != _tensor_to_data.end());
351
352 return _tensor_to_data[tensor];
353}

References luci::CircleReader::outputs(), and luci::CircleReader::tensors().

Referenced by luci_interpreter::execute_kernel_CircleIf().

◆ getOutputDataSizeByIndex()

int32_t luci_interpreter::RuntimeGraph::getOutputDataSizeByIndex ( int32_t  output_index)

Definition at line 322 of file RuntimeGraph.cpp.

323{
324 assert(_reader->get_current_subgraph_index() == _subgraph_index);
325
326 const auto tensor_index = _reader->outputs()[output_index];
327 assert(tensor_index != -1);
328 const auto tensor = _reader->tensors()[tensor_index];
329 assert(tensor != nullptr);
330
331 uint32_t num_elements = Tensor::num_elements(tensor);
332 auto it = _dynamic_tensor_shapes.find(tensor);
333 if (it != _dynamic_tensor_shapes.end())
334 {
335 num_elements = it->second.flatSize();
336 }
337
338 return num_elements * size(Tensor::element_type(tensor));
339}
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59

References luci::CircleReader::outputs(), size, and luci::CircleReader::tensors().

◆ getOutputTensorByIndex()

const circle::Tensor * luci_interpreter::RuntimeGraph::getOutputTensorByIndex ( int32_t  input_index)

Definition at line 312 of file RuntimeGraph.cpp.

313{
314 assert(_reader->get_current_subgraph_index() == _subgraph_index);
315
316 const auto tensor_index = _reader->outputs()[input_index];
317 const auto tensor = _reader->tensors()[tensor_index];
318 assert(tensor != nullptr);
319 return tensor;
320}

References luci::CircleReader::outputs(), and luci::CircleReader::tensors().

◆ getOutputTensors()

const std::vector< Tensor * > & luci_interpreter::RuntimeGraph::getOutputTensors ( ) const
inline

◆ getRuntimeModule()

RuntimeModule * luci_interpreter::RuntimeGraph::getRuntimeModule ( )
inline

◆ invalidate()

void luci_interpreter::RuntimeGraph::invalidate ( )
inline

Definition at line 99 of file RuntimeGraph.h.

99{ _is_valid = false; }

Referenced by luci_interpreter::RuntimeGraph::TensorAllocPlan::build().

◆ is_inplace_op()

◆ isValid()

bool luci_interpreter::RuntimeGraph::isValid ( ) const
inline

Definition at line 100 of file RuntimeGraph.h.

100{ return _is_valid; }

◆ makeInplaceOperation()

void luci_interpreter::RuntimeGraph::makeInplaceOperation ( const circle::Tensor *  src_tensor,
const circle::Tensor *  dst_tensor 
)

Definition at line 372 of file RuntimeGraph.cpp.

374{
375 assert(_reader->get_current_subgraph_index() == _subgraph_index);
376 assert(removing_tensor != nullptr);
377
378 auto src_it = _tensor_to_data.find(removing_tensor);
379
380 if (src_it == _tensor_to_data.end())
381 return;
382
383 auto *data = _tensor_to_data[removing_tensor];
384
385 _tensor_to_data.erase(src_it);
386
387 if (dst_tensor == nullptr)
388 {
389 delete[] data;
390 return;
391 }
392
393 assert(_tensor_to_data.find(dst_tensor) == _tensor_to_data.end() &&
394 "Failed makeInplaceOperation");
395 _tensor_to_data[dst_tensor] = data;
396}
CLTensor dst_tensor

References flatbuffers::data(), and dst_tensor.

Referenced by luci_interpreter::kernels::evalTISOInplaceKernel(), luci_interpreter::kernels::evalTISOInplaceQuantizedKernel(), luci_interpreter::execute_kernel_CircleAbs(), luci_interpreter::execute_kernel_CircleCeil(), luci_interpreter::execute_kernel_CircleCos(), luci_interpreter::execute_kernel_CircleElu(), luci_interpreter::execute_kernel_CircleExp(), luci_interpreter::execute_kernel_CircleExpandDims(), luci_interpreter::execute_kernel_CircleLeakyRelu(), luci_interpreter::execute_kernel_CircleLog(), luci_interpreter::execute_kernel_CircleLogistic(), luci_interpreter::execute_kernel_CircleRelu(), luci_interpreter::execute_kernel_CircleRelu6(), luci_interpreter::execute_kernel_CircleReshape(), luci_interpreter::execute_kernel_CircleRound(), luci_interpreter::execute_kernel_CircleRsqrt(), luci_interpreter::execute_kernel_CircleSin(), luci_interpreter::execute_kernel_CircleSqrt(), luci_interpreter::execute_kernel_CircleSquare(), luci_interpreter::execute_kernel_CircleTanh(), and luci_interpreter::execute_kernel_CircleZerosLike().

◆ removeDynamicShapeTensor()

void luci_interpreter::RuntimeGraph::removeDynamicShapeTensor ( const circle::Tensor *  tensor)

Definition at line 159 of file RuntimeGraph.cpp.

160{
161 assert(_reader->get_current_subgraph_index() == _subgraph_index);
162 auto it = _dynamic_tensor_shapes.find(tensor);
163
164 assert(it != _dynamic_tensor_shapes.end());
165
166 _dynamic_tensor_shapes.erase(it);
167}

◆ resetOutputTensorsData()

void luci_interpreter::RuntimeGraph::resetOutputTensorsData ( )

Definition at line 220 of file RuntimeGraph.cpp.

221{
222 assert(_reader->get_current_subgraph_index() == _subgraph_index);
223 const auto graph_inputs = _reader->inputs();
224 for (int i = 0; i < _reader->outputs().size(); ++i)
225 {
226 const auto tensor_index = _reader->outputs()[i];
227 assert(tensor_index != -1);
228
229 if (std::find(graph_inputs.begin(), graph_inputs.end(), tensor_index) != graph_inputs.end())
230 return;
231
232 const auto tensor = _reader->tensors()[tensor_index];
233 assert(tensor != nullptr);
234
235 auto tensor_it = _tensor_to_data.find(tensor);
236 if (tensor_it != _tensor_to_data.end())
237 {
238 auto *data = _tensor_to_data.at(tensor);
239 _memory_manager->release_memory(data);
240 _tensor_to_data.erase(tensor_it);
241 }
242 }
243}

References flatbuffers::data(), luci::CircleReader::inputs(), luci::CircleReader::outputs(), luci_interpreter::IMemoryManager::release_memory(), size, and luci::CircleReader::tensors().

Referenced by configureGraphInput(), and luci_interpreter::execute_kernel_CircleIf().

◆ resetTensorData()

void luci_interpreter::RuntimeGraph::resetTensorData ( uint8_t *  new_data,
const circle::Tensor *  tensor 
)

Definition at line 207 of file RuntimeGraph.cpp.

208{
209 assert(_reader->get_current_subgraph_index() == _subgraph_index);
210 auto tensor_it = _tensor_to_data.find(tensor);
211 if (tensor_it != _tensor_to_data.end())
212 {
213 auto *data = _tensor_to_data.at(tensor);
214 _memory_manager->release_memory(data);
215 }
216
217 _tensor_to_data[tensor] = new_data;
218}

References flatbuffers::data(), and luci_interpreter::IMemoryManager::release_memory().

Referenced by luci_interpreter::execute_kernel_CircleAdd(), luci_interpreter::execute_kernel_CircleReshape(), and luci_interpreter::execute_kernel_CircleSlice().

◆ selectOwnSubgraph()

void luci_interpreter::RuntimeGraph::selectOwnSubgraph ( )
inline

Definition at line 102 of file RuntimeGraph.h.

102{ _reader->select_subgraph(_subgraph_index); };
bool select_subgraph(uint32_t subgraph)

Referenced by configure(), execute(), and luci_interpreter::execute_kernel_CircleIf().

◆ setDataToTensor()

void luci_interpreter::RuntimeGraph::setDataToTensor ( const circle::Tensor *  tensor,
uint8_t *  data 
)

Definition at line 455 of file RuntimeGraph.cpp.

456{
457 _tensor_to_data[tensor] = data;
458}

References flatbuffers::data().

◆ setInputTensors()

void luci_interpreter::RuntimeGraph::setInputTensors ( const std::vector< Tensor * > &  input_tensors)

Definition at line 125 of file RuntimeGraph.cpp.

126{
127 assert(std::all_of(input_tensors.cbegin(), input_tensors.cend(),
128 [](Tensor *tensor) { return tensor != nullptr; }));
129 _input_tensors = input_tensors;
130}

Referenced by luci_interpreter::GraphLoader::initInputOutputTensors().

◆ setOutputTensors()

void luci_interpreter::RuntimeGraph::setOutputTensors ( const std::vector< Tensor * > &  output_tensors)

Definition at line 132 of file RuntimeGraph.cpp.

133{
134 assert(std::all_of(output_tensors.cbegin(), output_tensors.cend(),
135 [](Tensor *tensor) { return tensor != nullptr; }));
136 _output_tensors = output_tensors;
137}

Referenced by luci_interpreter::GraphLoader::initInputOutputTensors().

Friends And Related Symbol Documentation

◆ TensorAllocPlan

friend class TensorAllocPlan
friend

Definition at line 36 of file RuntimeGraph.h.


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