ArmNN
 20.05
GatherLayer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "GatherLayer.hpp"
7 #include "LayerCloneBase.hpp"
8 
9 #include <armnn/TypesUtils.hpp>
12 
13 namespace armnn
14 {
15 
16 GatherLayer::GatherLayer(const char* name)
17  : Layer(2, 1, LayerType::Gather, name)
18 {
19 }
20 
21 std::unique_ptr<IWorkload> GatherLayer::CreateWorkload(const armnn::IWorkloadFactory& factory) const
22 {
23  GatherQueueDescriptor descriptor;
24  return factory.CreateGather(descriptor, PrepInfoAndDesc(descriptor));
25 }
26 
28 {
29  return CloneBase<GatherLayer>(graph, GetName());
30 }
31 
33 {
35 
36  const TensorInfo& params = GetInputSlot(0).GetConnection()->GetTensorInfo();
37  const TensorInfo& indices = GetInputSlot(1).GetConnection()->GetTensorInfo();
38 
39  const unsigned int paramsDim = params.GetNumDimensions();
40  const unsigned int indicesDim = indices.GetNumDimensions();
41  const unsigned int outputDim = paramsDim - 1 + indicesDim;
42 
43  std::vector<unsigned int> dimSizes;
44 
45  for (unsigned int i = 0; i < indicesDim; ++i)
46  {
47  dimSizes.push_back(indices.GetShape()[i]);
48  }
49  for (unsigned int i = 1; i < paramsDim; ++i)
50  {
51  dimSizes.push_back(params.GetShape()[i]);
52  }
53 
54  const TensorShape& inferredShape = TensorShape(outputDim, dimSizes.data());
55 
56  ConditionalThrowIfNotEqual<LayerValidationException>(
57  "GatherLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
59  inferredShape);
60 }
61 
62 void GatherLayer::Accept(ILayerVisitor& visitor) const
63 {
64  visitor.VisitGatherLayer(this, GetName());
65 }
66 
67 } // namespace armnn
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
Copyright (c) 2020 ARM Limited.
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
GatherLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition: GatherLayer.cpp:27
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:339
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:310
This layer represents a Gather operator.
Definition: GatherLayer.hpp:14
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
Definition: Layer.hpp:351
GatherLayer(const char *name)
Constructor to create a GatherLayer.
Definition: GatherLayer.cpp:16
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
void Accept(ILayerVisitor &visitor) const override
Apply a visitor to this layer.
Definition: GatherLayer.cpp:62
virtual std::unique_ptr< IWorkload > CreateGather(const GatherQueueDescriptor &descriptor, const WorkloadInfo &info) const
void Gather(const TensorInfo &paramsInfo, const TensorInfo &indicesInfo, const TensorInfo &outputInfo, Decoder< float > &params, const int32_t *indices, Encoder< float > &output)
Definition: Gather.cpp:18
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:312
virtual const TensorInfo & GetTensorInfo() const =0
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:305
virtual void VisitGatherLayer(const IConnectableLayer *layer, const char *name=nullptr)=0
Function a Gather layer should call back to when its Accept(ILayerVisitor&) function is invoked...
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of GatherLayer.
Definition: GatherLayer.cpp:32
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:92
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Gather type.
Definition: GatherLayer.cpp:21