2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
5 #include "ConstantLayer.hpp"
6 #include "LayerCloneBase.hpp"
8 #include <armnn/TypesUtils.hpp>
9 #include <backendsCommon/CpuTensorHandle.hpp>
10 #include <backendsCommon/WorkloadData.hpp>
11 #include <backendsCommon/WorkloadFactory.hpp>
16 ConstantLayer::ConstantLayer(const char* name)
17 : Layer(0, 1, LayerType::Constant, name)
21 std::unique_ptr<IWorkload> ConstantLayer::CreateWorkload(const Graph& graph,
22 const IWorkloadFactory& factory) const
24 ConstantQueueDescriptor descriptor;
25 descriptor.m_LayerOutput = m_LayerOutput.get();
26 return factory.CreateConstant(descriptor, PrepInfoAndDesc(descriptor, graph));
29 ConstantLayer* ConstantLayer::Clone(Graph& graph) const
31 // Cloned layers share the same layer output object.
32 auto layer = CloneBase<ConstantLayer>(graph, GetName());
34 layer->m_LayerOutput = m_LayerOutput ? std::make_unique<ScopedCpuTensorHandle>(*m_LayerOutput) : nullptr;
36 return std::move(layer);
39 std::vector<TensorShape> ConstantLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
41 return std::vector<TensorShape>({ m_LayerOutput->GetTensorInfo().GetShape() });
44 void ConstantLayer::ValidateTensorShapesFromInputs()
46 // Get the output shape from the value of the constant layer.
47 TensorShape const& outShape = m_LayerOutput->GetTensorInfo().GetShape();
48 ConditionalThrowIfNotEqual<LayerValidationException>(
49 "ConstantLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
50 GetOutputSlot(0).GetTensorInfo().GetShape(),