From a615002abdfe8cfdab78f1b7b344ef2939345548 Mon Sep 17 00:00:00 2001 From: YuanRisheng Date: Mon, 20 Dec 2021 11:01:40 +0800 Subject: [PATCH] Fix bugs that copy occurs when tensor "in" and tensor "out" is same in reshape kernel (#38249) * fix bugs when run reshape * fix ci bug --- paddle/fluid/operators/reshape_op.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/operators/reshape_op.cc b/paddle/fluid/operators/reshape_op.cc index a796821729f..856f4020cfc 100644 --- a/paddle/fluid/operators/reshape_op.cc +++ b/paddle/fluid/operators/reshape_op.cc @@ -392,7 +392,9 @@ class ReshapeKernel { ctx.GetPlace()), std::move(meta)); pten::DenseTensor *pt_out = nullptr; - if (in == out) { + if (in != nullptr && out != nullptr && in->Holder() != nullptr && + out->Holder() != nullptr && + in->Holder()->ptr() == out->Holder()->ptr()) { pt_out = pt_x.get(); } else { pt_out = pt_out_tmp.get(); -- GitLab