Skip to content
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

Fix merge gradients error on multi GPUs #8224

Closed
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
22 changes: 14 additions & 8 deletions paddle/operators/parallel_do_op.cc
Original file line number Diff line number Diff line change
@@ -13,6 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include <vector>
#ifdef PADDLE_WITH_CUDA
#include <cuda_runtime.h>
#endif

#include "paddle/framework/executor.h"
#include "paddle/framework/op_registry.h"
@@ -95,17 +98,20 @@ inline void CopyOrShare(const framework::Variable &src,
}

void WaitOnPlace(const platform::Place place) {
platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance();
auto &dev_ctx = *pool.Get(place);
dev_ctx.Wait();
#ifdef PADDLE_WITH_CUDA
// FIXME(yuyang18): The previous implementation of WaitOnPlace has bug.
// Here just synchronize all streams of a device
// It should be changed if multi-streams are implemented
if (platform::is_gpu_place(place)) {
cudaSetDevice(boost::get<platform::CUDAPlace>(place).device);
cudaDeviceSynchronize();
}
#endif
}

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

for (auto &place : places) {
auto &dev_ctx = *pool.Get(place);
dev_ctx.Wait();
for (auto &p : places) {
WaitOnPlace(p);
}
}