17#include "loader/GraphLoader.h"
31 Shape shape(node->rank());
34 shape.dim(
i) = node->dim(
i).value();
45 if (num_elements < 0 ||
static_cast<uint64_t>(num_elements) >
SIZE_MAX / element_size)
47 throw std::runtime_error(
"Integer overflow in size calculation");
50 const int64_t total_size = num_elements * element_size;
51 *
data_size =
static_cast<size_t>(total_size);
55 return &node->
at<
DT>(0);
62 switch (node->dtype())
68 case DataType::FLOAT32:
83 throw std::runtime_error(
"luci-intp (getNodeData) Unsupported type.");
89 if (node->
custom_code() !=
"CircleReferencingConst")
94 struct ConstDataReference
96 const uint8_t *
data =
nullptr;
101 const auto &
const_data_ref = *
reinterpret_cast<const ConstDataReference *
>(custom_options.data());
112 case luci::CircleOpcode::CIRCLECONST:
113 case luci::CircleOpcode::CIRCLEINPUT:
114 case luci::CircleOpcode::CIRCLEOUTPUT:
115 case luci::CircleOpcode::CIRCLEOUTPUTEXCLUDE:
117 case luci::CircleOpcode::CIRCLEBIDIRECTIONAL_SEQUENCE_LSTM_OUT:
118 case luci::CircleOpcode::CIRCLECUSTOMOUT:
119 case luci::CircleOpcode::CIRCLEIFOUT:
120 case luci::CircleOpcode::CIRCLENONMAXSUPPRESSIONV4OUT:
121 case luci::CircleOpcode::CIRCLENONMAXSUPPRESSIONV5OUT:
122 case luci::CircleOpcode::CIRCLESPLITOUT:
123 case luci::CircleOpcode::CIRCLESPLITVOUT:
124 case luci::CircleOpcode::CIRCLETOPKV2OUT:
125 case luci::CircleOpcode::CIRCLEUNIQUEOUT:
126 case luci::CircleOpcode::CIRCLEUNPACKOUT:
127 case luci::CircleOpcode::CIRCLEVARIABLE:
128 case luci::CircleOpcode::CIRCLEWHILEOUT:
131 case luci::CircleOpcode::CUSTOM:
136 if (
custom_node->custom_code() ==
"CircleReferencingConst")
151 case luci::CircleOpcode::CIRCLEOUTPUT:
154 case luci::CircleOpcode::BIDIRECTIONAL_SEQUENCE_LSTM:
155 case luci::CircleOpcode::CUSTOM:
156 case luci::CircleOpcode::IF:
157 case luci::CircleOpcode::NON_MAX_SUPPRESSION_V4:
158 case luci::CircleOpcode::NON_MAX_SUPPRESSION_V5:
159 case luci::CircleOpcode::SPLIT:
160 case luci::CircleOpcode::SPLIT_V:
161 case luci::CircleOpcode::TOPK_V2:
162 case luci::CircleOpcode::UNIQUE:
163 case luci::CircleOpcode::UNPACK:
164 case luci::CircleOpcode::WHILE:
176 if (
custom_node->custom_code() ==
"CircleReferencingConst")
186 const std::unordered_map<const loco::Graph *, RuntimeGraph *> &graph_to_runtime_graph,
188 : _graph(graph), _runtime_graph(runtime_graph), _runtime_to_ir(
runtime_to_ir),
189 _graph_to_runtime_graph(graph_to_runtime_graph), _node_to_tensor(node_to_tensor),
203 throw std::runtime_error(
"Unsupported Custom operator. " +
cnode->custom_code() +
" in " +
215 case luci::CircleOpcode::CIRCLECONST:
216 case luci::CircleOpcode::CIRCLECUSTOMOUT:
217 case luci::CircleOpcode::CIRCLEINPUT:
218 case luci::CircleOpcode::CIRCLEVARIABLE:
229 assert(params->
scale.size() == params->
zerop.size());
230 quantization.
scale.assign(params->
scale.cbegin(), params->
scale.cend());
235 auto tensor = std::make_unique<Tensor>(node->dtype(), std::move(shape), std::move(quantization),
262 if (
custom_node->custom_code() ==
"CircleReferencingConst")
274 _node_to_tensor.emplace(node, tensor.get());
277 _runtime_graph->
addTensor(std::move(tensor));
284 std::vector<Tensor *> input_tensors(input_nodes.size());
285 for (
size_t i = 0;
i < input_nodes.size(); ++
i)
287 input_tensors[
i] = _node_to_tensor.at(input_nodes[
i]);
293 std::vector<Tensor *> output_tensors(output_nodes.size());
294 for (
size_t i = 0;
i < output_nodes.size(); ++
i)
297 output_tensors[
i] = _node_to_tensor.at(node->from());
338 _runtime_graph->
addKernel(std::move(kernel));
353 _runtime_graph->
addKernel(std::move(kernel));
NodeContext * nodes(void)
Logical unit of computation.
T * at(uint32_t n) const
Access N-th object.
Class to build tensor data.
const loco::DataTypeImpl< DT >::Type & at(uint32_t n) const
uint32_t size(void) const
const std::vector< uint8_t > & custom_options(void) const
const std::string & custom_code(void) const
Virtual CIRCLECUSTOMOUT in Circle.
uint32_t order_in_plan(void) const
void initInputOutputTensors() const
GraphLoader(const loco::Graph *graph, RuntimeGraph *runtime_graph, RuntimeToIR &runtime_to_ir, const std::unordered_map< const loco::Graph *, RuntimeGraph * > &graph_to_runtime_graph, std::unordered_map< const loco::Node *, Tensor * > &node_to_tensor, IMemoryManager *memory_manager)
virtual void allocate_memory(luci_interpreter::Tensor &tensor)=0
void addKernel(std::unique_ptr< Kernel > &&kernel)
Tensor * addTensor(std::unique_ptr< Tensor > &&tensor)
void setOutputTensors(const std::vector< Tensor * > &output_tensors)
void setInputTensors(const std::vector< Tensor * > &input_tensors)
std::vector< loco::Node * > postorder_traversal(const std::vector< loco::Node * > &roots)
Generate postorder traversal sequence starting from "roots".
std::set< Node * > all_nodes(Graph *)
Enumerate all the nodes in a given graph.
std::vector< Node * > input_nodes(const Graph *)
T must_cast(FeatureEncoder *node)
A helper dynamic_cast that throws when failed.
std::vector< Node * > output_nodes(Graph *)
size_t getDataTypeSize(DataType data_type)
T must_cast(loco::Node *node)
bool has_execution_plan(const luci::CircleNode *circle_node)
luci::CircleNodeExecutionPlan get_execution_plan(const luci::CircleNode *circle_node)
CircleQuantParam * quantparam(void) const
NodeName name(void) const
virtual CircleOpcode opcode(void) const =0
std::vector< float > scale
int32_t quantized_dimension
std::vector< int64_t > zerop
int32_t quantized_dimension
std::vector< float > scale
std::vector< int32_t > zero_point
std::unordered_map< const Tensor *, const luci::CircleNode * > tensor_to_node
std::unordered_map< const Kernel *, const luci::CircleNode * > kernel_to_node