2 * Copyright (c) 2023 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 __MIO_CIRCLE05_READER_H__
18 #define __MIO_CIRCLE05_READER_H__
20 #include <mio/circle/schema_generated.h>
26 // NOTE Reader class originated from circledump and for circle-tensordump
27 // where this class has more work to be done for stability
28 // as the tools are for developers not customores.
36 * @brief Loads Circle file and provides helpers to access attributes
41 using CircleSubGraphs_t = flatbuffers::Vector<flatbuffers::Offset<::circle::SubGraph>>;
42 using CircleBuffers_t = flatbuffers::Vector<flatbuffers::Offset<::circle::Buffer>>;
43 using CircleTensors_t = flatbuffers::Vector<flatbuffers::Offset<::circle::Tensor>>;
44 using CircleOperators_t = flatbuffers::Vector<flatbuffers::Offset<::circle::Operator>>;
45 using CircleMetadata_t = flatbuffers::Vector<flatbuffers::Offset<::circle::Metadata>>;
46 using CircleSignatureDef_t = flatbuffers::Vector<flatbuffers::Offset<::circle::SignatureDef>>;
49 Reader(const ::circle::Model *model);
54 uint32_t version() const { return _version; }
56 const std::vector<const ::circle::OperatorCode *> &opcodes() { return _op_codes; }
57 const CircleBuffers_t *buffers() { return _buffers; }
58 const CircleTensors_t *tensors() { return _tensors; }
59 const CircleOperators_t *operators() { return _operators; }
60 const std::vector<int32_t> &inputs() const { return _inputs; }
61 const std::vector<int32_t> &outputs() const { return _outputs; }
62 const ::circle::DataFormat &data_format() const { return _data_format; }
63 const CircleMetadata_t *metadata() const { return _metadata; }
64 const CircleSignatureDef_t *signature_defs() const { return _signature_defs; }
66 uint32_t num_subgraph() const { return _subgraphs->Length(); }
68 size_t buffer_info(uint32_t buf_idx, const uint8_t **buff_data);
69 ::circle::BuiltinOperator builtin_code(const ::circle::Operator *op) const;
70 std::string opcode_name(const ::circle::Operator *op) const;
71 std::vector<int32_t> outputs(const ::circle::Operator *op) const;
72 std::string tensor_name(const ::circle::Tensor *tensor) const;
73 std::string tensor_dtype(const ::circle::Tensor *tensor) const;
76 bool select_subgraph(uint32_t subgraph);
77 const std::string &subgraph_name(void) const { return _subgraph_name; }
78 uint32_t subgraph_index(void) const { return _subgraph_index; }
83 const CircleSubGraphs_t *_subgraphs{nullptr};
84 const CircleBuffers_t *_buffers{nullptr};
85 const CircleTensors_t *_tensors{nullptr};
86 const CircleOperators_t *_operators{nullptr};
87 const CircleMetadata_t *_metadata{nullptr};
88 const CircleSignatureDef_t *_signature_defs{nullptr};
90 uint32_t _subgraph_index = 0;
91 std::string _subgraph_name;
92 std::vector<const ::circle::OperatorCode *> _op_codes;
93 std::vector<int32_t> _inputs;
94 std::vector<int32_t> _outputs;
95 ::circle::DataFormat _data_format = ::circle::DataFormat::DataFormat_CHANNELS_FIRST;
101 #endif // __MIO_CIRCLE05_READER_H__