Skip to content

Commit

Permalink
read + appveyor & travis ci; boost and/or cereal serialization; unit …
Browse files Browse the repository at this point in the history
…testing

* add simple readme + build badges
* add appveyor + travis builds and tests
* cealn up cereal and/or boost serialization options
  + update xgboost submodule
  + disable tests for ios and android
  + fix indentation
  + fix travis
  + add option for to_string.h as needed (ANDROID listdc++ patch)
* add src/3rdparty/xgboost submodule for inital development
* move cereal + boost details from XGBoosterIOArchive*.cpp directly into xgboost
* update cmake options
* update bash build test scripts
* add some common model serialization template functions for common boost/serial archives
* add GTest + scikit gradient boosting “boston” regression problem
    + in memorty train + test
    + in memory train + cereal load and test
    + in memory train + boost load and test
* fix android missing strings (stdlib)
* add openmp global settings
* add Hunter/config.cmake
  • Loading branch information
headupinclouds committed May 7, 2017
1 parent 005b76a commit 0fea134
Show file tree
Hide file tree
Showing 28 changed files with 1,924 additions and 233 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/3rdparty/xgboost"]
path = src/3rdparty/xgboost
url = https://github.com/hunter-packages/xgboost.git
127 changes: 127 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# OSX/Linux (https://github.com/travis-ci-tester/toolchain-table)

language:
- cpp

# Container-based infrastructure (Linux)
# * https://docs.travis-ci.com/user/migrating-from-legacy/#How-can-I-use-container-based-infrastructure%3F
sudo:
- false

# Install packages differs for container-based infrastructure
# * https://docs.travis-ci.com/user/migrating-from-legacy/#How-do-I-install-APT-sources-and-packages%3F
# * http://stackoverflow.com/a/30925448/2288008
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- python3

# python3-pip package is not available, use 'easy_install3':
# * https://github.com/travis-ci/apt-package-whitelist/issues/768
- python3-setuptools # easy_install3

# https://github.com/travis-ci-tester/travis-test-clang-cxx-11
- libstdc++-4.8-dev

# https://github.com/travis-ci-tester/travis-test-gcc-cxx-11
- g++-4.8

# Packages for Android development: http://superuser.com/a/360398/252568
- libncurses5:i386
- libstdc++6:i386
- zlib1g:i386

matrix:
include:
# Linux {
- os: linux
env: CONFIG=Release TOOLCHAIN=gcc-4-8-pic-hid-sections INSTALL=--strip TO_STRING=OFF
# - os: linux
# env: CONFIG=Debug TOOLCHAIN=gcc-4-8-pic-hid-sections INSTALL=--strip TO_STRING=OFF
- os: linux
env: CONFIG=Release TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections INSTALL=--strip TO_STRING=ON
# - os: linux
# env: CONFIG=Debug TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections INSTALL=--strip TO_STRING=ON
# }

# OSX {
# - os: osx
# env: CONFIG=Release TOOLCHAIN=libcxx-hid-sections INSTALL=--strip TO_STRING=OFF
# - os: osx
# env: CONFIG=Debug TOOLCHAIN=libcxx-hid-sections INSTALL=--strip TO_STRING=OFF
- os: osx
env: CONFIG=Release TOOLCHAIN=osx-10-11-hid-sections INSTALL=--install TO_STRING=OFF
# - os: osx
# env: CONFIG=Debug TOOLCHAIN=osx-10-11-hid-sections INSTALL=--install TO_STRING=OFF
- os: osx
env: CONFIG=Release TOOLCHAIN=ios-nocodesign-9-3-device-hid-sections INSTALL=--install TO_STRING=OFF
# - os: osx
# env: CONFIG=Debug TOOLCHAIN=ios-nocodesign-9-3-device-hid-sections INSTALL=--install TO_STRING=OFF
- os: osx
osx_image: xcode8.1
env: CONFIG=Release TOOLCHAIN=osx-10-12-sanitize-address-hid-sections INSTALL=--install TO_STRING=OFF
- os: osx
osx_image: xcode8.1
env: CONFIG=Debug TOOLCHAIN=osx-10-12-sanitize-address-hid-sections INSTALL=--install TO_STRING=OFF
- os: osx
env: CONFIG=Release TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections INSTALL=--strip TO_STRING=ON
# - os: osx
# env: CONFIG=Debug TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections INSTALL=--strip TO_STRING=ON
# }

