diff --git a/paddle/fluid/framework/init.cc b/paddle/fluid/framework/init.cc index 2e0a224ff5df749fd8c809dc88a85a1643542abf..3c0d93642ac41e8d90f9a248e81cea7a4fe12293 100644 --- a/paddle/fluid/framework/init.cc +++ b/paddle/fluid/framework/init.cc @@ -26,6 +26,7 @@ namespace paddle { namespace framework { std::once_flag gflags_init_flag; +std::once_flag p2p_init_flag; void InitGflags(std::vector &argv) { std::call_once(gflags_init_flag, [&]() { @@ -42,6 +43,27 @@ void InitGflags(std::vector &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 */ @@ -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); } diff --git a/paddle/fluid/inference/CMakeLists.txt b/paddle/fluid/inference/CMakeLists.txt index f4609a3b5b1b2e91ae5ac07b152319e3f9bcfc11..aff427310f15be72f5c8d0fa1537ffa6bbe2881d 100644 --- a/paddle/fluid/inference/CMakeLists.txt +++ b/paddle/fluid/inference/CMakeLists.txt @@ -13,8 +13,11 @@ cc_library(paddle_fluid_shared SHARED SRCS io.cc DEPS ARCHIVE_START ${GLOB_OP_LIB} ${FLUID_CORE_MODULES} ARCHIVE_END) set_target_properties(paddle_fluid_shared PROPERTIES OUTPUT_NAME paddle_fluid) -set(LINK_FLAGS "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.map") -set_target_properties(paddle_fluid_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}") +if(NOT APPLE) + # TODO(liuyiqun): Temporarily disable the link flag because it is not support on Mac. + set(LINK_FLAGS "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.map") + set_target_properties(paddle_fluid_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}") +endif() if(WITH_TESTING) add_subdirectory(tests/book)