From 06e9233f82a70f899db2fedf828c5be454900663 Mon Sep 17 00:00:00 2001 From: zhangbo9674 <82555433+zhangbo9674@users.noreply.github.com> Date: Tue, 15 Aug 2023 09:36:58 +0800 Subject: [PATCH] [IR] Refine code (#56089) * refine code * refine code * refine code --- .../new_executor/interpreter_base_impl.h | 11 --------- .../new_executor/new_ir_interpreter.cc | 23 +++++-------------- .../new_executor/new_ir_interpreter.h | 11 ++------- .../new_executor/program_interpreter.cc | 23 +++++-------------- .../new_executor/program_interpreter.h | 10 ++------ 5 files changed, 16 insertions(+), 62 deletions(-) diff --git a/paddle/fluid/framework/new_executor/interpreter_base_impl.h b/paddle/fluid/framework/new_executor/interpreter_base_impl.h index 43d70883a48..934dd44771e 100644 --- a/paddle/fluid/framework/new_executor/interpreter_base_impl.h +++ b/paddle/fluid/framework/new_executor/interpreter_base_impl.h @@ -94,19 +94,8 @@ class InterpreterBaseImpl { virtual void SetOutputHooks(const std::vector& hookfuncs) = 0; - virtual const interpreter::DependencyBuilder& GetDependencyBuilder() - const = 0; - virtual std::shared_ptr> GetDependencyCount() const = 0; - virtual const interpreter::StreamAnalyzer& GetStreamAnalyzer() const = 0; - - virtual const interpreter::NewIrDependencyBuilder& GetNewIrDependencyBuilder() - const = 0; - - virtual const interpreter::NewIrStreamAnalyzer& GetNewIrStreamAnalyzer() - const = 0; - virtual bool IsSharedResultsBuild() const = 0; }; diff --git a/paddle/fluid/framework/new_executor/new_ir_interpreter.cc b/paddle/fluid/framework/new_executor/new_ir_interpreter.cc index ead957f7e87..e0b6d215cb9 100644 --- a/paddle/fluid/framework/new_executor/new_ir_interpreter.cc +++ b/paddle/fluid/framework/new_executor/new_ir_interpreter.cc @@ -201,26 +201,20 @@ void NewIRInterpreter::ShareWorkQueueFrom(InterpreterBaseImpl* src) { } void NewIRInterpreter::ShareBuildResultsFrom(const InterpreterBaseImpl& src) { - if (is_shared_results_build_ || !src.IsSharedResultsBuild()) { + const NewIRInterpreter& impl = dynamic_cast(src); + if (is_shared_results_build_ || !impl.IsSharedResultsBuild()) { return; } // share op dependency - ir_dependency_builder_.ShareDependencyFrom(src.GetNewIrDependencyBuilder()); - dependecy_count_ = src.GetDependencyCount(); + ir_dependency_builder_.ShareDependencyFrom(impl.GetNewIrDependencyBuilder()); + dependecy_count_ = impl.GetDependencyCount(); // share event analysis - ir_stream_analyzer_.ShareEventInfoFrom(src.GetNewIrStreamAnalyzer()); + ir_stream_analyzer_.ShareEventInfoFrom(impl.GetNewIrStreamAnalyzer()); is_shared_results_build_ = true; - VLOG(8) << "Share Build Results from InterpreterCore(" << &src + VLOG(8) << "Share Build Results from InterpreterCore(" << &impl << ") to InterpreterCore(" << this << ")"; } -// op dependences -const interpreter::DependencyBuilder& NewIRInterpreter::GetDependencyBuilder() - const { - PADDLE_THROW(platform::errors::Unimplemented( - "GetDependencyBuilder is not implemented in NewIRInterpreter.")); -} - const interpreter::NewIrDependencyBuilder& NewIRInterpreter::GetNewIrDependencyBuilder() const { return ir_dependency_builder_; @@ -231,11 +225,6 @@ std::shared_ptr> NewIRInterpreter::GetDependencyCount() return dependecy_count_; } -const interpreter::StreamAnalyzer& NewIRInterpreter::GetStreamAnalyzer() const { - PADDLE_THROW(platform::errors::Unimplemented( - "GetStreamAnalyzer is not implemented in NewIRInterpreter.")); -} - const interpreter::NewIrStreamAnalyzer& NewIRInterpreter::GetNewIrStreamAnalyzer() const { return ir_stream_analyzer_; diff --git a/paddle/fluid/framework/new_executor/new_ir_interpreter.h b/paddle/fluid/framework/new_executor/new_ir_interpreter.h index a6b24a8200a..3669d8f8dd9 100644 --- a/paddle/fluid/framework/new_executor/new_ir_interpreter.h +++ b/paddle/fluid/framework/new_executor/new_ir_interpreter.h @@ -53,13 +53,8 @@ class NewIRInterpreter : public InterpreterBaseImpl { void ShareBuildResultsFrom(const InterpreterBaseImpl& src) override; - // op dependences - const interpreter::DependencyBuilder& GetDependencyBuilder() const override; - std::shared_ptr> GetDependencyCount() const override; - const interpreter::StreamAnalyzer& GetStreamAnalyzer() const override; - bool IsSharedResultsBuild() const override; void SetCopyProgram(std::shared_ptr prog) override; @@ -195,11 +190,9 @@ class NewIRInterpreter : public InterpreterBaseImpl { void SolvePersisableVarNames(); - const interpreter::NewIrDependencyBuilder& GetNewIrDependencyBuilder() - const override; + const interpreter::NewIrDependencyBuilder& GetNewIrDependencyBuilder() const; - const interpreter::NewIrStreamAnalyzer& GetNewIrStreamAnalyzer() - const override; + const interpreter::NewIrStreamAnalyzer& GetNewIrStreamAnalyzer() const; InstructionSchedulingPriorityLess ir_instruction_scheduling_priority_less; diff --git a/paddle/fluid/framework/new_executor/program_interpreter.cc b/paddle/fluid/framework/new_executor/program_interpreter.cc index ca5f7f9eb49..64ffdbef619 100644 --- a/paddle/fluid/framework/new_executor/program_interpreter.cc +++ b/paddle/fluid/framework/new_executor/program_interpreter.cc @@ -287,16 +287,17 @@ void ProgramInterpreter::ShareWorkQueueFrom(InterpreterBaseImpl* src) { } void ProgramInterpreter::ShareBuildResultsFrom(const InterpreterBaseImpl& src) { - if (is_shared_results_build_ || !src.IsSharedResultsBuild()) { + const ProgramInterpreter& impl = dynamic_cast(src); + if (is_shared_results_build_ || !impl.IsSharedResultsBuild()) { return; } // share op dependency - dependency_builder_.ShareDependencyFrom(src.GetDependencyBuilder()); - dependecy_count_ = src.GetDependencyCount(); + dependency_builder_.ShareDependencyFrom(impl.GetDependencyBuilder()); + dependecy_count_ = impl.GetDependencyCount(); // share event analysis - stream_analyzer_.ShareEventInfoFrom(src.GetStreamAnalyzer()); + stream_analyzer_.ShareEventInfoFrom(impl.GetStreamAnalyzer()); is_shared_results_build_ = true; - VLOG(8) << "Share Build Results from InterpreterCore(" << &src + VLOG(8) << "Share Build Results from InterpreterCore(" << &impl << ") to InterpreterCore(" << this << ")"; } @@ -343,18 +344,6 @@ const interpreter::StreamAnalyzer& ProgramInterpreter::GetStreamAnalyzer() return stream_analyzer_; } -const interpreter::NewIrDependencyBuilder& -ProgramInterpreter::GetNewIrDependencyBuilder() const { - PADDLE_THROW(platform::errors::Unimplemented( - "GetDependencyBuilder is not implemented in ProgramInterpreter.")); -} - -const interpreter::NewIrStreamAnalyzer& -ProgramInterpreter::GetNewIrStreamAnalyzer() const { - PADDLE_THROW(platform::errors::Unimplemented( - "GetDependencyBuilder is not implemented in ProgramInterpreter.")); -} - bool ProgramInterpreter::IsSharedResultsBuild() const { return is_shared_results_build_; } diff --git a/paddle/fluid/framework/new_executor/program_interpreter.h b/paddle/fluid/framework/new_executor/program_interpreter.h index e21fe6e0a49..b258106cba9 100644 --- a/paddle/fluid/framework/new_executor/program_interpreter.h +++ b/paddle/fluid/framework/new_executor/program_interpreter.h @@ -53,17 +53,11 @@ class ProgramInterpreter : public InterpreterBaseImpl { void ShareBuildResultsFrom(const InterpreterBaseImpl& src) override; // op dependences - const interpreter::DependencyBuilder& GetDependencyBuilder() const override; + const interpreter::DependencyBuilder& GetDependencyBuilder() const; std::shared_ptr> GetDependencyCount() const override; - const interpreter::StreamAnalyzer& GetStreamAnalyzer() const override; - - const interpreter::NewIrDependencyBuilder& GetNewIrDependencyBuilder() - const override; - - const interpreter::NewIrStreamAnalyzer& GetNewIrStreamAnalyzer() - const override; + const interpreter::StreamAnalyzer& GetStreamAnalyzer() const; bool IsSharedResultsBuild() const override; -- GitLab