19 void UpdateOutputSlotFp16ToFp32(OutputSlot& outputSlot)
21 const TensorInfo& origTensorInfo = outputSlot.GetTensorInfo();
22 TensorInfo newTensorInfo(origTensorInfo);
24 outputSlot.SetTensorInfo(newTensorInfo);
27 void ChangeOutputFp16ToFp32(Layer& layer)
29 for (
auto&& outputSlot = layer.BeginOutputSlots(); outputSlot != layer.EndOutputSlots(); ++outputSlot)
33 UpdateOutputSlotFp16ToFp32(*outputSlot);
42 bool expectCorrectInputType)
44 std::vector<ConvertFp16ToFp32Layer*> convertLayers;
50 bool allowInsert =
true;
51 if (expectCorrectInputType)
54 OutputSlot* connectedOutputSlot = inputSlot->GetConnectedOutputSlot();
61 const std::string name =
62 std::string(
"convert_fp16_to_fp32-" + std::to_string(inputSlot->GetSlotIndex()) +
"-") +
72 convertLayers.emplace_back(convertLayer);
83 std::vector<ConvertFp32ToFp16Layer*> convertLayers;
84 convertLayers.reserve(numOutputSlots);
87 ChangeOutputFp16ToFp32(layer);
90 for (
unsigned int slotIndex = 0u; slotIndex < numOutputSlots; ++slotIndex)
95 const std::string name =
96 std::string(
"convert_fp32_to_fp16-" + std::to_string(slotIndex) +
"-") + layer.
GetName();
105 convertLayers.emplace_back(convertLayer);
109 return convertLayers;
114 std::vector<DebugLayer*> debugLayers;
120 const std::string debugName = std::string(
"DebugLayerAfter") + layer.
GetNameStr();
134 debugLayers.emplace_back(debugLayer);
unsigned int GetNumOutputSlots() const override
const char * GetName() const override
std::vector< InputSlot >::iterator BeginInputSlots()
std::vector< InputSlot >::iterator EndInputSlots()
This layer converts data type Float 32 to Float 16.
const std::string & GetNameStr() const
std::vector< ConvertFp32ToFp16Layer * > InsertConvertFp32ToFp16LayersAfter(Graph &graph, Layer &layer)
void SetBackendId(const BackendId &id)
void SetTensorInfo(const TensorInfo &tensorInfo) override
void SetDataType(DataType type)
CPU Execution: Reference C++ kernels.
std::vector< OutputSlot >::iterator EndOutputSlots()
This layer visualizes the data flowing through the network.
DataType GetDataType() const
std::vector< OutputSlot >::iterator BeginOutputSlots()
std::vector< ConvertFp16ToFp32Layer * > InsertConvertFp16ToFp32LayersBefore(Graph &graph, Layer &layer, bool expectCorrectInputType)
std::vector< DebugLayer * > InsertDebugLayerAfter(Graph &graph, Layer &layer)
unsigned int GetNumInputSlots() const override
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
const TensorInfo & GetTensorInfo() const override
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
This layer converts data type Float 16 to Float 32.
const InputSlot & GetInputSlot(unsigned int index) const override