ArmNN
 24.08
TileLayer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2023-2024 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "TileLayer.hpp"
7 
10 
11 namespace armnn
12 {
13 TileLayer::TileLayer(const TileDescriptor &param, const char *name)
14  : LayerWithParameters(1, 1, LayerType::Tile, param, name)
15 {}
16 
17 std::unique_ptr<IWorkload> TileLayer::CreateWorkload(const IWorkloadFactory &factory) const
18 {
19  TileQueueDescriptor descriptor;
20  SetAdditionalInfo(descriptor);
21 
22  return factory.CreateWorkload(LayerType::Tile, descriptor, PrepInfoAndDesc(descriptor));
23 }
24 
26 {
27  auto layer = CloneBase<TileLayer>(graph, m_Param, GetName());
28 
29  return std::move(layer);
30 }
31 
32 std::vector<TensorShape> TileLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
33 {
34  if (inputShapes.size() != 1)
35  {
36  throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) +
37  "\" - should be \"1\".");
38  }
39 
40  const TensorShape& inputShape = inputShapes[0];
41 
42  uint32_t numberOfDimensions = inputShape.GetNumDimensions();
43  std::vector<unsigned int> dimensionSizes;
44  dimensionSizes.reserve(numberOfDimensions);
45 
46  // Check input shape and multiples have same length and multiply them together to get output shape
47  if(numberOfDimensions == m_Param.m_Multiples.size())
48  {
49  for(uint32_t i = 0; i < numberOfDimensions; ++i)
50  {
51  dimensionSizes.emplace_back(inputShape[i] * m_Param.m_Multiples[i]);
52  }
53  }
54  else
55  {
56  throw LayerValidationException("TileLayer: input rank and multiples length are different.");
57  }
58 
59  return std::vector<TensorShape>({TensorShape({numberOfDimensions, dimensionSizes.data()})});
60 }
61 
63 {
65 
66  const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
67 
69 
70  auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() });
71 
72  if (inferredShapes.size() != 1)
73  {
74  throw armnn::LayerValidationException("inferredShapes has "
75  + std::to_string(inferredShapes.size()) +
76  " elements - should only have 1.");
77  }
78 
79  ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "TileLayer");
80 }
81 
82 }
armnn::TileLayer::CreateWorkload
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Tile type.
Definition: TileLayer.cpp:17
armnn::OutputSlot::GetTensorInfo
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:100
armnn::TileLayer::Clone
TileLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition: TileLayer.cpp:25
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::TileLayer::ValidateTensorShapesFromInputs
void ValidateTensorShapesFromInputs() override
Check if the input tensor tile(s) will lead to a valid configuration of TileLayer.
Definition: TileLayer.cpp:62
armnn::Layer::ValidateAndCopyShape
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition: Layer.cpp:457
armnn::Layer::GetOutputSlot
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:339
armnn::LayerType::Tile
@ Tile
TileLayer.hpp
armnn::Layer::GetInputSlot
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:337
WorkloadFactory.hpp
armnn::LayerWithParameters
Definition: LayerWithParameters.hpp:14
armnn::Layer::GetName
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:332
armnn::TileLayer
Definition: TileLayer.hpp:13
armnn::InputSlot::GetTensorInfo
const TensorInfo & GetTensorInfo() const override
Gets the TensorInfo for this InputSlot.
Definition: Layer.cpp:614
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::LayerWithParameters< TileDescriptor >::m_Param
TileDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
Definition: LayerWithParameters.hpp:52
armnn::TensorShape::GetNumDimensions
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
armnn::LayerWithParameters< TileDescriptor >::PrepInfoAndDesc
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *Layer::CreateWorkload.
Definition: LayerWithParameters.hpp:44
armnn::TileLayer::InferOutputShapes
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
Infers the output shapes from given input shapes and layer properties.
Definition: TileLayer.cpp:32
armnn::LayerValidationException
Definition: Exceptions.hpp:105
armnn::IWorkloadFactory
Definition: WorkloadFactory.hpp:22
armnn::TileQueueDescriptor
Definition: WorkloadData.hpp:763
armnn::Layer::VerifyShapeInferenceType
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition: Layer.cpp:526
armnn::Layer::SetAdditionalInfo
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition: Layer.cpp:303
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnn::Tile
void Tile(const TileDescriptor &params, const TensorInfo &inputInfo, Decoder< float > &inputDecoder, Encoder< float > &outputEncoder)
Definition: Tile.cpp:45
armnn::TileLayer::TileLayer
TileLayer(const TileDescriptor &param, const char *name)
Constructor to create a TileLayer.
Definition: TileLayer.cpp:13
armnn::TileDescriptor::m_Multiples
std::vector< uint32_t > m_Multiples
The vector to multiply the input shape by.
Definition: Descriptors.hpp:1656
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::Layer::VerifyLayerConnections
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:410
armnn::Layer::m_ShapeInferenceMethod
ShapeInferenceMethod m_ShapeInferenceMethod
Definition: Layer.hpp:441
armnn::LayerType
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition: Types.hpp:491
armnn::Graph
Definition: Graph.hpp:30
armnn::TileDescriptor
Definition: Descriptors.hpp:1640
armnn::IWorkloadFactory::CreateWorkload
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.
LayerCloneBase.hpp