Release 18.05
[platform/upstream/armnn.git] / src / armnn / layers / ConstantLayer.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 "ConstantLayer.hpp"
6 #include "LayerCloneBase.hpp"
7
8 #include <armnn/TypesUtils.hpp>
9 #include <backends/CpuTensorHandle.hpp>
10 #include <backends/WorkloadData.hpp>
11 #include <backends/WorkloadFactory.hpp>
12
13 namespace armnn
14 {
15
16 ConstantLayer::ConstantLayer(const std::shared_ptr<ScopedCpuTensorHandle>& input, const char* name)
17     : Layer(0, 1, LayerType::Constant, name)
18     , m_LayerOutput(input)
19 {
20 }
21
22 std::unique_ptr<IWorkload> ConstantLayer::CreateWorkload(const Graph& graph,
23     const IWorkloadFactory& factory) const
24 {
25     ConstantQueueDescriptor descriptor;
26     descriptor.m_LayerOutput = m_LayerOutput.get();
27     return factory.CreateConstant(descriptor, PrepInfoAndDesc(descriptor, graph));
28 }
29
30 ConstantLayer* ConstantLayer::Clone(Graph& graph) const
31 {
32     // Cloned layers share the same layer output object
33     return CloneBase<ConstantLayer>(graph, m_LayerOutput, GetName());
34 }
35
36 void ConstantLayer::ValidateTensorShapesFromInputs()
37 {
38     // get the output shape from the value of the constant layer
39     TensorShape const& outShape = m_LayerOutput->GetTensorInfo().GetShape();
40     ConditionalThrowIfNotEqual<LayerValidationException>(
41         "ConstantLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
42         GetOutputSlot(0).GetTensorInfo().GetShape(),
43         outShape);
44 }
45
46 } // namespace armnn