9eedcd21a61cbf6bb656468b8eb70b88177ca21f
[platform/core/ml/nnfw.git] / runtime / onert / core / src / ir / DataType.cc
1 /*
2  * Copyright (c) 2020 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 "ir/DataType.h"
18
19 #include <stdexcept>
20 #include <Half.h>
21
22 using float16 = Half;
23
24 namespace onert
25 {
26 namespace ir
27 {
28
29 size_t sizeOfDataType(DataType data_type)
30 {
31   switch (data_type)
32   {
33     case DataType::FLOAT32:
34       return sizeof(float);
35     case DataType::INT32:
36       return sizeof(int32_t);
37     case DataType::UINT32:
38       return sizeof(uint32_t);
39     case DataType::BOOL8:
40     case DataType::QUANT_UINT8_ASYMM:
41     case DataType::UINT8:
42       return sizeof(uint8_t);
43     case DataType::QUANT_INT8_SYMM:
44     case DataType::QUANT_INT8_ASYMM:
45       return sizeof(int8_t);
46     case DataType::FLOAT16:
47       return sizeof(float16);
48     case DataType::INT64:
49       return sizeof(int64_t);
50     case DataType::QUANT_INT16_ASYMM:
51       return sizeof(int16_t);
52     default:
53       throw std::runtime_error{"Unsupported type size"};
54   }
55 }
56
57 } // namespace ir
58 } // namespace onert