diff options
author | Francis Murtagh <francis.murtagh@arm.com> | 2019-11-19 12:06:47 +0000 |
---|---|---|
committer | Francis Murtagh <francis.murtagh@arm.com> | 2019-11-19 12:06:55 +0000 |
commit | 19fa0cc4fd4915451c3f56f6f4bdb51d8a5ac172 (patch) | |
tree | 62383c52829cac3f53d6aeab69715061062abb6e /ConversionUtils.hpp | |
parent | 0e2e31b9695f58181e15e770fcfe3d92aa09bf47 (diff) | |
download | android-nn-driver-19fa0cc4fd4915451c3f56f6f4bdb51d8a5ac172.tar.gz |
IVGCVSW-3697 Add Support for ANEURALNETWORKS_ARG[MAX|MIN] to HAL 1.2 Driver
!armnn:2313
Signed-off-by: Francis Murtagh <francis.murtagh@arm.com>
Change-Id: I543136e4e2ef9aece1378d2642064cc585246645
Diffstat (limited to 'ConversionUtils.hpp')
-rw-r--r-- | ConversionUtils.hpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/ConversionUtils.hpp b/ConversionUtils.hpp index 0637c2b5..a284a50a 100644 --- a/ConversionUtils.hpp +++ b/ConversionUtils.hpp @@ -1564,6 +1564,82 @@ bool ConvertAdd(const Operation& operation, const Model& model, ConversionData& template<typename HalPolicy, typename Operation = typename HalPolicy::Operation, typename Model = typename HalPolicy::Model> +bool ConvertArgMinMax(const Operation& operation, + const Model& model, + ConversionData& data, + armnn::ArgMinMaxFunction argMinMaxFunction) +{ + ALOGV("argMinMaxFunction = %s", GetArgMinMaxFunctionAsCString(argMinMaxFunction)); + + using HalOperand = typename HalPolicy::Operand; + using HalOperandType = typename HalPolicy::OperandType; + + LayerInputHandle input0 = ConvertToLayerInputHandle<HalPolicy>(operation, 0, model, data); + + if (!input0.IsValid()) + { + return Fail("%s: Operation has invalid inputs", __func__); + } + + int32_t axis; + if (!GetInputScalar<HalPolicy>(operation, 1, HalOperandType::INT32, axis, model, data)) + { + return Fail("%s: Operation has invalid inputs. Failed to read axis.", __func__); + } + + const armnn::TensorInfo& inputInfo = input0.GetTensorInfo(); + int rank = static_cast<int>(inputInfo.GetNumDimensions()); + + if (((axis < -rank) && (axis < 0)) || ((axis >= rank) && (axis > 0))) + { + // Square bracket denotes inclusive n while parenthesis denotes exclusive n + // E.g. Rank 4 tensor can have axis in range [-4, 3) + // -1 == 3, -2 == 2, -3 == 1, -4 == 0 + return Fail("%s: Axis must be in range [-n, n)", __func__); + } + + const HalOperand* output = GetOutputOperand<HalPolicy>(operation, 0, model); + if (!output) + { + return Fail("%s: Could not read output 0", __func__); + } + + const armnn::TensorInfo& inputInfo0 = input0.GetTensorInfo(); + + const armnn::TensorInfo& outputInfo = GetTensorInfoForOperand(*output); + if (IsDynamicTensor(outputInfo)) + { + return Fail("%s: Dynamic output tensors are not supported", __func__); + } + + armnn::ArgMinMaxDescriptor descriptor; + descriptor.m_Function = argMinMaxFunction; + descriptor.m_Axis = axis; + + bool isSupported = false; + FORWARD_LAYER_SUPPORT_FUNC(__func__, + IsArgMinMaxSupported, + data.m_Backends, + isSupported, + inputInfo0, + outputInfo, + descriptor); + if (!isSupported) + { + return false; + } + + armnn::IConnectableLayer* layer = data.m_Network->AddArgMinMaxLayer(descriptor); + assert(layer != nullptr); + + input0.Connect(layer->GetInputSlot(0)); + + return SetupAndTrackLayerOutputSlot<HalPolicy>(operation, 0, *layer, model, data); +} + +template<typename HalPolicy, + typename Operation = typename HalPolicy::Operation, + typename Model = typename HalPolicy::Model> bool ConvertConcatenation(const Operation& operation, const Model& model, ConversionData& data) { using HalOperand = typename HalPolicy::Operand; |