ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleExporterUtils.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __CIRCLE_EXPORTER_UTILS_H__
18#define __CIRCLE_EXPORTER_UTILS_H__
19
20#include "ExporterUtils.h"
21
22#include "circle_schema_generated.h"
23
24#include "Dialect/IR/TFLNodes.h"
25
26#include <loco.h>
27
28#include <unordered_map>
29
30namespace exo
31{
32namespace circle_detail
33{
34
35struct OpCode
36{
37 circle::BuiltinOperator opcode;
38
39 bool operator==(const OpCode &rhs) const { return opcode == rhs.opcode; }
40};
41
42} // namespace circle_detail
43} // namespace exo
44
45namespace exo
46{
47
48circle::ActivationFunctionType to_circle_actfunc(locoex::FusedActFunc func);
49
50} // namespace exo
51
52namespace std
53{
54
55template <> struct hash<exo::circle_detail::OpCode>
56{
57 size_t operator()(const exo::circle_detail::OpCode &x) const { return hash<int>()(x.opcode); }
58};
59
60} // namespace std
61
62namespace exo
63{
64namespace circle_detail
65{
66
71{
73 std::vector<int32_t> _inputs;
75 std::vector<int32_t> _outputs;
77 circle::DataFormat _data_format{circle::DataFormat::DataFormat_CHANNELS_LAST};
78};
79
80// Prerequisites for circle::Model object creation
82{
85
86 std::unordered_map<OpCode, uint32_t> _operator_codes;
87 std::unordered_map<OpCode, std::string> _custom_operator_codes;
88 std::vector<flatbuffers::Offset<circle::Operator>> _operators;
89 std::vector<flatbuffers::Offset<circle::Tensor>> _tensors;
90 std::vector<flatbuffers::Offset<circle::Buffer>> _buffers;
91
92 // Graph input and output names
93 std::unordered_map<loco::Pull *, std::string> _pull_to_name;
94 std::unordered_map<loco::Push *, std::string> _push_to_name;
95
101 uint32_t registerBuiltinOpcode(circle::BuiltinOperator builtin_code);
102 uint32_t registerCustomOpcode(const std::string &custom_op);
103};
104
105circle::Padding getOpPadding(const loco::Padding2D *pad, const loco::Stride<2> *stride,
106 const ShapeDescription &ifm, const ShapeDescription &ofm);
107circle::Padding getOpPadding(const locoex::Padding pad);
108
111
112using TFLTensorIndex = int32_t;
113
114void set_tensor_index(loco::Node *node, const TFLTensorIndex &tensor_id);
116
117} // namespace circle_detail
118} // namespace exo
119
120#endif // __TFL_EXPORTER_UTILS_H__
A neural network graph.
Definition Graph.h:161
Logical unit of computation.
Definition Node.h:54
Stride configuration for N-dimensional spatial operations.
Definition Stride.h:28
void registerGraphIOName(loco::Graph *graph, SerializedModelData &gd)
Register graph input and output names to SerializedModelData.
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)
void set_tensor_index(loco::Node *node, const TFLTensorIndex &tensor_id)
circle::ActivationFunctionType to_circle_actfunc(locoex::FusedActFunc func)
circle::BuiltinOperator opcode
bool operator==(const OpCode &rhs) const
SerializedModelData(const SerializedModelData &)=delete
uint32_t registerBuiltinOpcode(circle::BuiltinOperator builtin_code)
if opcode is not registered in table of opcodes add it
std::unordered_map< loco::Pull *, std::string > _pull_to_name
std::unordered_map< OpCode, std::string > _custom_operator_codes
std::vector< flatbuffers::Offset< circle::Tensor > > _tensors
std::vector< flatbuffers::Offset< circle::Operator > > _operators
std::vector< flatbuffers::Offset< circle::Buffer > > _buffers
std::unordered_map< loco::Push *, std::string > _push_to_name
std::unordered_map< OpCode, uint32_t > _operator_codes
uint32_t registerCustomOpcode(const std::string &custom_op)
Record the information of T/F Lite SubGraph and its mapping to loco.
std::vector< int32_t > _outputs
SubGraph output tensor id.
circle::DataFormat _data_format
@DataFormat for SubGraph
std::vector< int32_t > _inputs
SubGraph input tensor id.
size_t operator()(const exo::circle_detail::OpCode &x) const