From 7901fd9f4d9505d6987c8176de3f2c467c01d37f Mon Sep 17 00:00:00 2001 From: Wang Zhen Date: Mon, 15 Nov 2021 11:51:48 +0000 Subject: [PATCH 1/6] Add the `GetFetchNames` method in CinnGraphSymbolization. --- cmake/external/cinn.cmake | 1 + .../framework/paddle2cinn/cinn_compiler.cc | 3 +++ .../paddle2cinn/cinn_graph_symbolization.cc | 18 +++++++++++++++++- .../paddle2cinn/cinn_graph_symbolization.h | 10 +++++++++- .../cinn_graph_symbolization_test.cc | 4 +++- .../tests/unittests/test_resnet50_with_cinn.py | 4 ++-- 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/cmake/external/cinn.cmake b/cmake/external/cinn.cmake index 85ae5173b716c..d754a1224011a 100644 --- a/cmake/external/cinn.cmake +++ b/cmake/external/cinn.cmake @@ -35,6 +35,7 @@ set(CINN_OPTIONAL_ARGS -DPY_VERSION=${PY_VERSION} -DWITH_MKLDNN=${WITH_MKL} -DPUBLISH_LIBS=ON -DWITH_TESTING=ON + -DCMAKE_BUILD_TYPE=Debug ) set(CINN_BUILD_COMMAND $(MAKE) cinnapi -j) ExternalProject_Add( diff --git a/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc b/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc index dd7f1395a1cd6..138680659638b 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc @@ -201,6 +201,9 @@ std::unique_ptr CinnCompiler::CompileGraph( ApplyPass(cinn_graph.get(), "OpFusion"); auto scope = BuildScope(target, cinn_graph); + auto fetch_names = symbol.GetFetchNames(); + VLOG(4) << "All fetch var names: " << string::join_strings(fetch_names, ','); + auto graph_compiler = std::make_unique(target, scope, cinn_graph); GraphCompiler::CompileOptions options; diff --git a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc index 941e82cef1bcc..0568877d94601 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc @@ -16,6 +16,7 @@ limitations under the License. */ #include #include +#include #include #include #include @@ -27,6 +28,7 @@ limitations under the License. */ #include "cinn/frontend/var_type_utils.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/errors.h" +#include "paddle/fluid/string/string_helper.h" namespace paddle { namespace framework { @@ -225,6 +227,20 @@ void CinnGraphSymbolization::RunGraph(const OpMapperContext& ctx) const { } } +std::vector CinnGraphSymbolization::GetFetchNames() const { + std::vector fetch_names(fetch_var_names_.size()); + std::transform( + fetch_var_names_.begin(), fetch_var_names_.end(), fetch_names.begin(), + [this](const std::string& name) { + PADDLE_ENFORCE_EQ( + var_model_to_program_map_.count(name), 1, + platform::errors::PreconditionNotMet( + "Cannot find %s in var_model_to_program_map_", name.c_str())); + return var_model_to_program_map_.at(name); + }); + return fetch_names; +} + ::cinn::frontend::Program CinnGraphSymbolization::operator()() { std::string builder_name = "NetBuilder_of_graph_" + std::to_string(graph_id_); VLOG(4) << "NetBuilder Name " << builder_name; @@ -235,7 +251,7 @@ ::cinn::frontend::Program CinnGraphSymbolization::operator()() { auto cinn_scope = CreateCinnScope(feed_map); OpMapperContext ctx(*cinn_scope, target_, &builder, &var_map_, - &var_model_to_program_map_); + &var_model_to_program_map_, &fetch_var_names_); // add all tensor's feed info into context for (auto& feed_pair : feed_map) { ctx.AddFeedInfo(feed_pair.first, feed_pair.second); diff --git a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.h b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.h index af60493044cf3..a959b67342086 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.h +++ b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.h @@ -15,8 +15,10 @@ limitations under the License. */ #pragma once #include +#include #include #include +#include #include "paddle/fluid/framework/ir/graph.h" #include "paddle/fluid/framework/lod_tensor.h" @@ -84,6 +86,9 @@ class CinnGraphSymbolization { return var_model_to_program_map_; } + // get fetch var names used in CINN + std::vector GetFetchNames() const; + using OpMapperContext = ::cinn::frontend::OpMapperContext; using FeedInfoMap = std::unordered_map; @@ -95,10 +100,13 @@ class CinnGraphSymbolization { const ::cinn::common::Target& target_; const std::map& input_tensors_; - // preserve local variable map + // preserve cinn variable map std::unordered_map var_map_; std::unordered_map var_model_to_program_map_; + // fetch var names used in paddle + std::vector fetch_var_names_; + // transform all paddle var desc in feed list into cinn_var_descs_ FeedInfoMap GetFeedInfoMapFromInput() const; diff --git a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization_test.cc b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization_test.cc index be2ca2f73e186..9122cd28538c9 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization_test.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization_test.cc @@ -48,7 +48,8 @@ class CinnGraphSymbolizationForTest { return OpMapperContext(*cinn_symbol_->CreateCinnScope(feed_map), cinn_symbol_->target_, builder, &cinn_symbol_->var_map_, - &cinn_symbol_->var_model_to_program_map_); + &cinn_symbol_->var_model_to_program_map_, + &cinn_symbol_->fetch_var_names_); } FeedInfoMap GetFeedInfoMapFromInput() { @@ -292,6 +293,7 @@ TEST_F(CinnGraphSymbolizationTest, basic) { ASSERT_NO_THROW((*symbol_)()); ASSERT_FALSE(symbol_->var_map().empty()); ASSERT_FALSE(symbol_->var_model_to_program_map().empty()); + ASSERT_TRUE(symbol_->GetFetchNames().empty()); } } // namespace paddle2cinn diff --git a/python/paddle/fluid/tests/unittests/test_resnet50_with_cinn.py b/python/paddle/fluid/tests/unittests/test_resnet50_with_cinn.py index 2f6ca1dfa0cb0..406f3f3aeacc4 100644 --- a/python/paddle/fluid/tests/unittests/test_resnet50_with_cinn.py +++ b/python/paddle/fluid/tests/unittests/test_resnet50_with_cinn.py @@ -105,8 +105,8 @@ def test_check_resnet50_accuracy(self): feed = self.generate_random_data(loop_num) loss_c = self.train(place, loop_num, feed, use_cinn=True) - loss_p = self.train(place, loop_num, feed, use_cinn=False) - self.assertTrue(np.allclose(loss_c, loss_p, atol=1e-5)) + # loss_p = self.train(place, loop_num, feed, use_cinn=False) + # self.assertTrue(np.allclose(loss_c, loss_p, atol=1e-5)) if __name__ == '__main__': From 59ea213204258347ed7ca22858605f9b37e39fc8 Mon Sep 17 00:00:00 2001 From: Wang Zhen Date: Mon, 15 Nov 2021 12:10:47 +0000 Subject: [PATCH 2/6] Use unordered_set instead vector as the type of fetch_var_names. --- cmake/external/cinn.cmake | 1 - paddle/fluid/framework/paddle2cinn/cinn_compiler.cc | 7 ++++--- .../paddle2cinn/cinn_graph_symbolization.cc | 13 ++++++------- .../paddle2cinn/cinn_graph_symbolization.h | 6 +++--- .../paddle2cinn/cinn_graph_symbolization_test.cc | 2 +- .../tests/unittests/test_resnet50_with_cinn.py | 4 ++-- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cmake/external/cinn.cmake b/cmake/external/cinn.cmake index d754a1224011a..85ae5173b716c 100644 --- a/cmake/external/cinn.cmake +++ b/cmake/external/cinn.cmake @@ -35,7 +35,6 @@ set(CINN_OPTIONAL_ARGS -DPY_VERSION=${PY_VERSION} -DWITH_MKLDNN=${WITH_MKL} -DPUBLISH_LIBS=ON -DWITH_TESTING=ON - -DCMAKE_BUILD_TYPE=Debug ) set(CINN_BUILD_COMMAND $(MAKE) cinnapi -j) ExternalProject_Add( diff --git a/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc b/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc index 138680659638b..aa23c97e7f8b9 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc @@ -201,11 +201,12 @@ std::unique_ptr CinnCompiler::CompileGraph( ApplyPass(cinn_graph.get(), "OpFusion"); auto scope = BuildScope(target, cinn_graph); - auto fetch_names = symbol.GetFetchNames(); - VLOG(4) << "All fetch var names: " << string::join_strings(fetch_names, ','); + auto fetch_names = symbol.GetFetchIds(); + VLOG(4) << "All fetch var ids in CINN: " + << string::join_strings(fetch_names, ','); auto graph_compiler = - std::make_unique(target, scope, cinn_graph); + std::make_unique(target, scope, cinn_graph, fetch_names); GraphCompiler::CompileOptions options; options.with_instantiate_variables = false; auto compiled_res = graph_compiler->Build(options); diff --git a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc index 0568877d94601..ed7a7c254dc66 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc @@ -28,7 +28,6 @@ limitations under the License. */ #include "cinn/frontend/var_type_utils.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/errors.h" -#include "paddle/fluid/string/string_helper.h" namespace paddle { namespace framework { @@ -227,16 +226,16 @@ void CinnGraphSymbolization::RunGraph(const OpMapperContext& ctx) const { } } -std::vector CinnGraphSymbolization::GetFetchNames() const { - std::vector fetch_names(fetch_var_names_.size()); - std::transform( - fetch_var_names_.begin(), fetch_var_names_.end(), fetch_names.begin(), - [this](const std::string& name) { +std::unordered_set CinnGraphSymbolization::GetFetchIds() const { + std::unordered_set fetch_names(fetch_var_names_.size()); + std::for_each( + fetch_var_names_.begin(), fetch_var_names_.end(), + [this, &fetch_names](const std::string& name) { PADDLE_ENFORCE_EQ( var_model_to_program_map_.count(name), 1, platform::errors::PreconditionNotMet( "Cannot find %s in var_model_to_program_map_", name.c_str())); - return var_model_to_program_map_.at(name); + fetch_names.insert(var_model_to_program_map_.at(name)); }); return fetch_names; } diff --git a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.h b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.h index a959b67342086..526eb65a56ede 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.h +++ b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.h @@ -86,8 +86,8 @@ class CinnGraphSymbolization { return var_model_to_program_map_; } - // get fetch var names used in CINN - std::vector GetFetchNames() const; + // get fetch var ids used in CINN + std::unordered_set GetFetchIds() const; using OpMapperContext = ::cinn::frontend::OpMapperContext; using FeedInfoMap = @@ -105,7 +105,7 @@ class CinnGraphSymbolization { std::unordered_map var_model_to_program_map_; // fetch var names used in paddle - std::vector fetch_var_names_; + std::unordered_set fetch_var_names_; // transform all paddle var desc in feed list into cinn_var_descs_ FeedInfoMap GetFeedInfoMapFromInput() const; diff --git a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization_test.cc b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization_test.cc index 9122cd28538c9..09df9a7ad2ce4 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization_test.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization_test.cc @@ -293,7 +293,7 @@ TEST_F(CinnGraphSymbolizationTest, basic) { ASSERT_NO_THROW((*symbol_)()); ASSERT_FALSE(symbol_->var_map().empty()); ASSERT_FALSE(symbol_->var_model_to_program_map().empty()); - ASSERT_TRUE(symbol_->GetFetchNames().empty()); + ASSERT_TRUE(symbol_->GetFetchIds().empty()); } } // namespace paddle2cinn diff --git a/python/paddle/fluid/tests/unittests/test_resnet50_with_cinn.py b/python/paddle/fluid/tests/unittests/test_resnet50_with_cinn.py index 406f3f3aeacc4..2f6ca1dfa0cb0 100644 --- a/python/paddle/fluid/tests/unittests/test_resnet50_with_cinn.py +++ b/python/paddle/fluid/tests/unittests/test_resnet50_with_cinn.py @@ -105,8 +105,8 @@ def test_check_resnet50_accuracy(self): feed = self.generate_random_data(loop_num) loss_c = self.train(place, loop_num, feed, use_cinn=True) - # loss_p = self.train(place, loop_num, feed, use_cinn=False) - # self.assertTrue(np.allclose(loss_c, loss_p, atol=1e-5)) + loss_p = self.train(place, loop_num, feed, use_cinn=False) + self.assertTrue(np.allclose(loss_c, loss_p, atol=1e-5)) if __name__ == '__main__': From de6b91a7607567917ccdadaf81df688db1d6619c Mon Sep 17 00:00:00 2001 From: Wang Zhen Date: Tue, 16 Nov 2021 03:19:33 +0000 Subject: [PATCH 3/6] Reuse the definition of kCompilationKey. --- paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc | 7 ++++--- paddle/fluid/framework/paddle2cinn/build_cinn_pass.h | 1 - .../fluid/framework/paddle2cinn/build_cinn_pass_test.cc | 5 +++-- paddle/fluid/framework/paddle2cinn/cinn_compiler_test.cc | 8 +++++--- paddle/fluid/operators/cinn_launch_op.h | 6 +++--- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc b/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc index f280214ad0b0c..7e08d883625ad 100644 --- a/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc +++ b/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc @@ -34,6 +34,7 @@ limitations under the License. */ #include "paddle/fluid/framework/ir/subgraph_detector.h" #include "paddle/fluid/framework/op_proto_maker.h" #include "paddle/fluid/framework/paddle2cinn/cinn_compiler.h" +#include "paddle/fluid/operators/cinn_launch_op.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/errors.h" @@ -381,7 +382,7 @@ void AddCinnOpToGraph(const GraphNodeSet& cluster, input_names.emplace_back(n->Name()); } }); - cinn_op_desc.SetInput("X", input_names); + cinn_op_desc.SetInput(operators::kX, input_names); std::vector output_names; std::for_each(cluster_outputs.begin(), cluster_outputs.end(), [&output_names, &deny_var_set](Node* n) { @@ -389,8 +390,8 @@ void AddCinnOpToGraph(const GraphNodeSet& cluster, output_names.emplace_back(n->Name()); } }); - cinn_op_desc.SetOutput("Out", output_names); - cinn_op_desc.SetAttr(kCompilationKey, compilation_key); + cinn_op_desc.SetOutput(operators::kOutputs, output_names); + cinn_op_desc.SetAttr(operators::kCompilationKey, compilation_key); cinn_op_desc.SetAttr(OpProtoAndCheckerMaker::OpRoleAttrName(), ExtractOpRole(cluster)); cinn_op_desc.Flush(); diff --git a/paddle/fluid/framework/paddle2cinn/build_cinn_pass.h b/paddle/fluid/framework/paddle2cinn/build_cinn_pass.h index 1c07fb314e92d..8f7d5eb266ece 100644 --- a/paddle/fluid/framework/paddle2cinn/build_cinn_pass.h +++ b/paddle/fluid/framework/paddle2cinn/build_cinn_pass.h @@ -21,7 +21,6 @@ namespace framework { namespace paddle2cinn { constexpr char kCinnLaunchOp[] = "cinn_launch"; -constexpr char kCompilationKey[] = "compilation_key"; // A pass named BuildCinnPass, the function of this pass is: // diff --git a/paddle/fluid/framework/paddle2cinn/build_cinn_pass_test.cc b/paddle/fluid/framework/paddle2cinn/build_cinn_pass_test.cc index d76a855b122ae..1649cd24b341a 100644 --- a/paddle/fluid/framework/paddle2cinn/build_cinn_pass_test.cc +++ b/paddle/fluid/framework/paddle2cinn/build_cinn_pass_test.cc @@ -27,6 +27,7 @@ limitations under the License. */ #include "paddle/fluid/framework/paddle2cinn/cinn_compiler.h" #include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/framework/var_desc.h" +#include "paddle/fluid/operators/cinn_launch_op.h" namespace paddle { namespace framework { @@ -91,8 +92,8 @@ std::vector GetCompilationKeys(const Graph& graph) { std::vector compilation_keys; for (auto& node : graph.Nodes()) { if (node->IsOp() && node->Name() == kCinnLaunchOp) { - compilation_keys.emplace_back( - BOOST_GET_CONST(std::string, node->Op()->GetAttr(kCompilationKey))); + compilation_keys.emplace_back(BOOST_GET_CONST( + std::string, node->Op()->GetAttr(operators::kCompilationKey))); } } return compilation_keys; diff --git a/paddle/fluid/framework/paddle2cinn/cinn_compiler_test.cc b/paddle/fluid/framework/paddle2cinn/cinn_compiler_test.cc index 145d3d83d4509..5bed297417e01 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_compiler_test.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_compiler_test.cc @@ -34,6 +34,7 @@ #include "paddle/fluid/framework/paddle2cinn/build_cinn_pass.h" #include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/framework/scope.h" +#include "paddle/fluid/operators/cinn_launch_op.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/place.h" @@ -62,8 +63,8 @@ std::vector GetCompilationKeys(const Graph& graph) { std::vector compilation_keys; for (auto& node : graph.Nodes()) { if (node->IsOp() && node->Name() == kCinnLaunchOp) { - compilation_keys.emplace_back( - BOOST_GET_CONST(std::string, node->Op()->GetAttr(kCompilationKey))); + compilation_keys.emplace_back(BOOST_GET_CONST( + std::string, node->Op()->GetAttr(operators::kCompilationKey))); } } return compilation_keys; @@ -86,7 +87,8 @@ std::unordered_map> GetInputsInfo( std::unordered_set inputs; for (auto& node : graph.Nodes()) { if (node->IsOp() && node->Name() == kCinnLaunchOp) { - if (BOOST_GET_CONST(std::string, node->Op()->GetAttr(kCompilationKey)) != + if (BOOST_GET_CONST(std::string, + node->Op()->GetAttr(operators::kCompilationKey)) != key) { continue; } diff --git a/paddle/fluid/operators/cinn_launch_op.h b/paddle/fluid/operators/cinn_launch_op.h index 4e1a05a7a32d2..63858d40cba0e 100644 --- a/paddle/fluid/operators/cinn_launch_op.h +++ b/paddle/fluid/operators/cinn_launch_op.h @@ -29,9 +29,9 @@ namespace paddle { namespace operators { -static constexpr char kX[] = "X"; -static constexpr char kOutputs[] = "Out"; -static constexpr char kCompilationKey[] = "compilation_key"; +constexpr char kX[] = "X"; +constexpr char kOutputs[] = "Out"; +constexpr char kCompilationKey[] = "compilation_key"; using LoDTensor = framework::LoDTensor; using CinnTensor = ::cinn::hlir::framework::Tensor; From b2f1ffbc574cd9d08863832f039ea619c12aa496 Mon Sep 17 00:00:00 2001 From: Wang Zhen Date: Tue, 16 Nov 2021 11:32:18 +0000 Subject: [PATCH 4/6] Use CompileOptions to set fetch_var_ids. --- paddle/fluid/framework/paddle2cinn/cinn_compiler.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc b/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc index aa23c97e7f8b9..5fd37c41cc919 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc @@ -201,14 +201,15 @@ std::unique_ptr CinnCompiler::CompileGraph( ApplyPass(cinn_graph.get(), "OpFusion"); auto scope = BuildScope(target, cinn_graph); - auto fetch_names = symbol.GetFetchIds(); + auto fetch_ids = symbol.GetFetchIds(); VLOG(4) << "All fetch var ids in CINN: " - << string::join_strings(fetch_names, ','); + << string::join_strings(fetch_ids, ','); auto graph_compiler = - std::make_unique(target, scope, cinn_graph, fetch_names); + std::make_unique(target, scope, cinn_graph); GraphCompiler::CompileOptions options; options.with_instantiate_variables = false; + options.fetch_var_ids = std::move(fetch_ids); auto compiled_res = graph_compiler->Build(options); auto compiled_obj = std::make_unique(); *compiled_obj = {std::move(graph_compiler), From 0f101f36dcb5127e41c7077fcdb064855d97ab62 Mon Sep 17 00:00:00 2001 From: Wang Zhen Date: Wed, 17 Nov 2021 03:27:45 +0000 Subject: [PATCH 5/6] Update the argument passing of GraphCompiler.Build. --- paddle/fluid/framework/paddle2cinn/cinn_compiler.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc b/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc index 5fd37c41cc919..561ebeedb3059 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_compiler.cc @@ -209,8 +209,7 @@ std::unique_ptr CinnCompiler::CompileGraph( std::make_unique(target, scope, cinn_graph); GraphCompiler::CompileOptions options; options.with_instantiate_variables = false; - options.fetch_var_ids = std::move(fetch_ids); - auto compiled_res = graph_compiler->Build(options); + auto compiled_res = graph_compiler->Build(options, std::move(fetch_ids)); auto compiled_obj = std::make_unique(); *compiled_obj = {std::move(graph_compiler), std::move(compiled_res.runtime_program), scope, From a57fb529350b5817a0668898f67332b97e0a14a0 Mon Sep 17 00:00:00 2001 From: Wang Zhen Date: Wed, 17 Nov 2021 04:18:57 +0000 Subject: [PATCH 6/6] Fix some bugs in CinnGraphSymbolization::GetFetchIds. --- paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc index ed7a7c254dc66..9bdaf61858f45 100644 --- a/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc +++ b/paddle/fluid/framework/paddle2cinn/cinn_graph_symbolization.cc @@ -227,7 +227,8 @@ void CinnGraphSymbolization::RunGraph(const OpMapperContext& ctx) const { } std::unordered_set CinnGraphSymbolization::GetFetchIds() const { - std::unordered_set fetch_names(fetch_var_names_.size()); + std::unordered_set fetch_names; + fetch_names.reserve(fetch_var_names_.size()); std::for_each( fetch_var_names_.begin(), fetch_var_names_.end(), [this, &fetch_names](const std::string& name) {