Skip to content

Commit

Permalink
Disable fusing: convolution with activation (openvinotoolkit#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
l-bat authored Mar 30, 2021
1 parent 793f241 commit 96f9b8a
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 642 deletions.
32 changes: 4 additions & 28 deletions modules/arm_plugin/src/arm_converter/arm_converter_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,18 @@ static auto ConvParameters(const Conv& node) {
arm_compute::Size2D {node.get_dilations().at(D2::W), node.get_dilations().at(D2::H)});
}

template<typename Conv>
static arm_compute::ActivationLayerInfo GetActivation(const Conv& node) {
opset::ActivationInfo info = node.get_info();
arm_compute::ActivationLayerInfo::ActivationFunction func;
switch (info.function) {
case FUNC::LOGISTIC : func = arm_compute::ActivationLayerInfo::ActivationFunction::LOGISTIC; break;
case FUNC::TANH : func = arm_compute::ActivationLayerInfo::ActivationFunction::TANH; break;
case FUNC::RELU : func = arm_compute::ActivationLayerInfo::ActivationFunction::RELU; break;
case FUNC::LU_BOUNDED_RELU : func = arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU; break;
case FUNC::LEAKY_RELU : func = arm_compute::ActivationLayerInfo::ActivationFunction::LEAKY_RELU; break;
case FUNC::SOFT_RELU : func = arm_compute::ActivationLayerInfo::ActivationFunction::SOFT_RELU; break;
case FUNC::ELU : func = arm_compute::ActivationLayerInfo::ActivationFunction::ELU; break;
case FUNC::ABS : func = arm_compute::ActivationLayerInfo::ActivationFunction::ABS; break;
case FUNC::SQRT : func = arm_compute::ActivationLayerInfo::ActivationFunction::SQRT; break;
case FUNC::HARD_SWISH : func = arm_compute::ActivationLayerInfo::ActivationFunction::HARD_SWISH; break;
case FUNC::IDENTITY : return arm_compute::ActivationLayerInfo();
default:
IE_THROW() << "Arm Plugin: unsupported activation function for Convolution";
}
return arm_compute::ActivationLayerInfo(func, info.a, info.b);
}

template<> Converter::Conversion::Ptr Converter::Convert(const opset::ArmConvolution& node) {
arm_compute::PadStrideInfo conv_info;
arm_compute::Size2D dilation;
std::tie(conv_info, dilation) = ConvParameters(node);
auto act_info = GetActivation(node);
if (node.get_input_size() == 3) {
return MakeConversion<arm_compute::NEConvolutionLayer>(
node.input(Features), node.input(Weights), node.input(Bias), node.output(0),
conv_info, arm_compute::WeightsInfo{}, dilation, act_info);
conv_info, arm_compute::WeightsInfo{}, dilation);
} else {
return MakeConversion<arm_compute::NEConvolutionLayer>(
node.input(Features), node.input(Weights), nullptr, node.output(0),
conv_info, arm_compute::WeightsInfo{}, dilation, act_info);
conv_info, arm_compute::WeightsInfo{}, dilation);
}
}

Expand All @@ -83,15 +60,14 @@ template<> Converter::Conversion::Ptr Converter::Convert(const opset::ArmGroupCo
arm_compute::PadStrideInfo conv_info;
arm_compute::Size2D dilation;
std::tie(conv_info, dilation) = ConvParameters(node);
auto act_info = GetActivation(node);
if (node.get_input_size() == 3) {
return MakeConversion<arm_compute::NEDepthwiseConvolutionLayer>(
node.input(Features), MakeWeightsArgument(node), node.input(Bias), node.output(0),
conv_info, 1u, act_info, dilation);
conv_info, 1u, arm_compute::ActivationLayerInfo(), dilation);
} else {
return MakeConversion<arm_compute::NEDepthwiseConvolutionLayer>(
node.input(Features), MakeWeightsArgument(node), nullptr, node.output(0),
conv_info, 1u, act_info, dilation);
conv_info, 1u, arm_compute::ActivationLayerInfo(), dilation);
}
}
} // namespace ArmPlugin
20 changes: 7 additions & 13 deletions modules/arm_plugin/src/opset/conv_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ opset::ArmConvolution::ArmConvolution(const ngraph::Output<ngraph::Node>& data_b
const ngraph::CoordinateDiff& pads_begin,
const ngraph::CoordinateDiff& pads_end,
const ngraph::Strides& dilations,
const ngraph::op::PadType& auto_pad,
const ActivationInfo& activation)
const ngraph::op::PadType& auto_pad)
: Convolution{
data_batch,
filters,
strides,
pads_begin,
pads_end,
dilations,
auto_pad},
m_info(activation) {
auto_pad} {
constructor_validate_and_infer_types();
}

