| 2523 | } |
| 2524 | |
| 2525 | Scope* OperatorWithKernel::PrepareData( |
| 2526 | const Scope& scope, |
| 2527 | const phi::KernelKey& expected_kernel_key, |
| 2528 | std::vector<std::string>* transferred_inplace_vars, |
| 2529 | RuntimeContext* ctx, |
| 2530 | const phi::Place& place) const { |
| 2531 | Scope* new_scope = nullptr; |
| 2532 | |
| 2533 | const std::unordered_set<std::string>* no_buffer_ins = nullptr; |
| 2534 | if (info_) { |
| 2535 | auto& no_buffer_inferer = info_->NoNeedBufferVarsInferer(); |
| 2536 | // Some op may not register NoNeedBufferVarsInferer |
| 2537 | if (no_buffer_inferer) { |
| 2538 | no_buffer_ins = &(no_buffer_inferer(Inputs(), Outputs(), Attrs())); |
| 2539 | if (no_buffer_ins->empty()) no_buffer_ins = nullptr; |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | auto has_infer_varkernel_fn = |
| 2544 | (run_phi_kernel_ && phi_kernel_->get_kerneltype_forvar_fn_ != nullptr); |
| 2545 | phi::AttributeMap infer_attrs{}; |
| 2546 | auto fluid_attrs = Attrs(); |
| 2547 | phi::GetKernelTypeForVarContext infer_varkernel_context = |
| 2548 | BuildGetKernelTypeForVarContext(expected_kernel_key, |
| 2549 | fluid_attrs, |
| 2550 | &infer_attrs, |
| 2551 | has_infer_varkernel_fn); |
| 2552 | |
| 2553 | const auto& name_map = Inputs(); |
| 2554 | auto prepare_input_data = [&](const std::string& in_name, |
| 2555 | std::vector<Variable*>* in_vars, |
| 2556 | const phi::TensorArgDef* in_def, |
| 2557 | bool should_skip_input) -> void { |
| 2558 | auto& name_vec = name_map.at(in_name); |
| 2559 | for (size_t i = 0; i < in_vars->size(); ++i) { |
| 2560 | const auto& var_name = name_vec[i]; |
| 2561 | auto* var = in_vars->at(i); |
| 2562 | |
| 2563 | // Only tensor can be transfer to another device. |
| 2564 | if (var == nullptr || !VarIsTensor(*var)) { |
| 2565 | continue; |
| 2566 | } |
| 2567 | |
| 2568 | auto* tensor_in = GetDenseTensorOrSelectedRowsValueFromVar(*var); |
| 2569 | |
| 2570 | // When no_buffer_ins then checking of phi::DenseTensor::holder_ is |
| 2571 | // not a thread safe. And for infershape scenario checks |
| 2572 | // to be omitted are not really needed |
| 2573 | if (should_skip_input == true) { |
| 2574 | #ifdef PADDLE_WITH_DNNL |
| 2575 | // Var without buffer may be needed |
| 2576 | // for some situation like InferShape(). |
| 2577 | // In this situation We cannot skip Var analysis, as |
| 2578 | // ONEDNN shape of Var may differ from NHWC Var |
| 2579 | // In such situation corresponding resized Var |
| 2580 | // has to be created and registered |
| 2581 | if ((tensor_in->layout() == DataLayout::ONEDNN) && |
| 2582 | (var->IsType<DenseTensor>() == true) && |
nothing calls this directly
no test coverage detected