Skip to content

Commit 744dba4

Browse files
backyesreyoung
authored andcommitted
add rdma cmake support (#284)
* add rdma cmake support * move rdma related code to rdma.cmake
1 parent 8ff9aa3 commit 744dba4

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ endif()
5252
include(enableCXX11)
5353
include(cpplint)
5454
include(ccache)
55+
if(WITH_RDMA)
56+
include(rdma)
57+
endif()
5558
include(util)
5659
include(flags)
5760
include(cudnn)
@@ -133,9 +136,11 @@ else(WITH_PYTHON)
133136
add_definitions(-DPADDLE_NO_PYTHON)
134137
endif(WITH_PYTHON)
135138

136-
if(NOT WITH_RDMA)
137-
add_definitions(-DPADDLE_DISABLE_RDMA)
138-
endif()
139+
if(WITH_RDMA)
140+
include_directories("${RDMA_INC_DIR}")
141+
else(WITH_RDMA)
142+
add_definitions(-DPADDLE_DISABLE_RDMA)
143+
endif(WITH_RDMA)
139144

140145
if(WITH_GLOG)
141146
add_definitions(-DPADDLE_USE_GLOG)

cmake/rdma.cmake

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# user should download rdma first from subversion repository
2+
3+
# execute following instruction to download svn mannally
4+
# svn co https://svn.baidu.com/sys/ip/trunk/rdma/sockrdmav1 rdma/
5+
# svn co https://svn.baidu.com/sys/ip/trunk/rdma/thirdparty rdma/
6+
# we use static output in svn repositories to avoid implict bugs from not standard runtime env.
7+
8+
set(RDMA_ROOT $ENV{RDMA_ROOT} CACHE PATH "Folder contains RDMA sock library and thirdparty library")
9+
10+
function(generate_rdma_links)
11+
#redirect to current DIR to isolate the pollution from system runtime environment
12+
#it can benifits unified control for different gcc environment.
13+
#e.g, by default gcc48 did not refer /usr/lib64 which could contain low version
14+
#runtime libraries that will crash process while loading it. That redirect trick
15+
#can fix it.
16+
execute_process(
17+
COMMAND mkdir -p librdma
18+
COMMAND ln -s -f /usr/lib64/libibverbs.so.1.0.0 librdma/libibverbs.so.1
19+
COMMAND ln -s -f /usr/lib64/libibverbs.so.1.0.0 librdma/libibverbs.so
20+
COMMAND ln -s -f /usr/lib64/librdmacm.so.1.0.0 librdma/librdmacm.so.1
21+
COMMAND ln -s -f /usr/lib64/librdmacm.so.1.0.0 librdma/librdmacm.so
22+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
23+
)
24+
endfunction(generate_rdma_links)
25+
26+
27+
#check and set headers
28+
find_path(RDMA_INC_SXISOCK sxi_sock.h PATHS ${RDMA_ROOT}/sockrdmav1/output/include)
29+
find_path(RDMA_INC_XIO libxio.h PATHS ${RDMA_ROOT}/thirdparty/output/accelio)
30+
find_path(RDMA_INC_EVENT event2 PATHS ${RDMA_ROOT}/thirdparty/output/libevent)
31+
find_path(RDMA_INC_NUMA numa.h PATHS ${RDMA_ROOT}/thirdparty/output/libnuma)
32+
33+
#check and set libs
34+
find_library(RDMA_LIB_SXISOCK NAMES sxisock PATHS ${RDMA_ROOT}/sockrdmav1/output)
35+
find_library(RDMA_LIB_XIO NAMES xio PATHS ${RDMA_ROOT}/thirdparty/output/accelio)
36+
find_library(RDMA_LIB_EVENT NAMES event PATHS ${RDMA_ROOT}/thirdparty/output/libevent)
37+
find_library(RDMA_LIB_EVENT_CORE NAMES event_core PATHS ${RDMA_ROOT}/thirdparty/output/libevent)
38+
find_library(RDMA_LIB_EVENT_EXTRA NAMES event_extra PATHS ${RDMA_ROOT}/thirdparty/output/libevent)
39+
find_library(RDMA_LIB_EVENT_PTHREADS NAMES event_pthreads PATHS ${RDMA_ROOT}/thirdparty/output/libevent)
40+
find_library(RDMA_LIB_NUMA NAMES numa PATHS ${RDMA_ROOT}/thirdparty/output/libnuma)
41+
42+
if(
43+
RDMA_INC_SXISOCK AND
44+
RDMA_INC_XIO AND
45+
RDMA_INC_EVENT AND
46+
RDMA_INC_NUMA AND
47+
RDMA_LIB_SXISOCK AND
48+
RDMA_LIB_XIO AND
49+
RDMA_LIB_EVENT AND
50+
RDMA_LIB_EVENT_CORE AND
51+
RDMA_LIB_EVENT_EXTRA AND
52+
RDMA_LIB_EVENT_PTHREADS AND
53+
RDMA_LIB_NUMA
54+
)
55+
56+
set(RDMA_INC_DIR
57+
${RDMA_INC_SXISOCK}
58+
${RDMA_INC_XIO}
59+
${RDMA_INC_EVENT}
60+
${RDMA_INC_NUMA})
61+
set(RDMA_LIBS
62+
${RDMA_LIB_SXISOCK}
63+
${RDMA_LIB_XIO}
64+
${RDMA_LIB_EVENT}
65+
${RDMA_LIB_EVENT_CORE}
66+
${RDMA_LIB_EVENT_EXTRA}
67+
${RDMA_LIB_EVENT_PTHREADS}
68+
${RDMA_LIB_NUMA}
69+
)
70+
set(RDMA_LD_FLAGS "-L./librdma -libverbs -lrdmacm -Xlinker -rpath ./librdma")
71+
return()
72+
endif()
73+
74+
#if this module is not called, RDMA_INC_DIR RDMA_LIBS will be null, so top module always refer this variable
75+
76+
message(FATAL_ERROR, "RDMA libraries are not found, try to set RDMA_ROOT or check all related libraries.")

cmake/util.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ endmacro()
6767
#
6868
# It will handle WITH_PYTHON/WITH_GLOG etc.
6969
function(link_paddle_exe TARGET_NAME)
70+
if(WITH_RDMA)
71+
generate_rdma_links()
72+
endif()
73+
7074
if(WITH_METRIC)
7175
if(WITH_GPU)
7276
set(METRIC_LIBS paddle_metric_learning paddle_dserver_lib metric metric_cpu)
@@ -109,6 +113,12 @@ function(link_paddle_exe TARGET_NAME)
109113
${ZLIB_LIBRARIES}
110114
${INTERAL_LIBS}
111115
${CMAKE_DL_LIBS})
116+
117+
if(WITH_RDMA)
118+
target_link_libraries(${TARGET_NAME}
119+
${RDMA_LD_FLAGS}
120+
${RDMA_LIBS})
121+
endif()
112122

113123
if(WITH_PYTHON)
114124
target_link_libraries(${TARGET_NAME}

0 commit comments

Comments
 (0)