ArmNN
 25.11
Loading...
Searching...
No Matches
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
11namespace armnn
12{
13TileLayer::TileLayer(const TileDescriptor &param, const char *name)
14 : LayerWithParameters(1, 1, LayerType::Tile, param, name)
15{}
16
17std::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
32std::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}
#define CHECK_LOCATION()
Base class for all ArmNN exceptions so that users can filter to just those.
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 TileDescriptor &param, const char *name)
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
const TensorInfo & GetTensorInfo() const override
Definition Layer.cpp:100
const TensorShape & GetShape() const
Definition Tensor.hpp:193
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition Tensor.cpp:174
TileLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition TileLayer.cpp:25
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
void ValidateTensorShapesFromInputs() override
Check if the input tensor tile(s) will lead to a valid configuration of TileLayer.
Definition TileLayer.cpp:62
TileLayer(const TileDescriptor &param, const char *name)
Constructor to create a TileLayer.
Definition TileLayer.cpp:13
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Tile type.
Definition TileLayer.cpp:17
Copyright (c) 2021 ARM Limited and Contributors.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition Types.hpp:494
void Tile(const TileDescriptor &params, const TensorInfo &inputInfo, Decoder< I > &inputDecoder, Encoder< O > &outputEncoder)
Definition Tile.cpp:46