ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Convert.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "Convert.h"
19
20#include <cassert>
21#include <stdexcept>
22
23namespace moco
24{
25namespace onnx
26{
27
28loco::DataType as_loco_datatype(const int32_t tensor_dtype)
29{
30 switch (tensor_dtype)
31 {
32 case 0: // UNDEFINED
33 return loco::DataType::Unknown;
34 case 1: // FLOAT
35 return loco::DataType::FLOAT32;
36 case 2: // UINT8
37 return loco::DataType::U8;
38 case 3: // INT8
39 return loco::DataType::S8;
40 case 4: // UINT16
41 return loco::DataType::U16;
42 case 5: // INT16
43 return loco::DataType::S16;
44 case 6: // INT32
45 return loco::DataType::S32;
46 case 7: // INT64
47 return loco::DataType::S64;
48 case 10: // FLOAT16
49 return loco::DataType::FLOAT16;
50 case 11: // DOUBLE
51 return loco::DataType::FLOAT64;
52 case 12: // UINT32
53 return loco::DataType::U32;
54 case 13: // UINT64
55 return loco::DataType::U64;
56
57 case 8: // STRING
58 case 9: // BOOL
59 case 14: // COMPLEX64
60 case 15: // COMPLEX128
61 case 16: // BFLOAT16
62 default:
63 break;
64 }
65 throw std::runtime_error{"Unsupported onnx dtype"};
66}
67
68std::string tensor_dtype_as_string(const int32_t tensor_dtype)
69{
70 switch (tensor_dtype)
71 {
72 case 0: // UNDEFINED
73 return "UNDEFINED";
74 case 1: // FLOAT
75 return "FLOAT";
76 case 2: // UINT8
77 return "UINT8";
78 case 3: // INT8
79 return "INT8";
80 case 4: // UINT16
81 return "UINT16";
82 case 5: // INT16
83 return "INT16";
84 case 6: // INT32
85 return "INT32";
86 case 7: // INT64
87 return "INT64";
88 case 8: // STRING
89 return "STRING";
90 case 9: // BOOL
91 return "BOOL";
92 case 10: // FLOAT16
93 return "FLOAT16";
94 case 11: // DOUBLE
95 return "DOUBLE";
96 case 12: // UINT32
97 return "UINT32";
98 case 13: // UINT64
99 return "UINT64";
100 case 14: // COMPLEX64
101 return "COMPLEX64";
102 case 15: // COMPLEX128
103 return "COMPLEX128";
104 case 16: // BFLOAT16
105 return "BFLOAT16";
106 default:
107 break;
108 }
109 throw std::runtime_error{"Unsupported onnx dtype"};
110}
111
112} // namespace onnx
113} // namespace moco
DataType
"scalar" value type
Definition DataType.h:27
std::string tensor_dtype_as_string(const int32_t tensor_dtype)
Definition Convert.cpp:68
loco::DataType as_loco_datatype(const int32_t tensor_dtype)
Definition Convert.cpp:28
Definition Log.h:23