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 #include "coder/utils/type_cast.h" 17 #include <string> 18 19 namespace mindspore::lite::micro { EnumNameDataType(TypeId type)20std::string EnumNameDataType(TypeId type) { 21 switch (type) { 22 case kNumberTypeInt: 23 return "kNumberTypeInt"; 24 case kNumberTypeInt8: 25 return "kNumberTypeInt8"; 26 case kNumberTypeInt16: 27 return "kNumberTypeInt16"; 28 case kNumberTypeInt32: 29 return "kNumberTypeInt32"; 30 case kNumberTypeInt64: 31 return "kNumberTypeInt64"; 32 case kNumberTypeUInt: 33 return "kNumberTypeUInt"; 34 case kNumberTypeUInt8: 35 return "kNumberTypeUInt8"; 36 case kNumberTypeUInt16: 37 return "kNumberTypeUInt16"; 38 case kNumberTypeUInt32: 39 return "kNumberTypeUInt32"; 40 case kNumberTypeFloat: 41 case kNumberTypeFloat32: 42 return "kNumberTypeFloat32"; 43 case kNumberTypeFloat16: 44 return "kNumberTypeFloat16"; 45 case kNumberTypeFloat64: 46 return "kNumberTypeFloat64"; 47 case kTypeUnknown: 48 return "kTypeUnknown"; 49 default: 50 return "unsupported"; 51 } 52 } 53 GetTensorDataType(TypeId type)54std::string GetTensorDataType(TypeId type) { 55 switch (type) { 56 case kNumberTypeFloat: 57 case kNumberTypeFloat32: 58 return "float "; 59 case kNumberTypeInt8: 60 return "int8_t "; 61 case kNumberTypeInt16: 62 return "int16_t "; 63 case kNumberTypeInt: 64 case kNumberTypeInt32: 65 return "int32_t "; 66 case kNumberTypeUInt8: 67 return "uint8_t "; 68 case kNumberTypeUInt32: 69 return "uint32_t "; 70 case kNumberTypeInt64: 71 return "int64_t "; 72 default: 73 MS_LOG(ERROR) << "unsupported data type: " << EnumNameDataType(type); 74 return ""; 75 } 76 } 77 EnumMicroTensorFormat(mindspore::Format format)78std::string EnumMicroTensorFormat(mindspore::Format format) { 79 switch (format) { 80 case mindspore::NHWC: 81 return "Format_NHWC"; 82 case mindspore::NCHW: 83 return "Format_NCHW"; 84 case mindspore::HWKC: 85 return "Format_HWKC"; 86 case mindspore::HWCK: 87 return "Format_HWCK"; 88 case mindspore::KCHW: 89 return "Format_KCHW"; 90 case mindspore::CKHW: 91 return "Format_CKHW"; 92 case mindspore::NC4HW4: 93 return "Format_NC4HW4"; 94 default: 95 MS_LOG(ERROR) << "unsupported format: " << schema::EnumNameFormat(static_cast<schema::Format>(format)); 96 return "Format_NUM_OF_FORMAT"; 97 } 98 } 99 EnumMicroTensorDataType(TypeId type)100std::string EnumMicroTensorDataType(TypeId type) { 101 switch (type) { 102 case kNumberTypeFloat: 103 case kNumberTypeFloat32: 104 return "DataType_DT_FLOAT"; 105 case kNumberTypeInt8: 106 return "DataType_DT_INT8"; 107 case kNumberTypeInt: 108 case kNumberTypeInt32: 109 return "DataType_DT_INT32"; 110 case kNumberTypeUInt8: 111 return "DataType_DT_UINT8"; 112 case kNumberTypeInt16: 113 return "DataType_DT_INT16"; 114 case kNumberTypeUInt32: 115 return "DataType_DT_UINT32"; 116 case kNumberTypeInt64: 117 return "DataType_DT_INT64"; 118 case kNumberTypeUInt16: 119 return "DataType_DT_UINT16"; 120 case kNumberTypeFloat16: 121 MS_LOG(WARNING) << "unsupported data type: kNumberTypeFloat16"; 122 return "DataType_DT_FLOAT16"; 123 default: 124 MS_LOG(WARNING) << "unsupported data type: " << type << ", reference: " << kNumberTypeInt; 125 return "DataType_DT_UNDEFINED"; 126 } 127 } 128 EnumNameTarget(Target target)129std::string EnumNameTarget(Target target) { 130 switch (target) { 131 case kX86: 132 return "kX86"; 133 case kARM32M: 134 return "kARM32M"; 135 case kARM32A: 136 return "kARM32A"; 137 case kARM64: 138 return "kARM64"; 139 case kAllTargets: 140 return "kAllTargets"; 141 default: 142 return "kTargetUnknown"; 143 } 144 } 145 } // namespace mindspore::lite::micro 146