• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2024 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 
17 #include "src/litert/delegate/nnrt/nnrt_utils.h"
18 #include <unordered_map>
19 
20 namespace mindspore::lite {
CastToNNRtFormat(Format format)21 OH_NN_Format CastToNNRtFormat(Format format) {
22   const std::unordered_map<Format, OH_NN_Format> kFormatMap = {
23     {Format::NCHW, OH_NN_FORMAT_NCHW},
24     {Format::NHWC, OH_NN_FORMAT_NHWC},
25   };
26   auto iter = kFormatMap.find(format);
27   if (iter == kFormatMap.end()) {
28     return OH_NN_FORMAT_NONE;
29   }
30   return iter->second;
31 }
32 
CastToNNRtDataType(TypeId data_type)33 OH_NN_DataType CastToNNRtDataType(TypeId data_type) {
34   OH_NN_DataType oh_data_type;
35   switch (data_type) {
36     case TypeId::kMetaTypeBegin:
37     case TypeId::kMetaTypeType:
38     case TypeId::kMetaTypeAny:
39     case TypeId::kMetaTypeObject:
40     case TypeId::kMetaTypeTypeType:
41     case TypeId::kMetaTypeProblem:
42     case TypeId::kMetaTypeExternal:
43     case TypeId::kMetaTypeNone:
44     case TypeId::kMetaTypeNull:
45     case TypeId::kMetaTypeEllipsis:
46     case TypeId::kMetaTypeEnd:
47     case TypeId::kObjectTypeNumber:
48     case TypeId::kObjectTypeString:
49     case TypeId::kObjectTypeList:
50     case TypeId::kObjectTypeTuple:
51     case TypeId::kObjectTypeSlice:
52     case TypeId::kObjectTypeKeyword:
53     case TypeId::kObjectTypeTensorType:
54     case TypeId::kObjectTypeRowTensorType:
55     case TypeId::kObjectTypeCOOTensorType:
56     case TypeId::kObjectTypeUndeterminedType:
57     case TypeId::kObjectTypeClass:
58     case TypeId::kObjectTypeDictionary:
59     case TypeId::kObjectTypeFunction:
60     case TypeId::kObjectTypeJTagged:
61     case TypeId::kObjectTypeSymbolicKeyType:
62     case TypeId::kObjectTypeEnvType:
63     case TypeId::kObjectTypeRefKey:
64     case TypeId::kObjectTypeRef:
65     case TypeId::kObjectTypeEnd:
66       oh_data_type = OH_NN_UNKNOWN;
67       break;
68     case TypeId::kNumberTypeBool:
69       oh_data_type = OH_NN_BOOL;
70       break;
71     case TypeId::kNumberTypeInt8:
72       oh_data_type = OH_NN_INT8;
73       break;
74     case TypeId::kNumberTypeInt16:
75       oh_data_type = OH_NN_INT16;
76       break;
77     case TypeId::kNumberTypeInt32:
78       oh_data_type = OH_NN_INT32;
79       break;
80     case TypeId::kNumberTypeInt64:
81       oh_data_type = OH_NN_INT64;
82       break;
83     case TypeId::kNumberTypeUInt8:
84       oh_data_type = OH_NN_UINT8;
85       break;
86     case TypeId::kNumberTypeUInt16:
87       oh_data_type = OH_NN_UINT16;
88       break;
89     case TypeId::kNumberTypeUInt32:
90       oh_data_type = OH_NN_UINT32;
91       break;
92     case TypeId::kNumberTypeUInt64:
93       oh_data_type = OH_NN_UINT64;
94       break;
95     case TypeId::kNumberTypeFloat16:
96       oh_data_type = OH_NN_FLOAT16;
97       break;
98     case TypeId::kNumberTypeFloat32:
99       oh_data_type = OH_NN_FLOAT32;
100       break;
101     case TypeId::kNumberTypeFloat64:
102       oh_data_type = OH_NN_FLOAT64;
103       break;
104     default: {
105       oh_data_type = OH_NN_UNKNOWN;
106     }
107   }
108   return oh_data_type;
109 }
110 }  // namespace mindspore::lite
111