Skip to content

Commit 2faa744

Browse files
authored
[CI] Test federated learning plugin in the CI (dmlc#8325)
1 parent 97a5b08 commit 2faa744

16 files changed

+190
-117
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include(cmake/Utils.cmake)
44
list(APPEND CMAKE_MODULE_PATH "${xgboost_SOURCE_DIR}/cmake/modules")
55
cmake_policy(SET CMP0022 NEW)
66
cmake_policy(SET CMP0079 NEW)
7+
cmake_policy(SET CMP0076 NEW)
78
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
89
cmake_policy(SET CMP0063 NEW)
910

@@ -117,6 +118,20 @@ endif (BUILD_STATIC_LIB AND (R_LIB OR JVM_BINDINGS))
117118
if (PLUGIN_RMM AND (NOT BUILD_WITH_CUDA_CUB))
118119
message(SEND_ERROR "Cannot build with RMM using cub submodule.")
119120
endif (PLUGIN_RMM AND (NOT BUILD_WITH_CUDA_CUB))
121+
if (PLUGIN_FEDERATED)
122+
if (CMAKE_CROSSCOMPILING)
123+
message(SEND_ERROR "Cannot cross compile with federated learning support")
124+
endif ()
125+
if (BUILD_STATIC_LIB)
126+
message(SEND_ERROR "Cannot build static lib with federated learning support")
127+
endif ()
128+
if (R_LIB OR JVM_BINDINGS)
129+
message(SEND_ERROR "Cannot enable federated learning support when R or JVM packages are enabled.")
130+
endif ()
131+
if (WIN32)
132+
message(SEND_ERROR "Federated learning not supported for Windows platform")
133+
endif ()
134+
endif ()
120135

121136
#-- Sanitizer
122137
if (USE_SANITIZER)

plugin/federated/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
# gRPC needs to be installed first. See README.md.
2+
set(protobuf_MODULE_COMPATIBLE TRUE)
3+
set(protobuf_BUILD_SHARED_LIBS TRUE)
24
find_package(Protobuf CONFIG REQUIRED)
35
find_package(gRPC CONFIG REQUIRED)
4-
find_package(Threads)
6+
message(STATUS "Found gRPC: ${gRPC_CONFIG}")
57

68
# Generated code from the protobuf definition.
79
add_library(federated_proto federated.proto)
810
target_link_libraries(federated_proto PUBLIC protobuf::libprotobuf gRPC::grpc gRPC::grpc++)
911
target_include_directories(federated_proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
1012
xgboost_target_properties(federated_proto)
1113

12-
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION)
13-
protobuf_generate(TARGET federated_proto LANGUAGE cpp)
14+
protobuf_generate(
15+
TARGET federated_proto
16+
LANGUAGE cpp
17+
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
1418
protobuf_generate(
1519
TARGET federated_proto
1620
LANGUAGE grpc
1721
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
18-
PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}")
22+
PLUGIN "protoc-gen-grpc=\$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
23+
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
1924

2025
# Wrapper for the gRPC client.
2126
add_library(federated_client INTERFACE)

plugin/federated/README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,24 @@ This folder contains the plugin for federated learning. Follow these steps to bu
55

66
Install gRPC
77
------------
8-
```shell
9-
sudo apt-get install build-essential autoconf libtool pkg-config cmake ninja-build
10-
git clone -b v1.47.0 https://github.com/grpc/grpc
11-
cd grpc
12-
git submodule update --init
13-
cmake -S . -B build -GNinja -DABSL_PROPAGATE_CXX_STD=ON
14-
cmake --build build --target install
15-
```
8+
Refer to the [installation guide from the gRPC website](https://grpc.io/docs/languages/cpp/quickstart/).
169

1710
Build the Plugin
1811
----------------
1912
```shell
2013
# Under xgboost source tree.
2114
mkdir build
2215
cd build
23-
# For now NCCL needs to be turned off.
24-
cmake .. -GNinja\
25-
-DPLUGIN_FEDERATED=ON\
16+
cmake .. -GNinja \
17+
-DPLUGIN_FEDERATED=ON \
18+
-DBUILD_WITH_CUDA_CUB=ON \
2619
-DUSE_CUDA=ON\
27-
-DBUILD_WITH_CUDA_CUB=ON\
28-
-DUSE_NCCL=OFF
20+
-DUSE_NCCL=ON
2921
ninja
3022
cd ../python-package
3123
pip install -e . # or equivalently python setup.py develop
3224
```
25+
If CMake fails to locate gRPC, you may need to pass `-DCMAKE_PREFIX_PATH=<grpc path>` to CMake.
3326

3427
Test Federated XGBoost
3528
----------------------

tests/buildkite/build-containers.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -x
66
if [ "$#" -lt 1 ]
77
then
88
echo "Usage: $0 [container to build]"
9-
return 1
9+
exit 1
1010
fi
1111
container=$1
1212

@@ -17,18 +17,21 @@ echo "--- Build container ${container}"
1717
BUILD_ARGS=""
1818

1919
case "${container}" in
20+
cpu)
21+
;;
22+
2023
gpu|rmm)
2124
BUILD_ARGS="$BUILD_ARGS --build-arg CUDA_VERSION_ARG=$CUDA_VERSION"
2225
BUILD_ARGS="$BUILD_ARGS --build-arg RAPIDS_VERSION_ARG=$RAPIDS_VERSION"
2326
;;
2427

25-
jvm_gpu_build)
28+
gpu_build_centos7|jvm_gpu_build)
2629
BUILD_ARGS="$BUILD_ARGS --build-arg CUDA_VERSION_ARG=$CUDA_VERSION"
2730
;;
2831

