From c01b1d2a91236b59a1df25722aace7dc3c6e627f Mon Sep 17 00:00:00 2001 From: jiangcheng Date: Tue, 22 Mar 2022 06:25:07 +0000 Subject: [PATCH 1/2] fix build_cinn_pass internal var may be control var problem --- .../framework/paddle2cinn/build_cinn_pass.cc | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc b/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc index 6e55727c8bf67..9b9d91ffe171c 100644 --- a/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc +++ b/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc @@ -220,8 +220,12 @@ std::unordered_set ExtractNoNeedBufferFeeds( // 1. Find op with NoNeedBufferVarsInferer defined and collect its input nodes std::unordered_map op_node2no_need_buffer_nodes; for (auto* op_node : cluster) { - auto& inferer = - OpInfoMap::Instance().Get(op_node->Name()).NoNeedBufferVarsInferer(); + const auto* op = OpInfoMap::Instance().GetNullable(op_node->Name()); + // If op not registered in Paddle, skip + if (!op) { + continue; + } + auto& inferer = op->NoNeedBufferVarsInferer(); if (!inferer) { continue; } @@ -300,10 +304,10 @@ std::unique_ptr CreateNewSubGraph(const GraphNodeSet& cluster, GraphNodeMap old_var2new_var; for (auto* var : cluster_internals) { - PADDLE_ENFORCE_NOT_NULL(var->Var(), - platform::errors::PreconditionNotMet( - "The var desc of the node in cluster_internals " - "shouldn't be null.")); + if (!var->Var()) { + // skip control var + continue; + } auto* sub_node = subgraph->CreateVarNode(var->Var()); old_var2new_var[var] = sub_node; } @@ -327,6 +331,10 @@ std::unique_ptr CreateNewSubGraph(const GraphNodeSet& cluster, // out-graph. for (auto* op : cluster) { for (auto* var : op->inputs) { + if (!var->Var()) { + // skip control var + continue; + } // one output var maybe an input of the cluster if (cluster_internals.count(var) || (cluster_outputs.count(var) && old_var2new_var.count(var))) { @@ -346,6 +354,10 @@ std::unique_ptr CreateNewSubGraph(const GraphNodeSet& cluster, } } for (auto* var : op->outputs) { + if (!var->Var()) { + // skip control var + continue; + } if (cluster_internals.count(var)) { IR_NODE_LINK_TO(old_op2new_op.at(op), old_var2new_var.at(var)); } else if (cluster_outputs.count(var) && var->Var() != nullptr) { From 15d705d7164eafddbc4059340792657ae7a42e91 Mon Sep 17 00:00:00 2001 From: jiangcheng Date: Wed, 23 Mar 2022 06:55:10 +0000 Subject: [PATCH 2/2] add annotation and vlog by review advice --- paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc b/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc index 9b9d91ffe171c..e259d6d417a5c 100644 --- a/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc +++ b/paddle/fluid/framework/paddle2cinn/build_cinn_pass.cc @@ -306,6 +306,15 @@ std::unique_ptr CreateNewSubGraph(const GraphNodeSet& cluster, for (auto* var : cluster_internals) { if (!var->Var()) { // skip control var + + // TODO(jiangcheng05): CINN not support control var now, so here we skip + // it, but it may incur result incorrect problem. In detail, for two + // unconnected ops, with control var, an op must run before another op. + // If we remove the control var, the program wouldn't guarantee the run + // ordering, in other words, the result may incorrect. + VLOG(4) + << "The internal var [" << var->Name() << "]'s vardesc empty," + << " it may be a control var, but CINN not support control var now."; continue; } auto* sub_node = subgraph->CreateVarNode(var->Var());