206{
207 const auto root = load_json(_path);
208 const auto dir_path = directory_path(_path);
209
210 std::unordered_map<std::string, luci::CircleNode *> name_to_node;
212 {
213 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
214 if (circle_node->opcode() == luci::CircleOpcode::CIRCLEOUTPUT)
215 {
216 continue;
217 }
218
219 name_to_node[circle_node->name()] = circle_node;
220 }
221
223
224 for (
const auto tensor_name :
root.getMemberNames())
225 {
227
228 verify_tensor(tensor);
229
230 const auto scale_path = dir_path +
'/' +
tensor[
"scale"].asString();
231 const auto zerop_path = dir_path +
'/' +
tensor[
"zerop"].asString();
232 const auto quantized_dimension =
tensor[
"quantized_dimension"].asUInt();
234
235 auto node = name_to_node.at(tensor_name);
236
237
239
240 node->quantparam(std::make_unique<luci::CircleQuantParam>());
241
242 set_dtype(node, dtype);
243 set_scale(node, scale_path);
244 set_zerop(node, zerop_path);
245 set_quantized_dimension(node, quantized_dimension);
246
247 if (
tensor.isMember(
"value"))
248 {
249 auto const_node = loco::must_cast<luci::CircleConst *>(node);
250 const auto value_path = dir_path +
'/' +
tensor[
"value"].asString();
251
252 set_value(const_node, value_path, dtype);
253 }
254 }
255
256 forward_qparam(g);
257
258
259 auto graph_outputs =
g->outputs();
260 assert(graph_outputs);
262 {
263 auto out_node = loco::must_cast<luci::CircleOutput *>(node);
264 auto from_node = loco::must_cast<luci::CircleNode *>(out_node->from());
265
267
268 out_node->quantparam(std::make_unique<luci::CircleQuantParam>());
269 out_node->quantparam()->scale = from_node->quantparam()->scale;
270 out_node->quantparam()->zerop = from_node->quantparam()->zerop;
271 out_node->quantparam()->quantized_dimension = from_node->quantparam()->quantized_dimension;
272 out_node->dtype(from_node->dtype());
273
274 auto graph_output = graph_outputs->at(out_node->index());
275 graph_output->dtype(out_node->dtype());
276 }
277
278
280 {
281 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
282
283
284
285 THROW_UNLESS(circle_node->dtype() != loco::DataType::FLOAT32);
286 }
287}
#define THROW_UNLESS(COND, MSG)
Op * root(Op *)
Return the root Op from a given Op node.
std::set< Node * > all_nodes(Graph *)
Enumerate all the nodes in a given graph.
std::set< loco::Node * > active_nodes(const std::vector< loco::Node * > &roots)
Enumerate all the nodes required to compute "roots".
std::vector< Node * > output_nodes(Graph *)
const char * tensor_name(const circle::Tensor *tensor)
loco::DataType str_to_dtype(const std::string &str)