2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
5 #include "ConstantLayer.hpp"
6 #include "LayerCloneBase.hpp"
8 #include <armnn/TypesUtils.hpp>
9 #include <backends/CpuTensorHandle.hpp>
10 #include <backends/WorkloadData.hpp>
11 #include <backends/WorkloadFactory.hpp>
16 ConstantLayer::ConstantLayer(const std::shared_ptr<ScopedCpuTensorHandle>& input, const char* name)
17 : Layer(0, 1, LayerType::Constant, name)
18 , m_LayerOutput(input)
22 std::unique_ptr<IWorkload> ConstantLayer::CreateWorkload(const Graph& graph,
23 const IWorkloadFactory& factory) const
25 ConstantQueueDescriptor descriptor;
26 descriptor.m_LayerOutput = m_LayerOutput.get();
27 return factory.CreateConstant(descriptor, PrepInfoAndDesc(descriptor, graph));
30 ConstantLayer* ConstantLayer::Clone(Graph& graph) const
32 // Cloned layers share the same layer output object
33 return CloneBase<ConstantLayer>(graph, m_LayerOutput, GetName());
36 void ConstantLayer::ValidateTensorShapesFromInputs()
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(),