// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include #include #include #include #include "paddle/fluid/framework/details/exception_holder.h" #include "paddle/fluid/framework/new_executor/event_manager.h" #include "paddle/fluid/framework/new_executor/interpretercore_garbage_collector.h" #include "paddle/fluid/framework/new_executor/interpretercore_util.h" #include "paddle/fluid/framework/new_executor/new_executor_defs.h" #include "paddle/fluid/framework/new_executor/profiler.h" #include "paddle/fluid/framework/new_executor/stream_analyzer.h" #include "paddle/fluid/framework/new_executor/workqueue.h" #include "paddle/fluid/framework/new_executor/workqueue_utils.h" #include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/framework/tensor.h" #include "paddle/fluid/framework/variable.h" #include "paddle/fluid/memory/allocation/spin_lock.h" #include "paddle/fluid/platform/device_event.h" namespace paddle { namespace framework { using AtomicVectorSizeT = std::vector>>; class InterpreterCore { public: InterpreterCore(const platform::Place& place, BlockDesc* block, VariableScope* global_scope, const std::vector& feed_names); ~InterpreterCore(); paddle::framework::FetchList Run( const std::vector& feed_tensors); const CostInfo& DryRun(const std::vector& feed_tensors); private: void Convert(); void BuildAndCacheInstructionCtx(Instruction* instr_node, const VariableScope& var_scope, const platform::Place& place); void BuildInplace(); bool BuildInplaceCheckVarIsOnlyInput(size_t var_index); void RunInstruction(const Instruction& instr_node); void ExecuteInstructionList(const std::vector& vec_instr); void DryRunPrepare(const std::vector& feed_tensors); void CheckGC(const Instruction& instr); void RunInstructionAsync(size_t instr_id); void RunNextInstructions(const Instruction& instr_id, std::queue* reserved_next_ops); void BuildSkipShareLoDInfo(); bool is_build_; const platform::Place& place_; BlockDesc* block_; // not owned VariableScope* global_scope_; // not owned std::vector vec_func_list_; std::vector vec_instruction_; // deconstruct before OpFuncNode InstructionInfo instruction_info_; std::vector dependecy_count_; std::vector> input_var2op_info_; std::vector vec_meta_info_; std::vector feed_names_; InterpreterProfiler dry_run_profiler_; StreamAnalyzer stream_analyzer_; EventManager event_manager_; EventsWaiter main_thread_blocker_; std::unique_ptr async_work_queue_; details::ExceptionHolder exception_holder_; std::shared_ptr exception_notifier_{nullptr}; std::unique_ptr gc_; std::vector gc_event_; std::atomic op_run_number_{0}; }; } // namespace framework } // namespace paddle