From c2b3838cf56ef925a2d6fe9555cb2cb7bb420961 Mon Sep 17 00:00:00 2001 From: Xin Pan Date: Tue, 25 Sep 2018 10:33:23 +0800 Subject: [PATCH] add some comments --- paddle/fluid/framework/details/build_strategy.cc | 10 +++++----- paddle/fluid/framework/details/build_strategy.h | 8 ++++++++ paddle/fluid/framework/ir/pass_builder.h | 4 ++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/framework/details/build_strategy.cc b/paddle/fluid/framework/details/build_strategy.cc index 592d5c2bec..6a6b497fa8 100644 --- a/paddle/fluid/framework/details/build_strategy.cc +++ b/paddle/fluid/framework/details/build_strategy.cc @@ -27,7 +27,7 @@ class ParallelExecutorPassBuilder : public ir::PassBuilder { public: explicit ParallelExecutorPassBuilder(const BuildStrategy &strategy) : ir::PassBuilder(), strategy_(strategy) { - // Apply a graph viz pass to record a graph. + // Add a graph viz pass to record a graph. if (!strategy_.debug_graphviz_path_.empty()) { auto viz_pass = AppendPass("graph_viz_pass"); const std::string graph_path = string::Sprintf( @@ -35,10 +35,10 @@ class ParallelExecutorPassBuilder : public ir::PassBuilder { viz_pass->Set("graph_viz_path", new std::string(graph_path)); } - // Apply op fusion. + // Add op fusion. if (strategy.fuse_elewise_add_act_ops_) { auto fuse_elewise_add_act_pass = AppendPass("fuse_elewise_add_act_pass"); - // Apply a graph viz pass to record a graph. + // Add a graph viz pass to record a graph. if (!strategy.debug_graphviz_path_.empty()) { auto viz_pass = AppendPass("graph_viz_pass"); const std::string graph_path = string::Sprintf( @@ -53,7 +53,7 @@ class ParallelExecutorPassBuilder : public ir::PassBuilder { multi_devices_pass->SetNotOwned("strategy", &strategy_); - // Apply a graph print pass to record a graph with device info. + // Add a graph print pass to record a graph with device info. if (!strategy_.debug_graphviz_path_.empty()) { auto multi_devices_print_pass = AppendPass("multi_devices_print_pass"); multi_devices_print_pass->SetNotOwned( @@ -86,7 +86,7 @@ std::unique_ptr BuildStrategy::Apply( #else const bool use_cuda) const { #endif - // Create a default one if not intialized by user. + // Create a default one if not initialized by user. if (!pass_builder_) { CreatePassesFromStrategy(); } diff --git a/paddle/fluid/framework/details/build_strategy.h b/paddle/fluid/framework/details/build_strategy.h index f75a1913b7..79bc165904 100644 --- a/paddle/fluid/framework/details/build_strategy.h +++ b/paddle/fluid/framework/details/build_strategy.h @@ -69,8 +69,16 @@ struct BuildStrategy { bool enable_data_balance_{false}; + // The PassBuilder assembles passes based on the configs defined above. + // For example, if fuse_elewise_add_act_ops_ is true, the corresponding + // fuse pass will be added. + // The PassBuilder allows for more customized insert, remove of passes + // from python. + // A new PassBuilder is created and passes are owned by the PassBuilder. std::shared_ptr CreatePassesFromStrategy() const; + // Apply the passes built by the pass_builder_. The passes will be + // applied to the Program and output an ir::Graph. std::unique_ptr Apply( const ProgramDesc &main_program, const std::vector &places, diff --git a/paddle/fluid/framework/ir/pass_builder.h b/paddle/fluid/framework/ir/pass_builder.h index 9969cc90f3..733d3a3ad1 100644 --- a/paddle/fluid/framework/ir/pass_builder.h +++ b/paddle/fluid/framework/ir/pass_builder.h @@ -28,12 +28,16 @@ class PassBuilder { virtual ~PassBuilder() {} + // Append a new pass to the end. std::shared_ptr AppendPass(const std::string& pass_type); + // Insert a new pass after `idx`. std::shared_ptr InsertPass(size_t idx, const std::string& pass_type); + // Remove a new pass at `idx`. void RemovePass(size_t idx); + // Returns a list of all passes. std::vector> AllPasses() const { return passes_; } protected: