Skip to content

Commit

Permalink
onednn: remove post-sum fusion in fc kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyu-intel committed Jul 18, 2023
1 parent 576e2a4 commit 8de4ee8
Showing 1 changed file with 2 additions and 33 deletions.
35 changes: 2 additions & 33 deletions paddle/fluid/operators/mkldnn/fc_mkldnn_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ GetDNNLScales(const ExecutionContext& ctx) {
auto scale_in_data = ctx.Attr<float>("Scale_in");
auto scale_out = ctx.Attr<float>("Scale_out");
auto scale_weights_data = ctx.Attr<std::vector<float>>("Scale_weights");
auto scale_in_eltwise_data = ctx.HasAttr("Scale_in_eltwise")
? ctx.Attr<float>("Scale_in_eltwise")
: 1.0f;

std::vector<float> dnnl_src_scales = {1.f / scale_in_data};
size_t count = scale_weights_data.size();
Expand All @@ -57,7 +54,7 @@ GetDNNLScales(const ExecutionContext& ctx) {
for (size_t i = 0; i < count; i++) {
dnnl_wei_scales[i] = 1.f / scale_weights_data[i];
}
std::vector<float> dnnl_psum_scales = {1.f / scale_in_eltwise_data};
std::vector<float> dnnl_psum_scales = {1.f};
std::vector<float> dnnl_dst_scales = {1.f / scale_out};

return std::make_tuple(
Expand Down Expand Up @@ -127,7 +124,6 @@ class FCMKLDNNHandler
dnnl::primitive_attr attributes;
dnnl::post_ops post_operations;

float sum_scale = 1.0f;
float activation_scale = 1.0f;
if (phi::funcs::is_int8<T_w>()) {
std::vector<float> src_scales, wei_scales, psum_scales, dst_scales;
Expand Down Expand Up @@ -168,13 +164,6 @@ class FCMKLDNNHandler
dst_scales.data(),
dst_scales.size() * sizeof(float));
}

sum_scale = psum_scales[0];
}

if (ctx.HasAttr("fuse_residual_connection") &&
ctx.Attr<bool>("fuse_residual_connection")) {
post_operations.append_sum(sum_scale);
}

// ReLU from "fc_fuse_pass"
Expand Down Expand Up @@ -332,22 +321,6 @@ class FCMKLDNNHandler

std::shared_ptr<dnnl::memory> AcquireCustomDstMemory(
const ExecutionContext& ctx, phi::DenseTensor* out) {
if (ctx.HasAttr("fuse_residual_connection") &&
ctx.Attr<bool>("fuse_residual_connection")) {
auto* residual_param = ctx.Input<phi::DenseTensor>("ResidualData");

PADDLE_ENFORCE_EQ(
out->dims(),
residual_param->dims(),
phi::errors::InvalidArgument(
"Output and elementwise parameter need to have the "
"same dimension sizes, but got output's dimension = %d"
" and residual param's dimension =%d .",
out->dims().size(),
residual_param->dims().size()));

out->ShareDataWith(*residual_param);
}
return this->template AcquireDstMemory<T_out>(out);
} // namespace operators

Expand Down Expand Up @@ -458,11 +431,7 @@ class FCMKLDNNKernel : public framework::OpKernel<T_in> {

dst_memory_p =
std::make_shared<dnnl::memory>(inner_product_cache->dst_mem);
if (ctx.HasAttr("fuse_residual_connection") &&
ctx.Attr<bool>("fuse_residual_connection")) {
auto* residual_param = ctx.Input<phi::DenseTensor>("ResidualData");
out->ShareDataWith(*residual_param);
}

auto out_ptr = out->mutable_data<T_out>(
ctx.GetPlace(), dst_memory_p->get_desc().get_size());
dst_memory_p->set_data_handle(out_ptr);
Expand Down

0 comments on commit 8de4ee8

Please sign in to comment.