From 88fc7a7d6808df744300ae55ed012f6cf838e37f Mon Sep 17 00:00:00 2001 From: Wojciech Uss Date: Fri, 15 Jan 2021 04:19:21 +0100 Subject: [PATCH] fix cache key for inplaced elementwise ops (#30404) --- .../elementwise/mkldnn/elementwise_mkldnn_op.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/operators/elementwise/mkldnn/elementwise_mkldnn_op.h b/paddle/fluid/operators/elementwise/mkldnn/elementwise_mkldnn_op.h index c5f55138d9b..e679f62a25a 100644 --- a/paddle/fluid/operators/elementwise/mkldnn/elementwise_mkldnn_op.h +++ b/paddle/fluid/operators/elementwise/mkldnn/elementwise_mkldnn_op.h @@ -13,6 +13,7 @@ // limitations under the License. #pragma once +#include #include #include "paddle/fluid/memory/memcpy.h" #include "paddle/fluid/operators/elementwise/elementwise_add_op.h" @@ -45,19 +46,25 @@ class EltwiseMKLDNNKernel : public framework::OpKernel { float scale_x = ctx.Attr("Scale_x"); float scale_y = ctx.Attr("Scale_y"); float scale_o = ctx.Attr("Scale_out"); - int axis = ctx.Attr("axis"); + bool is_inplaced = x->IsSharedBufferWith(*z); + + std::string key = is_inplaced + ? platform::CreateKey(dev_ctx, ctx.OutputName("Out"), + x->format(), y->format()) + : ctx.OutputName("Out"); + platform::BinaryMKLDNNHandler handler( BINARY_OP, axis, dev_ctx, mkldnn_engine, ctx.GetPlace(), x, y, z, - scale_x, scale_y, scale_o, ctx.OutputName("Out")); + scale_x, scale_y, scale_o, key); const auto src_x_memory = handler.AcquireSrcMemory(x); const auto src_y_memory = handler.AcquireSecondSrcMemory(y); // For Inplace src and and dst are the same memory object const auto dst_memory = - x->IsSharedBufferWith(*z) ? src_x_memory : handler.AcquireDstMemory(z); + is_inplaced ? src_x_memory : handler.AcquireDstMemory(z); const auto binary_prim = handler.AcquireForwardPrimitive(); -- GitLab