[fed] Split up federated test CMake file. (#10566)

- Collect all federated test files into the same directory.
- Independently list the files.
This commit is contained in:
Jiaming Yuan 2024-07-11 13:09:18 +08:00 committed by GitHub
parent 5f910cd4ff
commit 89da9f9741
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 22 deletions

View File

@ -1,3 +1,6 @@
# The testxgboost executable is created in the top level CMakeLists. Most of the
# properties and compilation flags are already set. We just need to add source files and
# link gtest here.
if(USE_DMLC_GTEST) if(USE_DMLC_GTEST)
if(NOT TARGET gtest) if(NOT TARGET gtest)
message(FATAL_ERROR "USE_DMLC_GTEST=ON but dmlc-core didn't bundle gtest") message(FATAL_ERROR "USE_DMLC_GTEST=ON but dmlc-core didn't bundle gtest")
@ -6,6 +9,7 @@ if(USE_DMLC_GTEST)
else() else()
find_package(GTest REQUIRED) find_package(GTest REQUIRED)
endif() endif()
file(GLOB_RECURSE TEST_SOURCES "*.cc") file(GLOB_RECURSE TEST_SOURCES "*.cc")
if(USE_CUDA) if(USE_CUDA)
@ -13,6 +17,10 @@ if(USE_CUDA)
list(APPEND TEST_SOURCES ${CUDA_TEST_SOURCES}) list(APPEND TEST_SOURCES ${CUDA_TEST_SOURCES})
endif() endif()
# We will add them back later to separate the definition.
file(GLOB_RECURSE FEDERATED_TEST_SOURCES "plugin/federated/*.*")
list(REMOVE_ITEM TEST_SOURCES ${FEDERATED_TEST_SOURCES})
file(GLOB_RECURSE SYCL_TEST_SOURCES "plugin/test_sycl_*.cc") file(GLOB_RECURSE SYCL_TEST_SOURCES "plugin/test_sycl_*.cc")
list(REMOVE_ITEM TEST_SOURCES ${SYCL_TEST_SOURCES}) list(REMOVE_ITEM TEST_SOURCES ${SYCL_TEST_SOURCES})
@ -48,14 +56,14 @@ if(PLUGIN_SYCL)
endif() endif()
if(PLUGIN_FEDERATED) if(PLUGIN_FEDERATED)
target_include_directories(testxgboost PRIVATE ${xgboost_SOURCE_DIR}/plugin/federated) add_subdirectory(${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated)
target_link_libraries(testxgboost PRIVATE federated_client)
else()
file(GLOB_RECURSE FEDERATED_TEST_SOURCES "plugin/*_federated_*.*")
list(REMOVE_ITEM TEST_SOURCES ${FEDERATED_TEST_SOURCES})
endif() endif()
target_sources(testxgboost PRIVATE ${TEST_SOURCES} ${xgboost_SOURCE_DIR}/plugin/example/custom_obj.cc) target_sources(
testxgboost PRIVATE
${TEST_SOURCES}
${xgboost_SOURCE_DIR}/plugin/example/custom_obj.cc
)
if(USE_CUDA AND PLUGIN_RMM) if(USE_CUDA AND PLUGIN_RMM)
target_include_directories(testxgboost PRIVATE ${CUDA_INCLUDE_DIRS}) target_include_directories(testxgboost PRIVATE ${CUDA_INCLUDE_DIRS})
@ -63,7 +71,6 @@ endif()
target_include_directories(testxgboost target_include_directories(testxgboost
PRIVATE PRIVATE
${GTEST_INCLUDE_DIRS}
${xgboost_SOURCE_DIR}/include ${xgboost_SOURCE_DIR}/include
${xgboost_SOURCE_DIR}/dmlc-core/include) ${xgboost_SOURCE_DIR}/dmlc-core/include)
target_link_libraries(testxgboost target_link_libraries(testxgboost

View File

@ -0,0 +1,20 @@
target_sources(
testxgboost PRIVATE
${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated/test_federated_coll.cc
${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated/test_federated_comm.cc
${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated/test_federated_comm_group.cc
${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated/test_federated_tracker.cc
${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated/test_federated_learner.cc
${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated/test_federated_data.cc
)
if(USE_CUDA)
target_sources(
testxgboost PRIVATE
${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated/test_federated_coll.cu
${xgboost_SOURCE_DIR}/tests/cpp/plugin/federated/test_federated_comm_group.cu
)
endif()
target_include_directories(testxgboost PRIVATE ${xgboost_SOURCE_DIR}/plugin/federated)
target_link_libraries(testxgboost PRIVATE federated_client)

View File

@ -1,15 +1,13 @@
/*! /**
* Copyright 2023 XGBoost contributors * Copyright 2023-2024, XGBoost contributors
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <xgboost/data.h> #include <xgboost/data.h>
#include <thread> #include "../../../../src/collective/communicator-inl.h"
#include "../../filesystem.h"
#include "../../../src/collective/communicator-inl.h" #include "../../helpers.h"
#include "../filesystem.h" #include "test_worker.h"
#include "../helpers.h"
#include "federated/test_worker.h"
namespace xgboost { namespace xgboost {

View File

@ -1,19 +1,18 @@
/** /**
* Copyright 2023-2024, XGBoost contributors * Copyright 2023-2024, XGBoost contributors
* *
* Some other tests for federated learning are in the main test suite (test_learner.cc), * Some other tests for federated learning are in the main test suite (test_learner.cc).
* gaurded by the `XGBOOST_USE_FEDERATED`.
*/ */
#include <dmlc/parameter.h> #include <dmlc/parameter.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <xgboost/data.h> #include <xgboost/data.h>
#include <xgboost/objective.h> #include <xgboost/objective.h>
#include "../../../src/collective/communicator-inl.h" #include "../../../../src/collective/communicator-inl.h"
#include "../../../src/common/linalg_op.h" // for begin, end #include "../../../../src/common/linalg_op.h" // for begin, end
#include "../helpers.h" #include "../../helpers.h"
#include "../objective_helpers.h" // for MakeObjNamesForTest, ObjTestNameGenerator #include "../../objective_helpers.h" // for MakeObjNamesForTest, ObjTestNameGenerator
#include "federated/test_worker.h" #include "test_worker.h"
namespace xgboost { namespace xgboost {
namespace { namespace {