134 template <
class TFLPool2D>
135 void export_pool_2d(TFLPool2D *node, circle::BuiltinOperator builtin_op);
147 auto inputs = builder.CreateVector(inputs_vec);
148 auto outputs = builder.CreateVector(outputs_vec);
150 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
151 circle::BuiltinOptions_AddOptions,
options.Union());
152 gd._operators.push_back(op_offset);
157 export_pool_2d<locoex::TFLAveragePool2D>(node, circle::BuiltinOperator_AVERAGE_POOL_2D);
162 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_CONCATENATION);
163 std::vector<int32_t> inputs_vec;
166 for (uint32_t i = 0; i < node->
numValues(); ++i)
169 auto inputs = builder.CreateVector(inputs_vec);
170 auto outputs = builder.CreateVector(outputs_vec);
171 auto options = CreateConcatenationOptions(builder, node->
axis(),
173 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
174 circle::BuiltinOptions_ConcatenationOptions,
options.Union());
175 gd._operators.push_back(op_offset);
180 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_CONV_2D);
186 auto inputs = builder.CreateVector(inputs_vec);
187 auto outputs = builder.CreateVector(outputs_vec);
193 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
194 circle::BuiltinOptions_Conv2DOptions,
options.Union());
195 gd._operators.push_back(op_offset);
200 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_DEPTHWISE_CONV_2D);
206 auto inputs = builder.CreateVector(inputs_vec);
207 auto outputs = builder.CreateVector(outputs_vec);
209 auto options = CreateDepthwiseConv2DOptions(builder, padding, node->
stride()->
w(),
214 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
215 circle::BuiltinOptions_DepthwiseConv2DOptions,
options.Union());
216 gd._operators.push_back(op_offset);
221 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_DIV);
224 auto inputs = builder.CreateVector(inputs_vec);
225 auto outputs = builder.CreateVector(outputs_vec);
227 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
228 circle::BuiltinOptions_DivOptions,
options.Union());
229 gd._operators.push_back(op_offset);
234 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_FULLY_CONNECTED);
241 auto inputs = builder.CreateVector(inputs_vec);
242 auto outputs = builder.CreateVector(outputs_vec);
247 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
248 circle::BuiltinOptions_FullyConnectedOptions,
options.Union());
249 gd._operators.push_back(op_offset);
254 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_MAXIMUM);
257 auto inputs = builder.CreateVector(inputs_vec);
258 auto outputs = builder.CreateVector(outputs_vec);
259 auto options = CreateMaximumMinimumOptions(builder);
260 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
261 circle::BuiltinOptions_MaximumMinimumOptions,
options.Union());
262 gd._operators.push_back(op_offset);
267 export_pool_2d<locoex::TFLMaxPool2D>(node, circle::BuiltinOperator_MAX_POOL_2D);
272 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_MEAN);
276 auto inputs = builder.CreateVector(inputs_vec);
277 auto outputs = builder.CreateVector(outputs_vec);
279 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
280 circle::BuiltinOptions_ReducerOptions,
options.Union());
281 gd._operators.push_back(op_offset);
286 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_MUL);
289 auto inputs = builder.CreateVector(inputs_vec);
290 auto outputs = builder.CreateVector(outputs_vec);
292 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
293 circle::BuiltinOptions_MulOptions,
options.Union());
294 gd._operators.push_back(op_offset);
299 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_RELU);
302 auto inputs = builder.CreateVector(inputs_vec);
303 auto outputs = builder.CreateVector(outputs_vec);
304 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
305 gd._operators.push_back(op_offset);
310 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_RELU6);
313 auto inputs = builder.CreateVector(inputs_vec);
314 auto outputs = builder.CreateVector(outputs_vec);
315 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
316 gd._operators.push_back(op_offset);
323 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_RSQRT);
326 auto inputs = builder.CreateVector(inputs_vec);
327 auto outputs = builder.CreateVector(outputs_vec);
328 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
329 gd._operators.push_back(op_offset);
336 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_SQRT);
339 auto inputs = builder.CreateVector(inputs_vec);
340 auto outputs = builder.CreateVector(outputs_vec);
341 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
342 gd._operators.push_back(op_offset);
347 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_SQUARED_DIFFERENCE);
350 auto inputs = builder.CreateVector(inputs_vec);
351 auto outputs = builder.CreateVector(outputs_vec);
352 auto options = CreateSquaredDifferenceOptions(builder);
353 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
354 circle::BuiltinOptions_SquaredDifferenceOptions,
options.Union());
355 gd._operators.push_back(op_offset);
360 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_SUB);
363 auto inputs = builder.CreateVector(inputs_vec);
364 auto outputs = builder.CreateVector(outputs_vec);
366 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
367 circle::BuiltinOptions_SubOptions,
options.Union());
368 gd._operators.push_back(op_offset);
375 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_TRANSPOSE);
379 auto inputs = builder.CreateVector(inputs_vec);
380 auto outputs = builder.CreateVector(outputs_vec);
381 auto options = CreateTransposeOptions(builder);
384 CreateOperator(builder, op_idx, inputs, outputs,
385 circle::BuiltinOptions::BuiltinOptions_TransposeOptions,
options.Union());
386 gd._operators.push_back(op_offset);
391 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_TRANSPOSE_CONV);
398 auto inputs = builder.CreateVector(inputs_vec);
399 auto outputs = builder.CreateVector(outputs_vec);
402 CreateTransposeConvOptions(builder, padding, node->
stride()->
w(), node->
stride()->
h());
405 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
406 circle::BuiltinOptions_TransposeConvOptions,
options.Union());
407 gd._operators.push_back(op_offset);
410template <
class TFLPool2D>
411void OperationExporter::export_pool_2d(TFLPool2D *node, circle::BuiltinOperator builtin_op)
413 EXO_ASSERT(builtin_op == circle::BuiltinOperator_MAX_POOL_2D ||
414 builtin_op == circle::BuiltinOperator_AVERAGE_POOL_2D,
415 "should be maxpool or avgpool");
418 uint32_t op_idx = gd.registerBuiltinOpcode(builtin_op);
421 auto inputs = builder.CreateVector(inputs_vec);
422 auto outputs = builder.CreateVector(outputs_vec);
424 circle::Padding padding =
getOpPadding(node->padding());
426 auto options = CreatePool2DOptions(builder, padding, node->stride()->w(), node->stride()->h(),
427 node->filter()->w(), node->filter()->h(),
429 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
430 circle::BuiltinOptions_Pool2DOptions,
options.Union());
431 gd._operators.push_back(op_offset);
436 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_INSTANCE_NORM);
440 auto inputs = builder.CreateVector(inputs_vec);
441 auto outputs = builder.CreateVector(outputs_vec);
442 auto options = CreateInstanceNormOptions(builder, node->
epsilon(),
444 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
445 circle::BuiltinOptions_InstanceNormOptions,
options.Union());
446 gd._operators.push_back(op_offset);
449void OperationExporter::visit(
loco::ReLU *node)
451 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_RELU);
454 auto inputs = builder.CreateVector(inputs_vec);
455 auto outputs = builder.CreateVector(outputs_vec);
456 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
457 gd._operators.push_back(op_offset);
462 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_RELU6);
465 auto inputs = builder.CreateVector(inputs_vec);
466 auto outputs = builder.CreateVector(outputs_vec);
467 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
468 gd._operators.push_back(op_offset);
471void OperationExporter::visit(
loco::Tanh *node)
473 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_TANH);
476 auto inputs = builder.CreateVector(inputs_vec);
477 auto outputs = builder.CreateVector(outputs_vec);
478 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
479 gd._operators.push_back(op_offset);
484 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_MAX_POOL_2D);
487 auto inputs = builder.CreateVector(inputs_vec);
488 auto outputs = builder.CreateVector(outputs_vec);
494 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
495 circle::BuiltinOptions_Pool2DOptions,
options.Union());
496 gd._operators.push_back(op_offset);
504 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_AVERAGE_POOL_2D);
507 auto inputs = builder.CreateVector(inputs_vec);
508 auto outputs = builder.CreateVector(outputs_vec);
514 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
515 circle::BuiltinOptions_Pool2DOptions,
options.Union());
516 gd._operators.push_back(op_offset);
521 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_CONV_2D);
530 auto bias_vec_shape_offset = builder.CreateVector(std::vector<int32_t>{bias_vec_size});
531 size_t raw_bias_vec_size = bias_vec_size *
sizeof(int32_t);
533 std::vector<float> bias_vec_data(bias_vec_size);
535 auto bias_vec_offset =
536 builder.CreateVector(
reinterpret_cast<uint8_t *
>(bias_vec_data.data()), raw_bias_vec_size);
538 auto bias_buffer_offset = CreateBuffer(builder, bias_vec_offset);
540 const auto bias_buffer_id =
static_cast<uint32_t
>(gd._buffers.size());
542 gd._buffers.push_back(bias_buffer_offset);
544 auto bias_tensor_id =
static_cast<int32_t
>(gd._tensors.size());
545 auto name_offset = builder.CreateString(
"t_" + std::to_string(bias_tensor_id));
547 auto bias_tensor_offset =
548 CreateTensor(builder, bias_vec_shape_offset, TensorType_FLOAT32, bias_buffer_id, name_offset);
549 gd._tensors.push_back(bias_tensor_offset);
555 auto inputs = builder.CreateVector(inputs_vec);
556 auto outputs = builder.CreateVector(outputs_vec);
563 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
564 circle::BuiltinOptions_Conv2DOptions,
options.Union());
565 gd._operators.push_back(op_offset);
570 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_TRANSPOSE_CONV);
573 const int32_t outshape_vec_size = 4;
574 auto outshape_vec_shape_offset = builder.CreateVector(std::vector<int32_t>{outshape_vec_size});
575 size_t raw_outshape_vec_size = outshape_vec_size *
sizeof(int32_t);
577 std::vector<int32_t> outshape_vec_data(outshape_vec_size);
583 outshape_vec_data.at(0) = out_feature_shape.
count().
value();
584 outshape_vec_data.at(1) = out_feature_shape.height().value();
585 outshape_vec_data.at(2) = out_feature_shape.width().value();
586 outshape_vec_data.at(3) = out_feature_shape.depth().value();
589 auto outshape_vec_offset = builder.CreateVector(
590 reinterpret_cast<uint8_t *
>(outshape_vec_data.data()), raw_outshape_vec_size);
592 auto outshape_buffer_offset = CreateBuffer(builder, outshape_vec_offset);
594 const auto outshape_buffer_id =
static_cast<uint32_t
>(gd._buffers.size());
596 gd._buffers.push_back(outshape_buffer_offset);
598 auto outshape_tensor_id =
static_cast<int32_t
>(gd._tensors.size());
599 auto name_offset = builder.CreateString(
"t_" + std::to_string(outshape_tensor_id));
601 auto outshape_tensor_offset = CreateTensor(builder, outshape_vec_shape_offset, TensorType_INT32,
602 outshape_buffer_id, name_offset);
603 gd._tensors.push_back(outshape_tensor_offset);
609 auto inputs = builder.CreateVector(inputs_vec);
610 auto outputs = builder.CreateVector(outputs_vec);
618 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
619 circle::BuiltinOptions_TransposeConvOptions,
options.Union());
620 gd._operators.push_back(op_offset);
625 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_DEPTHWISE_CONV_2D);
634 auto bias_vec_shape_offset = builder.CreateVector(std::vector<int32_t>{bias_vec_size});
636 size_t raw_bias_vec_size = bias_vec_size *
sizeof(int32_t);
637 std::vector<float> bias_vec_data(bias_vec_size);
638 auto bias_vec_offset =
639 builder.CreateVector(
reinterpret_cast<uint8_t *
>(bias_vec_data.data()), raw_bias_vec_size);
641 auto bias_buffer_offset = CreateBuffer(builder, bias_vec_offset);
643 const auto bias_buffer_id =
static_cast<uint32_t
>(gd._buffers.size());
645 gd._buffers.push_back(bias_buffer_offset);
647 auto bias_tensor_id =
static_cast<int32_t
>(gd._tensors.size());
648 auto name_offset = builder.CreateString(
"t_" + std::to_string(bias_tensor_id));
650 auto bias_tensor_offset =
651 CreateTensor(builder, bias_vec_shape_offset, TensorType_FLOAT32, bias_buffer_id, name_offset);
652 gd._tensors.push_back(bias_tensor_offset);
657 auto inputs = builder.CreateVector(inputs_vec);
658 auto outputs = builder.CreateVector(outputs_vec);
665 CreateDepthwiseConv2DOptions(builder, padding, node->
stride()->
horizontal(),
668 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
669 circle::BuiltinOptions_DepthwiseConv2DOptions,
options.Union());
670 gd._operators.push_back(op_offset);
677 switch (node->
func())
680 op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_MEAN);
689 std::vector<int32_t> axes_vec;
691 for (uint32_t i = 0; i < rank; ++i)
693 axes_vec.push_back(i);
695 int32_t axes_vec_size = axes_vec.size();
696 auto axes_vec_shape_offset = builder.CreateVector(std::vector<int32_t>{axes_vec_size});
698 size_t raw_axes_vec_size = axes_vec_size *
sizeof(int32_t);
699 auto axes_vec_offset =
700 builder.CreateVector(
reinterpret_cast<uint8_t *
>(axes_vec.data()), raw_axes_vec_size);
702 auto axes_buffer_offset = CreateBuffer(builder, axes_vec_offset);
704 const auto axes_buffer_id =
static_cast<uint32_t
>(gd._buffers.size());
706 gd._buffers.push_back(axes_buffer_offset);
708 auto axes_tensor_id =
static_cast<int32_t
>(gd._tensors.size());
709 auto name_offset = builder.CreateString(
"t_" + std::to_string(axes_tensor_id));
711 auto axes_tensor_offset =
712 CreateTensor(builder, axes_vec_shape_offset, TensorType_INT32, axes_buffer_id, name_offset);
713 gd._tensors.push_back(axes_tensor_offset);
717 auto inputs = builder.CreateVector(inputs_vec);
718 auto outputs = builder.CreateVector(outputs_vec);
719 auto options = CreateReducerOptions(builder,
true);
720 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
721 circle::BuiltinOptions_ReducerOptions,
options.Union());
722 gd._operators.push_back(op_offset);
733 uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_SOFTMAX);
736 auto inputs = builder.CreateVector(inputs_vec);
737 auto outputs = builder.CreateVector(outputs_vec);
738 auto options = CreateSoftmaxOptions(builder, 1.0f);
739 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
740 circle::BuiltinOptions_SoftmaxOptions,
options.Union());
741 gd._operators.push_back(op_offset);
745template <
typename NodeT>
753 auto options = CreateConcatenationOptions(builder);
754 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
755 circle::BuiltinOptions_ConcatenationOptions,
options.Union());
766 auto options = CreateTransposeOptions(builder);
769 constexpr int perm_vec_size = 4;
770 assert(perm_vec_data.size() == perm_vec_size);
771 auto perm_vec_shape_offset = builder.
CreateVector(std::vector<int32_t>{perm_vec_size});
772 constexpr size_t raw_perm_vec_size = perm_vec_size *
sizeof(int32_t);
774 auto perm_vec_offset =
775 builder.
CreateVector(
reinterpret_cast<uint8_t *
>(perm_vec_data.data()), raw_perm_vec_size);
777 auto perm_buffer_offset = CreateBuffer(builder, perm_vec_offset);
779 const auto perm_buffer_id =
static_cast<uint32_t
>(gd.
_buffers.size());
781 gd.
_buffers.push_back(perm_buffer_offset);
783 auto perm_tensor_id =
static_cast<int32_t
>(gd.
_tensors.size());
784 auto name_offset = builder.
CreateString(
"t_" + std::to_string(perm_tensor_id));
786 auto perm_tensor_offset =
787 CreateTensor(builder, perm_vec_shape_offset, TensorType_INT32, perm_buffer_id, name_offset);
788 gd.
_tensors.push_back(perm_tensor_offset);
798 constexpr auto options_type = circle::BuiltinOptions::BuiltinOptions_TransposeOptions;
800 auto transpose_offset =
801 CreateOperator(builder, op_idx, inputs, outputs, options_type,
options.Union());
808 auto perm = encoder->perm();
813 exportIdentity(node, builder, gd);
817 std::vector<int32_t> perm_vec_data(4);
823 exportAsTranspose(node, builder, perm_vec_data, gd);
830 auto perm = decoder->perm();
835 exportIdentity(node, builder, gd);
839 std::vector<int32_t> perm_vec_data(4);
845 exportAsTranspose(node, builder, perm_vec_data, gd);
852 auto perm = encoder->perm();
857 exportIdentity(node, builder, gd);
861 std::vector<int32_t> perm_vec_data(4);
868 exportAsTranspose(node, builder, perm_vec_data, gd);
886 auto input_shape_shape_vec_offset =
887 builder.
CreateVector(std::vector<int32_t>{(int32_t)new_shape_vec.size()});
889 size_t input_shape_vec_size = new_shape_vec.size() *
sizeof(int32_t);
890 auto input_shape_input_vec_offset =
891 builder.
CreateVector(
reinterpret_cast<uint8_t *
>(new_shape_vec.data()), input_shape_vec_size);
892 auto input_shape_buffer_offset = CreateBuffer(builder, input_shape_input_vec_offset);
894 const auto input_shape_buffer_id =
static_cast<uint32_t
>(gd.
_buffers.size());
895 gd.
_buffers.push_back(input_shape_buffer_offset);
897 auto input_shape_tensor_id =
static_cast<int32_t
>(gd.
_tensors.size());
898 auto name_offset = builder.
CreateString(
"t_" + std::to_string(input_shape_tensor_id));
899 auto input_shape_tensor_offset = CreateTensor(
900 builder, input_shape_shape_vec_offset, TensorType_INT32, input_shape_buffer_id, name_offset);
901 gd.
_tensors.push_back(input_shape_tensor_offset);
910 auto new_shape_vec_offset = builder.
CreateVector(new_shape_vec);
911 auto options = CreateReshapeOptions(builder, new_shape_vec_offset);
913 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
914 circle::BuiltinOptions_ReshapeOptions,
options.Union());
921 auto ker = node->
input();
924 std::vector<int32_t> new_shape_vec(4);
925 new_shape_vec[0] = 1;
930 exportAsReshape(node, builder, new_shape_vec, gd);
940 auto options = CreateAddOptions(builder);
941 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
942 circle::BuiltinOptions_AddOptions,
options.Union());
953 auto options = CreateAddOptions(builder);
954 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
955 circle::BuiltinOptions_AddOptions,
options.Union());
967 auto options = CreateConcatenationOptions(builder, node->
axis());
968 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
969 circle::BuiltinOptions_ConcatenationOptions,
options.Union());
974void OperationExporter::visit(
loco::BiasEncode *encode) { exportIdentity(encode, builder, gd); }
983 auto options = CreateAddOptions(builder);
984 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
985 circle::BuiltinOptions_AddOptions,
options.Union());
996 auto options = CreateMaximumMinimumOptions(builder);
997 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
998 circle::BuiltinOptions_MaximumMinimumOptions,
options.Union());
1009 auto options = CreateMulOptions(builder);
1010 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
1011 circle::BuiltinOptions_MulOptions,
options.Union());
1022 auto options = CreateSubOptions(builder);
1023 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
1024 circle::BuiltinOptions_SubOptions,
options.Union());
1035 auto options = CreateDivOptions(builder);
1036 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
1037 circle::BuiltinOptions_DivOptions,
options.Union());
1048 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
1054 std::vector<int32_t> new_shape_vec;
1055 for (uint32_t axis = 0; axis < node->rank(); ++axis)
1057 assert(node->dim(axis).known());
1058 new_shape_vec.push_back(node->dim(axis).value());
1061 exportAsReshape(node, builder, new_shape_vec, gd);
1066 INTERNAL_EXN(
"loco graph has loco::TensorBroadcast, which should not exist in the graph");
1074 auto padding = node->
padding();
1076 int32_t padding_vec_size = padding->
rank();
1078 size_t padding_vec_byte_size = padding_vec_size *
sizeof(int32_t) * 2;
1080 std::vector<int32_t> padding_vec_data(padding_vec_size * 2);
1082 for (int32_t i = 0; i < padding_vec_size; i++)
1084 padding_vec_data.at(i * 2) = padding->front(i);
1085 padding_vec_data.at(i * 2 + 1) = padding->back(i);
1088 auto padding_vec_ptr = builder.
CreateVector(
reinterpret_cast<uint8_t *
>(padding_vec_data.data()),
1089 padding_vec_byte_size);
1092 auto padding_buffer_ptr = CreateBuffer(builder, padding_vec_ptr);
1094 const auto padding_buffer_id =
static_cast<uint32_t
>(gd.
_buffers.size());
1096 gd.
_buffers.push_back(padding_buffer_ptr);
1099 auto padding_shape_vec_ptr = builder.
CreateVector(std::vector<int32_t>{padding_vec_size, 2});
1101 auto padding_tensor_ptr =
1102 CreateTensor(builder, padding_shape_vec_ptr, TensorType_INT32, padding_buffer_id);
1104 const auto padding_tensor_id =
static_cast<int32_t
>(gd.
_tensors.size());
1106 gd.
_tensors.push_back(padding_tensor_ptr);
1112 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
1120 flexbuffers::Builder flexbuf;
1122 size_t map_start = flexbuf.StartMap();
1126 for (
auto name : names)
1129 flexbuf.Int(name.c_str(), int_val->val());
1131 flexbuf.Float(name.c_str(), float_val->val());
1134 INTERNAL_EXN_V(
"Unsupported dtype while writing flexbuffer for customop attr", name);
1137 flexbuf.EndMap(map_start);
1151 std::vector<int32_t> inputs_vec;
1153 inputs_vec.resize(call->
arity());
1154 for (uint32_t i = 0; i < call->
arity(); i++)
1163 auto custom_options = CreateCOpCallOptions(builder, call);
1164 auto op_offset = CreateOperator(builder, op_idx, inputs, outputs,
1165 circle::BuiltinOptions_NONE,
1168 circle::CustomOptionsFormat_FLEXBUFFERS);
1178 if (node->
arity() == 1)
1180 assert(node->
arg(0) !=
nullptr);
1194 OperationExporter exporter{builder,
data};
1195 canonical_node->accept(&exporter);
1199 OperationExporter exporter{builder,
data};
1200 tfl_node->accept(&exporter);
1204 OperationExporter exporter{builder,
data};
1205 circle_node->accept(&exporter);
1209 OperationExporter exporter{builder,
data};
1222namespace circle_detail
1229 exportNode(node, builder, gd);
#define INTERNAL_EXN(msg)
@ brief throw internal exception with message
#define INTERNAL_EXN_V(msg, val)
@ brief throw internal exception with message and value
Helper class to hold data needed in creation of a FlatBuffer. To serialize data, you typically call o...
Offset< String > CreateString(const char *str, size_t len)
Store a string in the buffer, which can contain any binary data.
Offset< Vector< T > > CreateVector(const T *v, size_t len)
Serialize an array into a FlatBuffer vector.
Convention convention(void) const
const Stride< 2 > * stride(void) const
const Padding2D * pad(void) const
const Window< 2 > * window(void) const
Add Feature and Bias along "depth" axis.
Produce a value of domain D from an input value (of domain D) and a bias.
Create a "Bias" from a "Tensor".
Create a value from constant byte array.
const Stride< 2 > * stride(void) const
const Padding2D * pad(void) const
Depthwise 2D Convolution.
const Stride< 2 > * stride(void) const
const Padding2D * pad(void) const
Create a depthwise filter from a tensor.
uint32_t value(void) const
Return the value.
Elementwise Add lhs and rhs.
Elementwise Div lhs and rhs.
Elementwise Maximum of lhs and rhs.
Elementwise Mul lhs and rhs.
Elementwise Sqrt of input.
Elementwise Sub lhs and rhs.
Create a tensor from a feature map.
FeatureDecoder * decoder(void) const
Create a feature map from a tensor.
FeatureEncoder * encoder(void) const
const Dimension & count(void) const
Create a filter from a tensor.
FilterEncoder * encoder(void) const
const Padding2D * pad(void) const
const Stride< 2 > * stride(void) const
const Window< 2 > * window(void) const
Logical unit of computation.
virtual Node * arg(uint32_t N) const =0
Access N-th argument node.
virtual uint32_t arity(void) const =0
Return the number of arguments.
uint32_t rank(void) const
Create a value from user data.
Make a value visible to user.
Create a new value that rectifies its input capping the units at 6.
Create a new value that rectifies its input.
Reshape a tensor to another tensor whose shape is known at compile time.
Computes softmax activations for Tensor domain.
uint32_t axis(void) const
uint32_t horizontal(void) const
uint32_t vertical(void) const
Create a new value that rectifies its input by tanh.
bool defined(const TensorAxis &axis) const
Duplicate elements along specified axes.
uint32_t axis(void) const
Pads a tensor with constant value.
const PaddingND * padding(void) const
Computes ReduceFunc operations for Tensor domain.
ReduceFunc func(void) const
const TensorAxisSet * axes(void) const
2D Transposed Convolution
const Stride< 2 > * stride(void) const
const Padding2D * pad(void) const
uint32_t horizontal(void) const
uint32_t vertical(void) const
Class to calls custom operation.
std::vector< std::string > attr_names() const
get all the names of attr
void op(const std::string &op)
void attr(const std::string &attr_name, std::unique_ptr< COpAttrData > &&attr_data)
Store [attr_name, attr_data].
loco::Node * input(void) const
loco::Node * gamma(void) const
loco::Node * beta(void) const
FusedActFunc fusedActivationFunction() const
loco::Node * arg(uint32_t n) const final
loco::Node * y(void) const
loco::Node * x(void) const
AVERAGE_POOL_2D in TensorFlow Lite.
CONCATENATION in TensorFlow Lite.
uint32_t axis(void) const
Node * values(uint32_t index) const
uint32_t numValues(void) const
Class to build tensor data.
CONV_2D in TensorFlow Lite.
loco::Node * filter(void) const
const Stride * stride(void) const
loco::Node * bias(void) const override
loco::Node * input(void) const
DEPTHWISE_CONV_2D in TensorFlow Lite.
loco::Node * filter(void) const
loco::Node * input(void) const
int32_t depthMultiplier(void) const
const Stride * stride(void) const
loco::Node * bias(void) const override
loco::Node * x(void) const
loco::Node * y(void) const
FULLY_CONNECTED in TensorFlow Lite.
loco::Node * bias(void) const override
loco::Node * weights(void) const
loco::Node * input(void) const
MAX_POOL_2D in TensorFlow Lite.
MAXIMUM in TensorFlow Lite.
loco::Node * x(void) const
loco::Node * y(void) const
loco::Node * input(void) const
bool keep_dims(void) const
loco::Node * reduction_indices(void) const
loco::Node * y(void) const
loco::Node * x(void) const
FusedActFunc fusedActivationFunction() const
loco::Node * features(void) const
loco::Node * features(void) const
loco::Node * x(void) const
loco::Node * x(void) const
loco::Node * x(void) const
loco::Node * y(void) const
loco::Node * y(void) const
loco::Node * x(void) const
TRANSPOSE_CONV in TensorFlow Lite.
const Stride * stride(void) const
const Padding & padding(void) const
loco::Node * filter(void) const
loco::Node * inputSizes(void) const
loco::Node * outBackprop(void) const
TRANSPOSE in TensorFlow Lite.
loco::Node * arg(uint32_t n) const final
uint32_t arity(void) const final
#define EXO_ASSERT(condition, msg)
__global uchar * offset(const Image *img, int x, int y)
circle::Padding getOpPadding(const loco::Padding2D *pad, const loco::Stride< 2 > *stride, const ShapeDescription &ifm, const ShapeDescription &ofm)
TFLTensorIndex get_tensor_index(loco::Node *node)
circle::ActivationFunctionType to_circle_actfunc(locoex::FusedActFunc func)
bool isNHWC(Permutation *perm)
const T * data(const std::vector< T, Alloc > &v)
std::vector< loco::Node * > postorder_traversal(const std::vector< loco::Node * > &roots)
Generate postorder traversal sequence starting from "roots".
std::vector< Node * > output_nodes(Graph *)
NodeShape shape_get(const Node *node)
std::vector< int32_t > _dims
static ShapeDescription get(loco::Node *node)
uint32_t registerBuiltinOpcode(circle::BuiltinOperator builtin_code)
if opcode is not registered in table of opcodes add it
std::vector< flatbuffers::Offset< circle::Tensor > > _tensors
std::vector< flatbuffers::Offset< circle::Operator > > _operators
std::vector< flatbuffers::Offset< circle::Buffer > > _buffers
uint32_t registerCustomOpcode(const std::string &custom_op)
virtual T visit(TFLNode *)
Default fallback.