aa8524a55af9a15b040799eb263d314104081a2f
[platform/core/ml/nnfw.git] / compiler / luci / service / src / CircleTypeInference.cpp
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 "luci/Service/CircleTypeInference.h"
18
19 #include <loco.h>
20 #include <loco/Service/TypeInference.h>
21
22 #include <mio/circle/schema_generated.h>
23 #include <oops/InternalExn.h>
24
25 #include <type_traits>
26
27 namespace
28 {
29
30 circle::TensorType translateLocoTypeToCircle(loco::DataType dtype)
31 {
32   switch (dtype)
33   {
34     case loco::DataType::U8:
35       return circle::TensorType_UINT8;
36     //  case loco::DataType::U16: unsupported
37     //  case loco::DataType::U32: unsupported
38     //  case loco::DataType::U64: unsupported
39     case loco::DataType::S8:
40       return circle::TensorType_INT8;
41     case loco::DataType::S16:
42       return circle::TensorType_INT16;
43     case loco::DataType::S32:
44       return circle::TensorType_INT32;
45     case loco::DataType::S64:
46       return circle::TensorType_INT64;
47     case loco::DataType::FLOAT16:
48       return circle::TensorType_FLOAT16;
49     case loco::DataType::FLOAT32:
50       return circle::TensorType_FLOAT32;
51     //  case loco::DataType::FLOAT64: unsupported
52     case loco::DataType::BOOL:
53       return circle::TensorType_BOOL;
54     default:
55       break;
56   }
57
58   INTERNAL_EXN_V("Invalid loco dtype", oops::to_uint32(dtype));
59 }
60
61 } // namespace
62
63 namespace luci
64 {
65
66 circle::TensorType TypeInference::get(loco::Node *node)
67 {
68   assert(loco::dtype_known(node));
69   return translateLocoTypeToCircle(loco::dtype_get(node));
70 }
71
72 } // namespace luci