17#ifndef LUCI_INTERPRETER_CORE_RUNTIMEGRAPH_H
18#define LUCI_INTERPRETER_CORE_RUNTIMEGRAPH_H
20#include "luci_interpreter/core/Tensor.h"
26#ifdef USE_STATIC_ALLOC
36#include <unordered_map>
37#include <unordered_set>
44#ifdef USE_STATIC_ALLOC
47class StaticRuntimeGraph final :
public IBaseRuntimeGraph
50 explicit StaticRuntimeGraph(IMemoryManager *memory_manager, CircleReader *circle_reader);
51 ~StaticRuntimeGraph() final;
53 void configureGraphInputs() final;
55 void configure() final;
57 void configure_kernels() final;
71 Tensor *
addTensor(
const circle::Tensor *raw_tensor, std::unique_ptr<Tensor> &&tensor);
73 const circle::Tensor *getCircleTensorByIndex(int32_t index);
75 void makeInplaceOperation(
const circle::Tensor *src_tensor,
const circle::Tensor *dst_tensor);
77 uint8_t *getDataByTensor(
const circle::Tensor *raw_tensor);
78 uint8_t *getConstDataByTensor(
const circle::Tensor *raw_tensor);
80 uint8_t *configureGraphInput(int32_t input_index);
81 void configureGraphInput(int32_t input_index, uint8_t *data);
83 int32_t getInputDataSizeByIndex(int32_t input_index);
84 int32_t getOutputDataSizeByIndex(int32_t output_index);
86 int32_t getNumOfInputTensors();
87 int32_t getNumOfOutputTensors();
89 const circle::Tensor *getInputTensorByIndex(int32_t input_index);
90 const circle::Tensor *getOutputTensorByIndex(int32_t input_index);
92 uint8_t *getOutputDataByIndex(int32_t output_index);
97 void configure(
bool dealloc_input);
103 void resetOutputTensorsData();
107 void setDataToTensor(
const circle::Tensor *tensor, uint8_t *data);
109 void resetTensorData(uint8_t *new_data,
const circle::Tensor *tensor);
115 return _inplace_op_indexes.find(op) != _inplace_op_indexes.end();
118#ifdef ENABLE_TRAINING
119 void setLastTrainingLayersNumber(uint32_t training_number)
121 _number_of_last_trainable_layers = training_number;
123 void setGradientCalculationStorage(training::GradientCalculationStorage *gradient_calc_storage)
125 _gradient_calc_storage = gradient_calc_storage;
127 void setTrainingWeightStorage(training::TrainableWeightStorage *storage) { _storage = storage; }
130#ifndef DIS_DYN_SHAPES
135 void removeDynamicShapeTensor(
const circle::Tensor *tensor);
139 void buildAllocDeallocPlan(
bool dealloc_input);
140 void allocate(
size_t kernel_index);
141 void deallocate(
size_t kernel_index);
144 SimpleMemoryManager *_memory_manager;
145 CircleReader *_reader;
146 RuntimeModule *_runtime_module;
148 std::unordered_map<const circle::Tensor *, uint8_t *> _tensor_to_data;
149 std::unordered_set<const circle::Operator *> _inplace_op_indexes;
151 bool _is_valid =
false;
153#ifdef ENABLE_TRAINING
154 uint32_t _number_of_last_trainable_layers = 0;
155 training::GradientCalculationStorage *_gradient_calc_storage =
nullptr;
156 training::TrainableWeightStorage *_storage =
nullptr;
160 std::vector<std::vector<const circle::Tensor *>> _alloc_plan;
161 std::vector<std::vector<const circle::Tensor *>> _dealloc_plan;
163 uint32_t _subgraph_index;
165#ifndef DIS_DYN_SHAPES
166 std::unordered_map<const circle::Tensor *, luci_interpreter::RuntimeShape> _dynamic_tensor_shapes;
Loads Circle file and provides helpers to access attributes.
void addInplaceOpIndex(const circle::Operator *op)
bool is_inplace_op(const circle::Operator *op)
Tensor * addTensor(const circle::Tensor *raw_tensor, std::unique_ptr< Tensor > &&tensor)
RuntimeModule * getRuntimeModule()