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

Function SetTensorToVariable

paddle/fluid/framework/data_transform.cc:133–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133void SetTensorToVariable(const Variable &in_var,
134 const DenseTensor &tensor,
135 Variable *out_var) {
136 if (in_var.IsType<DenseTensor>()) {
137 auto &in_dense_tensor = in_var.Get<DenseTensor>();
138 auto *tran_dense_tensor = out_var->GetMutable<DenseTensor>();
139 tran_dense_tensor->set_lod(in_dense_tensor.lod());
140 tran_dense_tensor->set_layout(in_dense_tensor.layout());
141#ifdef PADDLE_WITH_DNNL
142 tran_dense_tensor->set_mem_desc(in_dense_tensor.mem_desc());
143#endif
144 tran_dense_tensor->ShareDataWith(tensor);
145 } else if (in_var.IsType<phi::SelectedRows>()) {
146 auto &in_selected_rows = in_var.Get<phi::SelectedRows>();
147 auto *trans_selected_rows = out_var->GetMutable<phi::SelectedRows>();
148 trans_selected_rows->set_height(in_selected_rows.height());
149 trans_selected_rows->set_rows(in_selected_rows.rows());
150 trans_selected_rows->mutable_value()->ShareDataWith(tensor);
151 } else {
152 PADDLE_THROW(common::errors::Unavailable(
153 "Unsupported variable type, only supports DenseTensor or "
154 "SelectedRows, "
155 "but the input variable type is %s.",
156 ToTypeName(in_var.Type())));
157 }
158}
159
160phi::GetKernelTypeForVarContext BuildGetKernelTypeForVarContext(
161 const phi::KernelKey &kernel_key,

Callers 5

PrepareDataMethod · 0.85
PrepareDataFunction · 0.85
PreparePhiDataFunction · 0.85

Calls 11

ToTypeNameFunction · 0.85
set_mem_descMethod · 0.80
set_lodMethod · 0.45
lodMethod · 0.45
set_layoutMethod · 0.45
layoutMethod · 0.45
set_heightMethod · 0.45
heightMethod · 0.45
set_rowsMethod · 0.45
mutable_valueMethod · 0.45
TypeMethod · 0.45

Tested by

no test coverage detected