Skip to content

Commit

Permalink
Merge pull request #9190 from panyx0718/p2p
Browse files Browse the repository at this point in the history
Enable P2P memory copy
  • Loading branch information
panyx0718 authored Mar 19, 2018
2 parents a431f98 + ce55975 commit 898e0ff
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion paddle/fluid/framework/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace paddle {
namespace framework {

std::once_flag gflags_init_flag;
std::once_flag p2p_init_flag;

void InitGflags(std::vector<std::string> &argv) {
std::call_once(gflags_init_flag, [&]() {
Expand All @@ -42,6 +43,27 @@ void InitGflags(std::vector<std::string> &argv) {
});
}

void InitP2P(int count) {
#ifdef PADDLE_WITH_CUDA
std::call_once(p2p_init_flag, [&]() {
for (int i = 0; i < count; ++i) {
for (int j = 0; j < count; ++j) {
if (i == j) continue;
int can_acess = -1;
PADDLE_ENFORCE(cudaDeviceCanAccessPeer(&can_acess, i, j),
"Failed to test P2P access.");
if (can_acess != 1) {
LOG(WARNING) << "Cannot enable P2P access from " << i << " to " << j;
} else {
cudaSetDevice(i);
cudaDeviceEnablePeerAccess(j, 0);
}
}
}
});
#endif
}

void InitDevices() {
/*Init all avaiable devices by default */

Expand All @@ -63,7 +85,7 @@ void InitDevices() {
for (int i = 0; i < count; ++i) {
places.emplace_back(platform::CUDAPlace(i));
}

InitP2P(count);
platform::DeviceContextPool::Init(places);
}

Expand Down

0 comments on commit 898e0ff

Please sign in to comment.