Expand All @@ -38,17 +36,15 @@ opset::ArmConvolution::ArmConvolution(const ngraph::Output<ngraph::Node>& data_b
const ngraph::CoordinateDiff& pads_begin,
const ngraph::CoordinateDiff& pads_end,
const ngraph::Strides& dilations,
const ngraph::op::PadType& auto_pad,
const ActivationInfo& activation)
const ngraph::op::PadType& auto_pad)
: Convolution{
data_batch,
filters,
strides,
pads_begin,
pads_end,
dilations,
auto_pad},
m_info(activation) {
auto_pad} {
set_argument(2, bias);
constructor_validate_and_infer_types();
}
Expand All @@ -62,8 +58,7 @@ std::shared_ptr<ngraph::Node> ArmPlugin::opset::ArmConvolution::clone_with_new_i
m_pads_begin,
m_pads_end,
m_dilations,
m_auto_pad,
m_info);
m_auto_pad);
} else if (num_args == 3) {
return std::make_shared<ArmConvolution>(new_args.at(0),
new_args.at(1),
Expand All @@ -72,9 +67,8 @@ std::shared_ptr<ngraph::Node> ArmPlugin::opset::ArmConvolution::clone_with_new_i
m_pads_begin,
m_pads_end,
m_dilations,
m_auto_pad,
m_info);
m_auto_pad);
} else {
throw ngraph_error("Unsupported number of arguments for ConvolutionBias operation");
throw ngraph_error("Unsupported number of arguments for ArmConvolution operation");
}
}
10 changes: 2 additions & 8 deletions modules/arm_plugin/src/opset/conv_arm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ArmConvolution : public Convolution {
const ngraph::CoordinateDiff& pads_begin,
const ngraph::CoordinateDiff& pads_end,
const ngraph::Strides& dilations,
const ngraph::op::PadType& auto_pad,
const ActivationInfo& activation);
const ngraph::op::PadType& auto_pad);

ArmConvolution(const ngraph::Output<ngraph::Node>& data_batch,
const ngraph::Output<ngraph::Node>& filters,
Expand All @@ -34,14 +33,9 @@ class ArmConvolution : public Convolution {
const ngraph::CoordinateDiff& pads_begin,
const ngraph::CoordinateDiff& pads_end,
const ngraph::Strides& dilations,
const ngraph::op::PadType& auto_pad,
const ActivationInfo& activation);
const ngraph::op::PadType& auto_pad);

std::shared_ptr<ngraph::Node> clone_with_new_inputs(const ngraph::OutputVector& new_args) const override;
const ActivationInfo& get_info() const { return m_info; }

private:
ActivationInfo m_info;
};
} // namespace opset
} // namespace ArmPlugin
20 changes: 7 additions & 13 deletions modules/arm_plugin/src/opset/group_conv_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ opset::ArmGroupConvolution::ArmGroupConvolution(const ngraph::Output<ngraph::Nod
const ngraph::CoordinateDiff& pads_begin,
const ngraph::CoordinateDiff& pads_end,
const ngraph::Strides& dilations,
const ngraph::op::PadType& auto_pad,
const ActivationInfo& activation)
const ngraph::op::PadType& auto_pad)
: GroupConvolution{
data_batch,
filters,
strides,
pads_begin,
pads_end,
dilations,
auto_pad},
m_info(activation) {
auto_pad} {
constructor_validate_and_infer_types();
}

Expand All @@ -38,17 +36,15 @@ opset::ArmGroupConvolution::ArmGroupConvolution(const ngraph::Output<ngraph::Nod
const ngraph::CoordinateDiff& pads_begin,
const ngraph::CoordinateDiff& pads_end,
const ngraph::Strides& dilations,
const ngraph::op::PadType& auto_pad,
const ActivationInfo& activation)
const ngraph::op::PadType& auto_pad)
: GroupConvolution{
data_batch,
filters,
strides,
pads_begin,
pads_end,
dilations,
auto_pad},
m_info(activation) {
auto_pad} {
set_argument(2, bias);
constructor_validate_and_infer_types();
}
Expand All @@ -62,8 +58,7 @@ std::shared_ptr<ngraph::Node> ArmPlugin::opset::ArmGroupConvolution::clone_with_
m_pads_begin,
m_pads_end,
m_dilations,
m_auto_pad,
m_info);
m_auto_pad);
} else if (num_args == 3) {
return std::make_shared<ArmGroupConvolution>(new_args.at(0),
new_args.at(1),
Expand All @@ -72,9 +67,8 @@ std::shared_ptr<ngraph::Node> ArmPlugin::opset::ArmGroupConvolution::clone_with_
m_pads_begin,
m_pads_end,
m_dilations,
m_auto_pad,
m_info);
m_auto_pad);
} else {
throw ngraph_error("Unsupported number of arguments for ConvolutionBias operation");
throw ngraph_error("Unsupported number of arguments for ArmGroupConvolution operation");
}
}
6 changes: 2 additions & 4 deletions modules/arm_plugin/src/opset/group_conv_arm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ArmGroupConvolution : public GroupConvolution {
const ngraph::CoordinateDiff& pads_begin,
const ngraph::CoordinateDiff& pads_end,
const ngraph::Strides& dilations,
const ngraph::op::PadType& auto_pad,
const ActivationInfo& activation);
const ngraph::op::PadType& auto_pad);

ArmGroupConvolution(const ngraph::Output<ngraph::Node>& data_batch,
const ngraph::Output<ngraph::Node>& filters,
Expand All @@ -34,8 +33,7 @@ class ArmGroupConvolution : public GroupConvolution {
const ngraph::CoordinateDiff& pads_begin,
const ngraph::CoordinateDiff& pads_end,
const ngraph::Strides& dilations,
const ngraph::op::PadType& auto_pad,
const ActivationInfo& activation);
const ngraph::op::PadType& auto_pad);

std::shared_ptr<ngraph::Node> clone_with_new_inputs(const ngraph::OutputVector& new_args) const override;
const ActivationInfo& get_info() const { return m_info; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "transformations/op_conversions/convert_mvn1_to_mvn6.hpp"
#include "transformations/op_conversions/convert_gelu.hpp"

#include "conv_bias_activ_fusion.hpp"
#include "conv_bias_fusion.hpp"
#include "convert_eltwise.hpp"
#include "convert_sign.hpp"
#include "convert_round.hpp"
Expand Down
Loading

0 comments on commit 96f9b8a

Please sign in to comment.