From ba486c5e497d351e202bfe4fc27a4b19a5c40f21 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Sat, 30 Apr 2022 10:09:29 +0800 Subject: [PATCH] Remove useless lod copy in DenseTensor::ShareDataWith (#42395) * remove useless lod copy * fix test failed * revert meta change * revert tensor change --- paddle/phi/core/dense_tensor_impl.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/paddle/phi/core/dense_tensor_impl.cc b/paddle/phi/core/dense_tensor_impl.cc index 46c45837a53..3c030cac2e7 100644 --- a/paddle/phi/core/dense_tensor_impl.cc +++ b/paddle/phi/core/dense_tensor_impl.cc @@ -371,12 +371,20 @@ dnnl::memory::format_tag DenseTensor::format() const { } #endif +// NOTE: For historical reasons, this interface has a special behavior, +// sharing other tensor members except lod DenseTensor& DenseTensor::ShareDataWith(const DenseTensor& src) { src.check_memory_size(); - // Preserve LoD - auto lod = meta_.lod; - *this = src; - meta_.lod = lod; + holder_ = src.holder_; + meta_.is_scalar = src.meta_.is_scalar; + meta_.dims = src.meta_.dims; + meta_.dtype = src.meta_.dtype; + meta_.layout = src.meta_.layout; + meta_.offset = src.meta_.offset; +#ifdef PADDLE_WITH_MKLDNN + format_ = src.format_; + mem_desc_ = src.mem_desc_; +#endif return *this; } -- GitLab