-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Make placement of constants follow consumers if they are all on the same device #6615
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b8bcca9
Make placement of constants follow consumers if they are all on the s…
DavidNorman 9dcfb89
Merge https://github.com/tensorflow/tensorflow
DavidNorman 314957c
Merge https://github.com/tensorflow/tensorflow
DavidNorman 8cb1d2c
Update after review comments from vrv
DavidNorman db9e95b
Further change after review comments.
DavidNorman e879312
Update variable name.
e7800c9
Merge https://github.com/tensorflow/tensorflow
DavidNorman 8d7afe0
Merge https://github.com/tensorflow/tensorflow
DavidNorman c284714
Merge https://github.com/tensorflow/tensorflow
DavidNorman 23ba535
Merge https://github.com/tensorflow/tensorflow
DavidNorman 35e8adc
Merge branch 'master' of github.com:DavidNorman/tensorflow
DavidNorman 414b29a
Fix up test to match the new fake CPU/GPU names
DavidNorman File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 |
---|---|---|
|
@@ -1226,5 +1226,76 @@ TEST_F(SimplePlacerTest, TestUnsatisfiableConstraintWithReferenceConnections) { | |
.contains("Cannot colocate nodes 'var' and 'assign'")); | ||
} | ||
|
||
// Test that a generator node follows its consumers (where there are several | ||
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. (Feel free to rename the TestHeuristicA to your name)! 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. as you suggested, i think we can leave the name alone. |
||
// consumer nodes on the same devices). | ||
TEST_F(SimplePlacerTest, TestGeneratorNodeFollowsConsumerNode) { | ||
Graph g(OpRegistry::Global()); | ||
{ // Scope for temporary variables used to construct g. | ||
GraphDefBuilder b(GraphDefBuilder::kFailImmediately); | ||
|
||
// A variable is only on CPU | ||
Node* var1_cpu = | ||
ops::SourceOp("VariableCPU", b.opts().WithName("var1_cpu")); | ||
Node* var2_cpu = | ||
ops::SourceOp("VariableCPU", b.opts().WithName("var2_cpu")); | ||
|
||
// The constant to be assigned can be on both GPU or CPU. | ||
// | ||
// Because of the heuristic, it gets placed on CPU to avoid a | ||
// copy. | ||
Node* input = ops::SourceOp("TestCPUGPUOutput", b.opts().WithName("in")); | ||
|
||
// The assigns are bound to CPU by the reference edge. | ||
ops::BinaryOp("TestAssign", var1_cpu, input, b.opts().WithName("assign1")); | ||
ops::BinaryOp("TestAssign", var2_cpu, input, b.opts().WithName("assign2")); | ||
|
||
TF_EXPECT_OK(BuildGraph(b, &g)); | ||
} | ||
|
||
TF_EXPECT_OK(Place(&g)); | ||
EXPECT_COLOCATED(g, "var1_cpu", "in"); | ||
EXPECT_COLOCATED(g, "assign1", "in"); | ||
EXPECT_COLOCATED(g, "var2_cpu", "in"); | ||
EXPECT_COLOCATED(g, "assign2", "in"); | ||
} | ||
|
||
// Test that a generator node does not follow its consumers (where there are | ||
// several consumers on different devices). | ||
TEST_F(SimplePlacerTest, TestGeneratorNodeDoesntFollowNonColocatedConsumers) { | ||
Graph g(OpRegistry::Global()); | ||
{ // Scope for temporary variables used to construct g. | ||
GraphDefBuilder b(GraphDefBuilder::kFailImmediately); | ||
|
||
// A variable is only on CPU | ||
Node* var1_cpu = | ||
ops::SourceOp("VariableCPU", b.opts().WithName("var1_cpu")); | ||
Node* var2_cpu = | ||
ops::SourceOp("VariableCPU", b.opts().WithName("var2_cpu")); | ||
|
||
// The constant to be assigned can be on both GPU or CPU. | ||
// | ||
// Because of the heuristic, it ought to be on the GPU (cannot be | ||
// co-located with both consumers, so goes to the 'standard' place) | ||
Node* input = ops::SourceOp("TestCPUGPUOutput", b.opts().WithName("in")); | ||
|
||
// The assigns are bound to CPU by the reference edge. | ||
ops::BinaryOp("TestAssign", var1_cpu, input, b.opts().WithName("assign1")); | ||
ops::BinaryOp("TestAssign", var2_cpu, input, b.opts().WithName("assign2")); | ||
|
||
TF_EXPECT_OK(BuildGraph(b, &g)); | ||
|
||
GetNodeByName(g, "var1_cpu") | ||
->set_assigned_device_name("/job:a/replica:0/task:0/device:fakecpu:1"); | ||
|
||
GetNodeByName(g, "var2_cpu") | ||
->set_assigned_device_name("/job:a/replica:0/task:0/device:fakecpu:2"); | ||
} | ||
|
||
TF_EXPECT_OK(Place(&g)); | ||
EXPECT_COLOCATED(g, "assign1", "var1_cpu"); | ||
EXPECT_COLOCATED(g, "assign2", "var2_cpu"); | ||
EXPECT_DEVICE_TYPE(g, "in", "FakeGPU"); | ||
} | ||
|
||
} // namespace | ||
} // namespace tensorflow |
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.
You might be able to replace this entire block of code with:
If it turns out to be more complicated than this, let me know.
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.
My code pulls the name from the 1st iterator value, then tests it against all of the others. Your code captures 'output_device_name', which is the name from the 1st iterator value. This would need to be read in your version of the code too.
What we need is a:
std::when_calling_with_elements_from_a_collection_every_return_value_of_a_functor_is_the_same()
It might exist. My in-depth knowledge of the std c++ library is limited to pre 2004.
nevertheless - i will replace the while(.....) part of my code with the std::all_of(), since I can still start with the second element.