ArmNN
 25.11
Loading...
Searching...
No Matches
ScatterNdLayer.cpp
Go to the documentation of this file.
1//
2// Copyright © 2024 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ScatterNdLayer.hpp"
7#include "LayerCloneBase.hpp"
8
12
13namespace armnn
14{
15
17 : LayerWithParameters(3, 1, LayerType::ScatterNd, param, name)
18{
19}
20
21std::unique_ptr<IWorkload> ScatterNdLayer::CreateWorkload(const armnn::IWorkloadFactory& factory) const
22{
23 ScatterNdQueueDescriptor descriptor;
24 SetAdditionalInfo(descriptor);
25
26 return factory.CreateWorkload(LayerType::ScatterNd, descriptor, PrepInfoAndDesc(descriptor));
27}
28
30{
31 auto layer = CloneBase<ScatterNdLayer>(graph, m_Param, GetName());
32
33 return std::move(layer);
34}
35
36std::vector<TensorShape> ScatterNdLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
37{
38 const auto inputDims = inputShapes[0].GetNumDimensions();
39
40 std::vector<unsigned int> dimSizes(inputDims);
41
42 for (unsigned i = 0; i < inputDims; ++i)
43 {
44 dimSizes[i] = inputShapes[0][i];
45 }
46
47 TensorShape outputShape({ inputDims, dimSizes.data() });
48
49 return std::vector<TensorShape>({ outputShape });
50}
51
53{
55
56 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
57
59
60 if (m_Param.m_InputEnabled)
61 {
62 std::vector<TensorShape> inferredShapes = InferOutputShapes(
66
67 if (inferredShapes.size() != 1) {
68 throw armnn::LayerValidationException("inferredShape has " +
69 std::to_string(inferredShapes.size()) +
70 " elements - should only have 1.");
71 }
72
73 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "ScatterLayer");
74 }
75 else
76 {
77 // No input tensor, only shape provided via input slot
78 // In this case, we cannot validate the output shape from the input shape, but we can
79 // validate that the dimensions of shape and output tensor matched
80 unsigned int shapeDims = GetInputSlot(0).GetTensorInfo().GetShape().GetNumElements();
81 unsigned int outputDims = GetOutputSlot(0).GetTensorInfo().GetNumDimensions();
82
83 if (shapeDims != outputDims)
84 {
85 throw armnn::LayerValidationException("shape dimension " +
86 std::to_string(shapeDims) +
87 " and output dimension " +
88 std::to_string(outputDims) +
89 " are not matched.");
90 }
91 }
92}
93
94} // namespace armnn
#define CHECK_LOCATION()
virtual std::unique_ptr< IWorkload > CreateWorkload(LayerType type, const QueueDescriptor &descriptor, const WorkloadInfo &info) const =0
Backends should implement their own CreateWorkload function with a switch statement.
const TensorInfo & GetTensorInfo() const override
Gets the TensorInfo for this InputSlot.
Definition Layer.cpp:614
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition Layer.cpp:410
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition Layer.hpp:337
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition Layer.cpp:526
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition Layer.hpp:339
LayerType * CloneBase(Graph &graph, Params &&... params) const
const char * GetName() const override
Returns the name of the layer.
Definition Layer.hpp:332
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition Layer.cpp:457
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition Layer.cpp:303
ShapeInferenceMethod m_ShapeInferenceMethod
Definition Layer.hpp:441
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const ScatterNdDescriptor &param, const char *name)
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
const TensorInfo & GetTensorInfo() const override
Definition Layer.cpp:100
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
Infers the output shapes from given input shapes and layer properties.
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of ScatterNdLayer.
ScatterNdLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the ScatterNd type.
ScatterNdLayer(const ScatterNdDescriptor &param, const char *name)
Constructor to create a ScatterNdLayer.
const TensorShape & GetShape() const
Definition Tensor.hpp:193
unsigned int GetNumDimensions() const
Definition Tensor.hpp:197
unsigned int GetNumElements() const
Function that calculates the tensor elements by multiplying all dimension size which are Specified.
Definition Tensor.cpp:181
Copyright (c) 2021 ARM Limited and Contributors.
void ScatterNd(const TensorInfo &inputInfo, const TensorInfo &indicesInfo, const TensorInfo &updatesInfo, Decoder< float > &input, Decoder< int > &indices, Decoder< float > &updates, Encoder< float > &output, ScatterNdDescriptor descriptor)
Definition ScatterNd.cpp:41
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition Types.hpp:494
A ScatterNdDescriptor for the ScatterNdLayer.