diff --git a/paddle/fluid/operators/elementwise/mkldnn/elementwise_mkldnn_op.h b/paddle/fluid/operators/elementwise/mkldnn/elementwise_mkldnn_op.h index 77b573183835b723e3766836448d8b37c482babe..51ad81b9dd4834cb87d212414243afacd70359a9 100644 --- a/paddle/fluid/operators/elementwise/mkldnn/elementwise_mkldnn_op.h +++ b/paddle/fluid/operators/elementwise/mkldnn/elementwise_mkldnn_op.h @@ -54,8 +54,12 @@ class EltwiseMKLDNNKernel : public framework::OpKernel { 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 - auto dst_memory = - x->IsSharedBufferWith(*z) ? src_x_memory : handler.AcquireDstMemory(z); + // (jczaja) UT mechanics is testing inplace for this op + // regardless shapes, which is wrong when X is to be broadcasted as output + // is of bigger shape that X. + auto dst_memory = (x->numel() == z->numel() && x->IsSharedBufferWith(*z)) + ? src_x_memory + : handler.AcquireDstMemory(z); const auto binary_prim = handler.AcquireForwardPrimitive();