MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / GetInputsOutputsInBlock

Method GetInputsOutputsInBlock

paddle/fluid/framework/program_utils.cc:80–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80void ProgramProcessor::GetInputsOutputsInBlock(
81 const BlockDesc &current_block,
82 std::set<std::string> *inner_inputs,
83 std::set<std::string> *inner_outputs) {
84 /* Find inputs and outputs in current control flow block.
85 :param current_block: Current control flow block.
86 :param inner_inputs: Input var vector of ops in current block.
87 :param inner_outputs: Output var vector of ops in current block. */
88
89 // Step1: update inner_inputs and inner_outputs
90 // NOTE: Here assumes that all variables are input or output of Ops,
91
92 for (OpDesc *op : current_block.AllOps()) {
93 for (auto const &iname : op->InputNames()) {
94 for (auto const &in_var_name : op->Input(iname)) {
95 VLOG(3) << "insert inner_inputs_name:" << in_var_name;
96 inner_inputs->insert(in_var_name);
97 }
98 }
99
100 for (auto const &oname : op->OutputNames()) {
101 for (auto const &out_var_name : op->Output(oname)) {
102 VLOG(3) << "insert out_var_name:" << out_var_name;
103 inner_outputs->insert(out_var_name);
104 }
105 }
106 }
107
108 // Step2: Remove variable created in current control flow block.
109 BlockDesc *parent_block = current_block.ParentBlock();
110
111 if (parent_block) {
112 for (auto iter = inner_inputs->begin(); iter != inner_inputs->end();) {
113 const std::string &in_var_name = *iter;
114 if (current_block.HasVar(in_var_name)) {
115 VLOG(3) << "remove inner input var:" << in_var_name;
116 iter = inner_inputs->erase(iter);
117 } else {
118 ++iter;
119 }
120 }
121
122 for (auto iter = inner_outputs->begin(); iter != inner_outputs->end();) {
123 const std::string &out_var_name = *iter;
124 if (current_block.HasVar(out_var_name)) {
125 VLOG(3) << "remove inner output var:" << out_var_name;
126 iter = inner_outputs->erase(iter);
127 } else {
128 ++iter;
129 }
130 }
131 }
132}
133
134void ProgramProcessor::AddDepToBlockOp(const BlockDesc &block) {
135 VLOG(3) << "Op size:" << block.AllOps().size();

Callers 1

TESTFunction · 0.80

Calls 11

AllOpsMethod · 0.80
ParentBlockMethod · 0.80
InputNamesMethod · 0.45
InputMethod · 0.45
insertMethod · 0.45
OutputNamesMethod · 0.45
OutputMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
HasVarMethod · 0.45
eraseMethod · 0.45

Tested by 1

TESTFunction · 0.64