From 5607bcf22d2b15132be8572930a3a949a1faeb03 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Fri, 26 Nov 2021 04:48:28 -0600 Subject: [PATCH] fix reshape async copy error (#37595) --- paddle/fluid/operators/reshape_op.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/operators/reshape_op.cc b/paddle/fluid/operators/reshape_op.cc index 901a25b6f3..5148e3b094 100644 --- a/paddle/fluid/operators/reshape_op.cc +++ b/paddle/fluid/operators/reshape_op.cc @@ -376,13 +376,15 @@ class ReshapeKernel { // framework::DDim out_dims = out->dims(); auto pt_x = paddle::experimental::MakePtenDenseTensor(*in); - // we can't MakePtenDenseTensor by out, because reshape will realloc memory - // and this will throw error(can't realloc shared memory) in current - // DenseTensor - // design. So, codes below create a tmp densetensor for output. - // TODO(YuanRisheng) we can use MakePtenDenseTensor after #36916 merge. + // we can't MakePtenDenseTensor by out, because the out of reshape may have + // multiple states, some can MakePtenDenseTensor but other's cannot: + // 1. out tensor is not initialized + // 2. out tensor is input (complete inplace) + // 3. out tensor is view of input + // We can't MakePtenDenseTensor for case 2, so we solve this case by + // creating a temporary tensor here: const auto alloc = std::make_shared( - paddle::platform::CPUPlace()); + ctx.GetPlace()); pten::DenseTensorMeta meta{pten::TransToPtenDataType(in->type()), in->dims(), pten::TransToPtenDataLayout(in->layout())}; -- GitLab