// // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // #include "HalPolicy.hpp" namespace armnn_driver { namespace hal_1_2 { using namespace armnn; namespace { } // anonymous namespace bool HalPolicy::ConvertOperation(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { switch (operation.type) { case V1_2::OperationType::ABS: return ConvertElementwiseUnary(operation, model, data, UnaryOperation::Abs); case V1_2::OperationType::ADD: return ConvertAdd(operation, model, data); case V1_2::OperationType::ARGMAX: return ConvertArgMinMax(operation, model, data, ArgMinMaxFunction::Max); case V1_2::OperationType::ARGMIN: return ConvertArgMinMax(operation, model, data, ArgMinMaxFunction::Min); case V1_2::OperationType::AVERAGE_POOL_2D: return ConvertAveragePool2d(operation, model, data); case V1_2::OperationType::BATCH_TO_SPACE_ND: return ConvertBatchToSpaceNd(operation, model, data); case V1_2::OperationType::CONCATENATION: return ConvertConcatenation(operation, model, data); case V1_2::OperationType::CONV_2D: return ConvertConv2d(operation, model, data); case V1_2::OperationType::DEPTH_TO_SPACE: return ConvertDepthToSpace(operation, model, data); case V1_2::OperationType::DEPTHWISE_CONV_2D: return ConvertDepthwiseConv2d(operation, model, data); case V1_2::OperationType::DEQUANTIZE: return ConvertDequantize(operation, model, data); case V1_2::OperationType::DIV: return ConvertDiv(operation, model, data); case V1_2::OperationType::EQUAL: return ConvertComparison(operation, model, data, ComparisonOperation::Equal); case V1_2::OperationType::EXP: return ConvertElementwiseUnary(operation, model, data, UnaryOperation::Exp); case V1_2::OperationType::EXPAND_DIMS: return ConvertExpandDims(operation, model, data); case V1_2::OperationType::FLOOR: return ConvertFloor(operation, model, data); case V1_2::OperationType::FULLY_CONNECTED: return ConvertFullyConnected(operation, model, data); case V1_2::OperationType::GATHER: return ConvertGather(operation, model, data); case V1_2::OperationType::GREATER: return ConvertComparison(operation, model, data, ComparisonOperation::Greater); case V1_2::OperationType::GREATER_EQUAL: return ConvertComparison(operation, model, data, ComparisonOperation::GreaterOrEqual); case V1_2::OperationType::GROUPED_CONV_2D: return ConvertGroupedConv2d(operation, model, data); case V1_2::OperationType::INSTANCE_NORMALIZATION: return ConvertInstanceNormalization(operation, model, data); case V1_2::OperationType::L2_NORMALIZATION: return ConvertL2Normalization(operation, model, data); case V1_2::OperationType::L2_POOL_2D: return ConvertL2Pool2d(operation, model, data); case V1_2::OperationType::LESS: return ConvertComparison(operation, model, data, ComparisonOperation::Less); case V1_2::OperationType::LESS_EQUAL: return ConvertComparison(operation, model, data, ComparisonOperation::LessOrEqual); case V1_2::OperationType::LOCAL_RESPONSE_NORMALIZATION: return ConvertLocalResponseNormalization(operation, model, data); case V1_2::OperationType::LOGISTIC: return ConvertLogistic(operation, model, data); case V1_2::OperationType::LOG_SOFTMAX: return ConvertLogSoftmax(operation, model, data); case V1_2::OperationType::LSTM: return ConvertLstm(operation, model, data); case V1_2::OperationType::MAX_POOL_2D: return ConvertMaxPool2d(operation, model, data); case V1_2::OperationType::MAXIMUM: return ConvertMaximum(operation, model, data); case V1_2::OperationType::MEAN: return ConvertMean(operation, model, data); case V1_2::OperationType::MINIMUM: return ConvertMinimum(operation, model, data); case V1_2::OperationType::MUL: return ConvertMul(operation, model, data); case V1_2::OperationType::NEG: return ConvertElementwiseUnary(operation, model, data, UnaryOperation::Neg); case V1_2::OperationType::NOT_EQUAL: return ConvertComparison(operation, model, data, ComparisonOperation::NotEqual); case V1_2::OperationType::PAD: return ConvertPad(operation, model, data); case V1_2::OperationType::PAD_V2: return ConvertPadV2(operation, model, data); case V1_2::OperationType::PRELU: return ConvertPrelu(operation, model, data); case V1_2::OperationType::QUANTIZE: return ConvertQuantize(operation, model, data); case V1_2::OperationType::QUANTIZED_16BIT_LSTM: return ConvertQuantized16BitLstm(operation, model, data); case V1_2::OperationType::RELU: return ConvertReLu(operation, model, data); case V1_2::OperationType::RELU1: return ConvertReLu1(operation, model, data); case V1_2::OperationType::RELU6: return ConvertReLu6(operation, model, data); case V1_2::OperationType::RESHAPE: return ConvertReshape(operation, model, data); case V1_2::OperationType::RESIZE_BILINEAR: return ConvertResize(operation, model, data, ResizeMethod::Bilinear); case V1_2::OperationType::RESIZE_NEAREST_NEIGHBOR: return ConvertResize(operation, model, data, ResizeMethod::NearestNeighbor); case V1_2::OperationType::RSQRT: return ConvertElementwiseUnary(operation, model, data, UnaryOperation::Rsqrt); case V1_2::OperationType::SQRT: return ConvertSqrt(operation, model, data); case V1_2::OperationType::SQUEEZE: return ConvertSqueeze(operation, model, data); case V1_2::OperationType::STRIDED_SLICE: return ConvertStridedSlice(operation, model, data); case V1_2::OperationType::TRANSPOSE: return ConvertTranspose(operation, model, data); case V1_2::OperationType::TRANSPOSE_CONV_2D: return ConvertTransposeConv2d(operation, model, data); case V1_2::OperationType::SOFTMAX: return ConvertSoftmax(operation, model, data); case V1_2::OperationType::SPACE_TO_BATCH_ND : return ConvertSpaceToBatchNd(operation, model, data); case V1_2::OperationType::SPACE_TO_DEPTH: return ConvertSpaceToDepth(operation, model, data); case V1_2::OperationType::SUB: return ConvertSub(operation, model, data); case V1_2::OperationType::TANH: return ConvertTanH(operation, model, data); default: return Fail("%s: Operation type %s not supported in ArmnnDriver", __func__, toString(operation.type).c_str()); } } bool HalPolicy::ConvertAdd(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertAdd()"); return ::ConvertAdd(operation, model, data); } bool HalPolicy::ConvertArgMinMax(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data, armnn::ArgMinMaxFunction argMinMaxFunction) { ALOGV("hal_1_2::HalPolicy::ConvertArgMinMax()"); return ::ConvertArgMinMax(operation, model, data, argMinMaxFunction); } bool HalPolicy::ConvertAveragePool2d(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertAveragePool2d()"); return ConvertPooling2d(operation, __func__, PoolingAlgorithm::Average, model, data); } bool HalPolicy::ConvertBatchToSpaceNd(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertBatchToSpaceNd()"); return ::ConvertBatchToSpaceNd(operation, model, data); } bool HalPolicy::ConvertComparison(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data, ComparisonOperation comparisonOperation) { ALOGV("hal_1_2::HalPolicy::ConvertComparison()"); return ::ConvertComparison_1_2(operation, model, data, comparisonOperation); } bool HalPolicy::ConvertConcatenation(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertConcatenation()"); return ::ConvertConcatenation(operation, model, data); } bool HalPolicy::ConvertConv2d(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertConv2d()"); return ::ConvertConv2d_1_2(operation, model, data); } bool HalPolicy::ConvertDepthToSpace(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertDepthToSpace()"); return ::ConvertDepthToSpace(operation, model, data); } bool HalPolicy::ConvertDepthwiseConv2d(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertDepthwiseConv2d()"); return ::ConvertDepthwiseConv2d_1_2(operation, model, data); } bool HalPolicy::ConvertDequantize(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertDequantize()"); return ::ConvertDequantize_1_2(operation, model, data); } bool HalPolicy::ConvertDiv(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertDiv()"); return ::ConvertDiv(operation, model, data); } bool HalPolicy::ConvertElementwiseUnary(const Operation& operation, const V1_2::Model& model, ConversionData& data, UnaryOperation unaryOperation) { ALOGV("hal_1_2::HalPolicy::ConvertElementwiseUnary()"); return ::ConvertElementwiseUnary(operation, model, data, unaryOperation); } bool HalPolicy::ConvertExpandDims(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertExpandDims()"); return ::ConvertExpandDims(operation, model, data); } bool HalPolicy::ConvertFloor(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertFloor()"); return ::ConvertFloor(operation, model, data); } bool HalPolicy::ConvertFullyConnected(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertFullyConnected()"); return ::ConvertFullyConnected(operation, model, data); } bool HalPolicy::ConvertGather (const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertGather()"); return ::ConvertGather(operation, model, data); } bool HalPolicy::ConvertGroupedConv2d(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertGroupedConv2d()"); return ::ConvertGroupedConv2d(operation, model, data); } bool HalPolicy::ConvertInstanceNormalization(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertInstanceNormalization()"); return ::ConvertInstanceNormalization(operation, model, data); } bool HalPolicy::ConvertL2Normalization(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertL2Normalization()"); return ::ConvertL2Normalization(operation, model, data); } bool HalPolicy::ConvertL2Pool2d(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertL2Pool2d()"); return ConvertPooling2d(operation, __func__, PoolingAlgorithm::L2, model, data); } bool HalPolicy::ConvertLocalResponseNormalization(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertLocalResponseNormalization()"); return ::ConvertLocalResponseNormalization(operation, model, data); } bool HalPolicy::ConvertLogistic(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertLogistic()"); return ::ConvertLogistic(operation, model, data); } bool HalPolicy::ConvertLogSoftmax(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertLogSoftmax()"); return ::ConvertLogSoftmax(operation, model, data); } bool HalPolicy::ConvertMaxPool2d(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertMaxPool2d()"); return ConvertPooling2d(operation, __func__, PoolingAlgorithm::Max, model, data); } bool HalPolicy::ConvertMaximum(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertMaximum()"); return ::ConvertMaximum(operation, model, data); } bool HalPolicy::ConvertMean(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertMean()"); return ::ConvertMean(operation, model, data); } bool HalPolicy::ConvertMinimum(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertMinimum()"); return ::ConvertMinimum(operation, model, data); } bool HalPolicy::ConvertMul(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertMul()"); return ::ConvertMul(operation, model, data); } bool HalPolicy::ConvertPad(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertPad()"); return ::ConvertPad(operation, model, data); } bool HalPolicy::ConvertPadV2(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertPadV2()"); return ::ConvertPadV2(operation, model, data); } bool HalPolicy::ConvertPrelu(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertPrelu()"); return ::ConvertPrelu(operation, model, data); } bool HalPolicy::ConvertQuantize(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertQuantize()"); return ::ConvertQuantize(operation, model, data); } bool HalPolicy::ConvertQuantized16BitLstm(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertQuantized16BitLstm()"); return ::ConvertQuantized16BitLstm(operation, model, data); } bool HalPolicy::ConvertReLu(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertReLu()"); return ::ConvertReLu(operation, model, data); } bool HalPolicy::ConvertReLu1(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertReLu1()"); return ::ConvertReLu1(operation, model, data); } bool HalPolicy::ConvertReLu6(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertReLu6()"); return ::ConvertReLu6(operation, model, data); } bool HalPolicy::ConvertReshape(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertReshape()"); return ::ConvertReshape(operation, model, data); } bool HalPolicy::ConvertResize(const Operation& operation, const V1_2::Model& model, ConversionData& data, ResizeMethod resizeMethod) { ALOGV("hal_1_2::HalPolicy::ConvertResize()"); return ::ConvertResize(operation, model, data, resizeMethod); } bool HalPolicy::ConvertSpaceToBatchNd(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertSpaceToBatchNd()"); return ::ConvertSpaceToBatchNd(operation, model, data); } bool HalPolicy::ConvertSpaceToDepth(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertSpaceToDepth()"); return ::ConvertSpaceToDepth(operation, model, data); } bool HalPolicy::ConvertSoftmax(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertSoftmax()"); return ::ConvertSoftmax(operation, model, data); } bool HalPolicy::ConvertSub(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertSub()"); return ::ConvertSub(operation, model, data); } bool HalPolicy::ConvertTanH(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertTanH()"); return ::ConvertTanH(operation, model, data); } bool HalPolicy::ConvertLstm(const Operation& operation, const Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertLstm()"); return ::ConvertLstm(operation, model, data); } bool HalPolicy::ConvertSqrt(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertSqrt()"); ActivationDescriptor desc; desc.m_Function = ActivationFunction::Sqrt; return ::ConvertToActivation(operation, __func__, desc, model, data); } bool HalPolicy::ConvertSqueeze(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertSqueeze()"); return ::ConvertSqueeze(operation, model, data); } bool HalPolicy::ConvertStridedSlice(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertStridedSlice()"); return ::ConvertStridedSlice(operation, model, data); } bool HalPolicy::ConvertTranspose(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertTranspose()"); return ::ConvertTranspose(operation, model, data); } bool HalPolicy::ConvertTransposeConv2d(const V1_2::Operation& operation, const V1_2::Model& model, ConversionData& data) { ALOGV("hal_1_2::HalPolicy::ConvertTransposeConv2d()"); return ::ConvertTransposeConv2d(operation, model, data); } } // namespace hal_1_2 } // namespace armnn_driver