Release 18.08
[platform/upstream/armnn.git] / src / armnn / layers / ReshapeLayer.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
4 //
5 #include "ReshapeLayer.hpp"
6
7 #include "LayerCloneBase.hpp"
8
9 #include <armnn/TypesUtils.hpp>
10 #include <backends/WorkloadData.hpp>
11 #include <backends/WorkloadFactory.hpp>
12
13 namespace armnn
14 {
15
16 ReshapeLayer::ReshapeLayer(const ReshapeDescriptor& param, const char* name)
17     : LayerWithParameters(1, 1, LayerType::Reshape, param, name)
18 {
19 }
20
21 std::unique_ptr<IWorkload> ReshapeLayer::CreateWorkload(const Graph& graph,
22     const IWorkloadFactory& factory) const
23 {
24     ReshapeQueueDescriptor descriptor;
25     return factory.CreateReshape(descriptor, PrepInfoAndDesc(descriptor, graph));
26 }
27
28 ReshapeLayer* ReshapeLayer::Clone(Graph& graph) const
29 {
30     return CloneBase<ReshapeLayer>(graph, m_Param, GetName());
31 }
32
33 std::vector<TensorShape> ReshapeLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
34 {
35     return std::vector<TensorShape>({ m_Param.m_TargetShape });
36 }
37
38 void ReshapeLayer::ValidateTensorShapesFromInputs()
39 {
40     VerifyLayerConnections(1, CHECK_LOCATION());
41
42     auto inferredShapes = InferOutputShapes({  });
43
44     BOOST_ASSERT(inferredShapes.size() == 1);
45
46     ConditionalThrowIfNotEqual<LayerValidationException>(
47         "ReshapeLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
48         GetOutputSlot(0).GetTensorInfo().GetShape(),
49         inferredShapes[0]);
50 }
51
52 } // namespace armnn