1 /**
2 * Copyright 2021 Huawei Technologies Co., Ltd
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 #ifndef MINDSPORE_LITE_MICRO_CODER_UTILS_TYPE_CAST_H_
17 #define MINDSPORE_LITE_MICRO_CODER_UTILS_TYPE_CAST_H_
18
19 #include <map>
20 #include <limits>
21 #include <vector>
22 #include <string>
23 #include <typeinfo>
24 #include <typeindex>
25 #include "include/errorcode.h"
26 #include "securec/include/securec.h"
27 #include "src/tensor.h"
28 #include "nnacl/int8/quantize.h"
29 #include "coder/config.h"
30
31 namespace mindspore::lite::micro {
32 std::string EnumNameDataType(TypeId type);
33
34 std::string GetTensorDataType(TypeId type);
35
36 std::string EnumMicroTensorFormat(mindspore::Format format);
37
38 std::string EnumMicroTensorDataType(TypeId type);
39
40 std::string EnumNameTarget(Target target);
41
42 /**
43 * @tparam T
44 * @param t, basic data type variable, or tensor
45 * @return, data type name
46 */
47 template <typename T>
GetVariableTypeName()48 std::string GetVariableTypeName() {
49 std::map<std::type_index, std::string> types_name = {{std::type_index(typeid(int)), "int"},
50 {std::type_index(typeid(int32_t)), "int32_t"},
51 {std::type_index(typeid(int16_t)), "int16_t"},
52 {std::type_index(typeid(int8_t)), "int8_t"},
53 {std::type_index(typeid(uint8_t)), "uint8_t"},
54 {std::type_index(typeid(float)), "float"},
55 {std::type_index(typeid(double)), "double"},
56 {std::type_index(typeid(::QuantArg)), "QuantArg"},
57 {std::type_index(typeid(void *)), "void *"},
58 {std::type_index(typeid(std::string)), "float *"},
59 {std::type_index(typeid(int *)), "int *"},
60 {std::type_index(typeid(int32_t *)), "int32_t *"},
61 {std::type_index(typeid(int16_t *)), "int16_t *"},
62 {std::type_index(typeid(int8_t *)), "int8_t *"},
63 {std::type_index(typeid(uint8_t *)), "uint8_t *"},
64 {std::type_index(typeid(float *)), "float *"}};
65 auto item = types_name.find(std::type_index(typeid(T)));
66 if (item != types_name.end()) {
67 return item->second;
68 }
69 MS_LOG(ERROR) << "unsupported variable type";
70 return "";
71 }
72 } // namespace mindspore::lite::micro
73
74 #endif // MINDSPORE_LITE_MICRO_CODER_UTILS_TYPE_CAST_H_
75