MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / CopyVariable

Function CopyVariable

paddle/fluid/framework/variable_helper.cc:62–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void CopyVariable(const Variable &src_var, Variable *dst_var) {
63 // only support cpu now
64 auto cpu_place = CPUPlace();
65
66 if (src_var.IsType<DenseTensor>()) {
67 auto *tmp_grad_tensor = dst_var->GetMutable<DenseTensor>();
68 auto &src_tensor = src_var.Get<DenseTensor>();
69 tmp_grad_tensor->set_lod(src_tensor.lod());
70 framework::TensorCopy(src_tensor, cpu_place, tmp_grad_tensor);
71 } else if (src_var.IsType<phi::SelectedRows>()) {
72 auto &src_slr = src_var.Get<phi::SelectedRows>();
73 auto *tmp_grad_slr = dst_var->GetMutable<phi::SelectedRows>();
74 tmp_grad_slr->set_rows(src_slr.rows());
75 tmp_grad_slr->set_height(src_slr.height());
76 auto &src_t = src_slr.value();
77 auto *dst_t = tmp_grad_slr->mutable_value();
78 framework::TensorCopy(src_t, cpu_place, dst_t);
79 } else {
80 PADDLE_THROW(common::errors::Unavailable("Unknown variable type to copy."));
81 }
82}
83
84} // namespace paddle::framework

Callers

nothing calls this directly

Calls 9

TensorCopyFunction · 0.85
CPUPlaceClass · 0.50
set_lodMethod · 0.45
lodMethod · 0.45
set_rowsMethod · 0.45
set_heightMethod · 0.45
heightMethod · 0.45
valueMethod · 0.45
mutable_valueMethod · 0.45

Tested by

no test coverage detected