ArmNN
 24.02
TileLayer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2023 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  ARMNN_ASSERT(inputShapes.size() == 1);
35  const TensorShape& inputShape = inputShapes[0];
36 
37  uint32_t numberOfDimensions = inputShape.GetNumDimensions();
38  std::vector<unsigned int> dimensionSizes;
39  dimensionSizes.reserve(numberOfDimensions);
40 
41  // Check input shape and multiples have same length and multiply them together to get output shape
42  if(numberOfDimensions == m_Param.m_Multiples.size())
43  {
44  for(uint32_t i = 0; i < numberOfDimensions; ++i)
45  {
46  dimensionSizes.emplace_back(inputShape[i] * m_Param.m_Multiples[i]);
47  }
48  }
49  else
50  {
51  throw LayerValidationException("TileLayer: input rank and multiples length are different.");
52  }
53 
54  return std::vector<TensorShape>({TensorShape({numberOfDimensions, dimensionSizes.data()})});
55 }
56 
58 {
60 
61  const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
62 
64 
65  auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() });
66 
67  ARMNN_ASSERT(inferredShapes.size() == 1);
68 
69  ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "TileLayer");
70 }
71 
72 }
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
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:92
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:57
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:435
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:592
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:504
armnn::Layer::SetAdditionalInfo
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition: Layer.cpp:287
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:391
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