2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __SERIALIZED_DATA_H__
18 #define __SERIALIZED_DATA_H__
20 #include <mio/circle/schema_generated.h>
22 #include <luci/IR/CircleNodes.h>
26 #include <unordered_map>
34 circle::BuiltinOperator opcode;
35 std::string custom_code{""};
38 bool operator==(const OpCode &rhs) const
40 if (opcode == circle::BuiltinOperator_CUSTOM)
42 return custom_code == rhs.custom_code;
46 return opcode == rhs.opcode;
56 template <> struct hash<luci::OpCode>
58 size_t operator()(const luci::OpCode &x) const { return hash<int>()(x.opcode); }
67 * @brief Record the information of T/F Lite SubGraph and its mapping to loco
69 struct SubGraphContext
71 /// @brief SubGraph name
73 /// @brief SubGraph input tensor id
74 std::vector<int32_t> _inputs;
75 /// @brief SubGraph output tensor id
76 std::vector<int32_t> _outputs;
77 /// @brief DataFormat for SubGraph
78 circle::DataFormat _data_format{circle::DataFormat::DataFormat_CHANNELS_LAST};
81 // Prerequisites for circle::Model object creation
82 struct SerializedModelData final
84 SerializedModelData() = default;
85 SerializedModelData(const SerializedModelData &) = delete;
87 std::unordered_map<OpCode, uint32_t> _operator_codes;
88 std::vector<flatbuffers::Offset<circle::Buffer>> _buffers;
90 // This is used for removing buffers with same values
91 std::map<luci::CircleConst *, uint32_t> _cached_buffer_id;
94 * @brief if opcode is not registered in table of opcodes add it
96 * @return idx of opcode in table of opcodes (see schema)
98 uint32_t registerBuiltinOpcode(circle::BuiltinOperator builtin_code, const int32_t op_version);
99 uint32_t registerCustomOpcode(const std::string &custom_op);
102 // Prerequisites for circle::Model object creation
103 struct SerializedGraphData final : public SubGraphContext
105 SerializedGraphData() = default;
106 SerializedGraphData(const SerializedModelData &) = delete;
108 std::vector<flatbuffers::Offset<circle::Operator>> _operators;
109 std::vector<flatbuffers::Offset<circle::Tensor>> _tensors;
114 #endif // __SERIALIZED_DATA_H__