Skip to content

Commit 66c9191

Browse files
authored
Improve brpccmake (#11842)
1 parent 28172bb commit 66c9191

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ option(WITH_CONTRIB "Compile the third-party contributation" OFF)
6464
option(REPLACE_ENFORCE_GLOG "Replace PADDLE_ENFORCE with glog/CHECK for better debug." OFF)
6565
option(WITH_ANAKIN "Compile with Anakin library" OFF)
6666
option(WITH_GRPC "Use grpc as the default rpc framework" ${WITH_DISTRIBUTE})
67+
option(WITH_BRPC_RDMA "Use brpc rdma as the rpc protocal" OFF)
6768

6869
# CMAKE_BUILD_TYPE
6970
if(NOT CMAKE_BUILD_TYPE)
@@ -158,12 +159,24 @@ include(external/cares)
158159
if(WITH_DISTRIBUTE)
159160
if(WITH_GRPC)
160161
include(external/grpc)
162+
message(STATUS "Use grpc framework.")
161163
else()
164+
message(STATUS "Use brpc framework.")
162165
include(external/leveldb)
163166
include(external/brpc)
164167
endif()
165168
endif()
166169

170+
if(WITH_BRPC_RDMA)
171+
message(STATUS "Use brpc with rdma.")
172+
if(WITH_GRPC)
173+
message(FATAL_ERROR "Can't use grpc with brpc rdma.")
174+
endif()
175+
if(NOT WITH_DISTRIBUTE)
176+
message(FATAL_ERROR "Can't use brpc rdma in no distribute env.")
177+
endif()
178+
endif()
179+
167180
include(external/snappy) # download snappy
168181
include(external/snappystream)
169182
include(external/threadpool)

cmake/configure.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,7 @@ endif(WITH_GOLANG)
174174
if(WITH_GRPC)
175175
add_definitions(-DPADDLE_WITH_GRPC)
176176
endif(WITH_GRPC)
177+
178+
if(WITH_BRPC_RDMA)
179+
add_definitions(-DPADDLE_WITH_BRPC_RDMA)
180+
endif(WITH_BRPC_RDMA)

cmake/external/brpc.cmake

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414

1515
INCLUDE(ExternalProject)
1616

17+
find_library(SSL_LIBRARY NAMES ssl)
18+
ADD_LIBRARY(ssl SHARED IMPORTED GLOBAL)
19+
SET_PROPERTY(TARGET ssl PROPERTY IMPORTED_LOCATION ${SSL_LIBRARY})
20+
21+
find_library(CRYPTO_LIBRARY NAMES crypto)
22+
ADD_LIBRARY(crypto SHARED IMPORTED GLOBAL)
23+
SET_PROPERTY(TARGET crypto PROPERTY IMPORTED_LOCATION ${CRYPTO_LIBRARY})
24+
25+
1726
SET(BRPC_SOURCES_DIR ${THIRD_PARTY_PATH}/brpc)
1827
SET(BRPC_INSTALL_DIR ${THIRD_PARTY_PATH}/install/brpc)
1928
SET(BRPC_INCLUDE_DIR "${BRPC_INSTALL_DIR}/include" CACHE PATH "brpc include directory." FORCE)
@@ -22,14 +31,14 @@ SET(BRPC_LIBRARIES "${BRPC_INSTALL_DIR}/lib/libbrpc.a" CACHE FILEPATH "brpc libr
2231
INCLUDE_DIRECTORIES(${BRPC_INCLUDE_DIR})
2332

2433
# Reference https://stackoverflow.com/questions/45414507/pass-a-list-of-prefix-paths-to-externalproject-add-in-cmake-args
25-
set(prefix_path "${THIRD_PARTY_PATH}/install/gflags|${THIRD_PARTY_PATH}/install/leveldb|${THIRD_PARTY_PATH}/install/snappy|${THIRD_PARTY_PATH}/install/gtest|${THIRD_PARTY_PATH}/install/protobuf")
34+
set(prefix_path "${THIRD_PARTY_PATH}/install/gflags|${THIRD_PARTY_PATH}/install/leveldb|${THIRD_PARTY_PATH}/install/snappy|${THIRD_PARTY_PATH}/install/gtest|${THIRD_PARTY_PATH}/install/protobuf|${THIRD_PARTY_PATH}/install/zlib")
2635

2736
# If minimal .a is need, you can set WITH_DEBUG_SYMBOLS=OFF
2837
ExternalProject_Add(
2938
extern_brpc
3039
${EXTERNAL_PROJECT_LOG_ARGS}
31-
GIT_REPOSITORY "https://github.com/brpc/brpc"
32-
GIT_TAG "6d153dd7ff00f960ae6895c9c5fff0ce9f07aff2"
40+
GIT_REPOSITORY "https://github.com/gongweibao/brpc"
41+
GIT_TAG "7dc04defad1fd4173aae170c3fcbde131b65155a"
3342
PREFIX ${BRPC_SOURCES_DIR}
3443
UPDATE_COMMAND ""
3544
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
@@ -42,14 +51,16 @@ ExternalProject_Add(
4251
-DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
4352
-DCMAKE_PREFIX_PATH=${prefix_path}
4453
-DBRPC_WITH_GLOG=ON
54+
-DIOBUF_WITH_HUGE_BLOCK=ON
55+
-DBRPC_WITH_RDMA=${WITH_BRPC_RDMA}
4556
${EXTERNAL_OPTIONAL_ARGS}
4657
LIST_SEPARATOR |
4758
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${BRPC_INSTALL_DIR}
4859
-DCMAKE_INSTALL_LIBDIR:PATH=${BRPC_INSTALL_DIR}/lib
4960
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
5061
-DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
5162
)
52-
ADD_DEPENDENCIES(extern_brpc protobuf leveldb gflags glog gtest snappy)
63+
ADD_DEPENDENCIES(extern_brpc protobuf ssl crypto leveldb gflags glog gtest snappy)
5364
ADD_LIBRARY(brpc STATIC IMPORTED GLOBAL)
5465
SET_PROPERTY(TARGET brpc PROPERTY IMPORTED_LOCATION ${BRPC_LIBRARIES})
5566
ADD_DEPENDENCIES(brpc extern_brpc)

paddle/fluid/framework/executor.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ limitations under the License. */
2020
#include "paddle/fluid/framework/lod_tensor_array.h"
2121
#include "paddle/fluid/framework/op_registry.h"
2222
#include "paddle/fluid/framework/reader.h"
23-
#ifdef PADDLE_WITH_DISTRIBUTE
24-
#include "paddle/fluid/operators/distributed/grpc_client.h"
25-
#endif
23+
#include "paddle/fluid/operators/detail/macros.h"
2624
#include "paddle/fluid/platform/place.h"
2725
#include "paddle/fluid/platform/profiler.h"
2826

@@ -49,8 +47,7 @@ Executor::Executor(const platform::Place& place) : place_(place) {}
4947

5048
#ifdef PADDLE_WITH_DISTRIBUTE
5149
void Executor::Complete() {
52-
::paddle::operators::distributed::RPCClient::GetInstance<
53-
::paddle::operators::distributed::GRPCClient>()
50+
::paddle::operators::distributed::RPCClient::GetInstance<RPCCLIENT_T>()
5451
->SendComplete();
5552
}
5653
#endif

paddle/fluid/operators/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ else()
184184
set(DEPS_OPS ${DEPS_OPS} nccl_op)
185185
endif()
186186

187+
set(DISTRIBUTE_DEPS "")
187188
if(WITH_DISTRIBUTE)
188189
add_subdirectory(distributed)
189190

@@ -192,6 +193,18 @@ if(WITH_DISTRIBUTE)
192193
set(DISTRIBUTE_DEPS sendrecvop_grpc grpc++_unsecure grpc_unsecure gpr cares zlib protobuf)
193194
else()
194195
set(DISTRIBUTE_DEPS sendrecvop_brpc brpc leveldb snappystream snappy protobuf ssl crypto zlib)
196+
if(WITH_BRPC_RDMA)
197+
find_library(IBVERBS_LIBRARY NAMES ibverbs)
198+
ADD_LIBRARY(ibverbs SHARED IMPORTED GLOBAL)
199+
SET_PROPERTY(TARGET ibverbs PROPERTY IMPORTED_LOCATION ${IBVERBS_LIBRARY})
200+
201+
202+
find_library(RDMACM_LIBRARY NAMES rdmacm)
203+
ADD_LIBRARY(rdmacm SHARED IMPORTED GLOBAL)
204+
SET_PROPERTY(TARGET rdmacm PROPERTY IMPORTED_LOCATION ${RDMACM_LIBRARY})
205+
206+
set(DISTRIBUTE_DEPS ${DISTRIBUTE_DEPS} ibverbs rdmacm)
207+
endif()
195208
endif()
196209

197210
set(DISTRIBUTE_COMPILE_FLAGS "-Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor")
@@ -205,7 +218,7 @@ if(WITH_DISTRIBUTE)
205218
# listen_and_serv_op sum_op executor SERIAL)
206219
if(WITH_GPU)
207220
set_source_files_properties(test_send_nccl_id.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
208-
cc_test(test_send_nccl_id SRCS test_send_nccl_id.cc DEPS listen_and_serv_op executor SERIAL)
221+
cc_test(test_send_nccl_id SRCS test_send_nccl_id.cc DEPS listen_and_serv_op ${DISTRIBUTE_DEPS} executor SERIAL)
209222
if(WITH_GRPC)
210223
op_library(gen_nccl_id_op DEPS nccl_common sendrecvop_grpc)
211224
else()
@@ -297,6 +310,7 @@ foreach(src ${DETECTION_LIBRARY})
297310
endforeach()
298311

299312
set(GLOB_OP_LIB ${OP_LIBRARY} CACHE INTERNAL "Global OP library")
313+
set(GLOB_DISTRIBUTE_DEPS ${DISTRIBUTE_DEPS} CACHE INTERNAL "distributed dependency")
300314

301315
cc_test(gather_test SRCS gather_test.cc DEPS tensor)
302316
cc_test(scatter_test SRCS scatter_test.cc DEPS tensor)

paddle/fluid/operators/detail/macros.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@
1414

1515
#pragma once
1616

17+
#ifdef PADDLE_WITH_DISTRIBUTE
18+
1719
#ifdef PADDLE_WITH_GRPC
20+
1821
#include "paddle/fluid/operators/distributed/grpc_client.h"
1922
#include "paddle/fluid/operators/distributed/grpc_server.h"
20-
#define RPCSERVER_T distributed::AsyncGRPCServer
21-
#define RPCCLIENT_T distributed::GRPCClient
22-
#else
23+
#define RPCSERVER_T paddle::operators::distributed::AsyncGRPCServer
24+
#define RPCCLIENT_T paddle::operators::distributed::GRPCClient
25+
26+
#else // PADDLE_WITH_GRPC
27+
2328
#include "paddle/fluid/operators/distributed/brpc_client.h"
2429
#include "paddle/fluid/operators/distributed/brpc_server.h"
25-
#define RPCSERVER_T distributed::AsyncBRPCServer
26-
#define RPCCLIENT_T distributed::BRPCClient
27-
#endif
30+
#define RPCSERVER_T paddle::operators::distributed::AsyncBRPCServer
31+
#define RPCCLIENT_T paddle::operators::distributed::BRPCClient
32+
33+
#endif // PADDLE_WITH_GRPC
34+
35+
#endif // PADDLE_WITH_DISTRIBUTE

0 commit comments

Comments
 (0)