From 095de3bf5f9febba9908637197873630021c733a Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Sun, 6 Oct 2019 23:53:09 -0400 Subject: [PATCH] Export c++ headers in CMake installation. (#4897) * Move get transpose into cc. * Clean up headers in host device vector, remove thrust dependency. * Move span and host device vector into public. * Install c++ headers. * Short notes for c and c++. Co-Authored-By: Philip Hyunsu Cho --- CMakeLists.txt | 8 ++-- demo/c-api/CMakeLists.txt | 4 ++ doc/c++.rst | 12 +++++ doc/c.rst | 12 +++++ doc/index.rst | 2 + include/xgboost/data.h | 36 ++------------- include/xgboost/gbm.h | 3 +- .../xgboost}/host_device_vector.h | 34 ++------------ include/xgboost/linear_updater.h | 10 ++++- include/xgboost/metric.h | 3 +- include/xgboost/objective.h | 3 +- include/xgboost/predictor.h | 7 +-- {src/common => include/xgboost}/span.h | 6 +-- include/xgboost/tree_model.h | 12 ++--- include/xgboost/tree_updater.h | 3 +- src/common/bitfield.h | 7 ++- src/common/device_helpers.cuh | 25 ++++++++++- src/common/hist_util.cc | 2 + src/common/hist_util.cu | 8 ++-- src/common/host_device_vector.cc | 2 +- src/common/host_device_vector.cu | 45 +++---------------- src/common/random.h | 6 +-- src/common/transform.h | 5 ++- src/data/columnar.h | 3 +- src/data/data.cc | 31 ++++++++++++- src/data/sparse_page_source.h | 1 + src/gbm/gblinear.cc | 3 ++ src/gbm/gbtree.cc | 16 +++---- src/gbm/gbtree.h | 3 +- src/learner.cc | 11 ++--- src/linear/updater_gpu_coordinate.cu | 5 ++- src/metric/rank_metric.cc | 2 +- src/objective/hinge.cu | 7 +-- src/objective/objective.cc | 2 +- src/objective/regression_obj.cu | 5 ++- src/predictor/cpu_predictor.cc | 12 ++--- src/predictor/gpu_predictor.cu | 13 +++--- src/tree/constraints.cu | 5 +-- src/tree/constraints.cuh | 2 +- src/tree/split_evaluator.cc | 7 +-- src/tree/tree_updater.cc | 4 +- src/tree/updater_gpu_hist.cu | 6 ++- tests/cpp/common/test_host_device_vector.cu | 8 ++-- tests/cpp/common/test_span.cc | 2 +- tests/cpp/common/test_span.cu | 2 +- tests/cpp/common/test_span.h | 4 +- tests/cpp/common/test_transform_range.cc | 7 +-- tests/cpp/helpers.cc | 1 + tests/cpp/linear/test_linear.cc | 5 ++- tests/cpp/linear/test_linear.cu | 4 +- tests/cpp/predictor/test_cpu_predictor.cc | 2 + tests/cpp/predictor/test_gpu_predictor.cu | 1 + tests/cpp/tree/test_prune.cc | 2 +- tests/cpp/tree/test_quantile_hist.cc | 12 ++--- tests/cpp/tree/test_refresh.cc | 6 ++- 55 files changed, 240 insertions(+), 209 deletions(-) create mode 100644 demo/c-api/CMakeLists.txt create mode 100644 doc/c++.rst create mode 100644 doc/c.rst rename {src/common => include/xgboost}/host_device_vector.h (80%) rename {src/common => include/xgboost}/span.h (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b982a96ee..d498bb217 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,11 +187,9 @@ if (BUILD_C_DOC) endif (BUILD_C_DOC) include(GNUInstallDirs) -# Exposing only C APIs. -install(FILES - "${PROJECT_SOURCE_DIR}/include/xgboost/c_api.h" - DESTINATION - include/xgboost/) +# Install all headers. Please note that currently the C++ headers does not form an "API". +install(DIRECTORY ${xgboost_SOURCE_DIR}/include/xgboost + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(TARGETS xgboost runxgboost EXPORT XGBoostTargets diff --git a/demo/c-api/CMakeLists.txt b/demo/c-api/CMakeLists.txt new file mode 100644 index 000000000..308ac4a2c --- /dev/null +++ b/demo/c-api/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.3) +find_package(xgboost REQUIRED) +add_executable(api-demo c-api-demo.c) +target_link_libraries(api-demo xgboost::xgboost) diff --git a/doc/c++.rst b/doc/c++.rst new file mode 100644 index 000000000..4a045fc42 --- /dev/null +++ b/doc/c++.rst @@ -0,0 +1,12 @@ +############### +XGBoost C++ API +############### + +Starting from 1.0 release, CMake will generate installation rules to export all C++ headers. But +the c++ interface is much closer to the internal of XGBoost than other language bindings. +As a result it's changing quite often and we don't maintain its stability. Along with the +plugin system (see ``plugin/example`` in XGBoost's source tree), users can utilize some +existing c++ headers for gaining more access to the internal of XGBoost. + +* `C++ interface documentation (latest master branch) `_ +* `C++ interface documentation (last stable release) `_ diff --git a/doc/c.rst b/doc/c.rst new file mode 100644 index 000000000..2dc15269d --- /dev/null +++ b/doc/c.rst @@ -0,0 +1,12 @@ +################# +XGBoost C Package +################# + +XGBoost implements a set of C API designed for various bindings, we maintain its +stability and the CMake/make build interface. See ``demo/c-api/README.md`` for an +overview and related examples. Also one can generate doxygen document by providing +``-DBUILD_C_DOC=ON`` as parameter to ``CMake`` during build, or simply look at function +comments in ``include/xgboost/c_api.h``. + +* `C API documentation (latest master branch) `_ +* `C API documentation (last stable release) `_ diff --git a/doc/index.rst b/doc/index.rst index eadeacde2..223f9abbd 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -27,5 +27,7 @@ Contents JVM package Ruby package Julia package + C Package + C++ Interface CLI interface contrib/index diff --git a/include/xgboost/data.h b/include/xgboost/data.h index 44608e4a1..b8bce91de 100644 --- a/include/xgboost/data.h +++ b/include/xgboost/data.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -19,10 +21,6 @@ #include #include -#include "../../src/common/span.h" -#include "../../src/common/group_data.h" -#include "../../src/common/host_device_vector.h" - namespace xgboost { // forward declare learner. class LearnerImpl; @@ -214,35 +212,7 @@ class SparsePage { data.HostVector().clear(); } - SparsePage GetTranspose(int num_columns) const { - SparsePage transpose; - common::ParallelGroupBuilder builder(&transpose.offset.HostVector(), - &transpose.data.HostVector()); - const int nthread = omp_get_max_threads(); - builder.InitBudget(num_columns, nthread); - long batch_size = static_cast(this->Size()); // NOLINT(*) -#pragma omp parallel for default(none) shared(batch_size, builder) schedule(static) - for (long i = 0; i < batch_size; ++i) { // NOLINT(*) - int tid = omp_get_thread_num(); - auto inst = (*this)[i]; - for (const auto& entry : inst) { - builder.AddBudget(entry.index, tid); - } - } - builder.InitStorage(); -#pragma omp parallel for default(none) shared(batch_size, builder) schedule(static) - for (long i = 0; i < batch_size; ++i) { // NOLINT(*) - int tid = omp_get_thread_num(); - auto inst = (*this)[i]; - for (const auto& entry : inst) { - builder.Push( - entry.index, - Entry(static_cast(this->base_rowid + i), entry.fvalue), - tid); - } - } - return transpose; - } + SparsePage GetTranspose(int num_columns) const; void SortRows() { auto ncol = static_cast(this->Size()); diff --git a/include/xgboost/gbm.h b/include/xgboost/gbm.h index 3811d7283..5d5b8eb74 100644 --- a/include/xgboost/gbm.h +++ b/include/xgboost/gbm.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -21,8 +22,6 @@ #include #include -#include "../../src/common/host_device_vector.h" - namespace xgboost { /*! * \brief interface of gradient boosting model. diff --git a/src/common/host_device_vector.h b/include/xgboost/host_device_vector.h similarity index 80% rename from src/common/host_device_vector.h rename to include/xgboost/host_device_vector.h index e2d4a04f7..e533d134b 100644 --- a/src/common/host_device_vector.h +++ b/include/xgboost/host_device_vector.h @@ -44,31 +44,16 @@ * 'HostDeviceVector' with a special-case implementation in host_device_vector.cc * * @note: Size and Devices methods are thread-safe. - * DevicePointer, DeviceStart, DeviceSize, tbegin and tend methods are thread-safe - * if different threads call these methods with different values of the device argument. - * All other methods are not thread safe. */ -#ifndef XGBOOST_COMMON_HOST_DEVICE_VECTOR_H_ -#define XGBOOST_COMMON_HOST_DEVICE_VECTOR_H_ +#ifndef XGBOOST_HOST_DEVICE_VECTOR_H_ +#define XGBOOST_HOST_DEVICE_VECTOR_H_ -#include - -#include -#include #include -#include #include -#include "common.h" #include "span.h" -// only include thrust-related files if host_device_vector.h -// is included from a .cu file -#ifdef __CUDACC__ -#include -#endif // __CUDACC__ - namespace xgboost { #ifdef __CUDACC__ @@ -118,19 +103,6 @@ class HostDeviceVector { const T* ConstHostPointer() const { return ConstHostVector().data(); } const T* HostPointer() const { return ConstHostPointer(); } - // only define functions returning device_ptr - // if HostDeviceVector.h is included from a .cu file -#ifdef __CUDACC__ - thrust::device_ptr tbegin(); // NOLINT - thrust::device_ptr tend(); // NOLINT - thrust::device_ptr tcbegin() const; // NOLINT - thrust::device_ptr tcend() const; // NOLINT - thrust::device_ptr tbegin() const { // NOLINT - return tcbegin(); - } - thrust::device_ptr tend() const { return tcend(); } // NOLINT -#endif // __CUDACC__ - void Fill(T v); void Copy(const HostDeviceVector& other); void Copy(const std::vector& other); @@ -155,4 +127,4 @@ class HostDeviceVector { } // namespace xgboost -#endif // XGBOOST_COMMON_HOST_DEVICE_VECTOR_H_ +#endif // XGBOOST_HOST_DEVICE_VECTOR_H_ diff --git a/include/xgboost/linear_updater.h b/include/xgboost/linear_updater.h index 872dc83aa..4cbf84f9f 100644 --- a/include/xgboost/linear_updater.h +++ b/include/xgboost/linear_updater.h @@ -7,14 +7,20 @@ #include #include #include +#include + #include #include #include #include -#include "../../src/gbm/gblinear_model.h" -#include "../../src/common/host_device_vector.h" + namespace xgboost { + +namespace gbm { +class GBLinearModel; +} // namespace gbm + /*! * \brief interface of linear updater */ diff --git a/include/xgboost/metric.h b/include/xgboost/metric.h index 211689106..36b148b7f 100644 --- a/include/xgboost/metric.h +++ b/include/xgboost/metric.h @@ -11,14 +11,13 @@ #include #include #include +#include #include #include #include #include -#include "../../src/common/host_device_vector.h" - namespace xgboost { /*! * \brief interface of evaluation metric used to evaluate model performance. diff --git a/include/xgboost/objective.h b/include/xgboost/objective.h index 466f87e0e..b5b365a0b 100644 --- a/include/xgboost/objective.h +++ b/include/xgboost/objective.h @@ -11,14 +11,13 @@ #include #include #include +#include #include #include #include #include -#include "../../src/common/host_device_vector.h" - namespace xgboost { /*! \brief interface of objective function */ diff --git a/include/xgboost/predictor.h b/include/xgboost/predictor.h index 357435cd9..93316c0f8 100644 --- a/include/xgboost/predictor.h +++ b/include/xgboost/predictor.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -16,12 +17,12 @@ #include #include -#include "../../src/gbm/gbtree_model.h" -#include "../../src/common/host_device_vector.h" - // Forward declarations namespace xgboost { class TreeUpdater; +namespace gbm { +class GBTreeModel; +} // namespace gbm } namespace xgboost { diff --git a/src/common/span.h b/include/xgboost/span.h similarity index 99% rename from src/common/span.h rename to include/xgboost/span.h index 1a707df5f..d7e48ecb9 100644 --- a/src/common/span.h +++ b/include/xgboost/span.h @@ -26,8 +26,8 @@ * THE SOFTWARE. */ -#ifndef XGBOOST_COMMON_SPAN_H_ -#define XGBOOST_COMMON_SPAN_H_ +#ifndef XGBOOST_SPAN_H_ +#define XGBOOST_SPAN_H_ #include // CHECK @@ -637,4 +637,4 @@ XGBOOST_DEVICE auto as_writable_bytes(Span s) __span_noexcept -> // NOLIN #undef __span_noexcept #endif // _MSC_VER < 1910 -#endif // XGBOOST_COMMON_SPAN_H_ +#endif // XGBOOST_SPAN_H_ diff --git a/include/xgboost/tree_model.h b/include/xgboost/tree_model.h index 37f61dfae..53f1baca6 100644 --- a/include/xgboost/tree_model.h +++ b/include/xgboost/tree_model.h @@ -1,5 +1,5 @@ /*! - * Copyright 2014 by Contributors + * Copyright 2014-2019 by Contributors * \file tree_model.h * \brief model structure for tree * \author Tianqi Chen @@ -9,16 +9,18 @@ #include #include + +#include +#include +#include +#include + #include #include #include #include #include #include -#include "./base.h" -#include "./data.h" -#include "./logging.h" -#include "./feature_map.h" namespace xgboost { diff --git a/include/xgboost/tree_updater.h b/include/xgboost/tree_updater.h index 0a6a30fba..577ce4f0b 100644 --- a/include/xgboost/tree_updater.h +++ b/include/xgboost/tree_updater.h @@ -13,14 +13,13 @@ #include #include #include +#include #include #include #include #include -#include "../../src/common/host_device_vector.h" - namespace xgboost { /*! * \brief interface of tree update module, that performs update of a tree. diff --git a/src/common/bitfield.h b/src/common/bitfield.h index 3f951eed1..a4a109148 100644 --- a/src/common/bitfield.h +++ b/src/common/bitfield.h @@ -13,7 +13,12 @@ #include #include -#include "span.h" +#if defined(__CUDACC__) +#include +#include +#endif // defined(__CUDACC__) + +#include "xgboost/span.h" namespace xgboost { diff --git a/src/common/device_helpers.cuh b/src/common/device_helpers.cuh index df1d86abe..e3773ae2a 100644 --- a/src/common/device_helpers.cuh +++ b/src/common/device_helpers.cuh @@ -11,8 +11,10 @@ #include #include +#include "xgboost/host_device_vector.h" +#include "xgboost/span.h" + #include "common.h" -#include "span.h" #include #include @@ -1132,6 +1134,27 @@ xgboost::common::Span ToSpan(thrust::device_vector& vec, return ToSpan(vec, static_cast(offset), static_cast(size)); } +// thrust begin, similiar to std::begin +template +thrust::device_ptr tbegin(xgboost::HostDeviceVector& vector) { // NOLINT + return thrust::device_ptr(vector.DevicePointer()); +} + +template +thrust::device_ptr tend(xgboost::HostDeviceVector& vector) { // // NOLINT + return tbegin(vector) + vector.Size(); +} + +template +thrust::device_ptr tcbegin(xgboost::HostDeviceVector const& vector) { + return thrust::device_ptr(vector.ConstDevicePointer()); +} + +template +thrust::device_ptr tcend(xgboost::HostDeviceVector const& vector) { + return tcbegin(vector) + vector.Size(); +} + template class LauncherItr { public: diff --git a/src/common/hist_util.cc b/src/common/hist_util.cc index 678bee018..9db5f33de 100644 --- a/src/common/hist_util.cc +++ b/src/common/hist_util.cc @@ -8,6 +8,8 @@ #include #include #include + +#include "../common/common.h" #include "./random.h" #include "./column_matrix.h" #include "./quantile.h" diff --git a/src/common/hist_util.cu b/src/common/hist_util.cu index eb2f0ca4a..a10e1f7aa 100644 --- a/src/common/hist_util.cu +++ b/src/common/hist_util.cu @@ -2,7 +2,6 @@ * Copyright 2018 XGBoost contributors */ -#include "./hist_util.h" #include #include @@ -17,10 +16,11 @@ #include #include +#include "hist_util.h" +#include "xgboost/host_device_vector.h" +#include "device_helpers.cuh" +#include "quantile.h" #include "../tree/param.h" -#include "./host_device_vector.h" -#include "./device_helpers.cuh" -#include "./quantile.h" namespace xgboost { namespace common { diff --git a/src/common/host_device_vector.cc b/src/common/host_device_vector.cc index 8955dac54..1e03064ec 100644 --- a/src/common/host_device_vector.cc +++ b/src/common/host_device_vector.cc @@ -9,7 +9,7 @@ #include #include #include -#include "./host_device_vector.h" +#include "xgboost/host_device_vector.h" namespace xgboost { diff --git a/src/common/host_device_vector.cu b/src/common/host_device_vector.cu index 4cbe05da3..7f8f9e6b3 100644 --- a/src/common/host_device_vector.cu +++ b/src/common/host_device_vector.cu @@ -2,13 +2,16 @@ * Copyright 2017 XGBoost contributors */ -#include "./host_device_vector.h" #include -#include +#include + #include #include #include -#include "./device_helpers.cuh" + +#include "xgboost/data.h" +#include "xgboost/host_device_vector.h" +#include "device_helpers.cuh" namespace xgboost { @@ -75,22 +78,6 @@ class HostDeviceVectorImpl { return {data_d_.data().get(), static_cast(Size())}; } - thrust::device_ptr tbegin() { // NOLINT - return thrust::device_ptr(DevicePointer()); - } - - thrust::device_ptr tcbegin() { // NOLINT - return thrust::device_ptr(ConstDevicePointer()); - } - - thrust::device_ptr tend() { // NOLINT - return tbegin() + Size(); - } - - thrust::device_ptr tcend() { // NOLINT - return tcbegin() + Size(); - } - void Fill(T v) { // NOLINT if (HostCanWrite()) { std::fill(data_h_.begin(), data_h_.end(), v); @@ -304,26 +291,6 @@ common::Span HostDeviceVector::ConstDeviceSpan() const { return impl_->ConstDeviceSpan(); } -template -thrust::device_ptr HostDeviceVector::tbegin() { // NOLINT - return impl_->tbegin(); -} - -template -thrust::device_ptr HostDeviceVector::tcbegin() const { // NOLINT - return impl_->tcbegin(); -} - -template -thrust::device_ptr HostDeviceVector::tend() { // NOLINT - return impl_->tend(); -} - -template -thrust::device_ptr HostDeviceVector::tcend() const { // NOLINT - return impl_->tcend(); -} - template void HostDeviceVector::Fill(T v) { impl_->Fill(v); diff --git a/src/common/random.h b/src/common/random.h index 56c6a2b7e..a4749f2ae 100644 --- a/src/common/random.h +++ b/src/common/random.h @@ -17,8 +17,8 @@ #include #include +#include "xgboost/host_device_vector.h" #include "io.h" -#include "host_device_vector.h" namespace xgboost { namespace common { @@ -113,7 +113,7 @@ class ColumnSampler { } public: - /** + /** * \brief Column sampler constructor. * \note This constructor manually sets the rng seed */ @@ -169,7 +169,7 @@ class ColumnSampler { /** * \brief Samples a feature set. - * + * * \param depth The tree depth of the node at which to sample. * \return The sampled feature set. * \note If colsample_bynode_ < 1.0, this method creates a new feature set each time it diff --git a/src/common/transform.h b/src/common/transform.h index 205dbf575..09888338a 100644 --- a/src/common/transform.h +++ b/src/common/transform.h @@ -10,9 +10,10 @@ #include #include // enable_if -#include "host_device_vector.h" +#include "xgboost/host_device_vector.h" +#include "xgboost/span.h" + #include "common.h" -#include "span.h" #if defined (__CUDACC__) #include "device_helpers.cuh" diff --git a/src/data/columnar.h b/src/data/columnar.h index ca21f64d2..18c23b350 100644 --- a/src/data/columnar.h +++ b/src/data/columnar.h @@ -13,7 +13,8 @@ #include "xgboost/data.h" #include "xgboost/json.h" #include "xgboost/logging.h" -#include "../common/span.h" +#include "xgboost/span.h" + #include "../common/bitfield.h" namespace xgboost { diff --git a/src/data/data.cc b/src/data/data.cc index d7d58d58c..9f3088531 100644 --- a/src/data/data.cc +++ b/src/data/data.cc @@ -11,6 +11,7 @@ #include "./simple_dmatrix.h" #include "./simple_csr_source.h" #include "../common/io.h" +#include "../common/group_data.h" #if DMLC_ENABLE_STD_THREAD #include "./sparse_page_source.h" @@ -322,7 +323,35 @@ data::SparsePageFormat::DecideFormat(const std::string& cache_prefix) { return std::make_pair(raw, raw); } } - +SparsePage SparsePage::GetTranspose(int num_columns) const { + SparsePage transpose; + common::ParallelGroupBuilder builder(&transpose.offset.HostVector(), + &transpose.data.HostVector()); + const int nthread = omp_get_max_threads(); + builder.InitBudget(num_columns, nthread); + long batch_size = static_cast(this->Size()); // NOLINT(*) +#pragma omp parallel for default(none) shared(batch_size, builder) schedule(static) + for (long i = 0; i < batch_size; ++i) { // NOLINT(*) + int tid = omp_get_thread_num(); + auto inst = (*this)[i]; + for (const auto& entry : inst) { + builder.AddBudget(entry.index, tid); + } + } + builder.InitStorage(); +#pragma omp parallel for default(none) shared(batch_size, builder) schedule(static) + for (long i = 0; i < batch_size; ++i) { // NOLINT(*) + int tid = omp_get_thread_num(); + auto inst = (*this)[i]; + for (const auto& entry : inst) { + builder.Push( + entry.index, + Entry(static_cast(this->base_rowid + i), entry.fvalue), + tid); + } + } + return transpose; +} void SparsePage::Push(const SparsePage &batch) { auto& data_vec = data.HostVector(); auto& offset_vec = offset.HostVector(); diff --git a/src/data/sparse_page_source.h b/src/data/sparse_page_source.h index a6f15173b..5112972bf 100644 --- a/src/data/sparse_page_source.h +++ b/src/data/sparse_page_source.h @@ -21,6 +21,7 @@ #include #include "sparse_page_writer.h" +#include "../common/common.h" namespace { diff --git a/src/gbm/gblinear.cc b/src/gbm/gblinear.cc index c1bf9cc6b..cb05954cc 100644 --- a/src/gbm/gblinear.cc +++ b/src/gbm/gblinear.cc @@ -10,10 +10,13 @@ #include #include #include + #include #include #include #include + +#include "gblinear_model.h" #include "../common/timer.h" namespace xgboost { diff --git a/src/gbm/gbtree.cc b/src/gbm/gbtree.cc index 7a399aed2..26dff9fdb 100644 --- a/src/gbm/gbtree.cc +++ b/src/gbm/gbtree.cc @@ -6,11 +6,6 @@ */ #include #include -#include -#include -#include -#include -#include #include #include @@ -19,11 +14,16 @@ #include #include -#include "../common/common.h" -#include "../common/host_device_vector.h" -#include "../common/random.h" +#include "xgboost/logging.h" +#include "xgboost/gbm.h" +#include "xgboost/predictor.h" +#include "xgboost/tree_updater.h" +#include "xgboost/host_device_vector.h" + #include "gbtree.h" #include "gbtree_model.h" +#include "../common/common.h" +#include "../common/random.h" #include "../common/timer.h" diff --git a/src/gbm/gbtree.h b/src/gbm/gbtree.h index 9d65c7681..42a744068 100644 --- a/src/gbm/gbtree.h +++ b/src/gbm/gbtree.h @@ -23,8 +23,9 @@ #include #include "gbtree_model.h" +#include "xgboost/host_device_vector.h" + #include "../common/common.h" -#include "../common/host_device_vector.h" #include "../common/timer.h" namespace xgboost { diff --git a/src/learner.cc b/src/learner.cc index b4484ca05..c43ae744b 100644 --- a/src/learner.cc +++ b/src/learner.cc @@ -19,11 +19,12 @@ #include #include #include -#include "./common/common.h" -#include "./common/host_device_vector.h" -#include "./common/io.h" -#include "./common/random.h" -#include "./common/timer.h" + +#include "xgboost/host_device_vector.h" +#include "common/common.h" +#include "common/io.h" +#include "common/random.h" +#include "common/timer.h" namespace { diff --git a/src/linear/updater_gpu_coordinate.cu b/src/linear/updater_gpu_coordinate.cu index a249a8538..fe4193331 100644 --- a/src/linear/updater_gpu_coordinate.cu +++ b/src/linear/updater_gpu_coordinate.cu @@ -7,12 +7,13 @@ #include #include #include +#include "xgboost/span.h" + +#include "coordinate_common.h" #include "../common/common.h" -#include "../common/span.h" #include "../common/device_helpers.cuh" #include "../common/timer.h" #include "./param.h" -#include "coordinate_common.h" namespace xgboost { namespace linear { diff --git a/src/metric/rank_metric.cc b/src/metric/rank_metric.cc index c8c7edd82..a6b276b40 100644 --- a/src/metric/rank_metric.cc +++ b/src/metric/rank_metric.cc @@ -11,7 +11,7 @@ #include -#include "../common/host_device_vector.h" +#include "xgboost/host_device_vector.h" #include "../common/math.h" namespace { diff --git a/src/objective/hinge.cu b/src/objective/hinge.cu index 88a9b06f3..f770256d9 100644 --- a/src/objective/hinge.cu +++ b/src/objective/hinge.cu @@ -4,12 +4,13 @@ * \brief Provides an implementation of the hinge loss function * \author Henry Gouk */ -#include +#include "xgboost/objective.h" +#include "xgboost/span.h" +#include "xgboost/host_device_vector.h" + #include "../common/math.h" #include "../common/transform.h" #include "../common/common.h" -#include "../common/span.h" -#include "../common/host_device_vector.h" namespace xgboost { namespace obj { diff --git a/src/objective/objective.cc b/src/objective/objective.cc index 5eb51bf6e..52da83eab 100644 --- a/src/objective/objective.cc +++ b/src/objective/objective.cc @@ -6,7 +6,7 @@ #include #include -#include "../common/host_device_vector.h" +#include "xgboost/host_device_vector.h" namespace dmlc { DMLC_REGISTRY_ENABLE(::xgboost::ObjFunctionReg); diff --git a/src/objective/regression_obj.cu b/src/objective/regression_obj.cu index ea2c92566..373d31c87 100644 --- a/src/objective/regression_obj.cu +++ b/src/objective/regression_obj.cu @@ -12,10 +12,11 @@ #include #include -#include "../common/span.h" +#include "xgboost/span.h" +#include "xgboost/host_device_vector.h" + #include "../common/transform.h" #include "../common/common.h" -#include "../common/host_device_vector.h" #include "./regression_loss.h" diff --git a/src/predictor/cpu_predictor.cc b/src/predictor/cpu_predictor.cc index 28dd1d655..a20430b25 100644 --- a/src/predictor/cpu_predictor.cc +++ b/src/predictor/cpu_predictor.cc @@ -1,11 +1,13 @@ /*! * Copyright by Contributors 2017 */ -#include -#include -#include -#include "dmlc/logging.h" -#include "../common/host_device_vector.h" +#include "xgboost/predictor.h" +#include "xgboost/tree_model.h" +#include "xgboost/tree_updater.h" +#include "xgboost/logging.h" +#include "xgboost/host_device_vector.h" + +#include "../gbm/gbtree_model.h" namespace xgboost { namespace predictor { diff --git a/src/predictor/gpu_predictor.cu b/src/predictor/gpu_predictor.cu index 6a2fce52c..5ecb86db3 100644 --- a/src/predictor/gpu_predictor.cu +++ b/src/predictor/gpu_predictor.cu @@ -6,14 +6,17 @@ #include #include #include -#include -#include -#include -#include #include + +#include "xgboost/data.h" +#include "xgboost/predictor.h" +#include "xgboost/tree_model.h" +#include "xgboost/tree_updater.h" +#include "xgboost/host_device_vector.h" + +#include "../gbm/gbtree_model.h" #include "../common/common.h" #include "../common/device_helpers.cuh" -#include "../common/host_device_vector.h" namespace xgboost { namespace predictor { diff --git a/src/tree/constraints.cu b/src/tree/constraints.cu index dc553def3..20f800e35 100644 --- a/src/tree/constraints.cu +++ b/src/tree/constraints.cu @@ -6,17 +6,16 @@ #include #include -#include - #include #include #include #include #include +#include "xgboost/logging.h" +#include "xgboost/span.h" #include "constraints.cuh" #include "param.h" -#include "../common/span.h" #include "../common/device_helpers.cuh" diff --git a/src/tree/constraints.cuh b/src/tree/constraints.cuh index 956963a3d..2bb95d30c 100644 --- a/src/tree/constraints.cuh +++ b/src/tree/constraints.cuh @@ -12,7 +12,7 @@ #include #include "param.h" -#include "../common/span.h" +#include "xgboost/span.h" #include "../common/bitfield.h" #include "../common/device_helpers.cuh" diff --git a/src/tree/split_evaluator.cc b/src/tree/split_evaluator.cc index 7cf0756b3..acb9eb6f5 100644 --- a/src/tree/split_evaluator.cc +++ b/src/tree/split_evaluator.cc @@ -3,10 +3,8 @@ * \file split_evaluator.cc * \brief Contains implementations of different split evaluators. */ -#include "split_evaluator.h" #include #include -#include #include #include #include @@ -15,9 +13,12 @@ #include #include #include + +#include "xgboost/logging.h" +#include "xgboost/host_device_vector.h" #include "param.h" +#include "split_evaluator.h" #include "../common/common.h" -#include "../common/host_device_vector.h" namespace dmlc { DMLC_REGISTRY_ENABLE(::xgboost::tree::SplitEvaluatorReg); diff --git a/src/tree/tree_updater.cc b/src/tree/tree_updater.cc index 629306ffb..24ff2ab92 100644 --- a/src/tree/tree_updater.cc +++ b/src/tree/tree_updater.cc @@ -3,10 +3,10 @@ * \file tree_updater.cc * \brief Registry of tree updaters. */ -#include #include -#include "../common/host_device_vector.h" +#include "xgboost/tree_updater.h" +#include "xgboost/host_device_vector.h" namespace dmlc { DMLC_REGISTRY_ENABLE(::xgboost::TreeUpdaterReg); diff --git a/src/tree/updater_gpu_hist.cu b/src/tree/updater_gpu_hist.cu index e0c3e6209..7b22c4420 100644 --- a/src/tree/updater_gpu_hist.cu +++ b/src/tree/updater_gpu_hist.cu @@ -14,13 +14,15 @@ #include #include #include + +#include "xgboost/host_device_vector.h" +#include "xgboost/span.h" + #include "../common/common.h" #include "../common/compressed_iterator.h" #include "../common/device_helpers.cuh" #include "../common/hist_util.h" -#include "../common/host_device_vector.h" #include "../common/timer.h" -#include "../common/span.h" #include "../data/ellpack_page.cuh" #include "param.h" #include "updater_gpu_common.cuh" diff --git a/tests/cpp/common/test_host_device_vector.cu b/tests/cpp/common/test_host_device_vector.cu index 1869576d8..cb328dfdd 100644 --- a/tests/cpp/common/test_host_device_vector.cu +++ b/tests/cpp/common/test_host_device_vector.cu @@ -7,7 +7,7 @@ #include #include "../../../src/common/device_helpers.cuh" -#include "../../../src/common/host_device_vector.h" +#include namespace xgboost { namespace common { @@ -58,7 +58,7 @@ void InitHostDeviceVector(size_t n, int device, HostDeviceVector *v) { void PlusOne(HostDeviceVector *v) { int device = v->DeviceIdx(); SetDevice(device); - thrust::transform(v->tbegin(), v->tend(), v->tbegin(), + thrust::transform(dh::tcbegin(*v), dh::tcend(*v), dh::tbegin(*v), [=]__device__(unsigned int a){ return a + 1; }); } @@ -69,7 +69,7 @@ void CheckDevice(HostDeviceVector* v, ASSERT_EQ(v->Size(), size); SetDevice(v->DeviceIdx()); - ASSERT_TRUE(thrust::equal(v->tcbegin(), v->tcend(), + ASSERT_TRUE(thrust::equal(dh::tcbegin(*v), dh::tcend(*v), thrust::make_counting_iterator(first))); ASSERT_TRUE(v->DeviceCanRead()); // ensure that the device has at most the access specified by access @@ -77,7 +77,7 @@ void CheckDevice(HostDeviceVector* v, ASSERT_EQ(v->HostCanRead(), access == GPUAccess::kRead); ASSERT_FALSE(v->HostCanWrite()); - ASSERT_TRUE(thrust::equal(v->tbegin(), v->tend(), + ASSERT_TRUE(thrust::equal(dh::tbegin(*v), dh::tend(*v), thrust::make_counting_iterator(first))); ASSERT_TRUE(v->DeviceCanRead()); ASSERT_TRUE(v->DeviceCanWrite()); diff --git a/tests/cpp/common/test_span.cc b/tests/cpp/common/test_span.cc index d91bdb9b5..288cd1203 100644 --- a/tests/cpp/common/test_span.cc +++ b/tests/cpp/common/test_span.cc @@ -4,7 +4,7 @@ #include #include -#include "../../../src/common/span.h" +#include #include "test_span.h" namespace xgboost { diff --git a/tests/cpp/common/test_span.cu b/tests/cpp/common/test_span.cu index 04237497c..e7809b35a 100644 --- a/tests/cpp/common/test_span.cu +++ b/tests/cpp/common/test_span.cu @@ -8,7 +8,7 @@ #include #include "../../../src/common/device_helpers.cuh" -#include "../../../src/common/span.h" +#include #include "test_span.h" namespace xgboost { diff --git a/tests/cpp/common/test_span.h b/tests/cpp/common/test_span.h index bfefb6a91..96f4efa5b 100644 --- a/tests/cpp/common/test_span.h +++ b/tests/cpp/common/test_span.h @@ -4,8 +4,8 @@ #ifndef XGBOOST_TEST_SPAN_H_ #define XGBOOST_TEST_SPAN_H_ -#include "../../include/xgboost/base.h" -#include "../../../src/common/span.h" +#include +#include template XGBOOST_DEVICE void InitializeRange(Iter _begin, Iter _end) { diff --git a/tests/cpp/common/test_transform_range.cc b/tests/cpp/common/test_transform_range.cc index 4dee523ef..dbf6de3b3 100644 --- a/tests/cpp/common/test_transform_range.cc +++ b/tests/cpp/common/test_transform_range.cc @@ -1,10 +1,11 @@ -#include #include +#include +#include +#include + #include -#include "../../../src/common/host_device_vector.h" #include "../../../src/common/transform.h" -#include "../../../src/common/span.h" #include "../helpers.h" #if defined(__CUDACC__) diff --git a/tests/cpp/helpers.cc b/tests/cpp/helpers.cc index 16c4bdfca..3bd194fca 100644 --- a/tests/cpp/helpers.cc +++ b/tests/cpp/helpers.cc @@ -9,6 +9,7 @@ #include "xgboost/c_api.h" #include "../../src/data/simple_csr_source.h" +#include "../../src/gbm/gbtree_model.h" bool FileExists(const std::string& filename) { struct stat st; diff --git a/tests/cpp/linear/test_linear.cc b/tests/cpp/linear/test_linear.cc index 0a9c0178b..1f0ff6e2c 100644 --- a/tests/cpp/linear/test_linear.cc +++ b/tests/cpp/linear/test_linear.cc @@ -2,8 +2,11 @@ * Copyright 2018-2019 by Contributors */ #include +#include + #include "../helpers.h" -#include "xgboost/gbm.h" + +#include "../../../src/gbm/gblinear_model.h" TEST(Linear, shotgun) { auto mat = xgboost::CreateDMatrix(10, 10, 0); diff --git a/tests/cpp/linear/test_linear.cu b/tests/cpp/linear/test_linear.cu index b8f4c2722..4affce7f5 100644 --- a/tests/cpp/linear/test_linear.cu +++ b/tests/cpp/linear/test_linear.cu @@ -1,7 +1,9 @@ // Copyright by Contributors #include +#include + #include "../helpers.h" -#include "xgboost/gbm.h" +#include "../../../src/gbm/gblinear_model.h" namespace xgboost { diff --git a/tests/cpp/predictor/test_cpu_predictor.cc b/tests/cpp/predictor/test_cpu_predictor.cc index 32d323af3..2f22f2abd 100644 --- a/tests/cpp/predictor/test_cpu_predictor.cc +++ b/tests/cpp/predictor/test_cpu_predictor.cc @@ -2,7 +2,9 @@ #include #include #include + #include "../helpers.h" +#include "../../../src/gbm/gbtree_model.h" namespace xgboost { TEST(cpu_predictor, Test) { diff --git a/tests/cpp/predictor/test_gpu_predictor.cu b/tests/cpp/predictor/test_gpu_predictor.cu index 15ee3732c..487bad8ef 100644 --- a/tests/cpp/predictor/test_gpu_predictor.cu +++ b/tests/cpp/predictor/test_gpu_predictor.cu @@ -11,6 +11,7 @@ #include #include "gtest/gtest.h" #include "../helpers.h" +#include "../../../src/gbm/gbtree_model.h" namespace { diff --git a/tests/cpp/tree/test_prune.cc b/tests/cpp/tree/test_prune.cc index ba1d15d29..57fe002ba 100644 --- a/tests/cpp/tree/test_prune.cc +++ b/tests/cpp/tree/test_prune.cc @@ -2,7 +2,7 @@ * Copyright 2018-2019 by Contributors */ #include "../helpers.h" -#include "../../../src/common/host_device_vector.h" +#include #include #include #include diff --git a/tests/cpp/tree/test_quantile_hist.cc b/tests/cpp/tree/test_quantile_hist.cc index 1305e6593..0a999953b 100644 --- a/tests/cpp/tree/test_quantile_hist.cc +++ b/tests/cpp/tree/test_quantile_hist.cc @@ -1,12 +1,7 @@ /*! * Copyright 2018-2019 by Contributors */ -#include "../helpers.h" -#include "../../../src/tree/param.h" -#include "../../../src/tree/updater_quantile_hist.h" -#include "../../../src/tree/split_evaluator.h" -#include "../../../src/common/host_device_vector.h" - +#include #include #include @@ -14,6 +9,11 @@ #include #include +#include "../helpers.h" +#include "../../../src/tree/param.h" +#include "../../../src/tree/updater_quantile_hist.h" +#include "../../../src/tree/split_evaluator.h" + namespace xgboost { namespace tree { diff --git a/tests/cpp/tree/test_refresh.cc b/tests/cpp/tree/test_refresh.cc index 7d1f0d9e5..38474f857 100644 --- a/tests/cpp/tree/test_refresh.cc +++ b/tests/cpp/tree/test_refresh.cc @@ -1,14 +1,16 @@ /*! * Copyright 2018-2019 by Contributors */ -#include "../helpers.h" -#include "../../../src/common/host_device_vector.h" +#include #include #include + #include #include #include +#include "../helpers.h" + namespace xgboost { namespace tree {