diff options
author | Idriss Chaouch <idriss.chaouch@arm.com> | 2023-08-28 14:28:31 +0100 |
---|---|---|
committer | Idriss Chaouch <idriss.chaouch@arm.com> | 2023-08-31 11:26:28 +0100 |
commit | 98e383eadf4e670d057ad725c7fe7924fea8e36b (patch) | |
tree | 35acac15aa69ab405887289cb9674d388f06f96b /src/armnn/layers | |
parent | 2be039bce38a4fa436e8310dfe14ebfff20d57bd (diff) | |
download | armnn-98e383eadf4e670d057ad725c7fe7924fea8e36b.tar.gz |
IVGCVSW-7525 Add broadcast_to operator
Signed-off-by: Idriss Chaouch <idriss.chaouch@arm.com>
Signed-off-by: Narumol Prangnawarat <narumol.prangnawarat@arm.com>
Change-Id: I94ec5f9120b2d736fdf98d00ec5137a4efd739b8
Diffstat (limited to 'src/armnn/layers')
-rw-r--r-- | src/armnn/layers/BroadcastToLayer.cpp | 57 | ||||
-rw-r--r-- | src/armnn/layers/BroadcastToLayer.hpp | 48 |
2 files changed, 105 insertions, 0 deletions
diff --git a/src/armnn/layers/BroadcastToLayer.cpp b/src/armnn/layers/BroadcastToLayer.cpp new file mode 100644 index 0000000000..252aa46de0 --- /dev/null +++ b/src/armnn/layers/BroadcastToLayer.cpp @@ -0,0 +1,57 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "BroadcastToLayer.hpp" + +#include "LayerCloneBase.hpp" + +#include <armnn/TypesUtils.hpp> +#include <armnn/backends/WorkloadData.hpp> +#include <armnn/backends/WorkloadFactory.hpp> + +namespace armnn +{ + +BroadcastToLayer::BroadcastToLayer(const BroadcastToDescriptor& param, const char* name) + : LayerWithParameters(1, 1, LayerType::BroadcastTo, param, name) +{} + +std::unique_ptr<IWorkload> BroadcastToLayer::CreateWorkload(const IWorkloadFactory& factory) const +{ + BroadcastToQueueDescriptor descriptor; + SetAdditionalInfo(descriptor); + + return factory.CreateWorkload(LayerType::BroadcastTo, descriptor, PrepInfoAndDesc(descriptor)); +} + +BroadcastToLayer* BroadcastToLayer::Clone(armnn::Graph& graph) const +{ + return CloneBase<BroadcastToLayer>(graph, m_Param, GetName()); +} + +std::vector<TensorShape> BroadcastToLayer::InferOutputShapes(const std::vector<TensorShape>&) const +{ + return std::vector<TensorShape>({ m_Param.m_BroadcastToShape }); +} + +void BroadcastToLayer::ValidateTensorShapesFromInputs() +{ + VerifyLayerConnections(1, CHECK_LOCATION()); + + const TensorShape &outputShape = GetOutputSlot(0).GetTensorInfo().GetShape(); + + VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); + + auto inferredShapes = outputShape; + + ValidateAndCopyShape(outputShape, inferredShapes, m_ShapeInferenceMethod, "BroadcastToLayer"); +} + +void BroadcastToLayer::ExecuteStrategy(IStrategy& strategy) const +{ + strategy.ExecuteStrategy(this, GetParameters(), {}, GetName()); +} + +} //namespace armnn diff --git a/src/armnn/layers/BroadcastToLayer.hpp b/src/armnn/layers/BroadcastToLayer.hpp new file mode 100644 index 0000000000..5da27a7a66 --- /dev/null +++ b/src/armnn/layers/BroadcastToLayer.hpp @@ -0,0 +1,48 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "LayerWithParameters.hpp" + +namespace armnn +{ + + class BroadcastToLayer : public LayerWithParameters<BroadcastToDescriptor> + { + public: + /// Makes a workload for the BroadcastTo 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. + BroadcastToLayer* 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 BroadcastTo(s) + /// will lead to a valid configuration of @ref BroadcastToLayer. + void ValidateTensorShapesFromInputs() override; + + /// Execute Strategy on BroadcastTo layer + /// @param [in] strategy The input strategy for the layer + void ExecuteStrategy(IStrategy& strategy) const override; + + protected: + /// Constructor to create a BroadcastToLayer. + /// @param [in] param Parameters for the layer. + /// @param [in] name Optional name for the layer. + BroadcastToLayer(const BroadcastToDescriptor& param, const char* name); + + /// Default destructor. + ~BroadcastToLayer() = default; + }; + +} // namespace armnn
\ No newline at end of file |