Release 18.08
[platform/upstream/armnn.git] / src / armnn / layers / ConvertFp32ToFp16Layer.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 "ConvertFp32ToFp16Layer.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 ConvertFp32ToFp16Layer::ConvertFp32ToFp16Layer(const char* name)
17  : Layer(1, 1, LayerType::ConvertFp32ToFp16, name)
18 {
19 }
20
21 std::unique_ptr<IWorkload> ConvertFp32ToFp16Layer::CreateWorkload(const Graph& graph,
22     const IWorkloadFactory& factory) const
23 {
24     ConvertFp32ToFp16QueueDescriptor descriptor;
25     return factory.CreateConvertFp32ToFp16(descriptor, PrepInfoAndDesc(descriptor, graph));
26 }
27
28 ConvertFp32ToFp16Layer* ConvertFp32ToFp16Layer::Clone(Graph& graph) const
29 {
30     return CloneBase<ConvertFp32ToFp16Layer>(graph, GetName());
31 }
32
33 void ConvertFp32ToFp16Layer::ValidateTensorShapesFromInputs()
34 {
35     VerifyLayerConnections(1, CHECK_LOCATION());
36
37     auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
38
39     BOOST_ASSERT(inferredShapes.size() == 1);
40
41     ConditionalThrowIfNotEqual<LayerValidationException>(
42         "ConvertFp32ToFp16Layer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
43         GetOutputSlot(0).GetTensorInfo().GetShape(),
44         inferredShapes[0]);
45 }
46
47 } // namespace armnn