-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependence analysis #37231
Merged
wanghuancoder
merged 7 commits into
PaddlePaddle:develop
from
2742195759:dependence_analysis
Nov 17, 2021
Merged
Dependence analysis #37231
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4328fac
add
2742195759 580a3fc
add BuildOperatorDependences
2742195759 407b0b4
fix bug
2742195759 eae28e9
add unittest for write after write
2742195759 c291ccd
merge
2742195759 553295a
fix merge bug
2742195759 1602b10
fix
2742195759 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -77,6 +77,23 @@ paddle::framework::FetchList InterpreterCore::Run( | |||||
return *(fetch_var->GetMutable<framework::FetchList>()); | ||||||
} | ||||||
|
||||||
void InterpreterCore::BuildOperatorDependences() { | ||||||
// analysis the dependences between ops, set the dependecy_count_ and Call | ||||||
// Schedule | ||||||
auto op_nums = vec_instruction_.size(); | ||||||
dependecy_count_.resize(op_nums); | ||||||
auto op2downstream = interpreter::build_op_downstream_map(vec_instruction_); | ||||||
for (size_t op = 0; op < vec_instruction_.size(); ++op) { | ||||||
auto op_list = op2downstream[op]; | ||||||
std::vector<size_t> downsteam_vector(op_list.begin(), op_list.end()); | ||||||
stream_analyzer_.Schedule(downsteam_vector, &vec_instruction_, op); | ||||||
|
||||||
for (auto inst_id : op_list) { | ||||||
dependecy_count_[inst_id]++; | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
void InterpreterCore::Convert( | ||||||
std::vector<paddle::framework::OpFuncNode>* op_func_nodes) { | ||||||
auto& vec_meta_info = global_scope_->MutableVecMetaInfo(); | ||||||
|
@@ -86,7 +103,6 @@ void InterpreterCore::Convert( | |||||
|
||||||
auto op_nums = nodes.size(); | ||||||
vec_instruction_.reserve(op_nums); | ||||||
dependecy_count_.resize(op_nums); | ||||||
|
||||||
for (size_t op_idx = 0; op_idx < op_nums; ++op_idx) { | ||||||
auto& op_func_node = nodes[op_idx]; | ||||||
|
@@ -146,30 +162,7 @@ void InterpreterCore::Convert( | |||||
} | ||||||
} | ||||||
|
||||||
for (size_t i = 0; i < vec_instruction_.size(); ++i) { | ||||||
std::vector<size_t> vec_temp; | ||||||
for (auto& item : vec_instruction_[i].Outputs()) { | ||||||
for (auto id : item.second) { | ||||||
vec_temp = interpreter::merge_vector(vec_temp, input_var2op_info_[id]); | ||||||
} | ||||||
} | ||||||
|
||||||
// In Program, op order is a very important information. | ||||||
// Op can only add op after it as next as next ops. | ||||||
std::vector<size_t> filter_next; | ||||||
filter_next.reserve(vec_temp.size()); | ||||||
for (auto item : vec_temp) { | ||||||
if (item > i) { | ||||||
filter_next.push_back(item); | ||||||
} | ||||||
} | ||||||
|
||||||
stream_analyzer_.Schedule(filter_next, &vec_instruction_, i); | ||||||
|
||||||
for (auto inst_id : filter_next) { | ||||||
dependecy_count_[inst_id]++; | ||||||
} | ||||||
} | ||||||
BuildOperatorDependences(); | ||||||
|
||||||
for (size_t i = 0; i < vec_instruction_.size(); ++i) { | ||||||
BuildAndCacheInstructionCtx(&vec_instruction_[i]); | ||||||
|
@@ -289,7 +282,7 @@ void InterpreterCore::BuildSkipShareLoDInfo() { | |||||
void InterpreterCore::RunInstruction(const Instruction& instr_node) { | ||||||
auto* op = instr_node.OpBase(); | ||||||
auto place = instr_node.DeviceContext().GetPlace(); | ||||||
VLOG(4) << place << " " << op->DebugStringEx(global_scope_); | ||||||
VLOG(4) << "Start run" << place << " " << op->DebugStringEx(global_scope_); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
auto op_with_kernel = dynamic_cast<const framework::OperatorWithKernel*>(op); | ||||||
{ | ||||||
|
@@ -320,7 +313,7 @@ void InterpreterCore::RunInstruction(const Instruction& instr_node) { | |||||
instr_node.KernelFunc()(*instr_node.InnerExecutionContext().get()); | ||||||
} | ||||||
|
||||||
VLOG(3) << place << " " << op->DebugStringEx(global_scope_); | ||||||
VLOG(4) << "End run" << place << " " << op->DebugStringEx(global_scope_); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/*For profiling/benchmark only*/ | ||||||
if (FLAGS_benchmark) { | ||||||
|
@@ -494,6 +487,8 @@ void InterpreterCore::CheckGC(const Instruction& instr) { | |||||
continue; | ||||||
} | ||||||
if (is_ready) { | ||||||
VLOG(6) << "Async delete variable with name : " | ||||||
<< var_scope.GetNameById(var_id); | ||||||
gc_->Add(var_scope.Var(var_id), gc_event_.at(instr_id), | ||||||
&instr.DeviceContext()); | ||||||
} | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
python/paddle/fluid/tests/unittests/interpreter/test_standalone_multiply_write.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import sys | ||
import unittest | ||
import paddle | ||
from paddle.fluid import core | ||
from paddle.fluid.core import StandaloneExecutor | ||
import paddle.fluid as fluid | ||
from paddle.fluid.framework import Program, program_guard | ||
import paddle.fluid.layers as layers | ||
|
||
from test_standalone_controlflow import TestCompatibility | ||
import numpy as np | ||
|
||
paddle.enable_static() | ||
|
||
|
||
class TestMultiplyWrite(TestCompatibility): | ||
def _get_feed(self): | ||
""" return the feeds | ||
""" | ||
return None | ||
|
||
def build_program(self): | ||
main_program = paddle.static.default_main_program() | ||
startup_program = paddle.static.default_startup_program() | ||
with paddle.static.program_guard(main_program, startup_program): | ||
out = paddle.full((1, ), 1) | ||
inp1 = paddle.full((1, ), 2) | ||
inp2 = paddle.full((1, ), 3) | ||
|
||
paddle.fluid.layers.assign(inp1, out) | ||
paddle.fluid.layers.assign(inp2, out) | ||
return main_program, startup_program, out | ||
|
||
def setUp(self): | ||
self.place = paddle.CPUPlace() | ||
self.iter_run = 5 | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call -> call