-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cover change with gtest unittests, clean up cmake script and code includes #106
Changes from all commits
36e4c2f
77eea8d
4ff7cee
415f4c6
6aefaa0
8224bda
566e7bc
7a44877
bd8227f
700c86c
58344af
3346a46
216610b
d4abb6d
72a5f33
5650d99
64963dc
0f6bc00
3fa3803
8188f0a
6e13671
16d5f0d
0e90e01
492024a
65eb5c0
4114087
5bb3045
f0cfd4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,106 @@ | ||
cmake_minimum_required(VERSION 3.3) | ||
|
||
project(rabit VERSION 0.3.0) | ||
|
||
include(CheckCXXCompilerFlag) | ||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) | ||
if(COMPILER_SUPPORTS_CXX11) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | ||
else() | ||
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") | ||
endif() | ||
project(rabit VERSION 0.3.0 LANGUAGES CXX) | ||
|
||
option(RABIT_BUILD_TESTS "Build rabit tests" OFF) | ||
option(RABIT_BUILD_MPI "Build MPI" OFF) | ||
option(RABIT_BUILD_DMLC "Include DMLC_CORE in build" OFF) | ||
option(RABIT_WITH_R_LIB "Fit the strict environment of R" OFF) | ||
|
||
option(DMLC_ROOT "Specify root of external dmlc core.") | ||
# by default point to xgboost/dmlc-core | ||
set(DMLC_ROOT ${CMAKE_CURRENT_LIST_DIR}/../dmlc-core) | ||
|
||
# moved from xgboost build | ||
if(R_LIB OR MINGW OR WIN32) | ||
add_library(rabit_base src/allreduce_base.cc src/engine_base.cc src/c_api.cc) | ||
add_library(rabit src/engine_empty.cc src/c_api.cc) | ||
set(rabit_libs rabit) | ||
set_target_properties(rabit PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) | ||
ELSE() | ||
set_target_properties(rabit | ||
PROPERTIES CXX_STANDARD 11 | ||
CXX_STANDARD_REQUIRED ON | ||
POSITION_INDEPENDENT_CODE ON) | ||
else() | ||
add_library(rabit src/allreduce_base.cc src/allreduce_robust.cc src/engine.cc src/c_api.cc) | ||
add_library(rabit_base src/allreduce_base.cc src/engine_base.cc src/c_api.cc) | ||
add_library(rabit_empty src/engine_empty.cc src/c_api.cc) | ||
add_library(rabit_mock_static src/allreduce_base.cc src/allreduce_robust.cc src/engine_mock.cc src/c_api.cc) | ||
add_library(rabit_mock SHARED src/allreduce_base.cc src/allreduce_robust.cc src/engine_mock.cc src/c_api.cc) | ||
|
||
set(rabit_libs rabit rabit_base rabit_empty rabit_mock rabit_mock_static) | ||
set_target_properties(rabit rabit_base rabit_empty rabit_mock rabit_mock_static PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) | ||
set_target_properties(rabit rabit_base rabit_empty rabit_mock rabit_mock_static | ||
PROPERTIES CXX_STANDARD 11 | ||
CXX_STANDARD_REQUIRED ON | ||
POSITION_INDEPENDENT_CODE ON) | ||
ENDIF(R_LIB OR MINGW OR WIN32) | ||
|
||
if(RABIT_BUILD_MPI) | ||
find_package(MPI REQUIRED) | ||
if (NOT MPI_CXX_FOUND) | ||
message(FATAL_ERROR "CXX Interface for MPI is required for building MPI backend.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote this line, but do we actually want to support MPI backend? I thought it's a proof of concept for the paper. And now that the MPI CXX interface is deprecated, there will be some more works for bring it up. @chenqin What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might discuss this in another thread how to support MPI runtime. The rationale is there are lots of similar frameworks highly optimized such as facebook/gloo that just do MPI optimization. None of which offers failed single worker recover. But I don't have clear picture who is using rabit other than distributed XGBoost. |
||
endif (NOT MPI_CXX_FOUND) | ||
add_library(rabit_mpi src/engine_mpi.cc ${MPI_INCLUDE_PATH}) | ||
target_link_libraries(rabit_mpi ${MPI_CXX_LIBRARIES}) | ||
list(APPEND rabit_libs rabit_mpi) | ||
endif() | ||
|
||
# place binaries and libraries according to GNU standards | ||
include(GNUInstallDirs) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) | ||
|
||
if(RABIT_BUILD_DMLC) | ||
foreach(lib ${rabit_libs}) | ||
#include "./internal/utils.h" | ||
target_include_directories(${lib} PUBLIC | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>" | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/dmlc-core/include>" | ||
) | ||
endforeach() | ||
else() | ||
# we use this to get code coverage | ||
if ((CMAKE_CONFIGURATION_TYPES STREQUAL "Debug") AND (CMAKE_CXX_COMPILER_ID MATCHES GNU)) | ||
foreach(lib ${rabit_libs}) | ||
#include "./internal/utils.h" | ||
target_include_directories(${lib} PUBLIC | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>" | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../dmlc_core/include>" | ||
) | ||
endforeach() | ||
target_compile_options(${lib} | ||
-fprofile-arcs | ||
-ftest-coverage) | ||
endforeach() | ||
endif((CMAKE_CONFIGURATION_TYPES STREQUAL "Debug") AND (CMAKE_CXX_COMPILER_ID MATCHES GNU)) | ||
|
||
if(RABIT_BUILD_DMLC) | ||
set(DMLC_ROOT ${CMAKE_CURRENT_LIST_DIR}/dmlc-core) | ||
endif() | ||
|
||
if(RABIT_BUILD_TESTS) | ||
if(DMLC_ROOT) | ||
message("DMLC_ROOT point to " ${DMLC_ROOT}) | ||
endif(DMLC_ROOT) | ||
|
||
foreach(lib ${rabit_libs}) | ||
target_include_directories(${lib} PUBLIC | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>" | ||
"$<BUILD_INTERFACE:${DMLC_ROOT}/include>") | ||
endforeach() | ||
|
||
if (RABIT_BUILD_TESTS) | ||
enable_testing() | ||
add_subdirectory(${rabit_SOURCE_DIR}/test/cpp) | ||
|
||
# rabit mock based integration tests | ||
list(REMOVE_ITEM rabit_libs "rabit_mock_static") # remove here to avoid installing it | ||
set(tests lazy_recover local_recover model_recover) | ||
|
||
foreach(test ${tests}) | ||
add_executable(${test} test/${test}.cc) | ||
target_link_libraries(${test} rabit_mock_static) | ||
set_target_properties(${test} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) | ||
install(TARGETS ${test} DESTINATION test) | ||
install(TARGETS ${test} DESTINATION test) # Why are we installing these?? | ||
endforeach() | ||
|
||
if(RABIT_BUILD_MPI) | ||
add_executable(speed_test_mpi test/speed_test.cc) | ||
target_link_libraries(speed_test_mpi rabit_mpi) | ||
install(TARGETS speed_test_mpi DESTINATION test) | ||
endif() | ||
endif() | ||
endif (RABIT_BUILD_TESTS) | ||
|
||
# Installation (https://github.com/forexample/package-example) { | ||
|
||
# Layout. This works for all platforms: | ||
# * <prefix>/lib/cmake/<PROJECT-NAME> | ||
# * <prefix>/lib/ | ||
# * <prefix>/include/ | ||
set(CMAKE_INSTALL_PREFIX "../") | ||
set(CMAKE_INSTALL_PREFIX "${rabit_SOURCE_DIR}") | ||
set(config_install_dir "lib/cmake/${PROJECT_NAME}") | ||
set(include_install_dir "include") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# code copied from https://crascit.com/2015/07/25/cmake-gtest/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem necessary anymore. I'm OK for keeping it here for the convenience of others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trivialfis |
||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR) | ||
|
||
project(googletest-download NONE) | ||
|
||
include(ExternalProject) | ||
|
||
ExternalProject_Add( | ||
googletest | ||
SOURCE_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-src" | ||
BINARY_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-build" | ||
GIT_REPOSITORY | ||
https://github.com/google/googletest.git | ||
GIT_TAG | ||
release-1.8.0 | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# the following code to fetch googletest | ||
# is inspired by and adapted after https://crascit.com/2015/07/25/cmake-gtest/ | ||
# download and unpack googletest at configure time | ||
|
||
macro(fetch_googletest _download_module_path _download_root) | ||
set(GOOGLETEST_DOWNLOAD_ROOT ${_download_root}) | ||
configure_file( | ||
${_download_module_path}/googletest-download.cmake | ||
${_download_root}/CMakeLists.txt | ||
@ONLY | ||
) | ||
unset(GOOGLETEST_DOWNLOAD_ROOT) | ||
|
||
execute_process( | ||
COMMAND | ||
"${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . | ||
WORKING_DIRECTORY | ||
${_download_root} | ||
) | ||
execute_process( | ||
COMMAND | ||
"${CMAKE_COMMAND}" --build . | ||
WORKING_DIRECTORY | ||
${_download_root} | ||
) | ||
|
||
# adds the targers: gtest, gtest_main, gmock, gmock_main | ||
add_subdirectory( | ||
${_download_root}/googletest-src | ||
${_download_root}/googletest-build | ||
) | ||
endmacro() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
echo "Testing on: ${TRAVIS_OS_NAME}, Home directory: ${HOME}" | ||
|
||
pip3 install cpplint pylint urllib3 numpy cpplint | ||
pip3 install websocket-client kubernetes | ||
|
||
|
||
# Install googletest under home directory | ||
GTEST_VERSION=1.8.1 | ||
GTEST_RELEASE=release-${GTEST_VERSION}.tar.gz | ||
GTEST_TAR_BALL=googletest_${GTEST_RELEASE} | ||
|
||
wget https://github.com/google/googletest/archive/${GTEST_RELEASE} -O ${GTEST_TAR_BALL} | ||
echo "152b849610d91a9dfa1401293f43230c2e0c33f8 ${GTEST_TAR_BALL}" | sha1sum -c | ||
tar -xf ${GTEST_TAR_BALL} | ||
pushd . | ||
|
||
cd googletest-release-${GTEST_VERSION} | ||
mkdir build | ||
cd build | ||
echo "Installing to ${HOME}/.local" | ||
cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=${HOME}/.local | ||
make -j$(nproc) | ||
make install | ||
|
||
popd | ||
|
||
if [ ${TRAVIS_OS_NAME} == "linux" ]; then | ||
sudo apt-get install python3-pip tree | ||
fi | ||
|
||
if [ ${TRAVIS_OS_NAME} == "osx" ]; then | ||
brew install python3 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
option(DMLC_ROOT "Specify root of external dmlc core.") | ||
|
||
add_library(allreduce_base "") | ||
|
||
target_sources( | ||
allreduce_base | ||
PRIVATE | ||
allreduce_base.cc | ||
PUBLIC | ||
${CMAKE_CURRENT_LIST_DIR}/allreduce_base.h | ||
) | ||
|
||
target_include_directories( | ||
allreduce_base | ||
PUBLIC | ||
${DMLC_ROOT}/include | ||
${CMAKE_CURRENT_LIST_DIR}/../../include) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You spent so much effort on rabit I assume you don't want to make it XGBoost exclusive right? Since last time I check rabit is only using some headers from
dmlc-core
, there's no linkage involved. So technically rabit can use dmlc-core in system path, say/usr/
or/home/chenqin/.local/
or any other directories that follow thebin/include/lib/lib64
pattern without any problem, and you can set above path asDMLC_ROOT
for your convenience. With this, you can simply throw an error if DMLC_ROOT is not specified.In the future (not for this PR), I may add this to rabit as
dmlc-core
has very good support for CMake target.