2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "NNAPIConvert.h"
21 using namespace onert::ir;
23 DataType NNAPIConvert::getDataType(OperandCode type)
27 case ANEURALNETWORKS_FLOAT32:
28 case ANEURALNETWORKS_TENSOR_FLOAT32:
29 return DataType::FLOAT32;
30 case ANEURALNETWORKS_INT32:
31 case ANEURALNETWORKS_TENSOR_INT32:
32 return DataType::INT32;
33 case ANEURALNETWORKS_UINT32:
34 return DataType::UINT32;
35 case ANEURALNETWORKS_TENSOR_QUANT8_ASYMM:
36 return DataType::QUANT_UINT8_ASYMM;
37 case ANEURALNETWORKS_TENSOR_QUANT8_SYMM:
38 return DataType::QUANT_INT8_SYMM;
39 case ANEURALNETWORKS_BOOL:
40 case ANEURALNETWORKS_TENSOR_BOOL8:
41 return DataType::BOOL8;
42 case ANEURALNETWORKS_TENSOR_FLOAT16:
43 case ANEURALNETWORKS_FLOAT16:
44 return DataType::FLOAT16;
45 case ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL:
46 return DataType::QUANT_INT8_SYMM_PER_CHANNEL;
47 case ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED:
48 return DataType::QUANT_INT8_ASYMM;
50 throw std::runtime_error("Unsupported type");
54 TypeInfo NNAPIConvert::getTypeInfo(const ANeuralNetworksOperandType *type)
56 return TypeInfo(getDataType((OperandCode)(type->type)), type->scale, type->zeroPoint);
59 Shape NNAPIConvert::getShape(const ANeuralNetworksOperandType *type)
61 Shape shape(type->dimensionCount);
63 for (uint32_t axis = 0; axis < type->dimensionCount; ++axis)
65 shape.dim(axis) = type->dimensions[axis];
71 size_t NNAPIConvert::calculateSizeFromType(const ANeuralNetworksOperandType *type)
73 auto shape = getShape(type);
74 auto data_type = getDataType((OperandCode)(type->type));
76 return shape.num_elements() * sizeOfDataType(data_type);
79 Activation NNAPIConvert::getFusedActivation(FuseCode act)
83 case ANEURALNETWORKS_FUSED_NONE:
84 return Activation::NONE;
85 case ANEURALNETWORKS_FUSED_RELU:
86 return Activation::RELU;
87 case ANEURALNETWORKS_FUSED_RELU1:
88 return Activation::RELU1;
89 case ANEURALNETWORKS_FUSED_RELU6:
90 return Activation::RELU6;
92 throw std::runtime_error("Unsupported activation type");
96 PaddingType NNAPIConvert::getPaddingType(PaddingCode type)
100 case ANEURALNETWORKS_PADDING_SAME:
101 return PaddingType::SAME;
102 case ANEURALNETWORKS_PADDING_VALID:
103 return PaddingType::VALID;
105 throw std::runtime_error("Unsupported type");