diff options
Diffstat (limited to 'src/armnn')
-rw-r--r-- | src/armnn/BackendHelper.cpp | 19 | ||||
-rw-r--r-- | src/armnn/LayersFwd.hpp | 4 | ||||
-rw-r--r-- | src/armnn/Network.cpp | 13 | ||||
-rw-r--r-- | src/armnn/Network.hpp | 5 | ||||
-rw-r--r-- | src/armnn/layers/ScatterNdLayer.cpp | 94 | ||||
-rw-r--r-- | src/armnn/layers/ScatterNdLayer.hpp | 44 |
6 files changed, 175 insertions, 4 deletions
diff --git a/src/armnn/BackendHelper.cpp b/src/armnn/BackendHelper.cpp index 56938d021e..37ad5da2fe 100644 --- a/src/armnn/BackendHelper.cpp +++ b/src/armnn/BackendHelper.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2022-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -1276,6 +1276,23 @@ bool LayerSupportHandle::IsReverseV2Supported(const armnn::TensorInfo &input0, reasonIfUnsupported); } +bool LayerSupportHandle::IsScatterNdSupported(const TensorInfo& input, + const TensorInfo& indices, + const TensorInfo& updates, + const TensorInfo& output, + const armnn::ScatterNdDescriptor &descriptor, + Optional<std::string&> reasonIfUnsupported) +{ + TensorInfos infos{input, indices, updates, output}; + + return m_LayerSupport->IsLayerSupported(LayerType::ScatterNd, + infos, + descriptor, + EmptyOptional(), + EmptyOptional(), + reasonIfUnsupported); +} + bool LayerSupportHandle::IsShapeSupported(const TensorInfo& input, const TensorInfo& output, Optional<std::string&> reasonIfUnsupported) diff --git a/src/armnn/LayersFwd.hpp b/src/armnn/LayersFwd.hpp index 325bfc3875..6ba409de50 100644 --- a/src/armnn/LayersFwd.hpp +++ b/src/armnn/LayersFwd.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -67,6 +67,7 @@ #include "layers/ReshapeLayer.hpp" #include "layers/ResizeLayer.hpp" #include "layers/ReverseV2Layer.hpp" +#include "layers/ScatterNdLayer.hpp" #include "layers/ShapeLayer.hpp" #include "layers/SliceLayer.hpp" #include "layers/SoftmaxLayer.hpp" @@ -172,6 +173,7 @@ DECLARE_LAYER(Reduce) DECLARE_LAYER(Reshape) DECLARE_LAYER(Resize) DECLARE_LAYER(ReverseV2) +DECLARE_LAYER(ScatterNd) DECLARE_LAYER(Shape) DECLARE_LAYER(Slice) DECLARE_LAYER(Softmax) diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp index 2582403247..60df27d7fc 100644 --- a/src/armnn/Network.cpp +++ b/src/armnn/Network.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -663,6 +663,12 @@ IConnectableLayer* INetwork::AddBroadcastToLayer(const BroadcastToDescriptor& de return pNetworkImpl->AddBroadcastToLayer(descriptor, name); } +IConnectableLayer* INetwork::AddScatterNdLayer(const ScatterNdDescriptor &descriptor, + const char *name) +{ + return pNetworkImpl->AddScatterNdLayer(descriptor, name); +} + void INetwork::ExecuteStrategy(IStrategy& strategy) const { return pNetworkImpl->ExecuteStrategy(strategy); @@ -3085,6 +3091,11 @@ IConnectableLayer* NetworkImpl::AddBroadcastToLayer(const BroadcastToDescriptor return m_Graph->AddLayer<BroadcastToLayer>(desc, name); } +IConnectableLayer* NetworkImpl::AddScatterNdLayer(const ScatterNdDescriptor &desc, const char *name) +{ + return m_Graph->AddLayer<ScatterNdLayer>(desc, name); +} + void NetworkImpl::ExecuteStrategy(IStrategy& strategy) const { for (auto layer : GetGraph()) diff --git a/src/armnn/Network.hpp b/src/armnn/Network.hpp index 6ffdfb37a8..195f97e692 100644 --- a/src/armnn/Network.hpp +++ b/src/armnn/Network.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -196,6 +196,9 @@ public: IConnectableLayer* AddReverseV2Layer(const char* name = nullptr); + IConnectableLayer* AddScatterNdLayer(const ScatterNdDescriptor& scatterDescriptor, + const char* name = nullptr); + IConnectableLayer* AddShapeLayer(const char* name = nullptr); IConnectableLayer* AddSliceLayer(const SliceDescriptor& sliceDescriptor, const char* name = nullptr); diff --git a/src/armnn/layers/ScatterNdLayer.cpp b/src/armnn/layers/ScatterNdLayer.cpp new file mode 100644 index 0000000000..a0b270fba5 --- /dev/null +++ b/src/armnn/layers/ScatterNdLayer.cpp @@ -0,0 +1,94 @@ +// +// Copyright © 2024 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ScatterNdLayer.hpp" +#include "LayerCloneBase.hpp" + +#include <armnn/TypesUtils.hpp> +#include <armnn/backends/WorkloadData.hpp> +#include <armnn/backends/WorkloadFactory.hpp> + +namespace armnn +{ + +ScatterNdLayer::ScatterNdLayer(const ScatterNdDescriptor ¶m, const char* name) + : LayerWithParameters(3, 1, LayerType::ScatterNd, param, name) +{ +} + +std::unique_ptr<IWorkload> ScatterNdLayer::CreateWorkload(const armnn::IWorkloadFactory& factory) const +{ + ScatterNdQueueDescriptor descriptor; + SetAdditionalInfo(descriptor); + + return factory.CreateWorkload(LayerType::ScatterNd, descriptor, PrepInfoAndDesc(descriptor)); +} + +ScatterNdLayer* ScatterNdLayer::Clone(Graph& graph) const +{ + auto layer = CloneBase<ScatterNdLayer>(graph, m_Param, GetName()); + + return std::move(layer); +} + +std::vector<TensorShape> ScatterNdLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const +{ + const auto inputDims = inputShapes[0].GetNumDimensions(); + + std::vector<unsigned int> dimSizes(inputDims); + + for (unsigned i = 0; i < inputDims; ++i) + { + dimSizes[i] = inputShapes[0][i]; + } + + TensorShape outputShape({ inputDims, dimSizes.data() }); + + return std::vector<TensorShape>({ outputShape }); +} + +void ScatterNdLayer::ValidateTensorShapesFromInputs() +{ + VerifyLayerConnections(3, CHECK_LOCATION()); + + const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape(); + + VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); + + if (m_Param.m_InputEnabled) + { + std::vector<TensorShape> inferredShapes = InferOutputShapes( + {GetInputSlot(0).GetTensorInfo().GetShape(), + GetInputSlot(1).GetTensorInfo().GetShape(), + GetInputSlot(2).GetTensorInfo().GetShape()}); + + if (inferredShapes.size() != 1) { + throw armnn::LayerValidationException("inferredShape has " + + std::to_string(inferredShapes.size()) + + " elements - should only have 1."); + } + + ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ScatterLayer"); + } + else + { + // No input tensor, only shape provided via input slot + // In this case, we cannot validate the output shape from the input shape, but we can + // validate that the dimensions of shape and output tensor matched + unsigned int shapeDims = GetInputSlot(0).GetTensorInfo().GetNumDimensions(); + unsigned int outputDims = GetOutputSlot(0).GetTensorInfo().GetNumDimensions(); + + if (shapeDims != outputDims) + { + throw armnn::LayerValidationException("shape dimension " + + std::to_string(shapeDims) + + " and output dimension " + + std::to_string(outputDims) + + " are not matched."); + } + } +} + +} // namespace armnn diff --git a/src/armnn/layers/ScatterNdLayer.hpp b/src/armnn/layers/ScatterNdLayer.hpp new file mode 100644 index 0000000000..adad66758a --- /dev/null +++ b/src/armnn/layers/ScatterNdLayer.hpp @@ -0,0 +1,44 @@ +// +// Copyright © 2024 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "LayerWithParameters.hpp" + +namespace armnn +{ + +/// This layer represents a ScatterNd operator. +class ScatterNdLayer : public LayerWithParameters<ScatterNdDescriptor> +{ +public: + /// Makes a workload for the ScatterNd type. + /// @param [in] factory The workload factory which will create the workload. + /// @return A pointer to the created workload, or nullptr if not created. + virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override; + + /// Creates a dynamically-allocated copy of this layer. + /// @param [in] graph The graph into which this layer is being cloned. + ScatterNdLayer* Clone(Graph& graph) const override; + + /// Infers the output shapes from given input shapes and layer properties. + /// @param [in] inputShapes The input shapes layer has. + /// @return A vector to the inferred output shape. + std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override; + + /// Check if the input tensor shape(s) + /// will lead to a valid configuration of @ref ScatterNdLayer. + void ValidateTensorShapesFromInputs() override; + +protected: + /// Constructor to create a ScatterNdLayer. + /// @param [in] name Optional name for the layer. + ScatterNdLayer(const ScatterNdDescriptor& param, const char* name); + + /// Default destructor + ~ScatterNdLayer() = default; +}; + +} // namespace armnn |