diff --git a/paddle/fluid/operators/ops_extra_info.h b/paddle/fluid/operators/ops_extra_info.h index 77c0aa7a33fb3ce0fc75167d78b652fe646cd990..94adfaf3b4500b0b58153aec947a64acde59dc77 100644 --- a/paddle/fluid/operators/ops_extra_info.h +++ b/paddle/fluid/operators/ops_extra_info.h @@ -95,6 +95,7 @@ const std::unordered_map {"fuse_activation_alpha", ExtraAttrProperty::ONEDNN}, {"fuse_activation_beta", ExtraAttrProperty::ONEDNN}, {"fuse_activation_scale", ExtraAttrProperty::ONEDNN}, + {"fused_output_scale", ExtraAttrProperty::ONEDNN}, {"fuse_alpha", ExtraAttrProperty::ONEDNN}, {"fuse_beta", ExtraAttrProperty::ONEDNN}, {"fuse_relu", ExtraAttrProperty::ONEDNN}, diff --git a/paddle/phi/kernels/onednn/elementwise_kernel.cc b/paddle/phi/kernels/onednn/elementwise_kernel.cc index 51be7559772d7261821a0f2fc9b78c59e2288887..e103f23df0dc62dcb59d6261ccdb339d532bf5fd 100644 --- a/paddle/phi/kernels/onednn/elementwise_kernel.cc +++ b/paddle/phi/kernels/onednn/elementwise_kernel.cc @@ -43,6 +43,12 @@ void ElementwiseKernel(const OneDNNContext& dev_ctx, dnnl::post_ops post_operations; funcs::AppendActivation(dev_ctx, post_operations); + if (dev_ctx.HasDnnAttr("fused_output_scale")) { + float scale_alpha = + PADDLE_GET_CONST(float, dev_ctx.GetDnnAttr("fused_output_scale")); + post_operations.append_eltwise( + 1.0, dnnl::algorithm::eltwise_linear, scale_alpha, 0.0f); + } auto* non_const_x = &x; auto* non_const_y = &y; diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_elt_act_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_elt_act_fuse_pass.py index 068fbe1171d5887d9dfc99dc77f8ae2b130dae59..ac635436f6200af0dea9da26654ce11ff3db2caa 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_elt_act_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_elt_act_fuse_pass.py @@ -356,6 +356,42 @@ class ElementwiseActivationMkldnnFusePassTest_Mul_Sigmoid( self.act = paddle.nn.functional.sigmoid +class ElementwiseScaleOneDNNFusePassTest_Add( + ElementwiseActivationMkldnnFusePassTest +): + def set_params(self): + self.operand = fluid.layers.elementwise_add + self.act_alpha = 0.6 + self.act = paddle.scale + + +class ElementwiseScaleOneDNNFusePassTest_Sub( + ElementwiseActivationMkldnnFusePassTest +): + def set_params(self): + self.operand = fluid.layers.elementwise_sub + self.act_alpha = 0.6 + self.act = paddle.scale + + +class ElementwiseScaleOneDNNFusePassTest_Mul( + ElementwiseActivationMkldnnFusePassTest +): + def set_params(self): + self.operand = fluid.layers.elementwise_mul + self.act_alpha = 0.6 + self.act = paddle.scale + + +class ElementwiseScaleOneDNNFusePassTest_Div( + ElementwiseActivationMkldnnFusePassTest +): + def set_params(self): + self.operand = fluid.layers.elementwise_div + self.act_alpha = 0.6 + self.act = paddle.scale + + if __name__ == "__main__": paddle.enable_static() unittest.main()