Skip to content

Commit 9b637a7

Browse files
cherry-pick PR 71507 to release/3.0 (#71732)
* initial commit for flagcx integration * fix compilation issue related to dynamic loader * fix compilation issue * fix bugs and test distributed api functions * set WITH_FLAGCX flag to off by defalut * fix compilation issue when not compiling with flagcx * add unit test and remove redundant code * remove redundant code in comm_context_manager.cc * remove debug log * remove unit tests * restore test file format * modify code according review comments * fix code format * fix code format
1 parent 7776754 commit 9b637a7

28 files changed

+2043
-3
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ option(
313313
OFF)
314314
option(WITH_CINN "Compile PaddlePaddle with CINN" OFF)
315315
option(WITH_NCCL "Compile PaddlePaddle with NCCL support" ON)
316+
option(WITH_FLAGCX "Compile PaddlePaddle with FLAGCX support" OFF)
316317
option(WITH_RCCL "Compile PaddlePaddle with RCCL support" ON)
317318
option(WITH_XPU_BKCL "Compile PaddlePaddle with BAIDU KUNLUN XPU BKCL" OFF)
318319
option(WITH_CRYPTO "Compile PaddlePaddle with crypto support" ON)
@@ -538,6 +539,11 @@ else()
538539
endif()
539540
endif()
540541

542+
if(WITH_FLAGCX)
543+
add_definitions("-DPADDLE_WITH_FLAGCX")
544+
include(flagcx)
545+
endif()
546+
541547
if(WITH_HETERPS AND WITH_PSLIB)
542548
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
543549
endif()

cmake/flagcx.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
set(CMAKE_FIND_DEBUG_MODE ON)
2+
# flagcx.cmake
3+
if(NOT WITH_FLAGCX)
4+
return()
5+
endif()
6+
7+
if(WITH_FLAGCX)
8+
set(FLAGCX_ROOT
9+
$ENV{FLAGCX_ROOT}
10+
CACHE PATH "FLAGCX_ROOT")
11+
message(STATUS "FLAGCX_ROOT is ${FLAGCX_ROOT}")
12+
find_path(
13+
FLAGCX_INCLUDE_DIR flagcx.h
14+
PATHS ${FLAGCX_ROOT}/flagcx/include
15+
NO_DEFAULT_PATH)
16+
message(STATUS "FLAGCX_INCLUDE_DIR is ${FLAGCX_INCLUDE_DIR}")
17+
include_directories(SYSTEM ${FLAGCX_INCLUDE_DIR})
18+
set(FLAGCX_LIB
19+
"${FLAGCX_ROOT}/build/lib/libflagcx.so"
20+
CACHE FILEPATH "flagcx library." FORCE)
21+
generate_dummy_static_lib(LIB_NAME "flagcx" GENERATOR "flagcx.cmake")
22+
target_link_libraries(flagcx ${FLAGCX_LIB})
23+
message(STATUS "FLAGCX_LIB is ${FLAGCX_LIB}")
24+
endif()

paddle/common/flags.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,19 @@ PHI_DEFINE_EXPORTED_bool(multi_node_sample_use_gpu_table,
12611261
PHI_DEFINE_EXPORTED_bool(nccl_blocking_wait, false, "nccl blocking wait");
12621262
#endif
12631263

1264+
/**
1265+
* ProcessGroupFlagCX related FLAG
1266+
* Name: flagcx_blocking_wait
1267+
* Since Version:
1268+
* Value Range: bool, default=false
1269+
* Example:
1270+
* Note: nccl blocking wait.
1271+
* blocks host thread until collective operation completes
1272+
*/
1273+
#if defined(PADDLE_WITH_FLAGCX)
1274+
PHI_DEFINE_EXPORTED_bool(flagcx_blocking_wait, false, "flagcx blocking wait");
1275+
#endif
1276+
12641277
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
12651278
PHI_DEFINE_EXPORTED_bool(benchmark_nccl,
12661279
false,
@@ -1766,6 +1779,13 @@ PHI_DEFINE_EXPORTED_string(
17661779
"For instance, /usr/local/cuda/lib64. If default, "
17671780
"dlopen will search cuda from LD_LIBRARY_PATH");
17681781

1782+
PHI_DEFINE_EXPORTED_string(
1783+
flagcx_dir, // NOLINT
1784+
"",
1785+
"Specify path for loading libflagcx.so. For instance, "
1786+
"For instance, /usr/local/flagcx/lib. If default, "
1787+
"dlopen will search flagcx from LD_LIBRARY_PATH");
1788+
17691789
PHI_DEFINE_EXPORTED_string(cupti_dir,
17701790
"",
17711791
"Specify path for loading cupti.so."); // NOLINT

paddle/fluid/distributed/collective/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if(WITH_NCCL OR WITH_RCCL)
3636

3737
endif()
3838

39+
if(WITH_FLAGCX)
40+
cc_library(
41+
process_group_flagcx
42+
SRCS process_group_flagcx.cc common.cc
43+
DEPS process_group phi)
44+
endif()
45+
3946
if(WITH_XPU_BKCL)
4047
cc_library(
4148
process_group_bkcl
@@ -66,6 +73,9 @@ set(COMM_UTILS_DEPS process_group)
6673
if(WITH_NCCL OR WITH_RCCL)
6774
set(COMM_UTILS_DEPS ${PROCESS_GROUP_UTILS_DEPS} process_group_nccl)
6875
endif()
76+
if(WITH_FLAGCX)
77+
set(COMM_UTILS_DEPS ${PROCESS_GROUP_UTILS_DEPS} process_group_flagcx)
78+
endif()
6979
if(WITH_CUSTOM_DEVICE)
7080
set(COMM_UTILS_DEPS ${PROCESS_GROUP_UTILS_DEPS} process_group_custom)
7181
endif()

0 commit comments

Comments
 (0)