ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Dump.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 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#include "Dump.h"
18
19#include <mio_circle/Helper.h>
20#include <mio_circle/Reader.h>
21
22#include <ostream>
23
24namespace
25{
26
27void dump_ops(std::ostream &os, mio::circle::Reader &reader, const cirops::DumpOption &option)
28{
29 auto ops = reader.operators();
30 for (uint32_t i = 0; i < ops->size(); ++i)
31 {
32 const auto op = ops->Get(i);
33 const auto op_name = reader.opcode_name(op);
34
35 if (option.all_graphs)
36 {
37 // NOTE all_graphs is false for now
38 // TODO check using '$' as split key
39 os << i << "$";
40 }
41
42 if (option.codes)
43 {
44 const auto op_name = reader.opcode_name(op);
45 os << op_name;
46 }
47 if (option.names)
48 {
49 // TODO multiple outputs?
50 const auto tensors = reader.tensors();
51 const auto output_tensors = reader.outputs(op);
52 const auto output = output_tensors.at(0);
53 const auto tensor = tensors->Get(output);
54 const std::string name = mio::circle::tensor_name(tensor);
55 if (option.codes)
56 {
57 os << ",";
58 }
59 os << name;
60 }
61 os << std::endl;
62 }
63}
64
65} // namespace
66
67namespace cirops
68{
69
70void DumpOperators::run(std::ostream &os, const circle::Model *model, const DumpOption &option)
71{
72 mio::circle::Reader reader(model);
73
74 const uint32_t subgraph_size = reader.num_subgraph();
75 for (uint32_t g = 0; g < subgraph_size; g++)
76 {
77 reader.select_subgraph(g);
78 dump_ops(os, reader, option);
79
80 if (!option.all_graphs)
81 break;
82 }
83}
84
85} // namespace cirops
void run(std::ostream &os, const circle::Model *model, const DumpOption &option)
Definition Dump.cpp:70
Loads Circle file and provides helpers to access attributes.
Definition Reader.h:39
const CircleTensors_t * tensors()
Definition Reader.h:58
std::string opcode_name(const ::circle::Operator *op) const
Definition Reader.cpp:85
uint32_t num_subgraph() const
Definition Reader.h:66
const std::vector< int32_t > & outputs() const
Definition Reader.h:61
const CircleOperators_t * operators()
Definition Reader.h:59
bool select_subgraph(uint32_t subgraph)
Definition Reader.cpp:116
const char * tensor_name(const ::circle::Tensor *tensor)
Definition Helper.cpp:69
bool all_graphs
Definition Dump.h:31