23 auto& maxLayer = *PolymorphicDowncast<ElementwiseBinaryLayer*>(&base);
28 auto& minLayer = *PolymorphicDowncast<ElementwiseBinaryLayer*>(&child);
34 if (maxLayer.GetDataType() != minLayer.GetDataType())
41 if (!GetValue(maxLayer, maxValue))
46 if (!GetValue(minLayer, minValue))
52 OutputSlot& parentOut = *maxLayer.GetInputSlot(0).GetConnectedOutputSlot();
56 const std::string name = std::string(
"replaced-") + maxLayer.GetName() + std::string(
"-") + minLayer.GetName()
57 + std::string(
"-with-BoundedRelu");
59 boundedReluDescriptor,
68 minLayer.GetOutputSlot().MoveAllConnections(boundedReluLayer.GetOutputSlot());
76 static float_t GetConstTensorValue(
Layer& layer)
78 auto& constLayer = *PolymorphicDowncast<ConstantLayer*>(&layer);
79 switch (constLayer.GetDataType())
82 return *constLayer.m_LayerOutput->GetConstTensor<
float>();
84 return static_cast<float_t
>(*constLayer.m_LayerOutput->GetConstTensor<
BFloat16>());
86 return static_cast<float_t
>(*constLayer.m_LayerOutput->GetConstTensor<half_float::half>());
89 return static_cast<float_t
>(*constLayer.m_LayerOutput->GetConstTensor<uint8_t>());
92 return static_cast<float_t
>(*constLayer.m_LayerOutput->GetConstTensor<int8_t>());
94 return static_cast<float_t
>(*constLayer.m_LayerOutput->GetConstTensor<int16_t>());
96 return static_cast<float_t
>(*constLayer.m_LayerOutput->GetConstTensor<int32_t>());
98 return static_cast<float_t
>(*constLayer.m_LayerOutput->GetConstTensor<int64_t>());
104 static bool GetValue(Layer& layer, float_t& value)
106 Layer& input0 = layer.GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
107 Layer& input1 = layer.GetInputSlot(1).GetConnectedOutputSlot()->GetOwningLayer();
110 if (input0.GetOutputSlot(0).GetTensorInfo().GetNumElements() != 1)
114 value = GetConstTensorValue(input0);
118 if (input1.GetOutputSlot(0).GetTensorInfo().GetNumElements() != 1)
122 value = GetConstTensorValue(input1);
133 ElementwiseBinaryLayer,