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 __CIRCLE_MODEL_H__
18 #define __CIRCLE_MODEL_H__
20 #include <mio/tflite/schema_generated.h>
21 #include <mio/circle/schema_generated.h>
29 namespace tflite2circle
32 using FlatBufBuilder = std::unique_ptr<flatbuffers::FlatBufferBuilder>;
34 struct OperatorCodeLink
36 using TFL = flatbuffers::Offset<::tflite::OperatorCode>;
37 using CIR = flatbuffers::Offset<::circle::OperatorCode>;
42 using TFL = flatbuffers::Offset<::tflite::SubGraph>;
43 using CIR = flatbuffers::Offset<::circle::SubGraph>;
48 using TFL = flatbuffers::Offset<::tflite::Buffer>;
49 using CIR = flatbuffers::Offset<::circle::Buffer>;
52 struct MetaDataBufferLink
58 template <typename T> class Offset
61 using TFLFlatBufVec = flatbuffers::Vector<typename T::TFL>;
62 using CIRFlatBufVecOffset = flatbuffers::Offset<flatbuffers::Vector<typename T::CIR>>;
63 using SignatureDefs = flatbuffers::Vector<flatbuffers::Offset<::tflite::SignatureDef>>;
66 Offset(void) = delete;
67 Offset(FlatBufBuilder &fb) : _fb{fb} {};
70 void set_signature_defs(const SignatureDefs *offset) { _tfl_signature_def_offsets = offset; }
73 void build(const TFLFlatBufVec *tflite_flatbuffer_vec);
76 CIRFlatBufVecOffset offset(void) const { return _circle_flatbuffer_vec_offset; }
80 CIRFlatBufVecOffset _circle_flatbuffer_vec_offset;
81 // TODO revise this when Circle supports SignatureDef
82 const SignatureDefs *_tfl_signature_def_offsets = nullptr;
88 using Description = flatbuffers::Offset<flatbuffers::String>;
91 CircleModel(void) = delete;
92 CircleModel(FlatBufBuilder &fb);
95 void load_offsets(const tflite::Model *tfl_model);
96 void model_build(void) const;
97 const char *base(void) const;
98 size_t size(void) const;
102 Description _description;
104 std::unique_ptr<Offset<OperatorCodeLink>> _operator_codes_offset;
105 std::unique_ptr<Offset<SubGraphLink>> _subGraphs_offset;
106 std::unique_ptr<Offset<BufferLink>> _buffers_offset;
107 std::unique_ptr<Offset<MetaDataBufferLink>> _metadata_buffer_offset;
110 } // namespace tflite2circle
112 #endif // __CIRCLE_MODEL_H__