Skip to content

Commit 4a37adc

Browse files
【Comm】pack flagcx library into paddle whl (#71981)
1 parent b536396 commit 4a37adc

File tree

7 files changed

+29
-2
lines changed

7 files changed

+29
-2
lines changed

paddle/fluid/pybind/pybind.cc

+9
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ bool IsCompiledWithNCCL() {
308308
#endif
309309
}
310310

311+
bool IsCompiledWithFlagcx() {
312+
#ifdef PADDLE_WITH_FLAGCX
313+
return true;
314+
#else
315+
return false;
316+
#endif
317+
}
318+
311319
bool IsCompiledWithMPI() {
312320
#ifdef PADDLE_WITH_MPI
313321
return true;
@@ -2582,6 +2590,7 @@ All parameter, weight, gradient are variables in Paddle.
25822590
std::make_unique<paddle::operants::PhiTensorOperants>();
25832591
VLOG(4) << "Initialize tensor operants successfully";
25842592
});
2593+
m.def("is_compiled_with_flagcx", IsCompiledWithFlagcx);
25852594
m.def("is_compiled_with_avx", IsCompiledWithAVX);
25862595
m.def("is_compiled_with_cuda", IsCompiledWithCUDA);
25872596
m.def("is_compiled_with_cudnn_frontend", IsCompiledWithCudnnFrontend);

python/env_dict.py.in

+2
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,6 @@ env_dict={
110110
'WITH_TENSORRT':'@WITH_TENSORRT@',
111111
'TR_INFER_RT':'@TR_INFER_RT@',
112112
'TENSORRT_LIBRARY_DIR':'@TENSORRT_LIBRARY_DIR@',
113+
'WITH_FLAGCX':'@WITH_FLAGCX@',
114+
'FLAGCX_LIB':'@FLAGCX_LIB@',
113115
}

python/paddle/distributed/fleet/launch_utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,7 @@ def check_backend(backend):
19371937
'auto',
19381938
'heter',
19391939
'xccl',
1940+
'flagcx',
19401941
]:
19411942
raise ValueError(
19421943
"paddle.distributed initialize error, "
@@ -1957,6 +1958,12 @@ def check_backend(backend):
19571958
"your paddle is not compiled with xpu but you assign 'bkcl' as backend."
19581959
)
19591960

1961+
if backend == 'flagcx' and not framework.core.is_compiled_with_flagcx():
1962+
raise ValueError(
1963+
"paddle.distributed initialize error, "
1964+
"your paddle is not compiled with flagcx but you assign 'flagcx' as backend."
1965+
)
1966+
19601967

19611968
def block_windows_and_macos(backend):
19621969
if backend != 'gloo':

python/paddle/distributed/parallel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def _start_kv_server(port, http_server_d, size):
932932
def _is_cpuonly(backend):
933933
check_backend(backend)
934934
if (
935-
backend in ['auto', 'nccl', 'bkcl', 'heter']
935+
backend in ['auto', 'nccl', 'bkcl', 'heter', 'flagcx']
936936
and (core.is_compiled_with_cuda() or core.is_compiled_with_xpu())
937937
) or backend == 'xccl':
938938
# passes 'auto' and can use cuda or xpu, use the default logics. so return False
@@ -1134,7 +1134,7 @@ def init_parallel_env() -> Group:
11341134
default_store = core.create_or_get_global_tcp_store()
11351135
_set_default_store(default_store)
11361136

1137-
if backend in ["nccl", 'xccl', 'bkcl']:
1137+
if backend in ["nccl", 'xccl', 'bkcl', 'flagcx']:
11381138
core.CommContextManager.set_device_id(parallel_env.device_id)
11391139

11401140
pg = _new_process_group_impl(

python/paddle/jit/sot/utils/paddle_api_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,6 @@ def is_directly_run_api(api):
163163
paddle.base.libpaddle.is_compiled_with_distribute,
164164
paddle.base.libpaddle.is_compiled_with_brpc,
165165
paddle.base.libpaddle.is_compiled_with_dist,
166+
paddle.base.libpaddle.is_compiled_with_flagcx,
166167
}
167168
return api in NATIVE_CODE_PURE_FUNCTIONS

python/setup.py.in

+3
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,9 @@ package_dir={
960960
libs_path='${PADDLE_BINARY_DIR}/python/paddle/libs'
961961

962962
package_data['paddle.libs']= []
963+
if('${WITH_FLAGCX}' == 'ON'):
964+
package_data['paddle.libs'] += [('libflagcx' if os.name != 'nt' else 'flagcx') + ext_name]
965+
shutil.copy('${FLAGCX_LIB}', libs_path)
963966
if('${WITH_SHARED_PHI}' == 'ON'):
964967
package_data['paddle.libs'] += [('libphi' if os.name != 'nt' else 'phi') + ext_name]
965968
shutil.copy('${PHI_LIB}', libs_path)

setup.py

+5
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,11 @@ def get_package_data_and_package_dir():
13391339
# put all thirdparty libraries in paddle.libs
13401340
libs_path = paddle_binary_dir + '/python/paddle/libs'
13411341
package_data['paddle.libs'] = []
1342+
if env_dict.get("WITH_FLAGCX") == 'ON':
1343+
package_data['paddle.libs'] += [
1344+
('libflagcx' if os.name != 'nt' else 'flagcx') + ext_suffix
1345+
]
1346+
shutil.copy(env_dict.get("FLAGCX_LIB"), libs_path)
13421347
if env_dict.get("WITH_SHARED_PHI") == "ON":
13431348
package_data['paddle.libs'] += [
13441349
('libphi' if os.name != 'nt' else 'phi') + ext_suffix

0 commit comments

Comments
 (0)