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;
43 throw std::runtime_error("Unsupported type");
47 TypeInfo NNAPIConvert::getTypeInfo(const ANeuralNetworksOperandType *type)
49 return TypeInfo(getDataType((OperandCode)(type->type)), type->scale, type->zeroPoint);
52 Shape NNAPIConvert::getShape(const ANeuralNetworksOperandType *type)
54 Shape shape(type->dimensionCount);
56 for (uint32_t axis = 0; axis < type->dimensionCount; ++axis)
58 shape.dim(axis) = type->dimensions[axis];
64 size_t NNAPIConvert::calculateSizeFromType(const ANeuralNetworksOperandType *type)
66 auto shape = getShape(type);
67 auto data_type = getDataType((OperandCode)(type->type));
69 return shape.num_elements() * sizeOfDataType(data_type);
72 Activation NNAPIConvert::getFusedActivation(FuseCode act)
76 case ANEURALNETWORKS_FUSED_NONE:
77 return Activation::NONE;
78 case ANEURALNETWORKS_FUSED_RELU:
79 return Activation::RELU;
80 case ANEURALNETWORKS_FUSED_RELU1:
81 return Activation::RELU1;
82 case ANEURALNETWORKS_FUSED_RELU6:
83 return Activation::RELU6;
85 throw std::runtime_error("Unsupported activation type");
89 PaddingType NNAPIConvert::getPaddingType(PaddingCode type)
93 case ANEURALNETWORKS_PADDING_SAME:
94 return PaddingType::SAME;
95 case ANEURALNETWORKS_PADDING_VALID:
96 return PaddingType::VALID;
98 throw std::runtime_error("Unsupported type");