| 131 | } |
| 132 | |
| 133 | void 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 | |
| 160 | phi::GetKernelTypeForVarContext BuildGetKernelTypeForVarContext( |
| 161 | const phi::KernelKey &kernel_key, |
no test coverage detected