Skip to content

bring back test_parallel_do #7676

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

Merged
merged 1 commit into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion paddle/operators/parallel_do_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ static void SplitTensorAndMoveTensorToScopes(
}
}

void WaitOnPlace(const platform::Place place) {
platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance();
auto &dev_ctx = *pool.Get(place);
dev_ctx.Wait();
}

void WaitOnPlaces(const std::vector<platform::Place> places) {
platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance();

Expand Down Expand Up @@ -214,6 +220,7 @@ class ParallelDoGradOp : public framework::OperatorBase {
auto &tensor_to_merge = sub_scopes[i]->FindVar(s)->Get<LoDTensor>();
if (!(places[i] == places[0])) {
framework::Copy(tensor_to_merge, places[0], tmp);
WaitOnPlace(places[0]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to wait after copy

} else {
tmp->ShareDataWith(tensor_to_merge);
}
Expand All @@ -222,12 +229,13 @@ class ParallelDoGradOp : public framework::OperatorBase {
"sum", {{"X", {s, tmp_name}}}, {{"Out", {s}}},
framework::AttributeMap{});
sum_op->Run(*sub_scopes[0], places[0]);
WaitOnPlaces(places);
WaitOnPlace(places[0]);
}

VLOG(3) << result;
framework::Copy(result, place, scope.FindVar(s)->GetMutable<LoDTensor>());
}
WaitOnPlaces(places);
}
};

Expand Down
7 changes: 2 additions & 5 deletions python/paddle/v2/fluid/tests/test_parallel_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

import paddle.v2.fluid as fluid
import numpy
import sys
# TODO(dzhwinter): get places op check need to be enhanced.
sys.exit(0)


class BaseParallelForTest(unittest.TestCase):
Expand Down Expand Up @@ -165,13 +162,13 @@ def test_simple_fc(self):
feed={
'img': numpy.random.random(size=(51, 784)).astype('float32')
},
fetch='fc1.w@GRAD')
fetch=['fc1.w@GRAD'])

def test_fc_with_tiny_data(self):
self.run_test(
callback=ParallelOpTest.__network__,
feed={'img': numpy.random.random(size=(1, 784)).astype('float32')},
fetch='fc1.w@GRAD')
fetch=['fc1.w@GRAD'])


if __name__ == '__main__':
Expand Down