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

Function prune_impl

paddle/fluid/framework/prune.cc:226–457  ·  view source on GitHub ↗

block_id is the idx of the current block in the input desc parent_block_id is the idx of the parent of the current block in the output desc, -1 means the current block is global block dependent_vars is passed recursively from the parent block to the child block to help pruning

Source from the content-addressed store, hash-verified

224// dependent_vars is passed recursively from the parent block to
225// the child block to help pruning
226void prune_impl(const proto::ProgramDesc& input,
227 proto::ProgramDesc* output,
228 int block_id,
229 int parent_block_id,
230 std::unordered_set<std::string>* dependent_vars,
231 const std::set<std::string> feed_var_names,
232 std::map<int, int>* pruned_origin_block_id_map) {
233 auto& block = input.blocks(block_id);
234 auto& ops = block.ops();
235 auto add_dependent_var = [&](const std::string& name) {
236 if (feed_var_names.count(name) == 0) dependent_vars->insert(name);
237 };
238
239 bool expect_feed = true;
240 for (auto& op_desc : ops) {
241 PADDLE_ENFORCE_EQ(
242 op_desc.type() != kFeedOpType || expect_feed,
243 true,
244 common::errors::PreconditionNotMet(
245 "All FeedOps are at the beginning of the ProgramDesc"));
246 expect_feed = (op_desc.type() == kFeedOpType);
247 }
248
249 bool expect_fetch = true;
250 for (auto op_iter = ops.rbegin(); op_iter != ops.rend(); ++op_iter) {
251 auto& op_desc = *op_iter;
252 PADDLE_ENFORCE_EQ(op_desc.type() != kFetchOpType || expect_fetch,
253 true,
254 common::errors::PreconditionNotMet(
255 "All FetchOps must at the end of the ProgramDesc"));
256 expect_fetch = (op_desc.type() == kFetchOpType);
257 }
258
259 std::vector<bool> should_run;
260 for (auto op_iter = ops.rbegin(); op_iter != ops.rend(); ++op_iter) {
261 auto& op_desc = *op_iter;
262
263 // TODO(wanghaipeng03) reconstruct the following if/else block
264 // to extract common code
265 //
266 // bool should_run_flag = false;
267 // if (IsTarget........) {
268 // should_run_flag = true;
269 // } else {
270 // if (parent......) {
271 // for (....) {
272 // for (.....) {
273 // if (.....) {
274 // should_run_flag = true;
275 // }
276 // }
277 // }
278 // }
279 // }
280 //
281 // should_run.push_back(should_run_flag);
282 // if (should_run_flag) {
283 // for (auto & var: op_desc.inputs()) {

Callers 1

PruneFunction · 0.85

Calls 15

IsTargetFunction · 0.85
HasDependentOutputVarFunction · 0.85
IsSubBlockDependentFunction · 0.85
GetOpRoleFunction · 0.85
reverseFunction · 0.85
HasSubBlockFunction · 0.85
HasSubBlocksFunction · 0.85
GetSubBlockIndexFunction · 0.85
GetSubBlocksIndicesFunction · 0.85
set_idxMethod · 0.80
mutable_opsMethod · 0.80
opsMethod · 0.45

Tested by

no test coverage detected