# disable the default submodule logic to support local modification of .gitmodules paths
git:
submodules: false

before_install:
# Add '--quiet' to avoid leaking the token to logs
- git submodule update --init --recursive --quiet

install:
# Info about OS
- uname -a

# Install Python 3
- if [[ "`uname`" == "Darwin" ]]; then travis_retry brew install python3; fi

# Install Python package 'requests'
# 'easy_install3' is not installed by 'brew install python3' on OS X 10.9 Maverick
- if [[ "`uname`" == "Darwin" ]]; then pip3 install requests; fi
- if [[ "`uname`" == "Linux" ]]; then travis_retry easy_install3 --user requests==2.10.0; fi

# Install latest Polly toolchains and scripts
- wget https://github.com/ruslo/polly/archive/master.zip
- unzip master.zip
- POLLY_ROOT="`pwd`/polly-master"
- export PATH="${POLLY_ROOT}/bin:${PATH}"

# Install dependencies (CMake, Android NDK)
- install-ci-dependencies.py

# Tune locations
- export PATH="`pwd`/_ci/cmake/bin:${PATH}"

# Installed if toolchain is Android (otherwise directory doesn't exist)
- export ANDROID_NDK_r10e="`pwd`/_ci/android-ndk-r10e"

script:

# optional to_string.h
- >
polly.py
--toolchain ${TOOLCHAIN}
--config ${CONFIG}
--verbose
--fwd
HUNTER_CONFIGURATION_TYPES=${CONFIG}
XGBOOSTER_ADD_TO_STRING=${TO_STRING}
--test
--discard 10
--tail 100
${INSTALL}
branches:
except:
- /^pr\..*/
45 changes: 40 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.18.44.tar.gz"
SHA1 "a78f0b377b8e53c038f12fc18b0c02564c4534c8"
FILEPATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/config.cmake"
)

set(XGBOOSTCPP_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}")
Expand All @@ -25,27 +26,61 @@ project(xgboostcpp VERSION 0.1.0) # WIP!

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# make sure these are before first hunter_add_package() call
option(XGBOOSTER_BUILD_TESTS "Build tests" ON)
option(XGBOOSTER_SERIALIZE_WITH_BOOST "Serialize w/ boost" ON)
option(XGBOOSTER_SERIALIZE_WITH_CEREAL "Serialize w/ cereal" ON)
option(XGBOOSTER_BUILD_APPS "Build applications" ON)
option(XGBOOSTER_SERIALIZE_WITH_BOOST "Serialize w/ boost" OFF) # hunter update
option(XGBOOSTER_SERIALIZE_WITH_CEREAL "Serialize w/ cereal" ON) # hunter update
option(XGBOOSTER_ADD_TO_STRING "Add local to_string definitions" OFF) # for android

###################
## Dependencies ###
###################

hunter_add_package(xgboost)
find_package(xgboost CONFIG REQUIRED)

if(XGBOOSTER_SERIALIZE_WITH_BOOST)
# boost
hunter_add_package(Boost COMPONENTS filesystem system serialization iostreams)
find_package(Boost CONFIG REQUIRED filesystem system serialization iostreams)

# boost-pba
hunter_add_package(boost-pba)
find_package(boost-pba CONFIG REQUIRED)

set(xgboostcpp_boost_libs
boost-pba::boost-pba
Boost::filesystem
Boost::system
Boost::serialization
Boost::iostreams
)

endif()

# cereal
if(XGBOOSTER_SERIALIZE_WITH_CEREAL)
hunter_add_package(cereal)
find_package(cereal CONFIG REQUIRED)
endif()

# GTest
if(XGBOOSTER_BUILD_TESTS)
enable_testing()
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
endif()

if(NOT XCODE AND NOT MSVC) # We'll never have openmp on ios, and this test is really slow
# This is only used for xgboost training and it will be removed once the
# xgboost interface is updated.
find_package(OpenMP)
if(OPENMP_FOUND)
# Set the globally for now (no clean cmake way to propagate OpenMP_EXE_LINKER_FLAGS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
endif()

