diff --git a/include/xgboost/gbm.h b/include/xgboost/gbm.h index d00f9ceaf..07758a524 100644 --- a/include/xgboost/gbm.h +++ b/include/xgboost/gbm.h @@ -9,7 +9,6 @@ #define XGBOOST_GBM_H_ #include -#include #include #include #include diff --git a/plugin/updater_oneapi/predictor_oneapi.cc b/plugin/updater_oneapi/predictor_oneapi.cc index eafe83e19..59b170b28 100755 --- a/plugin/updater_oneapi/predictor_oneapi.cc +++ b/plugin/updater_oneapi/predictor_oneapi.cc @@ -1,23 +1,22 @@ /*! * Copyright by Contributors 2017-2020 */ +#include // for any #include #include #include +#include "../../src/common/math.h" +#include "../../src/data/adapter.h" +#include "../../src/gbm/gbtree_model.h" +#include "CL/sycl.hpp" #include "xgboost/base.h" #include "xgboost/data.h" +#include "xgboost/host_device_vector.h" +#include "xgboost/logging.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 "../../src/data/adapter.h" -#include "../../src/common/math.h" -#include "../../src/gbm/gbtree_model.h" - -#include "CL/sycl.hpp" namespace xgboost { namespace predictor { @@ -200,7 +199,7 @@ class DeviceModelOneAPI { tree_beg_ = tree_begin; tree_end_ = tree_end; - num_group = model.learner_model_param->num_output_group; + num_group = model.learner_model_param->num_output_group; } }; @@ -396,9 +395,9 @@ class PredictorOneAPI : public Predictor { out_preds->Size() == dmat->Info().num_row_); } - void InplacePredict(dmlc::any const &x, const gbm::GBTreeModel &model, - float missing, PredictionCacheEntry *out_preds, - uint32_t tree_begin, unsigned tree_end) const override { + void InplacePredict(std::any const& x, const gbm::GBTreeModel& model, float missing, + PredictionCacheEntry* out_preds, uint32_t tree_begin, + unsigned tree_end) const override { cpu_predictor->InplacePredict(x, model, missing, out_preds, tree_begin, tree_end); } diff --git a/src/data/proxy_dmatrix.cuh b/src/data/proxy_dmatrix.cuh index 38cbffe50..6ea858e7e 100644 --- a/src/data/proxy_dmatrix.cuh +++ b/src/data/proxy_dmatrix.cuh @@ -1,27 +1,24 @@ -/*! - * Copyright 2021 XGBoost contributors +/** + * Copyright 2021-2023 XGBoost contributors */ +#include // for any, any_cast + #include "device_adapter.cuh" #include "proxy_dmatrix.h" -namespace xgboost { -namespace data { +namespace xgboost::data { template decltype(auto) Dispatch(DMatrixProxy const* proxy, Fn fn) { if (proxy->Adapter().type() == typeid(std::shared_ptr)) { - auto value = dmlc::get>( - proxy->Adapter())->Value(); + auto value = std::any_cast>(proxy->Adapter())->Value(); return fn(value); } else if (proxy->Adapter().type() == typeid(std::shared_ptr)) { - auto value = dmlc::get>( - proxy->Adapter())->Value(); + auto value = std::any_cast>(proxy->Adapter())->Value(); return fn(value); } else { LOG(FATAL) << "Unknown type: " << proxy->Adapter().type().name(); - auto value = dmlc::get>( - proxy->Adapter())->Value(); + auto value = std::any_cast>(proxy->Adapter())->Value(); return fn(value); } } -} // namespace data -} // namespace xgboost +} // namespace xgboost::data diff --git a/src/data/proxy_dmatrix.h b/src/data/proxy_dmatrix.h index fa55a481f..7a15d6498 100644 --- a/src/data/proxy_dmatrix.h +++ b/src/data/proxy_dmatrix.h @@ -1,11 +1,10 @@ -/*! - * Copyright 2020-2022, XGBoost contributors +/** + * Copyright 2020-2023, XGBoost contributors */ #ifndef XGBOOST_DATA_PROXY_DMATRIX_H_ #define XGBOOST_DATA_PROXY_DMATRIX_H_ -#include - +#include // for any, any_cast #include #include #include @@ -15,8 +14,7 @@ #include "xgboost/context.h" #include "xgboost/data.h" -namespace xgboost { -namespace data { +namespace xgboost::data { /* * \brief A proxy to external iterator. */ @@ -44,7 +42,7 @@ class DataIterProxy { */ class DMatrixProxy : public DMatrix { MetaInfo info_; - dmlc::any batch_; + std::any batch_; Context ctx_; #if defined(XGBOOST_USE_CUDA) @@ -115,9 +113,7 @@ class DMatrixProxy : public DMatrix { LOG(FATAL) << "Not implemented."; return BatchSet(BatchIterator(nullptr)); } - dmlc::any Adapter() const { - return batch_; - } + std::any Adapter() const { return batch_; } }; inline DMatrixProxy* MakeProxy(DMatrixHandle proxy) { @@ -131,15 +127,13 @@ inline DMatrixProxy* MakeProxy(DMatrixHandle proxy) { template decltype(auto) HostAdapterDispatch(DMatrixProxy const* proxy, Fn fn, bool* type_error = nullptr) { if (proxy->Adapter().type() == typeid(std::shared_ptr)) { - auto value = - dmlc::get>(proxy->Adapter())->Value(); + auto value = std::any_cast>(proxy->Adapter())->Value(); if (type_error) { *type_error = false; } return fn(value); } else if (proxy->Adapter().type() == typeid(std::shared_ptr)) { - auto value = dmlc::get>( - proxy->Adapter())->Value(); + auto value = std::any_cast>(proxy->Adapter())->Value(); if (type_error) { *type_error = false; } @@ -154,6 +148,5 @@ decltype(auto) HostAdapterDispatch(DMatrixProxy const* proxy, Fn fn, bool* type_ decltype(std::declval>()->Value()))>(); } } -} // namespace data -} // namespace xgboost +} // namespace xgboost::data #endif // XGBOOST_DATA_PROXY_DMATRIX_H_ diff --git a/src/predictor/cpu_predictor.cc b/src/predictor/cpu_predictor.cc index 288dc5fb0..4473173d2 100644 --- a/src/predictor/cpu_predictor.cc +++ b/src/predictor/cpu_predictor.cc @@ -1,9 +1,9 @@ /** * Copyright 2017-2023 by XGBoost Contributors */ -#include #include +#include // for any, any_cast #include #include #include @@ -637,12 +637,12 @@ class CPUPredictor : public Predictor { } template - void DispatchedInplacePredict(dmlc::any const &x, std::shared_ptr p_m, + void DispatchedInplacePredict(std::any const &x, std::shared_ptr p_m, const gbm::GBTreeModel &model, float missing, - PredictionCacheEntry *out_preds, - uint32_t tree_begin, uint32_t tree_end) const { + PredictionCacheEntry *out_preds, uint32_t tree_begin, + uint32_t tree_end) const { auto const n_threads = this->ctx_->Threads(); - auto m = dmlc::get>(x); + auto m = std::any_cast>(x); CHECK_EQ(m->NumColumns(), model.learner_model_param->num_feature) << "Number of columns in data must equal to trained model."; if (p_m) { diff --git a/src/predictor/gpu_predictor.cu b/src/predictor/gpu_predictor.cu index caf4b6bb4..ecd399e22 100644 --- a/src/predictor/gpu_predictor.cu +++ b/src/predictor/gpu_predictor.cu @@ -8,6 +8,7 @@ #include #include +#include // for any, any_cast #include #include "../common/bitfield.h" @@ -741,13 +742,13 @@ class GPUPredictor : public xgboost::Predictor { } template - void DispatchedInplacePredict(dmlc::any const &x, std::shared_ptr p_m, - const gbm::GBTreeModel &model, float missing, - PredictionCacheEntry *out_preds, - uint32_t tree_begin, uint32_t tree_end) const { + void DispatchedInplacePredict(std::any const& x, std::shared_ptr p_m, + const gbm::GBTreeModel& model, float missing, + PredictionCacheEntry* out_preds, uint32_t tree_begin, + uint32_t tree_end) const { uint32_t const output_groups = model.learner_model_param->num_output_group; - auto m = dmlc::get>(x); + auto m = std::any_cast>(x); CHECK_EQ(m->NumColumns(), model.learner_model_param->num_feature) << "Number of columns in data must equal to trained model."; CHECK_EQ(dh::CurrentDevice(), m->DeviceIdx()) diff --git a/tests/cpp/data/test_file_iterator.cc b/tests/cpp/data/test_file_iterator.cc index 21029620b..31da2c1fa 100644 --- a/tests/cpp/data/test_file_iterator.cc +++ b/tests/cpp/data/test_file_iterator.cc @@ -1,8 +1,9 @@ -/*! - * Copyright 2021 XGBoost contributors +/** + * Copyright 2021-2023 XGBoost contributors */ #include +#include // for any_cast #include #include "../../../src/data/adapter.h" @@ -11,15 +12,14 @@ #include "../filesystem.h" // dmlc::TemporaryDirectory #include "../helpers.h" -namespace xgboost { -namespace data { +namespace xgboost::data { TEST(FileIterator, Basic) { auto check_n_features = [](FileIterator *iter) { size_t n_features = 0; iter->Reset(); while (iter->Next()) { auto proxy = MakeProxy(iter->Proxy()); - auto csr = dmlc::get>(proxy->Adapter()); + auto csr = std::any_cast>(proxy->Adapter()); n_features = std::max(n_features, csr->NumColumns()); } ASSERT_EQ(n_features, 5); @@ -42,5 +42,4 @@ TEST(FileIterator, Basic) { check_n_features(&iter); } } -} // namespace data -} // namespace xgboost +} // namespace xgboost::data diff --git a/tests/cpp/data/test_proxy_dmatrix.cu b/tests/cpp/data/test_proxy_dmatrix.cu index a599ada6d..ab38f51bb 100644 --- a/tests/cpp/data/test_proxy_dmatrix.cu +++ b/tests/cpp/data/test_proxy_dmatrix.cu @@ -1,22 +1,24 @@ +/** + * Copyright 2020-2023 XGBoost contributors + */ #include #include + +#include // for any_cast #include -#include "../helpers.h" + #include "../../../src/data/device_adapter.cuh" #include "../../../src/data/proxy_dmatrix.h" +#include "../helpers.h" -namespace xgboost { -namespace data { +namespace xgboost::data { TEST(ProxyDMatrix, DeviceData) { constexpr size_t kRows{100}, kCols{100}; HostDeviceVector storage; - auto data = RandomDataGenerator(kRows, kCols, 0.5) - .Device(0) - .GenerateArrayInterface(&storage); + auto data = RandomDataGenerator(kRows, kCols, 0.5).Device(0).GenerateArrayInterface(&storage); std::vector> label_storage(1); - auto labels = RandomDataGenerator(kRows, 1, 0) - .Device(0) - .GenerateColumnarArrayInterface(&label_storage); + auto labels = + RandomDataGenerator(kRows, 1, 0).Device(0).GenerateColumnarArrayInterface(&label_storage); DMatrixProxy proxy; proxy.SetCUDAArray(data.c_str()); @@ -24,23 +26,16 @@ TEST(ProxyDMatrix, DeviceData) { ASSERT_EQ(proxy.Adapter().type(), typeid(std::shared_ptr)); ASSERT_EQ(proxy.Info().labels.Size(), kRows); - ASSERT_EQ(dmlc::get>(proxy.Adapter())->NumRows(), - kRows); - ASSERT_EQ( - dmlc::get>(proxy.Adapter())->NumColumns(), - kCols); + ASSERT_EQ(std::any_cast>(proxy.Adapter())->NumRows(), kRows); + ASSERT_EQ(std::any_cast>(proxy.Adapter())->NumColumns(), kCols); std::vector> columnar_storage(kCols); data = RandomDataGenerator(kRows, kCols, 0) - .Device(0) - .GenerateColumnarArrayInterface(&columnar_storage); + .Device(0) + .GenerateColumnarArrayInterface(&columnar_storage); proxy.SetCUDAArray(data.c_str()); ASSERT_EQ(proxy.Adapter().type(), typeid(std::shared_ptr)); - ASSERT_EQ(dmlc::get>(proxy.Adapter())->NumRows(), - kRows); - ASSERT_EQ( - dmlc::get>(proxy.Adapter())->NumColumns(), - kCols); + ASSERT_EQ(std::any_cast>(proxy.Adapter())->NumRows(), kRows); + ASSERT_EQ(std::any_cast>(proxy.Adapter())->NumColumns(), kCols); } -} // namespace data -} // namespace xgboost +} // namespace xgboost::data