2932
*)
3033
echo "Unrecognized container ID: ${container}"
31-
return 2
34+
exit 2
3235
;;
3336
esac
3437

tests/buildkite/build-cpu.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ $command_wrapper rm -fv dmlc-core/include/dmlc/build_config_default.h
1414
# the configured header build/dmlc/build_config.h instead of
1515
# include/dmlc/build_config_default.h.
1616
echo "--- Build libxgboost from the source"
17-
$command_wrapper tests/ci_build/build_via_cmake.sh -DPLUGIN_DENSE_PARSER=ON
17+
$command_wrapper tests/ci_build/build_via_cmake.sh -DCMAKE_PREFIX_PATH=/opt/grpc \
18+
-DPLUGIN_DENSE_PARSER=ON -DPLUGIN_FEDERATED=ON
1819
echo "--- Run Google Test"
1920
$command_wrapper bash -c "cd build && ctest --extra-verbose"
2021
echo "--- Stash XGBoost CLI executable"

tests/buildkite/build-cuda.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ command_wrapper="tests/ci_build/ci_build.sh gpu_build_centos7 docker --build-arg
2020

2121
echo "--- Build libxgboost from the source"
2222
$command_wrapper tests/ci_build/prune_libnccl.sh
23-
$command_wrapper tests/ci_build/build_via_cmake.sh -DUSE_CUDA=ON -DUSE_NCCL=ON \
24-
-DUSE_OPENMP=ON -DHIDE_CXX_SYMBOLS=ON -DUSE_NCCL_LIB_PATH=ON \
25-
-DNCCL_INCLUDE_DIR=/usr/include -DNCCL_LIBRARY=/workspace/libnccl_static.a \
26-
${arch_flag}
23+
$command_wrapper tests/ci_build/build_via_cmake.sh -DCMAKE_PREFIX_PATH=/opt/grpc \
24+
-DUSE_CUDA=ON -DUSE_NCCL=ON -DUSE_OPENMP=ON -DHIDE_CXX_SYMBOLS=ON -DPLUGIN_FEDERATED=ON \
25+
-DUSE_NCCL_LIB_PATH=ON -DNCCL_INCLUDE_DIR=/usr/include \
26+
-DNCCL_LIBRARY=/workspace/libnccl_static.a ${arch_flag}
2727
echo "--- Build binary wheel"
2828
$command_wrapper bash -c \
2929
"cd python-package && rm -rf dist/* && python setup.py bdist_wheel --universal"

tests/buildkite/pipeline-mgpu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ steps:
1717
- label: ":docker: Build containers"
1818
commands:
1919
- "tests/buildkite/build-containers.sh gpu"
20+
- "tests/buildkite/build-containers.sh gpu_build_centos7"
2021
- "tests/buildkite/build-containers.sh jvm_gpu_build"
2122
key: build-containers
2223
agents:

tests/buildkite/pipeline.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ steps:
1313
#### -------- CONTAINER BUILD --------
1414
- label: ":docker: Build containers"
1515
commands:
16+
- "tests/buildkite/build-containers.sh cpu"
1617
- "tests/buildkite/build-containers.sh gpu"
18+
- "tests/buildkite/build-containers.sh gpu_build_centos7"
1719
- "tests/buildkite/build-containers.sh rmm"
1820
key: build-containers
1921
agents:

tests/ci_build/Dockerfile.cpu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ ENV CPP=cpp-8
2626
ENV GOSU_VERSION 1.10
2727
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
2828

29+
# Install gRPC
30+
RUN git clone -b v1.49.1 https://github.com/grpc/grpc.git \
31+
--recurse-submodules --depth 1 --shallow-submodules && \
32+
pushd grpc && \
33+
cmake -S . -B build -GNinja -DCMAKE_INSTALL_PREFIX=/opt/grpc && \
34+
cmake --build build --target install && \
35+
popd && \
36+
rm -rf grpc
37+
2938
# Create new Conda environment
3039
COPY conda_env/cpu_test.yml /scripts/
3140
RUN mamba env create -n cpu_test --file=/scripts/cpu_test.yml

tests/ci_build/Dockerfile.gpu_build

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)