|
|
@ -117,7 +117,15 @@ Graph::Graph(const ProgramDesc &program) : program_(program) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// For output args, always create a new var.
|
|
|
|
// For output args, always create a new var.
|
|
|
|
for (auto &each_var_name : op->OutputArgumentNames()) {
|
|
|
|
for (auto &each_var_name : op->OutputArgumentNames()) {
|
|
|
|
ir::Node *var = CreateVarNode(all_vars.at(each_var_name));
|
|
|
|
ir::Node *var = nullptr;
|
|
|
|
|
|
|
|
if (all_vars.count(each_var_name) != 0) {
|
|
|
|
|
|
|
|
var = CreateVarNode(all_vars.at(each_var_name));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Operation output vars can be @EMPTY@. For example, while_grad
|
|
|
|
|
|
|
|
// can have multi @EMPTY@ outputs with no VarDesc.
|
|
|
|
|
|
|
|
// TODO(panyx0718): Add a test.
|
|
|
|
|
|
|
|
var = CreateEmptyNode(each_var_name, ir::Node::Type::kVariable);
|
|
|
|
|
|
|
|
}
|
|
|
|
var_nodes[each_var_name].push_back(var);
|
|
|
|
var_nodes[each_var_name].push_back(var);
|
|
|
|
node->outputs.push_back(var);
|
|
|
|
node->outputs.push_back(var);
|
|
|
|
var->inputs.push_back(node);
|
|
|
|
var->inputs.push_back(node);
|
|
|
@ -208,7 +216,8 @@ Graph::Graph(const ProgramDesc &program) : program_(program) {
|
|
|
|
// Add write after write dependence
|
|
|
|
// Add write after write dependence
|
|
|
|
ir::Node *upstream_op =
|
|
|
|
ir::Node *upstream_op =
|
|
|
|
(*it_old)->inputs.empty() ? nullptr : (*it_old)->inputs[0];
|
|
|
|
(*it_old)->inputs.empty() ? nullptr : (*it_old)->inputs[0];
|
|
|
|
if (upstream_op) {
|
|
|
|
// TODO(zcd): Add a test.
|
|
|
|
|
|
|
|
if (upstream_op && upstream_op != write_op) {
|
|
|
|
ir::Node *dep_var = CreateControlDepVar();
|
|
|
|
ir::Node *dep_var = CreateControlDepVar();
|
|
|
|
write_op->inputs.push_back(dep_var);
|
|
|
|
write_op->inputs.push_back(dep_var);
|
|
|
|
upstream_op->outputs.push_back(dep_var);
|
|
|
|
upstream_op->outputs.push_back(dep_var);
|
|
|
|