ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Helper.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 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 "mio_circle/Helper.h"
18
19#include <sstream>
20
21namespace mio
22{
23namespace circle
24{
25
26bool is_valid(const ::circle::OperatorCode *opcode)
27{
28 ::circle::BuiltinOperator code = opcode->builtin_code();
29 return (::circle::BuiltinOperator_MIN <= code && code <= ::circle::BuiltinOperator_MAX);
30}
31
32bool is_custom(const ::circle::OperatorCode *opcode)
33{
34 ::circle::BuiltinOperator code = opcode->builtin_code();
35 return (code == ::circle::BuiltinOperator_CUSTOM);
36}
37
38std::string opcode_name(const ::circle::OperatorCode *opcode)
39{
40 assert(opcode);
41
42 if (!is_valid(opcode))
43 {
44 std::ostringstream oss;
45 oss << "(invalid)";
46 return oss.str();
47 }
48
49 if (is_custom(opcode))
50 {
51 if (!opcode->custom_code())
52 return "(invalid custom)";
53
54 std::string custom_op = "CUSTOM(";
55 custom_op += opcode->custom_code()->c_str();
56 custom_op += ")";
57 return custom_op;
58 }
59
60 ::circle::BuiltinOperator code = opcode->builtin_code();
61 return ::circle::EnumNameBuiltinOperator(code);
62}
63
64const char *tensor_type(const ::circle::Tensor *tensor)
65{
66 return ::circle::EnumNameTensorType(tensor->type());
67}
68
69const char *tensor_name(const ::circle::Tensor *tensor)
70{
71 static const char *kEmptyTensorName = "(noname)";
72
73 auto name = tensor->name();
74 if (name)
75 return name->c_str();
76
77 return kEmptyTensorName;
78}
79
80} // namespace circle
81} // namespace mio
const char * tensor_name(const ::circle::Tensor *tensor)
Definition Helper.cpp:69
std::string opcode_name(const ::circle::OperatorCode *opcode)
Definition Helper.cpp:38
const char * tensor_type(const ::circle::Tensor *tensor)
Definition Helper.cpp:64
bool is_custom(const ::circle::OperatorCode *opcode)
Definition Helper.cpp:32
bool is_valid(const ::circle::OperatorCode *opcode)
Definition Helper.cpp:26
Definition Helper.h:23