ArmNN
 24.02
ConvertFp32NetworkToFp16Impl Class Reference

#include <ConvertFp32NetworkToFp16.hpp>

Public Member Functions

void Run (Graph &graph, Layer &layer) const
 

Protected Member Functions

 ConvertFp32NetworkToFp16Impl ()=default
 
 ~ConvertFp32NetworkToFp16Impl ()=default
 

Detailed Description

Definition at line 15 of file ConvertFp32NetworkToFp16.hpp.

Constructor & Destructor Documentation

◆ ConvertFp32NetworkToFp16Impl()

ConvertFp32NetworkToFp16Impl ( )
protecteddefault

◆ ~ConvertFp32NetworkToFp16Impl()

~ConvertFp32NetworkToFp16Impl ( )
protecteddefault

Member Function Documentation

◆ Run()

void Run ( Graph graph,
Layer layer 
) const
inline

Definition at line 18 of file ConvertFp32NetworkToFp16.hpp.

19  {
20  if(layer.GetType() == LayerType::Input)
21  {
22  // if the outputs of this layer are DataType::Float32
23  // add a ConvertFloat32ToFloat16 layer after each of the outputs
24  if (layer.GetDataType() == DataType::Float32)
25  {
27  }
28  }
29  else if (layer.GetType() == LayerType::Output)
30  {
31  // For DetectionPostProcess Layer output is always Float32 regardless of input type
32  Layer& connectedLayer = layer.GetInputSlots()[0].GetConnectedOutputSlot()->GetOwningLayer();
33  if (connectedLayer.GetType() != LayerType::DetectionPostProcess)
34  {
35  // if the inputs of this layer are DataType::Float32
36  // add a ConvertFloat16ToFloat32 layer before each of the inputs
37  if (layer.GetDataType() == DataType::Float32)
38  {
39  // NOTE: We need to call InsertConvertFp16ToFp32LayersBefore with expectCorrectInputType = false
40  // here, otherwise it will expect the inputs to be DataType::Float16
41  InsertConvertFp16ToFp32LayersBefore(graph, layer, false);
42  }
43  }
44  }
45  else if (layer.GetType() != LayerType::ConvertFp32ToFp16 && layer.GetType() != LayerType::ConvertFp16ToFp32)
46  {
47  // if the inputs/outputs of this layer are DataType::Float32
48  // change the data type for all inputs and outputs to DataType::Float16
49  for (auto&& input = layer.BeginInputSlots(); input != layer.EndInputSlots(); ++input)
50  {
51  // if it is connected to OutputSlot of the InputLayer do not change the DataType of connection
52  // InputSlots of the current layer will be updated when conversion layer is inserted after InputLayer
53  Layer& base = input->GetConnectedOutputSlot()->GetOwningLayer();
54  if (base.GetType() != LayerType::Input)
55  {
56  TensorInfo convertInfo = input->GetConnection()->GetTensorInfo();
57  if (convertInfo.GetDataType() == DataType::Float32)
58  {
59  convertInfo.SetDataType(DataType::Float16);
60  input->GetConnection()->SetTensorInfo(convertInfo);
61  }
62  }
63  }
64 
65  // For DetectionPostProcess Layer output is always Float32 regardless of input type
66  if (layer.GetType() != LayerType::DetectionPostProcess)
67  {
68  // change outputs to DataType::Float16
69  for (auto&& output = layer.BeginOutputSlots(); output != layer.EndOutputSlots(); ++output)
70  {
71  TensorInfo convertInfo = output->GetTensorInfo();
72  if (convertInfo.GetDataType() == DataType::Float32)
73  {
74  convertInfo.SetDataType(DataType::Float16);
75  output->SetTensorInfo(convertInfo);
76  }
77  }
78  }
79  }
80  }

References Layer::BeginInputSlots(), Layer::BeginOutputSlots(), armnn::ConvertFp16ToFp32, armnn::ConvertFp32ToFp16, armnn::DetectionPostProcess, Layer::EndInputSlots(), Layer::EndOutputSlots(), armnn::Float16, armnn::Float32, TensorInfo::GetDataType(), Layer::GetDataType(), Layer::GetInputSlots(), Layer::GetType(), armnn::Input, armnn::InsertConvertFp16ToFp32LayersBefore(), armnn::InsertConvertFp32ToFp16LayersAfter(), armnn::Output, and TensorInfo::SetDataType().


The documentation for this class was generated from the following file:
armnn::InsertConvertFp16ToFp32LayersBefore
std::vector< ConvertFp16ToFp32Layer * > InsertConvertFp16ToFp32LayersBefore(Graph &graph, Layer &layer, bool expectCorrectInputType)
Definition: NetworkUtils.cpp:40
armnn::LayerType::ConvertFp16ToFp32
@ ConvertFp16ToFp32
armnn::DataType::Float32
@ Float32
armnn::LayerType::ConvertFp32ToFp16
@ ConvertFp32ToFp16
armnn::DataType::Float16
@ Float16
armnn::InsertConvertFp32ToFp16LayersAfter
std::vector< ConvertFp32ToFp16Layer * > InsertConvertFp32ToFp16LayersAfter(Graph &graph, Layer &layer)
Definition: NetworkUtils.cpp:79
armnn::LayerType::DetectionPostProcess
@ DetectionPostProcess
armnn::LayerType::Input
@ Input
armnn::LayerType::Output
@ Output