Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIR] Fix Deepcopy: new-push_back #60879

Merged
merged 10 commits into from
Jan 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ void ShareVarData(const Variable* src_var, Variable* dst_var) {
auto src_tensor_array = src_var->Get<phi::TensorArray>();
auto* dst_tensor_array = dst_var->GetMutable<phi::TensorArray>();
if (src_tensor_array.size() == 0) return;
dst_tensor_array->clear();
dst_tensor_array->resize(0);
chen2016013 marked this conversation as resolved.
Show resolved Hide resolved
for (auto src_tensor : src_tensor_array) {
phi::DenseTensor* tmp_dst_tensor = new phi::DenseTensor();
phi::DenseTensor tmp_dst_tensor = phi::DenseTensor();
chen2016013 marked this conversation as resolved.
Show resolved Hide resolved
if (src_tensor.numel() == 0) {
tmp_dst_tensor->set_meta(src_tensor.meta());
tmp_dst_tensor.set_meta(src_tensor.meta());
} else {
tmp_dst_tensor->ShareDataWith(src_tensor);
tmp_dst_tensor.ShareDataWith(src_tensor);
}
dst_tensor_array->push_back(*tmp_dst_tensor);
dst_tensor_array->push_back(tmp_dst_tensor);
chen2016013 marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
PADDLE_THROW(phi::errors::PreconditionNotMet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ void DeepCopyVariable(const Variable* src_var,
"TensorArray shouldn't be null"));
}
}
dst_tensor_array->clear();
dst_tensor_array->resize(0);
for (auto src_tensor : src_tensor_array) {
phi::DenseTensor* tmp_dst_tensor = new phi::DenseTensor();
phi::DenseTensor tmp_dst_tensor = phi::DenseTensor();
if (src_tensor.numel() == 0) {
tmp_dst_tensor->set_meta(src_tensor.meta());
tmp_dst_tensor.set_meta(src_tensor.meta());
continue;
}
framework::TensorCopy(src_tensor, src_tensor.place(), tmp_dst_tensor);
dst_tensor_array->push_back(*tmp_dst_tensor);
framework::TensorCopy(src_tensor, src_tensor.place(), &tmp_dst_tensor);
dst_tensor_array->push_back(tmp_dst_tensor);
}
} else if (src_var->IsType<VariableRefArray>()) {
auto src_ref_array = src_var->Get<VariableRefArray>();
Expand Down