diff --git a/paddle/fluid/framework/new_executor/collect_shape_manager.cc b/paddle/fluid/framework/new_executor/collect_shape_manager.cc index 550aa59c529e28..19b3a1a6bf4bd1 100644 --- a/paddle/fluid/framework/new_executor/collect_shape_manager.cc +++ b/paddle/fluid/framework/new_executor/collect_shape_manager.cc @@ -46,16 +46,15 @@ void CollectShapeManager::CollectShapeInfo( } auto var_name = value_exe_info->GetVarName(input.first); auto *var = scope->FindVar(var_name); - if (!var || !var->IsType()) { + if (!var || !var->IsType()) { VLOG(3) << "input var is null : " << (var == nullptr); - VLOG(3) << "input var is dense_tensor : " - << (var->IsType()); + VLOG(3) << "input var is dense_tensor : " << (var->IsType()); VLOG(3) << "input is null or not dense_tensor, jump it, and input id:" << input.first.impl(); continue; } - auto tensor = var->Get(); + auto tensor = var->Get(); if (!tensor.has_allocation() && !instr->NoNeedBuffer().count(input.first)) { VLOG(3) << "input tensor is has_allocation: " << (tensor.has_allocation()); diff --git a/paddle/fluid/framework/new_executor/feed_fetch_utils.h b/paddle/fluid/framework/new_executor/feed_fetch_utils.h index e618f44c5d116a..e30bbc13339d4c 100644 --- a/paddle/fluid/framework/new_executor/feed_fetch_utils.h +++ b/paddle/fluid/framework/new_executor/feed_fetch_utils.h @@ -30,7 +30,7 @@ void SetColAttrForFeedFetchOps(std::shared_ptr program_desc, void SplitFeedTensors(const std::vector& feed_names, const int64_t micro_batch_num, Scope* scope, - std::vector>* out); + std::vector>* out); void FetchTensors(const std::vector& job_fetch_names, const std::vector& fetch_var_names, diff --git a/paddle/fluid/framework/new_executor/garbage_collector/async_fast_garbage_collector.cc b/paddle/fluid/framework/new_executor/garbage_collector/async_fast_garbage_collector.cc index 5f48aecbd7c7c3..2b3c0eb192626b 100644 --- a/paddle/fluid/framework/new_executor/garbage_collector/async_fast_garbage_collector.cc +++ b/paddle/fluid/framework/new_executor/garbage_collector/async_fast_garbage_collector.cc @@ -90,8 +90,8 @@ void FreeVariable(Variable* var) { return; } - if (var->IsType()) { - Garbage garbage = var->GetMutable()->MoveMemoryHolder(); + if (var->IsType()) { + Garbage garbage = var->GetMutable()->MoveMemoryHolder(); } else if ( var->IsType< operators::reader:: diff --git a/paddle/fluid/framework/new_executor/garbage_collector/event_garbage_collector.cc b/paddle/fluid/framework/new_executor/garbage_collector/event_garbage_collector.cc index 4393f322a2f429..6d6ee0a2ad0ae0 100644 --- a/paddle/fluid/framework/new_executor/garbage_collector/event_garbage_collector.cc +++ b/paddle/fluid/framework/new_executor/garbage_collector/event_garbage_collector.cc @@ -87,8 +87,8 @@ void InterpreterCoreEventGarbageCollector::Add(Variable* var, return; } - if (var->IsType()) { - Add(var->GetMutable()->MoveMemoryHolder(), event, ctx); + if (var->IsType()) { + Add(var->GetMutable()->MoveMemoryHolder(), event, ctx); } else if ( var->IsType< operators::reader:: diff --git a/paddle/fluid/framework/new_executor/garbage_collector/fast_garbage_collector.cc b/paddle/fluid/framework/new_executor/garbage_collector/fast_garbage_collector.cc index 5d7b9281e67d36..f61116c7575e3e 100644 --- a/paddle/fluid/framework/new_executor/garbage_collector/fast_garbage_collector.cc +++ b/paddle/fluid/framework/new_executor/garbage_collector/fast_garbage_collector.cc @@ -32,8 +32,8 @@ void InterpreterCoreFastGarbageCollector::Add(Variable* var) { return; } - if (var->IsType()) { - Add(var->GetMutable()->MoveMemoryHolder()); + if (var->IsType()) { + Add(var->GetMutable()->MoveMemoryHolder()); } else if ( var->IsType< operators::reader:: diff --git a/paddle/fluid/framework/new_executor/garbage_collector/no_event_garbage_collector.cc b/paddle/fluid/framework/new_executor/garbage_collector/no_event_garbage_collector.cc index 9a0d744f8cb4fc..7c20d57328173e 100644 --- a/paddle/fluid/framework/new_executor/garbage_collector/no_event_garbage_collector.cc +++ b/paddle/fluid/framework/new_executor/garbage_collector/no_event_garbage_collector.cc @@ -46,8 +46,8 @@ void InterpreterCoreNoEventGarbageCollector::Add( return; } - if (var->IsType()) { - Add(var->GetMutable()->MoveMemoryHolder(), ctx); + if (var->IsType()) { + Add(var->GetMutable()->MoveMemoryHolder(), ctx); } else if ( var->IsType< operators::reader:: diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/assert_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/assert_instruction.cc index 081e57f66800b6..682d09ed25e938 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/assert_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/assert_instruction.cc @@ -60,7 +60,7 @@ void AssertInstruction::Run() { } DeviceContext().Wait(); - const phi::DenseTensor& cond = cond_var_->Get(); + const phi::DenseTensor& cond = cond_var_->Get(); PADDLE_ENFORCE_EQ( cond.numel(), @@ -87,7 +87,7 @@ void AssertInstruction::Run() { for (pir::Value val : inputs_data_val) { const std::string& name = value_exe_info_->GetVarName(val); const phi::DenseTensor& tensor = - value_exe_info_->GetVarByValue(val)->Get(); + value_exe_info_->GetVarByValue(val)->Get(); formatter.Print(tensor, name); } const std::string& error_msg = [&]() -> std::string { diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/has_elements_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/has_elements_instruction.cc index 42dc272fd208f0..c7f8501bd5b932 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/has_elements_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/has_elements_instruction.cc @@ -44,8 +44,8 @@ HasElementsInstruction::HasElementsInstruction( type_ = OpFuncType::kCpuSync; - bool_tensor_ = value_exe_info_->GetVarByValue(op_->result(0)) - ->GetMutable(); + bool_tensor_ = + value_exe_info_->GetVarByValue(op_->result(0))->GetMutable(); bool_tensor_->Resize(phi::make_ddim({1})); auto stack_value = diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/if_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/if_instruction.cc index 16a3f3de94de1d..4c25d09c0f8266 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/if_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/if_instruction.cc @@ -219,8 +219,8 @@ void IfInstruction::Run() { } bool cond = true; - if (cond_var_->IsType()) { - auto& cond_tensor = cond_var_->Get(); + if (cond_var_->IsType()) { + auto& cond_tensor = cond_var_->Get(); if (phi::is_cpu_place(cond_tensor.place())) { cond = cond_tensor.data()[0]; } else { @@ -228,7 +228,7 @@ void IfInstruction::Run() { // phi::is_xpu_place(cond.place()) is true #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \ defined(PADDLE_WITH_XPU) || defined(PADDLE_WITH_CUSTOM_DEVICE) - phi::DenseTensor cpu_cond; + DenseTensor cpu_cond; paddle::framework::TensorCopySync(cond_tensor, CPUPlace(), &cpu_cond); cond = cpu_cond.data()[0]; #else @@ -242,7 +242,7 @@ void IfInstruction::Run() { auto& cond_array = cond_var_->Get(); cond = std::all_of( cond_array.begin(), cond_array.end(), [](const Variable* t) { - return t->Get().numel() != 0; + return t->Get().numel() != 0; }); } if (cond) { diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/select_input_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/select_input_instruction.cc index c49a9a3f89787d..22e335f798e197 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/select_input_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/select_input_instruction.cc @@ -51,7 +51,7 @@ SelectInputInstruction::SelectInputInstruction( SetOutputs(outputs); } -inline int GetBranchNumber(const phi::DenseTensor &mask) { +inline int GetBranchNumber(const DenseTensor &mask) { PADDLE_ENFORCE_EQ( mask.numel(), 1, @@ -64,7 +64,7 @@ inline int GetBranchNumber(const phi::DenseTensor &mask) { return mask.data()[0]; } // when phi::is_gpu_place(mask.place()) is true - std::unique_ptr cpu_mask{new phi::DenseTensor()}; + std::unique_ptr cpu_mask{new phi::DenseTensor()}; #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \ defined(PADDLE_WITH_CUSTOM_DEVICE) || defined(PADDLE_WITH_XPU) framework::TensorCopySync(mask, CPUPlace(), cpu_mask.get()); @@ -81,8 +81,8 @@ class AssignFunctor { public: explicit AssignFunctor(Variable *out) : out_(out) {} - void operator()(const phi::DenseTensor &dense_tensor) const { - auto &out_tensor = *out_->GetMutable(); + void operator()(const DenseTensor &dense_tensor) const { + auto &out_tensor = *out_->GetMutable(); copy_tensor(dense_tensor, &out_tensor); } @@ -113,8 +113,7 @@ class AssignFunctor { } private: - void copy_tensor(const phi::DenseTensor &dense_tensor, - phi::DenseTensor *out) const { + void copy_tensor(const DenseTensor &dense_tensor, DenseTensor *out) const { if (!dense_tensor.IsInitialized()) return; auto &out_tensor = *out; TensorCopy(dense_tensor, dense_tensor.place(), &out_tensor); @@ -130,7 +129,7 @@ void SelectInputInstruction::Run() { CUDAErrorCheck("SelectInputInstruction begin"); } - auto &mask = mask_->Get(); + auto &mask = mask_->Get(); size_t output_branch = static_cast(GetBranchNumber(mask)); PADDLE_ENFORCE_LT( output_branch, diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/select_output_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/select_output_instruction.cc index 7b8f7d849a0a89..8fcce5a39484f4 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/select_output_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/select_output_instruction.cc @@ -50,7 +50,7 @@ SelectOutputInstruction::SelectOutputInstruction( SetOutputs(outputs); } -inline int GetBranchNumber(const phi::DenseTensor &mask) { +inline int GetBranchNumber(const DenseTensor &mask) { PADDLE_ENFORCE_EQ( mask.numel(), 1, @@ -63,7 +63,7 @@ inline int GetBranchNumber(const phi::DenseTensor &mask) { return mask.data()[0]; } // when phi::is_gpu_place(mask.place()) is true - std::unique_ptr cpu_mask{new phi::DenseTensor()}; + std::unique_ptr cpu_mask{new phi::DenseTensor()}; #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \ defined(PADDLE_WITH_CUSTOM_DEVICE) || defined(PADDLE_WITH_XPU) framework::TensorCopySync(mask, CPUPlace(), cpu_mask.get()); @@ -80,8 +80,8 @@ class AssignFunctor { public: explicit AssignFunctor(Variable *out) : out_(out) {} - void operator()(const phi::DenseTensor &dense_tensor) const { - auto &out_tensor = *out_->GetMutable(); + void operator()(const DenseTensor &dense_tensor) const { + auto &out_tensor = *out_->GetMutable(); copy_tensor(dense_tensor, &out_tensor); } @@ -112,8 +112,7 @@ class AssignFunctor { } private: - void copy_tensor(const phi::DenseTensor &dense_tensor, - phi::DenseTensor *out) const { + void copy_tensor(const DenseTensor &dense_tensor, DenseTensor *out) const { if (!dense_tensor.IsInitialized()) return; auto &out_tensor = *out; TensorCopy(dense_tensor, dense_tensor.place(), &out_tensor); @@ -129,7 +128,7 @@ void SelectOutputInstruction::Run() { CUDAErrorCheck("SelectOutputInstruction begin"); } - auto &mask = mask_->Get(); + auto &mask = mask_->Get(); size_t output_branch = static_cast(GetBranchNumber(mask)); PADDLE_ENFORCE_LE( output_branch, diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/tuple_pop_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/tuple_pop_instruction.cc index 0a1967e0da0c26..b13f0cb98a6c75 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/tuple_pop_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/tuple_pop_instruction.cc @@ -80,9 +80,9 @@ static std::stack PopElements(VariableRefArray* var_array, return rtn; } void ShareVarData(const Variable* src_var, Variable* dst_var) { - if (src_var->IsType()) { - auto& src_tensor = src_var->Get(); - auto* tmp_dst_tensor = dst_var->GetMutable(); + if (src_var->IsType()) { + auto& src_tensor = src_var->Get(); + auto* tmp_dst_tensor = dst_var->GetMutable(); if (src_tensor.numel() == 0) { tmp_dst_tensor->set_meta(src_tensor.meta()); if (!src_tensor.IsInitialized()) { diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/while_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/while_instruction.cc index eff3a28de259af..0f0eafbf150b71 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/while_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/while_instruction.cc @@ -154,9 +154,9 @@ WhileInstruction::WhileInstruction( void WhileInstruction::ShareInputsToOutputs() { for (size_t i = 0; i < outputs_.size(); ++i) { - if (inputs_[i]->IsType()) { - outputs_[i]->GetMutable()->ShareDataWith( - inputs_[i]->Get()); + if (inputs_[i]->IsType()) { + outputs_[i]->GetMutable()->ShareDataWith( + inputs_[i]->Get()); } else if (inputs_[i]->IsType()) { const auto& input_array = inputs_[i]->Get(); auto* output_array = outputs_[i]->GetMutable(); @@ -174,9 +174,9 @@ void WhileInstruction::ShareOutputsToBlockArgs() { auto var_name = body_inter_->GetNameByValue(block_arg); auto* inner_var = body_inter_->local_scope()->GetVar(var_name); - if (outputs_[i]->IsType()) { - inner_var->GetMutable()->ShareDataWith( - outputs_[i]->Get()); + if (outputs_[i]->IsType()) { + inner_var->GetMutable()->ShareDataWith( + outputs_[i]->Get()); } else if (outputs_[i]->IsType()) { const auto& outer_array = outputs_[i]->Get(); auto* inner_array = inner_var->GetMutable(); @@ -192,8 +192,8 @@ void WhileInstruction::ShareOutputsToBlockArgs() { void WhileInstruction::ShareConditionData() { auto inner_cond_var = body_inter_->local_scope()->GetVar(inner_cond_); - cond_var_->GetMutable()->ShareDataWith( - inner_cond_var->Get()); + cond_var_->GetMutable()->ShareDataWith( + inner_cond_var->Get()); } void WhileInstruction::SetOutputHooks( @@ -228,7 +228,7 @@ void WhileInstruction::Run() { } VLOG(6) << "while instruction start loop ..."; - while (GetCondData(cond_var_->Get())) { + while (GetCondData(cond_var_->Get())) { VLOG(6) << "while instruction pass args to body block"; ShareOutputsToBlockArgs(); VLOG(6) << "while instruction interpretercore run"; diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/yield_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/yield_instruction.cc index 9c56ebc697e22b..92d79f8a3ba1de 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/yield_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/yield_instruction.cc @@ -54,7 +54,7 @@ YieldInstruction::YieldInstruction(size_t id, "_input_" + std::to_string(i) + "_"; Variable *fake_var = value_exe_info_->GetScope()->Var(new_name); if (out_type.isa()) { - fake_var->GetMutable(); + fake_var->GetMutable(); input_vars_.push_back(fake_var); } else { PADDLE_THROW(common::errors::Unimplemented( @@ -121,16 +121,15 @@ void YieldInstruction::Run() { for (size_t i = 0; i < input_vars_.size(); ++i) { if (input_vars_[i] == nullptr) { output_vars_[i] = nullptr; - } else if (input_vars_[i]->IsType()) { + } else if (input_vars_[i]->IsType()) { if (input_vars_[i]->IsInitialized() && - !input_vars_[i]->Get().initialized()) { + !input_vars_[i]->Get().initialized()) { // 对应 input 为 NULL VALUE 的情况,fake tensor - FullFakeTensor( + FullFakeTensor( value_exe_info_->GetValueByVar(output_vars_[i]), output_vars_[i]); } else { - output_vars_[i]->GetMutable()->ShareDataWith( - input_vars_[i]->Get()); + output_vars_[i]->GetMutable()->ShareDataWith( + input_vars_[i]->Get()); } } else if (input_vars_[i]->IsType()) { const auto &inner_array = input_vars_[i]->Get(); diff --git a/paddle/fluid/framework/new_executor/instruction/cuda_graph_instruction.cc b/paddle/fluid/framework/new_executor/instruction/cuda_graph_instruction.cc index 5622b9a1e9676a..ffabde489071d1 100644 --- a/paddle/fluid/framework/new_executor/instruction/cuda_graph_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/cuda_graph_instruction.cc @@ -174,8 +174,8 @@ void CudaGraphInstruction::Run() { if (cuda_graph_ != nullptr && *cuda_graph_state_ref_ == 3) { VLOG(4) << "Start replaying cuda graph @" << cuda_graph_.get(); for (size_t i = 0; i < input_vars_.size(); ++i) { - if (input_vars_[i]->IsType()) { - auto* tensor = input_vars_[i]->GetMutable(); + if (input_vars_[i]->IsType()) { + auto* tensor = input_vars_[i]->GetMutable(); if (tensor->data() != input_tensors_.at(i).data()) { LOG(WARNING) << "The input [" << i << "] tensor addr for " << "cuda graph is changed. Pay attention to this!"; @@ -192,8 +192,7 @@ void CudaGraphInstruction::Run() { // set the output tensors into scope for (size_t i = 0; i < output_vars_.size(); ++i) { - *(output_vars_[i]->GetMutable()) = - output_tensors_.at(i); + *(output_vars_[i]->GetMutable()) = output_tensors_.at(i); } VLOG(4) << "Finish replaying cuda graph"; return; @@ -206,10 +205,10 @@ void CudaGraphInstruction::Run() { place_, cudaStreamCaptureModeRelaxed, cuda_graph_capture_pool_id_); auto RecordTensorsForReplay = [&](const std::vector& vars) { - std::vector record_tensors; + std::vector record_tensors; record_tensors.reserve(vars.size()); for (auto& var : vars) { - auto& tensor = var->Get(); + auto& tensor = var->Get(); const auto& holder = tensor.Holder(); // Note: new_holder only record the memory address of the tensor for // cuda graph, original tensor memory will be freed to allocator after diff --git a/paddle/fluid/framework/new_executor/instruction/cuda_graph_instruction.h b/paddle/fluid/framework/new_executor/instruction/cuda_graph_instruction.h index b01401f0c06343..2877ab74017c69 100644 --- a/paddle/fluid/framework/new_executor/instruction/cuda_graph_instruction.h +++ b/paddle/fluid/framework/new_executor/instruction/cuda_graph_instruction.h @@ -72,8 +72,8 @@ class CudaGraphInstruction : public InstructionBase { std::vector skip_gc_names_; std::unique_ptr cuda_graph_ = nullptr; - std::vector input_tensors_; - std::vector output_tensors_; + std::vector input_tensors_; + std::vector output_tensors_; }; } // namespace framework diff --git a/paddle/fluid/framework/new_executor/instruction/custom_engine_instruction.cc b/paddle/fluid/framework/new_executor/instruction/custom_engine_instruction.cc index 957cf8794eed91..129f2ca0c9037e 100644 --- a/paddle/fluid/framework/new_executor/instruction/custom_engine_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/custom_engine_instruction.cc @@ -82,7 +82,7 @@ void BuildEngineInputOutputValue(pir::Operation *op, void BuildEngineValueMap( pir::Operation *op, ValueExecutionInfo *value_exec_info, - std::unordered_map> + std::unordered_map> &engine_value_to_tensors, std::unordered_map> &engine_value_to_var_names) { @@ -91,20 +91,19 @@ void BuildEngineValueMap( std::string var_name = kv.second; auto var = value_exec_info->GetVarByValue(value); - if (var->IsType()) { - const phi::DenseTensor *tensor = &(var->Get()); - engine_value_to_tensors[value] = {const_cast(tensor)}; + if (var->IsType()) { + const DenseTensor *tensor = &(var->Get()); + engine_value_to_tensors[value] = {const_cast(tensor)}; engine_value_to_var_names[value] = {var_name}; VLOG(6) << "Build engine value map for " << var_name; } else if (var->IsType()) { - std::vector tensors; + std::vector tensors; std::vector var_names; auto &variable_array = var->Get(); for (size_t i = 0; i < variable_array.size(); ++i) { - if (variable_array[i]->IsType()) { - const phi::DenseTensor *tensor = - &(variable_array[i]->Get()); - tensors.emplace_back(const_cast(tensor)); + if (variable_array[i]->IsType()) { + const DenseTensor *tensor = &(variable_array[i]->Get()); + tensors.emplace_back(const_cast(tensor)); auto var_name_i = value_exec_info->GetVarName(variable_array[i]); var_names.emplace_back(var_name_i); VLOG(6) << "Build engine value map for Variable[" << i diff --git a/paddle/fluid/framework/new_executor/instruction/custom_kernel_instruction.cc b/paddle/fluid/framework/new_executor/instruction/custom_kernel_instruction.cc index 3e3f4a10c740f9..498f2eac908ff2 100644 --- a/paddle/fluid/framework/new_executor/instruction/custom_kernel_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/custom_kernel_instruction.cc @@ -99,10 +99,10 @@ void CustomKernelInstruction::BuildCustomContext( common::errors::PreconditionNotMet( "can not find var[%s] in scope", in_var_name)); auto var = inner_scope->FindVar(in_var_name); - if (var->IsType()) { - auto dense_tensor_in = var->GetMutable(); + if (var->IsType()) { + auto dense_tensor_in = var->GetMutable(); - std::shared_ptr tensor_in( + std::shared_ptr tensor_in( dense_tensor_in, [](phi::DenseTensor* ptr) { VLOG(6) << ptr << " ptr will not be deleted by shared_ptr"; }); @@ -117,10 +117,10 @@ void CustomKernelInstruction::BuildCustomContext( std::vector vec_custom_in; auto& variable_array = var->Get(); for (size_t i = 0; i < variable_array.size(); ++i) { - if (variable_array[i]->IsType()) { + if (variable_array[i]->IsType()) { phi::DenseTensor* dense_tensor_in = const_cast( - &(variable_array[i]->Get())); - std::shared_ptr tensor_in( + &(variable_array[i]->Get())); + std::shared_ptr tensor_in( dense_tensor_in, [](phi::DenseTensor* ptr) { VLOG(6) << ptr << " ptr will not be deleted by shared_ptr"; }); @@ -290,9 +290,9 @@ void CustomKernelInstruction::BuildCustomContext( if (out_ptr.type().isa()) { auto dense_tensor_out = inner_scope->FindVar(value_exec_info_.GetVarName(out_ptr)) - ->GetMutable(); + ->GetMutable(); cache_out_ptrs_.push_back(dense_tensor_out); - std::shared_ptr tensor_out( + std::shared_ptr tensor_out( dense_tensor_out, [](phi::DenseTensor* ptr) { VLOG(6) << ptr << " ptr will not be deleted by shared_ptr"; }); @@ -315,11 +315,11 @@ void CustomKernelInstruction::BuildCustomContext( "If custom operator's outputs contains `paddle::Vec()` type " "without setting InplaceMap, it only can hold one output.")); for (size_t j = 0; j < variable_array.size(); ++j) { - if (variable_array[j]->IsType()) { + if (variable_array[j]->IsType()) { auto dense_tensor_out = const_cast( - &(variable_array[j]->Get())); + &(variable_array[j]->Get())); cache_out_ptrs_.emplace_back(dense_tensor_out); - std::shared_ptr tensor_out( + std::shared_ptr tensor_out( dense_tensor_out, [](phi::DenseTensor* ptr) { VLOG(6) << ptr << " ptr will not be deleted by shared_ptr"; }); diff --git a/paddle/fluid/framework/new_executor/instruction/instruction_base.cc b/paddle/fluid/framework/new_executor/instruction/instruction_base.cc index 7e591494725dc5..9dc8c7175a3fb8 100644 --- a/paddle/fluid/framework/new_executor/instruction/instruction_base.cc +++ b/paddle/fluid/framework/new_executor/instruction/instruction_base.cc @@ -33,8 +33,8 @@ static DDim GetDimsDebug(const Scope& scope, return DDim({-1}); } - if (var->IsType()) { - const phi::DenseTensor& tensor = var->Get(); + if (var->IsType()) { + const phi::DenseTensor& tensor = var->Get(); return tensor.dims(); } else if (var->IsType()) { if (get_actual_dim) { @@ -61,8 +61,8 @@ static std::string GetDtype(const Scope& scope, const std::string& name) { return ""; } - if (var->IsType()) { - const phi::DenseTensor& tensor = var->Get(); + if (var->IsType()) { + const phi::DenseTensor& tensor = var->Get(); if (UNLIKELY(!tensor.has_allocation())) { return ""; } @@ -92,8 +92,8 @@ static std::string GetPlace(const Scope& scope, const std::string& name) { return sstream.str(); }; - if (var->IsType()) { - const phi::DenseTensor& tensor = var->Get(); + if (var->IsType()) { + const phi::DenseTensor& tensor = var->Get(); if (UNLIKELY(!tensor.has_allocation())) { return ""; } @@ -135,8 +135,8 @@ static LegacyLoD GetLoDDebug(const Scope& scope, const std::string& name) { return default_lod; } - if (var->IsType()) { - const phi::DenseTensor& tensor = var->Get(); + if (var->IsType()) { + const phi::DenseTensor& tensor = var->Get(); return tensor.lod(); } else { return default_lod; @@ -149,14 +149,12 @@ static double GetDenseTensorEleSum(const Scope& scope, if (var == nullptr) { return std::numeric_limits::quiet_NaN(); } - if (var->IsType() && - var->Get().initialized()) { - phi::DenseTensor cpu_tensor; + if (var->IsType() && var->Get().initialized()) { + DenseTensor cpu_tensor; CPUPlace place; - paddle::framework::TensorCopy( - var->Get(), place, &cpu_tensor); + paddle::framework::TensorCopy(var->Get(), place, &cpu_tensor); phi::DeviceContextPool& pool = phi::DeviceContextPool::Instance(); - auto& dev_ctx = *pool.Get(var->Get().place()); + auto& dev_ctx = *pool.Get(var->Get().place()); dev_ctx.Wait(); double sum = 0.0; for (int64_t i = 0; i < cpu_tensor.numel(); i++) { diff --git a/paddle/fluid/framework/new_executor/instruction/instruction_util.cc b/paddle/fluid/framework/new_executor/instruction/instruction_util.cc index bce302b17f008d..143e0f225ace86 100644 --- a/paddle/fluid/framework/new_executor/instruction/instruction_util.cc +++ b/paddle/fluid/framework/new_executor/instruction/instruction_util.cc @@ -548,7 +548,7 @@ bool GetCondData(const phi::DenseTensor& cond) { } // when phi::is_gpu_place(cond.place()) or // phi::is_xpu_place(cond.place()) is true - std::unique_ptr cpu_cond{new phi::DenseTensor()}; + std::unique_ptr cpu_cond{new phi::DenseTensor()}; #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \ defined(PADDLE_WITH_XPU) || defined(PADDLE_WITH_CUSTOM_DEVICE) paddle::framework::TensorCopySync(cond, CPUPlace(), cpu_cond.get()); @@ -635,9 +635,9 @@ void HandleForInplaceOp(pir::Operation* op, } void ShareVarBuffer(const Variable* src_var, Variable* dst_var) { - if (src_var->IsType()) { - auto& src_tensor = src_var->Get(); - auto* tmp_dst_tensor = dst_var->GetMutable(); + if (src_var->IsType()) { + auto& src_tensor = src_var->Get(); + auto* tmp_dst_tensor = dst_var->GetMutable(); tmp_dst_tensor->ShareBufferWith(src_tensor); return; } else if (src_var->IsType()) { diff --git a/paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc b/paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc index bb7e15f92d433e..e3e5db795f606a 100644 --- a/paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc @@ -412,11 +412,11 @@ void OneDNNPhiKernelInstruction::Run() { CUDAErrorCheck("OneDNNPhiKernelInstruction " + phi_op_name_ + " begin"); } - std::vector> tmp_holders; + std::vector> tmp_holders; auto tmp_kernel_context = kernel_context_; auto tmp_infer_meta_context_ = infer_meta_context_; // Step1. TransLayout - auto inputs = tmp_kernel_context.InputsBetween( + auto inputs = tmp_kernel_context.InputsBetween( size_t(0), tmp_kernel_context.InputsSize()); for (size_t i = 0; i < inputs.size(); ++i) { auto input = inputs[i]; @@ -433,7 +433,7 @@ void OneDNNPhiKernelInstruction::Run() { << ", shape = " << input->dims(); if (input->layout() != phi::DataLayout::ONEDNN) { phi::DataLayout from_layout = input->layout(); - tmp_holders.emplace_back(std::make_shared(*input)); + tmp_holders.emplace_back(std::make_shared(*input)); auto transed_tensor = tmp_holders.back().get(); std::set elementwise_kernels = {"onednn_op.add", diff --git a/paddle/fluid/framework/new_executor/instruction/onednn/onednn_legacy_instruction.cc b/paddle/fluid/framework/new_executor/instruction/onednn/onednn_legacy_instruction.cc index e7c57a3b8aee1b..d2ecbe173cd015 100644 --- a/paddle/fluid/framework/new_executor/instruction/onednn/onednn_legacy_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/onednn/onednn_legacy_instruction.cc @@ -273,8 +273,8 @@ void OneDNNLegacyKernelInstruction::Run() { } auto input_vars = kernel_context_->MultiInputVar(*input_name); for (auto& var : input_vars) { - if (var->IsType()) { - auto input = var->GetMutable(); + if (var->IsType()) { + auto input = var->GetMutable(); if (input->layout() != phi::DataLayout::ONEDNN) { phi::DataLayout from_layout = input->layout(); diff --git a/paddle/fluid/framework/new_executor/instruction/onednn/onednn_mixed_instruction.cc b/paddle/fluid/framework/new_executor/instruction/onednn/onednn_mixed_instruction.cc index 7495a7ed4b5ffa..31c273914cb347 100644 --- a/paddle/fluid/framework/new_executor/instruction/onednn/onednn_mixed_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/onednn/onednn_mixed_instruction.cc @@ -64,7 +64,7 @@ void OneDNNMixedPhiKernelInstruction::Run() { " begin"); } - std::vector> tmp_holders; + std::vector> tmp_holders; // Step1. Mixed Dynamic Choose Kernel if (!has_choose_kernel_) { has_choose_kernel_ = true; @@ -86,7 +86,7 @@ void OneDNNMixedPhiKernelInstruction::Run() { auto tmp_kernel_context = kernel_context_; auto tmp_infer_meta_context_ = infer_meta_context_; // TransLayout first - auto inputs = tmp_kernel_context.InputsBetween( + auto inputs = tmp_kernel_context.InputsBetween( size_t(0), tmp_kernel_context.InputsSize()); for (size_t i = 0; i < inputs.size(); ++i) { @@ -98,7 +98,7 @@ void OneDNNMixedPhiKernelInstruction::Run() { // NOTE(zhiqiu): to handle the special case in ApplyDataTransform() in // data_transfer.cc if (!input->IsInitialized() && tmp_layout == DataLayout::NHWC) { - tmp_holders.emplace_back(std::make_shared(*input)); + tmp_holders.emplace_back(std::make_shared(*input)); auto transed_tensor = tmp_holders.back().get(); transed_tensor->set_layout(tmp_layout); phi::funcs::MatchShapeToLayout( @@ -123,7 +123,7 @@ void OneDNNMixedPhiKernelInstruction::Run() { } } } else { - tmp_holders.emplace_back(std::make_shared()); + tmp_holders.emplace_back(std::make_shared()); auto transed_tensor = tmp_holders.back().get(); transed_tensor->set_meta(input->meta()); phi::funcs::TransDataLayoutFromOneDNN(phi::DataLayout::ONEDNN, diff --git a/paddle/fluid/framework/new_executor/instruction/python_function_instruction.cc b/paddle/fluid/framework/new_executor/instruction/python_function_instruction.cc index a605db3214d77d..e1dc2d540ac7f2 100644 --- a/paddle/fluid/framework/new_executor/instruction/python_function_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/python_function_instruction.cc @@ -95,10 +95,10 @@ void PythonFunctionInstruction::BuildPythonFunctionContext( common::errors::PreconditionNotMet( "can not find var[%s] in scope", in_var_name)); auto var = inner_scope->FindVar(in_var_name); - if (var->IsType()) { - auto dense_tensor_in = var->GetMutable(); + if (var->IsType()) { + auto dense_tensor_in = var->GetMutable(); - std::shared_ptr tensor_in( + std::shared_ptr tensor_in( dense_tensor_in, [](phi::DenseTensor* ptr) { VLOG(6) << ptr << " ptr will not be deleted by shared_ptr"; }); @@ -170,9 +170,9 @@ void PythonFunctionInstruction::BuildPythonFunctionContext( if (out_ptr.type().isa()) { auto dense_tensor_out = inner_scope->FindVar(value_exec_info_.GetVarName(out_ptr)) - ->GetMutable(); + ->GetMutable(); cache_out_ptrs_.push_back(dense_tensor_out); - std::shared_ptr tensor_out( + std::shared_ptr tensor_out( dense_tensor_out, [](phi::DenseTensor* ptr) { VLOG(6) << ptr << " ptr will not be deleted by shared_ptr"; }); diff --git a/paddle/fluid/framework/new_executor/instruction/tensorrt_engine_instruction.cc b/paddle/fluid/framework/new_executor/instruction/tensorrt_engine_instruction.cc index cb1d9f5aee999e..23d4a77a296005 100644 --- a/paddle/fluid/framework/new_executor/instruction/tensorrt_engine_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/tensorrt_engine_instruction.cc @@ -227,7 +227,7 @@ TensorRTEngineInstruction::TensorRTEngineInstruction( std::vector param_names = refit_param_names_; std::sort(param_names.begin(), param_names.end()); - std::vector tensor_out; + std::vector tensor_out; for (size_t i = 0; i < len; ++i) { auto *tensor_temp = new phi::DenseTensor(); tensor_temp->Resize({1}); @@ -406,13 +406,12 @@ void TensorRTEngineInstruction::InputsCheck() { } } -void TensorRTEngineInstruction::BindInputTensor( - const std::string &input_name, - const phi::DenseTensor &input_tensor, - const Scope &scope, - std::vector &buffers, - std::vector &shape_v, - int *runtime_batch) { +void TensorRTEngineInstruction::BindInputTensor(const std::string &input_name, + const DenseTensor &input_tensor, + const Scope &scope, + std::vector &buffers, + std::vector &shape_v, + int *runtime_batch) { auto dev_place = dev_ctx_->GetPlace(); const int num_bindings = trt_engine_->GetNbBindings(); int binding_offset = 0; @@ -435,9 +434,9 @@ void TensorRTEngineInstruction::BindInputTensor( // check the input_tensor if (!(input_tensor.place().GetType() == phi::AllocationType::GPU)) { - phi::DenseTensor out; + DenseTensor out; phi::Copy(*dev_ctx_, input_tensor, dev_place, false, &out); - const_cast(input_tensor).ShareDataWith(out); + const_cast(input_tensor).ShareDataWith(out); } auto input_shape = common::vectorize(input_tensor.dims()); @@ -509,7 +508,7 @@ void TensorRTEngineInstruction::BindInputTensor( if (scope.FindVar(x_t) == nullptr) { const_cast(&scope)->Var(x_t); } - auto int32_tensor = scope.FindVar(x_t)->GetMutable(); + auto int32_tensor = scope.FindVar(x_t)->GetMutable(); *int32_tensor = phi::Cast( reinterpret_cast(*dev_ctx_), input_tensor, @@ -561,7 +560,7 @@ void TensorRTEngineInstruction::BindInputTensor( if (scope.FindVar(x_t) == nullptr) { const_cast(&scope)->Var(x_t); } - auto fp32_tensor = scope.FindVar(x_t)->GetMutable(); + auto fp32_tensor = scope.FindVar(x_t)->GetMutable(); *fp32_tensor = phi::Cast(reinterpret_cast(*dev_ctx_), input_tensor, @@ -575,7 +574,7 @@ void TensorRTEngineInstruction::BindInputTensor( if (scope.FindVar(x_t) == nullptr) { const_cast(&scope)->Var(x_t); } - auto int32_tensor = scope.FindVar(x_t)->GetMutable(); + auto int32_tensor = scope.FindVar(x_t)->GetMutable(); *int32_tensor = phi::Cast(reinterpret_cast(*dev_ctx_), input_tensor, @@ -598,12 +597,11 @@ void TensorRTEngineInstruction::BindInputTensor( } } -void TensorRTEngineInstruction::BindOutputTensor( - std::string output_name, - phi::DenseTensor *output_tensor, - int output_index, - std::vector &buffers, - int *runtime_batch) { +void TensorRTEngineInstruction::BindOutputTensor(std::string output_name, + DenseTensor *output_tensor, + int output_index, + std::vector &buffers, + int *runtime_batch) { int binding_offset = 0; const int num_bindings = trt_engine_->GetNbBindings(); [[maybe_unused]] nvinfer1::IExecutionContext *trt_context = nullptr; @@ -642,7 +640,7 @@ void TensorRTEngineInstruction::BindOutputTensor( binding_offset; #endif std::vector ddim; - phi::DenseTensor *fluid_t = nullptr; + DenseTensor *fluid_t = nullptr; #if IS_TRT_VERSION_GE(8500) auto x_name = trt_engine_->engine()->getIOTensorName(bind_index); auto dims = trt_context->getTensorShape(x_name); @@ -669,7 +667,7 @@ void TensorRTEngineInstruction::BindOutputTensor( if (scope.FindVar(tmp_output) == nullptr) { const_cast(&scope)->Var(tmp_output); } - fluid_t = scope.FindVar(tmp_output)->GetMutable(); + fluid_t = scope.FindVar(tmp_output)->GetMutable(); } else { fluid_t = output_tensor; } @@ -727,8 +725,8 @@ void TensorRTEngineInstruction::RunTrt() { for (const auto &index_name_pair : input_names_) { size_t i = index_name_pair.first; - if (in_variable_array[i]->IsType()) { - auto input_tensor = in_variable_array[i]->Get(); + if (in_variable_array[i]->IsType()) { + auto input_tensor = in_variable_array[i]->Get(); // Bind input tensor to TRT. BindInputTensor(index_name_pair.second, input_tensor, @@ -757,9 +755,9 @@ void TensorRTEngineInstruction::RunTrt() { out_variable_array = out_var->GetMutable(); for (const auto &index_name_pair : output_names_) { size_t i = index_name_pair.first; - if (out_variable_array->at(i)->IsType()) { - auto output_tensor = const_cast( - &(out_variable_array->at(i)->Get())); + if (out_variable_array->at(i)->IsType()) { + auto output_tensor = const_cast( + &(out_variable_array->at(i)->Get())); // Bind input tensor to TRT. BindOutputTensor( index_name_pair.second, output_tensor, i, buffers, &runtime_batch); @@ -820,9 +818,9 @@ void TensorRTEngineInstruction::RunTrt() { std::string tmp_output = output_name + "_tmp"; if (scope.FindVar(tmp_output) != nullptr) { auto *output_tensor_tmp = - scope.FindVar(tmp_output)->GetMutable(); - auto *output_tensor = const_cast( - &(out_variable_array->at(i)->Get())); + scope.FindVar(tmp_output)->GetMutable(); + auto *output_tensor = const_cast( + &(out_variable_array->at(i)->Get())); std::vector ddim; for (int i = 0; i < trt_dims.nbDims; i++) { ddim.push_back(trt_dims.d[i]); @@ -866,13 +864,12 @@ void TensorRTEngineInstruction::RunTrt() { if (type == phi::DataType::INT64 && !support_int64) { auto y = index_name_pair.second; auto *fluid_v = out_variable_array->at(i); - auto *fluid_t = - const_cast(&(fluid_v->Get())); + auto *fluid_t = const_cast(&(fluid_v->Get())); std::string y_t = y + "_cast_to_INT64"; if (scope.FindVar(y_t) == nullptr) { const_cast(&scope)->Var(y_t); } - auto int32_tensor = scope.FindVar(y_t)->GetMutable(); + auto int32_tensor = scope.FindVar(y_t)->GetMutable(); int32_tensor->Resize(fluid_t->dims()); dev_ctx_->Alloc(int32_tensor); phi::Copy(*dev_ctx_, *fluid_t, dev_place, false, int32_tensor); @@ -883,13 +880,12 @@ void TensorRTEngineInstruction::RunTrt() { } else if (type == phi::DataType::FLOAT64) { auto y = index_name_pair.second; auto *fluid_v = out_variable_array->at(i); - auto *fluid_t = - const_cast(&(fluid_v->Get())); + auto *fluid_t = const_cast(&(fluid_v->Get())); std::string y_t = y + "_cast_to_FP64"; if (scope.FindVar(y_t) == nullptr) { const_cast(&scope)->Var(y_t); } - auto fp32_tensor = scope.FindVar(y_t)->GetMutable(); + auto fp32_tensor = scope.FindVar(y_t)->GetMutable(); fp32_tensor->Resize(fluid_t->dims()); dev_ctx_->Alloc(fp32_tensor); phi::Copy(*dev_ctx_, *fluid_t, dev_place, false, fp32_tensor); diff --git a/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc b/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc index e950bcaa0d39b2..040efcab9c4325 100644 --- a/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc +++ b/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc @@ -237,7 +237,7 @@ void DataTransferHelper::RunAndConstructOpFuncNode( // Var is initialized && var contains tensor && tensor is initialized bool IsTensorOfVarInitialized(Variable* var) { if (var->IsInitialized()) { - if (var->IsType() || var->IsType()) { + if (var->IsType() || var->IsType()) { return GetDenseTensorOrSelectedRowsValueFromVar(*var)->IsInitialized(); } else if (var->IsType()) { return static_cast( @@ -508,8 +508,7 @@ void ApplyDataTransform(const OpKernelType& expected_kernel_key, Variable* var = arguments->at(i); const phi::DenseTensor* tensor_in = nullptr; - if (var->IsType() || - var->IsType()) { + if (var->IsType() || var->IsType()) { tensor_in = GetDenseTensorOrSelectedRowsValueFromVar(*var); } else if (var->IsType()) { if (var->Get().empty()) { @@ -534,10 +533,10 @@ void ApplyDataTransform(const OpKernelType& expected_kernel_key, // In such situation corresponding resized Var // has to be created and registered if ((tensor_in->layout() == DataLayout::ONEDNN) && - (var->IsType() == true) && + (var->IsType() == true) && (expected_kernel_key.data_layout_ != DataLayout::ONEDNN)) { VLOG(7) << "Created reshaped dummy input based on MKL-DNN " - "phi::DenseTensor , " + "DenseTensor , " "but NHWC layout" << parameter_name << " in Operator " << op_base->Type(); auto op = TransferLayout( diff --git a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc index 248877aa95d319..dbb37e33e2416a 100644 --- a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc +++ b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc @@ -1011,8 +1011,8 @@ void BuildOpFuncList(const phi::Place& place, auto* var = local_scope->FindVar(vname); if (var == nullptr) continue; const phi::DenseTensor* tensor{nullptr}; - if (var->IsType()) { - tensor = &var->Get(); + if (var->IsType()) { + tensor = &var->Get(); } else { VLOG(6) << vname << " is not DenseTensor"; continue; @@ -1027,8 +1027,8 @@ void BuildOpFuncList(const phi::Place& place, auto* var = local_scope->FindVar(vname); if (var == nullptr) continue; const phi::DenseTensor* tensor{nullptr}; - if (var->IsType()) { - tensor = &var->Get(); + if (var->IsType()) { + tensor = &var->Get(); } else { VLOG(6) << vname << " is not DenseTensor"; continue; @@ -1100,9 +1100,9 @@ void BuildOpFuncList(const phi::Place& place, } VLOG(6) << "Erase variable " << var_name; - if (var->IsType()) { + if (var->IsType()) { garbages->emplace_back( - var->GetMutable()->MoveMemoryHolder()); + var->GetMutable()->MoveMemoryHolder()); } else if (var->IsType()) { garbages->emplace_back(var->GetMutable() ->mutable_value() @@ -1147,9 +1147,9 @@ void BuildOpFuncList(const phi::Place& place, auto* var = local_scope->FindVar(var_name); if (var == nullptr) continue; VLOG(6) << "Erase variable " << var_name; - if (var->IsType()) { + if (var->IsType()) { garbages->emplace_back( - var->GetMutable()->MoveMemoryHolder()); + var->GetMutable()->MoveMemoryHolder()); } else if (var->IsType()) { garbages->emplace_back(var->GetMutable() ->mutable_value() diff --git a/paddle/fluid/framework/new_executor/interpreter/static_build.cc b/paddle/fluid/framework/new_executor/interpreter/static_build.cc index 2a287550e8e00b..b5328978f26e84 100644 --- a/paddle/fluid/framework/new_executor/interpreter/static_build.cc +++ b/paddle/fluid/framework/new_executor/interpreter/static_build.cc @@ -71,8 +71,8 @@ static VarMetaInfo GetVarMetaInfo(const Scope& scope, const std::string& name) { return VarMetaInfo(name, dtype, place); } - if (var->IsType()) { - const phi::DenseTensor& tensor = var->Get(); + if (var->IsType()) { + const phi::DenseTensor& tensor = var->Get(); if (!UNLIKELY(!tensor.has_allocation())) { dtype = tensor.dtype(); place = tensor.place(); @@ -274,8 +274,8 @@ bool TensorShouldBeFakeInitialized(const OperatorBase& op, phi::TensorBase* GetTensorFormVar(framework::Variable* var) { if (var) { - if (var->template IsType()) { - return var->template GetMutable(); + if (var->template IsType()) { + return var->template GetMutable(); } else if (var->template IsType()) { return var->template GetMutable(); } else if (var->template IsType()) { @@ -540,8 +540,7 @@ void RunWhileBlockPreStaticBuild(const framework::Scope& scope, } if (var->Type() == framework::proto::VarType::DENSE_TENSOR) { - input_var_original_places[in_name] = - (var->Get()).place(); + input_var_original_places[in_name] = (var->Get()).place(); } else { VLOG(10) << "[while op]" << "skip backup input " << in_name << " type:" @@ -572,11 +571,11 @@ void RunWhileBlockPreStaticBuild(const framework::Scope& scope, if (no_copy_var_names.find(input_var_name) == no_copy_var_names.end()) { std::string input_var_rename = input_var_name + "@TMP_COPY"; framework::Variable* input_var = scope.FindVar(input_var_name); - if (input_var->IsType()) { + if (input_var->IsType()) { rename_vars.push_back(input_var_rename); - auto input_var_tensor = input_var->Get(); - auto* rename_input_var_tensor = current_scope.Var(input_var_rename) - ->GetMutable(); + auto input_var_tensor = input_var->Get(); + auto* rename_input_var_tensor = + current_scope.Var(input_var_rename)->GetMutable(); framework::TensorCopy( input_var_tensor, dev_place, rename_input_var_tensor); rename_input_var_tensor->set_lod(input_var_tensor.lod()); @@ -620,9 +619,9 @@ void RunWhileBlockPreStaticBuild(const framework::Scope& scope, for (auto& name : current_scope->LocalVarNames()) { auto* var = current_scope->Var(name); - if (var->IsType()) { + if (var->IsType()) { // Clear all lod information for all lod_tensors. - auto* t = var->GetMutable(); + auto* t = var->GetMutable(); phi::LegacyLoD empty_lod; t->set_lod(empty_lod); } else if (var->IsType()) { diff --git a/paddle/fluid/framework/new_executor/interpreter_base_impl.h b/paddle/fluid/framework/new_executor/interpreter_base_impl.h index dd7014df23a40c..362ac7f324f615 100644 --- a/paddle/fluid/framework/new_executor/interpreter_base_impl.h +++ b/paddle/fluid/framework/new_executor/interpreter_base_impl.h @@ -65,7 +65,7 @@ class InterpreterBaseImpl { virtual ~InterpreterBaseImpl() = default; virtual paddle::framework::FetchList Run( const std::vector& feed_names, - const std::vector& feed_tensors, + const std::vector& feed_tensors, bool need_fetch = true, bool enable_job_schedule_profiler = false, bool switch_stream = false) = 0; diff --git a/paddle/fluid/framework/new_executor/interpretercore.cc b/paddle/fluid/framework/new_executor/interpretercore.cc index 00d1c50c559e74..04ad56b5422877 100644 --- a/paddle/fluid/framework/new_executor/interpretercore.cc +++ b/paddle/fluid/framework/new_executor/interpretercore.cc @@ -64,12 +64,11 @@ InterpreterCore::~InterpreterCore() { impl_.reset(nullptr); } -FetchList InterpreterCore::Run( - const std::vector& feed_names, - const std::vector& feed_tensors, - bool need_fetch, - bool enable_job_schedule_profiler, - bool switch_stream) { +FetchList InterpreterCore::Run(const std::vector& feed_names, + const std::vector& feed_tensors, + bool need_fetch, + bool enable_job_schedule_profiler, + bool switch_stream) { return impl_->Run(feed_names, feed_tensors, need_fetch, diff --git a/paddle/fluid/framework/new_executor/interpretercore.h b/paddle/fluid/framework/new_executor/interpretercore.h index 7ee7639167360a..b6a144d0c17763 100644 --- a/paddle/fluid/framework/new_executor/interpretercore.h +++ b/paddle/fluid/framework/new_executor/interpretercore.h @@ -49,7 +49,7 @@ class InterpreterCore { TEST_API paddle::framework::FetchList Run( const std::vector& feed_names, - const std::vector& feed_tensors, + const std::vector& feed_tensors, bool need_fetch = true, bool enable_job_schedule_profiler = false, bool switch_stream = false); diff --git a/paddle/fluid/framework/new_executor/nan_inf_utils.cc b/paddle/fluid/framework/new_executor/nan_inf_utils.cc index 99a813e9af5924..016dc0f8731dbe 100644 --- a/paddle/fluid/framework/new_executor/nan_inf_utils.cc +++ b/paddle/fluid/framework/new_executor/nan_inf_utils.cc @@ -67,8 +67,8 @@ void CheckTensorHasNanOrInf(InstructionBase* instruction, VLOG(10) << "No var found for tensor_name: " << tensor_name; continue; } - if (var->IsType()) { - dense_tensor = var->GetMutable(); + if (var->IsType()) { + dense_tensor = var->GetMutable(); } else if (var->IsType()) { dense_tensor = var->GetMutable()->mutable_value(); } else { diff --git a/paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.cc b/paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.cc index 3b4edb4f689fb2..c9cea267739f53 100644 --- a/paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.cc +++ b/paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.cc @@ -315,9 +315,9 @@ void DeepCopyVariable(const Variable* src_var, return; } - if (src_var->IsType()) { - auto& src_tensor = src_var->Get(); - auto* tmp_dst_tensor = (*dst_var)->GetMutable(); + if (src_var->IsType()) { + auto& src_tensor = src_var->Get(); + auto* tmp_dst_tensor = (*dst_var)->GetMutable(); tmp_dst_tensor->set_lod(src_tensor.lod()); // NOTE(chenxi67): why add ? In some case(e.g. // Opresult reserve_space generated by BatchNorm Op), Variable pointer is @@ -428,7 +428,7 @@ void BuildValue(pir::Value value, // Only support DenseTensor or Vector if (!value.type() || value.type().isa()) { - var->GetMutable(); + var->GetMutable(); } else if (value.type().isa()) { var->GetMutable(); } else if (value.type() @@ -455,7 +455,7 @@ void BuildValue(pir::Value value, "DenseTensorType")); auto var_i = CreateVar(value, var_name_prefix, false, value_exe_info); - var_i->GetMutable(); + var_i->GetMutable(); tensor_array->emplace_back(var_i); } } else { @@ -489,7 +489,7 @@ void HandleForSpecialOp(pir::Operation* op, .isa()) { var->GetMutable(); } else { - var->GetMutable(); + var->GetMutable(); } auto value = op->result(0); @@ -506,7 +506,7 @@ void HandleForSpecialOp(pir::Operation* op, Variable* var = value_exe_info->GetScope()->FindVar(name); if (var == nullptr) { var = value_exe_info->GetScope()->Var(name); - auto* t = var->GetMutable(); + auto* t = var->GetMutable(); if (op_name == paddle::dialect::DataOp::name()) { auto shape = op->attribute("shape"); auto dim = phi::make_ddim(shape.data().GetData()); diff --git a/paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.h b/paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.h index 1404b304b3c02d..6f352f756bc889 100644 --- a/paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.h +++ b/paddle/fluid/framework/new_executor/pir_adaptor/pir_adaptor_util.h @@ -210,8 +210,8 @@ void BuildPhiContext(pir::Operation* op, common::errors::PreconditionNotMet( "can not find var[%s] in scope", in_var_name)); auto var = inner_scope->FindVar(in_var_name); - if (var->IsType()) { - const phi::TensorBase* tensor_in = &(var->Get()); + if (var->IsType()) { + const phi::TensorBase* tensor_in = &(var->Get()); ctx->EmplaceBackInput(InType(tensor_in)); } else if (var->IsType()) { const phi::TensorBase* tensor_in = &(var->Get()); @@ -220,9 +220,9 @@ void BuildPhiContext(pir::Operation* op, InListType inputs; auto& variable_array = var->Get(); for (size_t i = 0; i < variable_array.size(); ++i) { - if (variable_array[i]->IsType()) { + if (variable_array[i]->IsType()) { inputs.emplace_back(InType(const_cast( - &(variable_array[i]->Get())))); + &(variable_array[i]->Get())))); } else if (variable_array[i]->IsType()) { inputs.emplace_back(InType(const_cast( &(variable_array[i]->Get())))); @@ -267,20 +267,20 @@ void BuildPhiContext(pir::Operation* op, if (tensor_attr_type == "paddle::dialect::IntArrayAttribute") { if (ptr.type().isa()) { phi::Attribute attr = phi::TensorRef( - &(inner_scope->FindVar(in_var_name)->Get())); + &(inner_scope->FindVar(in_var_name)->Get())); ctx->EmplaceBackAttr(attr); } else if (ptr.type().isa()) { auto& tensor_array = inner_scope->FindVar(in_var_name)->Get(); if (tensor_array.size() == 1) { phi::Attribute attr = - phi::TensorRef(&(tensor_array[0]->Get())); + phi::TensorRef(&(tensor_array[0]->Get())); ctx->EmplaceBackAttr(attr); } else { std::vector vec_ref; for (size_t i = 0; i < tensor_array.size(); ++i) { vec_ref.emplace_back( - phi::TensorRef(&(tensor_array[i]->Get()))); + phi::TensorRef(&(tensor_array[i]->Get()))); } ctx->EmplaceBackAttr(vec_ref); } @@ -291,7 +291,7 @@ void BuildPhiContext(pir::Operation* op, } } else if (tensor_attr_type == "paddle::dialect::ScalarAttribute") { phi::Attribute attr = phi::TensorRef( - &(inner_scope->FindVar(in_var_name)->Get())); + &(inner_scope->FindVar(in_var_name)->Get())); ctx->EmplaceBackAttr(attr); } else { @@ -478,7 +478,7 @@ void BuildPhiContext(pir::Operation* op, if (out_ptr.type().isa()) { ctx->EmplaceBackOutput(OutType(const_cast( &(inner_scope->FindVar(value_exec_info.GetVarName(out_ptr)) - ->Get())))); + ->Get())))); VLOG(8) << "ctx->EmplaceBackOutput DenseTensor: " << value_exec_info.GetVarName(out_ptr); } else if (out_ptr.type() @@ -515,9 +515,9 @@ void BuildPhiContext(pir::Operation* op, inner_scope->FindVar(value_exec_info.GetVarName(out_ptr)) ->Get(); for (size_t i = 0; i < variable_array.size(); ++i) { - if (variable_array[i]->IsType()) { + if (variable_array[i]->IsType()) { outputs.emplace_back(OutType(const_cast( - &(variable_array[i]->Get())))); + &(variable_array[i]->Get())))); } else if (variable_array[i]->IsType()) { outputs.emplace_back(OutType(const_cast( &(variable_array[i]->Get())))); diff --git a/paddle/fluid/framework/new_executor/pir_interpreter.cc b/paddle/fluid/framework/new_executor/pir_interpreter.cc index f0a5f82b0ff4aa..9104582262dbb6 100644 --- a/paddle/fluid/framework/new_executor/pir_interpreter.cc +++ b/paddle/fluid/framework/new_executor/pir_interpreter.cc @@ -1269,8 +1269,8 @@ void PirInterpreter::RecordStreamForGC(InstructionBase* instr) { continue; } - if (var->IsType()) { - TensorRecordStream(*(var->GetMutable())); + if (var->IsType()) { + TensorRecordStream(*(var->GetMutable())); } else if ( var->IsType< operators::reader:: @@ -1395,7 +1395,7 @@ void PirInterpreter::CalculateLastLiveOps() { "Var(id=%d,%s) should not be nullptr.", static_cast(var_id), value_exe_info_->GetNameById(static_cast(var_id)))); - if (var->IsType() || var->IsType() || + if (var->IsType() || var->IsType() || var->IsType() || var->IsType() || var->IsType()) { @@ -1495,7 +1495,7 @@ void PirInterpreter::ConstructEventForJitInput() { paddle::framework::FetchList PirInterpreter::Run( const std::vector& feed_names, - const std::vector& feed_tensors, + const std::vector& feed_tensors, bool need_fetch, bool enable_job_schedule_profiler, bool switch_stream) { @@ -1510,7 +1510,7 @@ paddle::framework::FetchList PirInterpreter::Run( common::errors::NotFound("Variable %s should not be nullptr.", feed_names[i])); - auto feed_tensor = feed_var->GetMutable(); + auto feed_tensor = feed_var->GetMutable(); feed_tensor->ShareDataWith(feed_tensors[i]); feed_tensor->set_lod(feed_tensors[i].lod()); } @@ -1575,7 +1575,7 @@ paddle::framework::FetchList PirInterpreter::Run( for (auto& var_name : fetch_var_names_) { auto* var = inner_scope->FindVar(var_name); VLOG(4) << "fetch " << var_name << "[" << var << "]"; - fetch_res.push_back(var->Get()); + fetch_res.push_back(var->Get()); } } @@ -1654,7 +1654,7 @@ FetchList PirInterpreter::Run(const std::vector& feed_names, for (auto& var_name : fetch_var_names_) { auto* var = inner_scope->FindVar(var_name); VLOG(4) << "fetch " << var_name << "[" << var << "]"; - fetch_res.push_back(var->Get()); + fetch_res.push_back(var->Get()); } VLOG(4) << "get fetch list size: " << fetch_res.size(); diff --git a/paddle/fluid/framework/new_executor/pir_interpreter.h b/paddle/fluid/framework/new_executor/pir_interpreter.h index 3fff4227241054..d6b3be49247ae0 100644 --- a/paddle/fluid/framework/new_executor/pir_interpreter.h +++ b/paddle/fluid/framework/new_executor/pir_interpreter.h @@ -54,12 +54,11 @@ class PirInterpreter : public InterpreterBaseImpl { ~PirInterpreter(); - paddle::framework::FetchList Run( - const std::vector& feed_names, - const std::vector& feed_tensors, - bool need_fetch = true, - bool enable_job_schedule_profiler = false, - bool switch_stream = false) override; + paddle::framework::FetchList Run(const std::vector& feed_names, + const std::vector& feed_tensors, + bool need_fetch = true, + bool enable_job_schedule_profiler = false, + bool switch_stream = false) override; paddle::framework::FetchList Run(const std::vector& feed_names, bool need_fetch = true, diff --git a/paddle/fluid/framework/new_executor/program_interpreter.cc b/paddle/fluid/framework/new_executor/program_interpreter.cc index ebd5ef4e6fc5e0..39a8c5da95c05c 100644 --- a/paddle/fluid/framework/new_executor/program_interpreter.cc +++ b/paddle/fluid/framework/new_executor/program_interpreter.cc @@ -270,12 +270,11 @@ void ProgramInterpreter::Build( } } -FetchList ProgramInterpreter::Run( - const std::vector& feed_names, - const std::vector& feed_tensors, - bool need_fetch, - bool enable_job_schedule_profiler, - bool switch_stream) { +FetchList ProgramInterpreter::Run(const std::vector& feed_names, + const std::vector& feed_tensors, + bool need_fetch, + bool enable_job_schedule_profiler, + bool switch_stream) { enable_job_schedule_profiler_ = enable_job_schedule_profiler; SetDeviceId(place_); @@ -541,8 +540,8 @@ void ProgramInterpreter::BuildInplace() { auto invar = local_scope->FindVar(invar_name); auto outvar = local_scope->FindVar(outvar_name); - if (invar && outvar && invar->IsType() && - outvar->IsType() && + if (invar && outvar && invar->IsType() && + outvar->IsType() && skip_inplace_outvars.find(outvar_name) == skip_inplace_outvars.end()) { instr.AddInplace(invar, outvar); @@ -678,7 +677,7 @@ void ProgramInterpreter::BuildOperatorDependences() { } } -// At the end of each step, the holder of phi::DenseTensor in phi::TensorArray +// At the end of each step, the holder of DenseTensor in phi::TensorArray // is null. Clear these Tensors and leave phi::TensorArray empty, otherwise an // exception will occur in the next step void ProgramInterpreter::ClearDenseTensorArrayInLocalScope() { @@ -823,7 +822,7 @@ void ProgramInterpreter::Convert( HasLocalScope() ? local_scope_ : var_scope_.GetMutableScope(); paddle::framework::Variable* var = inner_scope->FindVar( var_scope_.GetNameById(static_cast(var_id))); - if (var->IsType() || var->IsType() || + if (var->IsType() || var->IsType() || var->IsType() || var->IsType() || var->IsType()) { @@ -916,8 +915,8 @@ void ProgramInterpreter::BuildSkipShareLoDInfo() { bool can_skip_lod = true; for (auto& input : vec_instruction_[i].InnerRuntimeContext()->inputs) { for (auto& var : input.second) { - if (var->IsType()) { - if (!var->Get().lod().empty()) { + if (var->IsType()) { + if (!var->Get().lod().empty()) { can_skip_lod = false; break; } @@ -1131,8 +1130,8 @@ void ProgramInterpreter::RunOperator(const Instruction& instr_node) { auto* var = local_scope->FindVar(vname); if (var == nullptr) continue; const phi::DenseTensor* tensor{nullptr}; - if (var->IsType()) { - tensor = &var->Get(); + if (var->IsType()) { + tensor = &var->Get(); } else { VLOG(6) << vname << " is not DenseTensor"; continue; @@ -1147,8 +1146,8 @@ void ProgramInterpreter::RunOperator(const Instruction& instr_node) { auto* var = local_scope->FindVar(vname); if (var == nullptr) continue; const phi::DenseTensor* tensor{nullptr}; - if (var->IsType()) { - tensor = &var->Get(); + if (var->IsType()) { + tensor = &var->Get(); } else { VLOG(6) << vname << " is not DenseTensor"; continue; @@ -1490,8 +1489,8 @@ void ProgramInterpreter::RecordStreamForGC(const Instruction& instr) { continue; } - if (var->IsType()) { - TensorRecordStream(*(var->GetMutable()), instr.stream_); + if (var->IsType()) { + TensorRecordStream(*(var->GetMutable()), instr.stream_); } else if ( var->IsType< operators::reader:: @@ -1555,11 +1554,10 @@ void ProgramInterpreter::CheckGC(const Instruction& instr) { } } -void ProgramInterpreter::Prepare( - const std::vector& feed_names, - const std::vector& feed_tensors, - bool prepare_feed, - bool switch_stream) { +void ProgramInterpreter::Prepare(const std::vector& feed_names, + const std::vector& feed_tensors, + bool prepare_feed, + bool switch_stream) { PADDLE_ENFORCE_EQ(feed_names.size(), feed_tensors.size(), common::errors::PreconditionNotMet( @@ -1576,7 +1574,7 @@ void ProgramInterpreter::Prepare( common::errors::NotFound("Variable %s should not be nullptr.", feed_names[i])); - auto feed_tensor = feed_var->GetMutable(); + auto feed_tensor = feed_var->GetMutable(); feed_tensor->ShareDataWith(feed_tensors[i]); feed_tensor->set_lod(feed_tensors[i].lod()); } diff --git a/paddle/fluid/framework/new_executor/program_interpreter.h b/paddle/fluid/framework/new_executor/program_interpreter.h index c7621f3401206f..49b5dfd5b0a9d7 100644 --- a/paddle/fluid/framework/new_executor/program_interpreter.h +++ b/paddle/fluid/framework/new_executor/program_interpreter.h @@ -45,12 +45,11 @@ class ProgramInterpreter : public InterpreterBaseImpl { ~ProgramInterpreter(); - paddle::framework::FetchList Run( - const std::vector& feed_names, - const std::vector& feed_tensors, - bool need_fetch = true, - bool enable_job_schedule_profiler = false, - bool switch_stream = false) override; + paddle::framework::FetchList Run(const std::vector& feed_names, + const std::vector& feed_tensors, + bool need_fetch = true, + bool enable_job_schedule_profiler = false, + bool switch_stream = false) override; paddle::framework::FetchList Run(const std::vector& feed_names, bool need_fetch = true, @@ -161,7 +160,7 @@ class ProgramInterpreter : public InterpreterBaseImpl { // only used when program contains no feed op void Prepare(const std::vector& feed_names, - const std::vector& feed_tensors, + const std::vector& feed_tensors, bool prepare_feed, bool switch_stream = false); @@ -255,8 +254,8 @@ class ProgramInterpreter : public InterpreterBaseImpl { }; static inline const phi::DenseTensor& GetTensorFromVar(const Variable* var) { - if (var->IsType()) { - return var->Get(); + if (var->IsType()) { + return var->Get(); } else { PADDLE_THROW(common::errors::InvalidArgument( "Variable must be type of phi::DenseTensor, but received %s.", @@ -265,8 +264,8 @@ static inline const phi::DenseTensor& GetTensorFromVar(const Variable* var) { } static inline phi::DenseTensor* GetMutableTensorFromVar(Variable* var) { - if (var->IsType()) { - return var->GetMutable(); + if (var->IsType()) { + return var->GetMutable(); } else { PADDLE_THROW(common::errors::InvalidArgument( "Variable must be type of phi::DenseTensor, but received %s.", diff --git a/paddle/fluid/framework/new_executor/standalone_executor.cc b/paddle/fluid/framework/new_executor/standalone_executor.cc index 70bc62069c102d..fd4712f23450e1 100644 --- a/paddle/fluid/framework/new_executor/standalone_executor.cc +++ b/paddle/fluid/framework/new_executor/standalone_executor.cc @@ -216,7 +216,7 @@ paddle::framework::FetchList StandaloneExecutor::Run( is_interpretercore_build_result_shared_ = true; } - std::vector> splited_feeds; + std::vector> splited_feeds; if (FLAGS_enable_pir_in_executor) { SplitFeedTensors(feed_names, plan_.MicroBatchNum(), scope_, &splited_feeds); }