##############
## Project ###
##############
Expand Down
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,44 @@
Simple C++ interface for xgboost with cross platform and size reduce serialization

This is a work in progress, and is posted initially as a reference for using the xgboost C++ API.

[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause)
[![HUNTER](https://img.shields.io/badge/hunter-v0.18.44-blue.svg)](http://github.com/ruslo/hunter)


| Linux/OSX/Android/iOS | Windows |
|-------------------------------------------------|-----------------------------------------------------|
| [![Build Status][travis_status]][travis_builds] | [![Build Status][appveyor_status]][appveyor_builds] |


[travis_status]: https://travis-ci.org/elucideye/xgboostcpp.svg?branch=master
[travis_builds]: https://travis-ci.com/elucideye/xgboostcpp


[appveyor_status]: https://ci.appveyor.com/api/projects/status/vh2hu8q7s17p00et?svg=true
[appveyor_builds]: https://ci.appveyor.com/api/projects/elucideye/xgboostcpp


HOWTO
=====

# Install latest Polly toolchains and scripts for cmake (not needed but very easy)
```
wget https://github.com/ruslo/polly/archive/master.zip
unzip master.zip
POLLY_ROOT="`pwd`/polly-master"
export PATH="${POLLY_ROOT}/bin:${PATH}"
```

# Build (see poll.py for list of available toolchains)
```
polly.py --toolchain libcxx --install --reconfig --verbose
```

The standard build should use hunter xgboost.
Initial builds may still require the xgboost submodule, in which case you
may need to run:

```
git submodule update --init --recursive --quiet
```
58 changes: 58 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Windows (https://github.com/travis-ci-tester/toolchain-table)

environment:
matrix:
###
- TOOLCHAIN: "default"
CONFIG: Release

- TOOLCHAIN: "default"
CONFIG: Debug

###
- TOOLCHAIN: "vs-14-2015"
CONFIG: Release

- TOOLCHAIN: "vs-14-2015"
CONFIG: Debug

install:
# Python 3
- cmd: set PATH=C:\Python34-x64;C:\Python34-x64\Scripts;%PATH%

# Install Python package 'requests'
- cmd: pip install requests

# Install latest Polly toolchains and scripts
- cmd: appveyor DownloadFile https://github.com/ruslo/polly/archive/master.zip
- cmd: 7z x master.zip
- cmd: set POLLY_SOURCE_DIR=%cd%\polly-master

# Install dependencies (CMake, Ninja)
- cmd: python %POLLY_SOURCE_DIR%\bin\install-ci-dependencies.py

# Tune locations
- cmd: set PATH=%cd%\_ci\cmake\bin;%PATH%
- cmd: set PATH=%cd%\_ci\ninja;%PATH%

# Add '--quiet' to avoid leaking the token to logs
- cmd: git submodule update --init --recursive --quiet

# Remove entry with sh.exe from PATH to fix error with MinGW toolchain
# (For MinGW make to work correctly sh.exe must NOT be in your path)
# * http://stackoverflow.com/a/3870338/2288008
- cmd: set PATH=%PATH:C:\Program Files\Git\usr\bin;=%

# Use MinGW from Qt tools because version is higher
# * http://www.appveyor.com/docs/installed-software#qt
- cmd: set MINGW_PATH=C:\Qt\Tools\mingw492_32\bin

# MSYS2 location
- cmd: set MSYS_PATH=C:\msys64\usr\bin

build_script:
- cmd: python %POLLY_SOURCE_DIR%\bin\polly.py --toolchain "%TOOLCHAIN%" --config "%CONFIG%" --verbose --test

branches:
except:
- /^pr\..*/
15 changes: 14 additions & 1 deletion bin/build-android.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#!/bin/bash

build.py --toolchain android-ndk-r10e-api-16-armeabi-v7a-neon-clang-35 --verbose --fwd HUNTER_CONFIGURATION_TYPES=Release ANDROID=TRUE --clear
TOOLCHAIN=android-ndk-r10e-api-19-armeabi-v7a-neon-hid-sections

ARGS=(
--verbose
--config Release
--fwd ANDROID=TRUE
HUNTER_CONFIGURATION_TYPES=Release
XGBOOSTER_SERIALIZE_WITH_BOOST=OFF
XGBOOSTER_SERIALIZE_WITH_CEREAL=ON
XGBOOSTER_ADD_TO_STRING=ON
)

export HUNTER_ROOT=${HOME}/devel/ruslo/hunter
build.py --toolchain ${TOOLCHAIN} ${ARGS[@]} --clear
9 changes: 6 additions & 3 deletions bin/build-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

ARGS=(
--verbose
--config Release
--fwd HUNTER_CONFIGURATION_TYPES=Release
XGBOOSTER_SERIALIZE_WITH_BOOST=OFF
XGBOOSTER_SERIALIZE_WITH_CEREAL=ON
--jobs 8
--reconfig
--install
)

build.py --toolchain xcode ${ARGS[@]} --open --nobuild
export HUNTER_ROOT=${HOME}/devel/ruslo/hunter
build.py --toolchain xcode ${ARGS[@]} --reconfig --install --open --test

15 changes: 15 additions & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(XGBOOST_CMAKE_ARGS
XGBOOST_USE_HALF=ON
XGBOOST_USE_BOOST=ON
XGBOOST_DO_LEAN=ON
XGBOOST_ADD_TO_STRING=${XGBOOSTER_ADD_TO_STRING}
XGBOOST_USE_BOOST=${XGBOOSTER_SERIALIZE_WITH_BOOST}
XGBOOST_USE_CEREAL=${XGBOOSTER_SERIALIZE_WITH_CEREAL}
)

if(ANDROID)
list(APPEND XGBOOST_CMAKE_ARGS XGBOOST_ADD_TO_STRING=ON)
endif()

hunter_config(Boost VERSION ${HUNTER_Boost_VERSION} CMAKE_ARGS IOSTREAMS_NO_BZIP2=1)
hunter_config(xgboost VERSION ${HUNTER_xgboost_VERSION} CMAKE_ARGS ${XGBOOST_CMAKE_ARGS})
1 change: 1 addition & 0 deletions src/3rdparty/xgboost
Submodule xgboost added at eb4af7
31 changes: 31 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
###############
### xgboost ###
###############

option(DRISHTI_USE_LOCAL_XGBOOST "Use local xgboost" ON)
if(DRISHTI_USE_LOCAL_XGBOOST)
option(SKIP_INSTALL "Avoid installation of submodule libraries" OFF)

option(SKIP_INSTALL "Skip the package install" OFF)
option(XGBOOST_USE_BOOST "Use boost serialization" ${XGBOOSTER_SERIALIZE_WITH_BOOST})
option(XGBOOST_USE_CEREAL "Use cereal serialization" ${XGBOOSTER_SERIALIZE_WITH_CEREAL})
option(XGBOOST_ADD_TO_STRING "Add standard library std::to_string()" ${XGBOOSTER_ADD_TO_STRING})
option(XGBOOST_USE_HALF "Support half precision floating point storage" ON)
option(XGBOOST_DO_LEAN "Build lean library for evaluation only" OFF)

add_subdirectory(3rdparty/xgboost)
unset(SKIP_INSTALL CACHE)
add_library(xgboost::xgboost ALIAS xgboost)
set_property(TARGET xgboost PROPERTY FOLDER "libs/3rdparty")
target_include_directories(xgboost PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/3rdparty>")

else()
hunter_add_package(xgboost)
find_package(xgboost CONFIG REQUIRED)
endif()

message("XGBOOST_USE_BOOST = ${XGBOOST_USE_BOOST}")
message("XGBOOST_USE_CEREAL = ${XGBOOST_USE_CEREAL}")
message("XGBOOSTER_SERIALIZE_WITH_BOOST = ${XGBOOSTER_SERIALIZE_WITH_BOOST}")
message("XGBOOSTER_SERIALIZE_WITH_CEREAL = ${XGBOOSTER_SERIALIZE_WITH_CEREAL}")

add_subdirectory(lib)
add_subdirectory(test)
Loading

0 comments on commit 0fea134

Please sign in to comment.