From 142a208a90357758216b436686a6dd0f77409eec Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Wed, 22 Jun 2022 21:29:10 +0800 Subject: [PATCH] Fix compiler warnings. (#8022) - Remove/fix unused parameters - Remove deprecated code in rabit. - Update dmlc-core. --- cmake/Utils.cmake | 4 +- dmlc-core | 2 +- include/xgboost/gbm.h | 8 --- include/xgboost/learner.h | 4 -- plugin/example/custom_obj.cc | 6 +- rabit/include/rabit/c_api.h | 32 --------- rabit/include/rabit/internal/engine.h | 63 ++-------------- rabit/include/rabit/internal/rabit-inl.h | 27 +++---- rabit/include/rabit/internal/socket.h | 2 +- rabit/include/rabit/rabit.h | 65 ++--------------- rabit/src/allreduce_base.h | 71 ++----------------- rabit/src/allreduce_mock.h | 49 ++----------- rabit/src/engine.cc | 3 +- rabit/src/rabit_c_api.cc | 41 +---------- src/c_api/c_api.cc | 10 +-- src/cli_main.cc | 14 +--- src/common/device_helpers.cu | 9 ++- src/common/json.cc | 6 +- src/common/quantile.cu | 28 +++----- src/data/data.cc | 3 +- src/data/device_adapter.cuh | 1 + src/data/ellpack_page.cu | 19 +++-- src/data/ellpack_page.cuh | 8 +-- src/data/iterative_device_dmatrix.cu | 14 ++-- src/data/iterative_device_dmatrix.h | 12 ++-- src/data/simple_dmatrix.cu | 2 +- src/gbm/gblinear.cc | 21 +++--- src/gbm/gblinear_model.h | 5 +- src/gbm/gbtree.h | 4 -- src/learner.cc | 5 -- src/linear/updater_gpu_coordinate.cu | 15 ++-- src/metric/auc.cu | 8 +-- src/metric/elementwise_metric.cu | 34 ++++----- src/metric/multiclass_metric.cu | 12 ++-- src/metric/survival_metric.cu | 17 ++--- src/objective/adaptive.cu | 16 ++--- src/objective/aft_obj.cu | 6 +- src/objective/hinge.cu | 6 +- src/objective/regression_obj.cu | 8 ++- src/predictor/cpu_predictor.cc | 12 ++-- src/tree/gpu_hist/feature_groups.cu | 2 +- src/tree/gpu_hist/histogram.cu | 2 +- src/tree/gpu_hist/row_partitioner.cu | 3 +- src/tree/hist/histogram.h | 12 ++-- src/tree/param.cc | 6 +- src/tree/tree_model.cc | 16 ++--- src/tree/updater_colmaker.cc | 2 +- src/tree/updater_refresh.cc | 2 +- src/tree/updater_sync.cc | 2 +- tests/cpp/common/test_hist_util.cc | 22 +++--- tests/cpp/common/test_hist_util.cu | 22 +++--- tests/cpp/common/test_hist_util.h | 11 ++- tests/cpp/common/test_quantile.cu | 3 +- tests/cpp/common/test_span.h | 2 +- tests/cpp/common/test_threading_utils.cc | 5 +- tests/cpp/helpers.cc | 2 +- tests/cpp/predictor/test_gpu_predictor.cu | 4 +- tests/cpp/predictor/test_predictor.cc | 13 ++-- tests/cpp/tree/gpu_hist/test_histogram.cu | 1 - .../cpp/tree/gpu_hist/test_row_partitioner.cu | 2 +- tests/cpp/tree/hist/test_histogram.cc | 3 +- 61 files changed, 230 insertions(+), 579 deletions(-) diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake index cbc11feb4..a38ed955f 100644 --- a/cmake/Utils.cmake +++ b/cmake/Utils.cmake @@ -228,7 +228,9 @@ macro(xgboost_target_properties target) if (ENABLE_ALL_WARNINGS) target_compile_options(${target} PUBLIC - $,-Xcompiler=-Wall -Xcompiler=-Wextra,-Wall -Wextra> + $, + -Xcompiler=-Wall -Xcompiler=-Wextra -Xcompiler=-Wno-expansion-to-defined, + -Wall -Wextra -Wno-expansion-to-defined> ) endif(ENABLE_ALL_WARNINGS) diff --git a/dmlc-core b/dmlc-core index 97e9afa32..dfd936526 160000 --- a/dmlc-core +++ b/dmlc-core @@ -1 +1 @@ -Subproject commit 97e9afa320731763c12e4e80182725465a572600 +Subproject commit dfd9365264a060a5096734b7d892e1858b6d2722 diff --git a/include/xgboost/gbm.h b/include/xgboost/gbm.h index 1d95a8c82..9951f7778 100644 --- a/include/xgboost/gbm.h +++ b/include/xgboost/gbm.h @@ -72,14 +72,6 @@ class GradientBooster : public Model, public Configurable { GradientBooster* /*out*/, bool* /*out_of_bound*/) const { LOG(FATAL) << "Slice is not supported by current booster."; } - /*! - * \brief whether the model allow lazy checkpoint - * return true if model is only updated in DoBoost - * after all Allreduce calls - */ - virtual bool AllowLazyCheckPoint() const { - return false; - } /*! \brief Return number of boosted rounds. */ virtual int32_t BoostedRounds() const = 0; diff --git a/include/xgboost/learner.h b/include/xgboost/learner.h index b16ea67ec..51fefac13 100644 --- a/include/xgboost/learner.h +++ b/include/xgboost/learner.h @@ -241,10 +241,6 @@ class Learner : public Model, public Configurable, public dmlc::Serializable { */ virtual void GetFeatureTypes(std::vector* ft) const = 0; - /*! - * \return whether the model allow lazy checkpoint in rabit. - */ - bool AllowLazyCheckPoint() const; /*! * \brief Slice the model. * diff --git a/plugin/example/custom_obj.cc b/plugin/example/custom_obj.cc index e220e4497..3f18330ce 100644 --- a/plugin/example/custom_obj.cc +++ b/plugin/example/custom_obj.cc @@ -35,10 +35,8 @@ class MyLogistic : public ObjFunction { ObjInfo Task() const override { return ObjInfo::kRegression; } - void GetGradient(const HostDeviceVector &preds, - const MetaInfo &info, - int iter, - HostDeviceVector *out_gpair) override { + void GetGradient(const HostDeviceVector& preds, const MetaInfo& info, int32_t /*iter*/, + HostDeviceVector* out_gpair) override { out_gpair->Resize(preds.Size()); const std::vector& preds_h = preds.HostVector(); std::vector& out_gpair_h = out_gpair->HostVector(); diff --git a/rabit/include/rabit/c_api.h b/rabit/include/rabit/c_api.h index 77d4b17fd..6c9e798be 100644 --- a/rabit/include/rabit/c_api.h +++ b/rabit/include/rabit/c_api.h @@ -135,38 +135,6 @@ RABIT_DLL int RabitAllreduce(void *sendrecvbuf, size_t count, int enum_dtype, int enum_op, void (*prepare_fun)(void *arg), void *prepare_arg); -/*! - * \brief load latest check point - * \param out_global_model hold output of serialized global_model - * \param out_global_len the output length of serialized global model - * \param out_local_model hold output of serialized local_model, can be NULL - * \param out_local_len the output length of serialized local model, can be NULL - * - * \return the version number of check point loaded - * if returned version == 0, this means no model has been CheckPointed - * nothing will be touched - */ -RABIT_DLL int RabitLoadCheckPoint(char **out_global_model, - rbt_ulong *out_global_len, - char **out_local_model, - rbt_ulong *out_local_len); -/*! - * \brief checkpoint the model, meaning we finished a stage of execution - * every time we call check point, there is a version number which will increase by one - * - * \param global_model hold content of serialized global_model - * \param global_len the content length of serialized global model - * \param local_model hold content of serialized local_model, can be NULL - * \param local_len the content length of serialized local model, can be NULL - * - * NOTE: local_model requires explicit replication of the model for fault-tolerance, which will - * bring replication cost in CheckPoint function. global_model do not need explicit replication. - * So only CheckPoint with global_model if possible - */ -RABIT_DLL void RabitCheckPoint(const char *global_model, - rbt_ulong global_len, - const char *local_model, - rbt_ulong local_len); /*! * \return version number of current stored model, * which means how many calls to CheckPoint we made so far diff --git a/rabit/include/rabit/internal/engine.h b/rabit/include/rabit/internal/engine.h index 84d92143a..4ebbf68db 100644 --- a/rabit/include/rabit/internal/engine.h +++ b/rabit/include/rabit/internal/engine.h @@ -87,68 +87,13 @@ class IEngine { */ virtual void Broadcast(void *sendrecvbuf_, size_t size, int root) = 0; /*! - * \brief loads the latest check point - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller needs to guarantee that the global_model - * is the same in all nodes - * \param local_model pointer to the local model that is specific to current node/rank - * this can be NULL when no local model is needed - * - * \return the version number of the model loaded - * if returned version == 0, this means no model has been CheckPointed - * the p_model is not touched, users should do necessary initialization by themselves - * - * Common usage example: - * int iter = rabit::LoadCheckPoint(&model); - * if (iter == 0) model.InitParameters(); - * for (i = iter; i < max_iter; ++i) { - * do many things, include allreduce - * rabit::CheckPoint(model); - * } - * - * \sa CheckPoint, VersionNumber + * deprecated */ - virtual int LoadCheckPoint(Serializable *global_model, - Serializable *local_model = nullptr) = 0; + virtual int LoadCheckPoint() = 0; /*! - * \brief checkpoints the model, meaning a stage of execution was finished - * every time we call check point, a version number increases by ones - * - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller needs to guarantee that the global_model - * is the same in every node - * \param local_model pointer to the local model that is specific to current node/rank - * this can be NULL when no local state is needed - * - * NOTE: local_model requires explicit replication of the model for fault-tolerance, which will - * bring replication cost in CheckPoint function. global_model does not need explicit replication. - * So, only CheckPoint with global_model if possible - * - * \sa LoadCheckPoint, VersionNumber + * \brief Increase internal version number. Deprecated. */ - virtual void CheckPoint(const Serializable *global_model, - const Serializable *local_model = nullptr) = 0; - /*! - * \brief This function can be used to replace CheckPoint for global_model only, - * when certain condition is met (see detailed explanation). - * - * This is a "lazy" checkpoint such that only the pointer to global_model is - * remembered and no memory copy is taken. To use this function, the user MUST ensure that: - * The global_model must remain unchanged until the last call of Allreduce/Broadcast in the current version finishes. - * In other words, global_model can be changed only between the last call of - * Allreduce/Broadcast and LazyCheckPoint in the current version - * - * For example, suppose the calling sequence is: - * LazyCheckPoint, code1, Allreduce, code2, Broadcast, code3, LazyCheckPoint - * - * If the user can only change global_model in code3, then LazyCheckPoint can be used to - * improve the efficiency of the program. - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller needs to guarantee that global_model - * is the same in every node - * \sa LoadCheckPoint, CheckPoint, VersionNumber - */ - virtual void LazyCheckPoint(const Serializable *global_model) = 0; + virtual void CheckPoint() = 0; /*! * \return version number of the current stored model, * which means how many calls to CheckPoint we made so far diff --git a/rabit/include/rabit/internal/rabit-inl.h b/rabit/include/rabit/internal/rabit-inl.h index 6ad296f79..1f4b2c0e2 100644 --- a/rabit/include/rabit/internal/rabit-inl.h +++ b/rabit/include/rabit/internal/rabit-inl.h @@ -92,10 +92,10 @@ struct BitOR { dst |= src; } }; -template -inline void Reducer(const void *src_, void *dst_, int len, const MPI::Datatype &dtype) { - const DType* src = static_cast(src_); - DType* dst = (DType*)dst_; // NOLINT(*) +template +inline void Reducer(const void *src_, void *dst_, int len, const MPI::Datatype &) { + const DType *src = static_cast(src_); + DType *dst = (DType *)dst_; // NOLINT(*) for (int i = 0; i < len; i++) { OP::Reduce(dst[i], src[i]); } @@ -207,20 +207,11 @@ inline void TrackerPrintf(const char *fmt, ...) { } #endif // RABIT_STRICT_CXX98_ -// load latest check point -inline int LoadCheckPoint(Serializable *global_model, - Serializable *local_model) { - return engine::GetEngine()->LoadCheckPoint(global_model, local_model); -} -// checkpoint the model, meaning we finished a stage of execution -inline void CheckPoint(const Serializable *global_model, - const Serializable *local_model) { - engine::GetEngine()->CheckPoint(global_model, local_model); -} -// lazy checkpoint the model, only remember the pointer to global_model -inline void LazyCheckPoint(const Serializable *global_model) { - engine::GetEngine()->LazyCheckPoint(global_model); -} + +// deprecated, planned for removal after checkpoing from JVM package is removed. +inline int LoadCheckPoint() { return engine::GetEngine()->LoadCheckPoint(); } +// deprecated, increase internal version number +inline void CheckPoint() { engine::GetEngine()->CheckPoint(); } // return the version number of currently stored model inline int VersionNumber() { return engine::GetEngine()->VersionNumber(); diff --git a/rabit/include/rabit/internal/socket.h b/rabit/include/rabit/internal/socket.h index bdd38fe8f..d42df39d7 100644 --- a/rabit/include/rabit/internal/socket.h +++ b/rabit/include/rabit/internal/socket.h @@ -397,7 +397,7 @@ class TCPSocket : public Socket{ */ inline void Create(int af = PF_INET) { #if !IS_MINGW() - sockfd = socket(PF_INET, SOCK_STREAM, 0); + sockfd = socket(af, SOCK_STREAM, 0); if (sockfd == kInvalidSocket) { Socket::Error("Create"); } diff --git a/rabit/include/rabit/rabit.h b/rabit/include/rabit/rabit.h index 3da8ca268..8284a4b6b 100644 --- a/rabit/include/rabit/rabit.h +++ b/rabit/include/rabit/rabit.h @@ -205,69 +205,16 @@ template inline void Allreduce(DType *sendrecvbuf, size_t count, std::function prepare_fun); #endif // C++11 + /*! - * \brief loads the latest check point - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller needs to guarantee that the global_model - * is the same in every node - * \param local_model pointer to the local model that is specific to the current node/rank - * this can be NULL when no local model is needed - * - * \return the version number of the check point loaded - * if returned version == 0, this means no model has been CheckPointed - * the p_model is not touched, users should do the necessary initialization by themselves - * - * \code{.cpp} - * // Example usage code of LoadCheckPoint - * int iter = rabit::LoadCheckPoint(&model); - * if (iter == 0) model.InitParameters(); - * for (i = iter; i < max_iter; ++i) { - * // do many things, include allreduce - * rabit::CheckPoint(model); - * } - * \endcode - * \sa CheckPoint, VersionNumber + * \brief deprecated, planned for removal after checkpoing from JVM package is removed. */ -inline int LoadCheckPoint(Serializable *global_model, - Serializable *local_model = nullptr); +inline int LoadCheckPoint(); /*! - * \brief checkpoints the model, meaning a stage of execution has finished. - * every time we call check point, a version number will be increased by one - * - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller needs to guarantee that the global_model - * is the same in every node - * \param local_model pointer to the local model that is specific to the current node/rank - * this can be NULL when no local state is needed - * NOTE: local_model requires explicit replication of the model for fault-tolerance, which will - * bring replication cost in the CheckPoint function. global_model does not need explicit replication. - * So, only CheckPoint with the global_model if possible - * \sa LoadCheckPoint, VersionNumber - */ -inline void CheckPoint(const Serializable *global_model, - const Serializable *local_model = nullptr); -/*! - * \brief This function can be used to replace CheckPoint for global_model only, - * when certain condition is met (see detailed explanation). - * - * This is a "lazy" checkpoint such that only the pointer to the global_model is - * remembered and no memory copy is taken. To use this function, the user MUST ensure that: - * The global_model must remain unchanged until the last call of Allreduce/Broadcast in the current version finishes. - * In other words, the global_model model can be changed only between the last call of - * Allreduce/Broadcast and LazyCheckPoint, both in the same version - * - * For example, suppose the calling sequence is: - * LazyCheckPoint, code1, Allreduce, code2, Broadcast, code3, LazyCheckPoint/(or can be CheckPoint) - * - * Then the user MUST only change the global_model in code3. - * - * The use of LazyCheckPoint instead of CheckPoint will improve the efficiency of the program. - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller needs to guarantee that the global_model - * is the same in every node - * \sa LoadCheckPoint, CheckPoint, VersionNumber + * \brief deprecated, planned for removal after checkpoing from JVM package is removed. */ -inline void LazyCheckPoint(const Serializable *global_model); +inline void CheckPoint(); + /*! * \return version number of the current stored model, * which means how many calls to CheckPoint we made so far diff --git a/rabit/src/allreduce_base.h b/rabit/src/allreduce_base.h index 14d2b7db8..0cd11c73f 100644 --- a/rabit/src/allreduce_base.h +++ b/rabit/src/allreduce_base.h @@ -144,74 +144,13 @@ class AllreduceBase : public IEngine { "Broadcast failed"); } /*! - * \brief load latest check point - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller need to guarantees that global_model - * is the same in all nodes - * \param local_model pointer to local model, that is specific to current node/rank - * this can be NULL when no local model is needed - * - * \return the version number of check point loaded - * if returned version == 0, this means no model has been CheckPointed - * the p_model is not touched, user should do necessary initialization by themselves - * - * Common usage example: - * int iter = rabit::LoadCheckPoint(&model); - * if (iter == 0) model.InitParameters(); - * for (i = iter; i < max_iter; ++i) { - * do many things, include allreduce - * rabit::CheckPoint(model); - * } - * + * \brief deprecated * \sa CheckPoint, VersionNumber */ - int LoadCheckPoint(Serializable *global_model, - Serializable *local_model = nullptr) override { - return 0; - } - /*! - * \brief checkpoint the model, meaning we finished a stage of execution - * every time we call check point, there is a version number which will increase by one - * - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller need to guarantees that global_model - * is the same in all nodes - * \param local_model pointer to local model, that is specific to current node/rank - * this can be NULL when no local state is needed - * - * NOTE: local_model requires explicit replication of the model for fault-tolerance, which will - * bring replication cost in CheckPoint function. global_model do not need explicit replication. - * So only CheckPoint with global_model if possible - * - * \sa LoadCheckPoint, VersionNumber - */ - void CheckPoint(const Serializable *global_model, - const Serializable *local_model = nullptr) override { - version_number += 1; - } - /*! - * \brief This function can be used to replace CheckPoint for global_model only, - * when certain condition is met(see detailed explanation). - * - * This is a "lazy" checkpoint such that only the pointer to global_model is - * remembered and no memory copy is taken. To use this function, the user MUST ensure that: - * The global_model must remain unchanged until the last call of Allreduce/Broadcast in current version finishes. - * In another words, global_model model can be changed only between last call of - * Allreduce/Broadcast and LazyCheckPoint in current version - * - * For example, suppose the calling sequence is: - * LazyCheckPoint, code1, Allreduce, code2, Broadcast, code3, LazyCheckPoint - * - * If user can only changes global_model in code3, then LazyCheckPoint can be used to - * improve efficiency of the program. - * \param global_model pointer to the globally shared model/state - * when calling this function, the caller need to guarantees that global_model - * is the same in all nodes - * \sa LoadCheckPoint, CheckPoint, VersionNumber - */ - void LazyCheckPoint(const Serializable *global_model) override { - version_number += 1; - } + int LoadCheckPoint() override { return 0; } + + // deprecated, increase internal version number + void CheckPoint() override { version_number += 1; } /*! * \return version number of current stored model, * which means how many calls to CheckPoint we made so far diff --git a/rabit/src/allreduce_mock.h b/rabit/src/allreduce_mock.h index a1ef01513..b24346586 100644 --- a/rabit/src/allreduce_mock.h +++ b/rabit/src/allreduce_mock.h @@ -65,31 +65,21 @@ class AllreduceMock : public AllreduceBase { this->Verify(MockKey(rank, version_number, seq_counter, num_trial_), "Broadcast"); AllreduceBase::Broadcast(sendrecvbuf_, total_size, root); } - int LoadCheckPoint(Serializable *global_model, - Serializable *local_model) override { + int LoadCheckPoint() override { tsum_allreduce_ = 0.0; tsum_allgather_ = 0.0; time_checkpoint_ = dmlc::GetTime(); if (force_local_ == 0) { - return AllreduceBase::LoadCheckPoint(global_model, local_model); + return AllreduceBase::LoadCheckPoint(); } else { - DummySerializer dum; - ComboSerializer com(global_model, local_model); - return AllreduceBase::LoadCheckPoint(&dum, &com); + return AllreduceBase::LoadCheckPoint(); } } - void CheckPoint(const Serializable *global_model, - const Serializable *local_model) override { + void CheckPoint() override { this->Verify(MockKey(rank, version_number, seq_counter, num_trial_), "CheckPoint"); double tstart = dmlc::GetTime(); double tbet_chkpt = tstart - time_checkpoint_; - if (force_local_ == 0) { - AllreduceBase::CheckPoint(global_model, local_model); - } else { - DummySerializer dum; - ComboSerializer com(global_model, local_model); - AllreduceBase::CheckPoint(&dum, &com); - } + AllreduceBase::CheckPoint(); time_checkpoint_ = dmlc::GetTime(); double tcost = dmlc::GetTime() - tstart; if (report_stats_ != 0 && rank == 0) { @@ -105,11 +95,6 @@ class AllreduceMock : public AllreduceBase { tsum_allgather_ = 0.0; } - void LazyCheckPoint(const Serializable *global_model) override { - this->Verify(MockKey(rank, version_number, seq_counter, num_trial_), "LazyCheckPoint"); - AllreduceBase::LazyCheckPoint(global_model); - } - protected: // force checkpoint to local int force_local_; @@ -122,30 +107,6 @@ class AllreduceMock : public AllreduceBase { double time_checkpoint_; private: - struct DummySerializer : public Serializable { - void Load(Stream *fi) override {} - void Save(Stream *fo) const override {} - }; - struct ComboSerializer : public Serializable { - Serializable *lhs; - Serializable *rhs; - const Serializable *c_lhs; - const Serializable *c_rhs; - ComboSerializer(Serializable *lhs, Serializable *rhs) - : lhs(lhs), rhs(rhs), c_lhs(lhs), c_rhs(rhs) { - } - ComboSerializer(const Serializable *lhs, const Serializable *rhs) - : lhs(nullptr), rhs(nullptr), c_lhs(lhs), c_rhs(rhs) { - } - void Load(Stream *fi) override { - if (lhs != nullptr) lhs->Load(fi); - if (rhs != nullptr) rhs->Load(fi); - } - void Save(Stream *fo) const override { - if (c_lhs != nullptr) c_lhs->Save(fo); - if (c_rhs != nullptr) c_rhs->Save(fo); - } - }; // key to identify the mock stage struct MockKey { int rank; diff --git a/rabit/src/engine.cc b/rabit/src/engine.cc index 5e325383c..89f25fa1e 100644 --- a/rabit/src/engine.cc +++ b/rabit/src/engine.cc @@ -100,8 +100,7 @@ void Allreduce_(void *sendrecvbuf, // NOLINT mpi::OpType , IEngine::PreprocFunction prepare_fun, void *prepare_arg) { - GetEngine()->Allreduce(sendrecvbuf, type_nbytes, count, red, prepare_fun, - prepare_arg); + GetEngine()->Allreduce(sendrecvbuf, type_nbytes, count, red, prepare_fun, prepare_arg); } } // namespace engine } // namespace rabit diff --git a/rabit/src/rabit_c_api.cc b/rabit/src/rabit_c_api.cc index 1caf1e406..63abcf83f 100644 --- a/rabit/src/rabit_c_api.cc +++ b/rabit/src/rabit_c_api.cc @@ -120,6 +120,7 @@ void Allreduce(void *sendrecvbuf, default: utils::Error("unknown enum_op"); } } + void Allgather(void *sendrecvbuf_, size_t total_size, size_t beginIndex, @@ -298,46 +299,6 @@ RABIT_DLL int RabitAllreduce(void *sendrecvbuf, size_t count, int enum_dtype, API_END() } -RABIT_DLL int RabitLoadCheckPoint(char **out_global_model, - rbt_ulong *out_global_len, - char **out_local_model, - rbt_ulong *out_local_len) { - // no-op as XGBoost 1.3 - using rabit::BeginPtr; - using namespace rabit::c_api; // NOLINT(*) - static std::string global_buffer; - static std::string local_buffer; - - ReadWrapper sg(&global_buffer); - ReadWrapper sl(&local_buffer); - int version; - - if (out_local_model == nullptr) { - version = rabit::LoadCheckPoint(&sg, nullptr); - *out_global_model = BeginPtr(global_buffer); - *out_global_len = static_cast(global_buffer.length()); - } else { - version = rabit::LoadCheckPoint(&sg, &sl); - *out_global_model = BeginPtr(global_buffer); - *out_global_len = static_cast(global_buffer.length()); - *out_local_model = BeginPtr(local_buffer); - *out_local_len = static_cast(local_buffer.length()); - } - return version; -} - -RABIT_DLL void RabitCheckPoint(const char *global_model, rbt_ulong global_len, - const char *local_model, rbt_ulong local_len) { - using namespace rabit::c_api; // NOLINT(*) - WriteWrapper sg(global_model, global_len); - WriteWrapper sl(local_model, local_len); - if (local_model == nullptr) { - rabit::CheckPoint(&sg, nullptr); - } else { - rabit::CheckPoint(&sg, &sl); - } -} - RABIT_DLL int RabitVersionNumber() { return rabit::VersionNumber(); } diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index 94c9109bc..daabc45d2 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1076,7 +1076,7 @@ XGB_DLL int XGBoosterLoadRabitCheckpoint(BoosterHandle handle, API_BEGIN(); CHECK_HANDLE(); auto* bst = static_cast(handle); - *version = rabit::LoadCheckPoint(bst); + *version = rabit::LoadCheckPoint(); if (*version != 0) { bst->Configure(); } @@ -1086,13 +1086,9 @@ XGB_DLL int XGBoosterLoadRabitCheckpoint(BoosterHandle handle, XGB_DLL int XGBoosterSaveRabitCheckpoint(BoosterHandle handle) { API_BEGIN(); CHECK_HANDLE(); - auto* learner = static_cast(handle); + auto *learner = static_cast(handle); learner->Configure(); - if (learner->AllowLazyCheckPoint()) { - rabit::LazyCheckPoint(learner); - } else { - rabit::CheckPoint(learner); - } + rabit::CheckPoint(); API_END(); } diff --git a/src/cli_main.cc b/src/cli_main.cc index 82140c9ca..dc99cf4f0 100644 --- a/src/cli_main.cc +++ b/src/cli_main.cc @@ -184,7 +184,7 @@ class CLI { int ResetLearner(std::vector> const &matrices) { learner_.reset(Learner::Create(matrices)); - int version = rabit::LoadCheckPoint(learner_.get()); + int version = rabit::LoadCheckPoint(); if (version == 0) { if (param_.model_in != CLIParam::kNull) { this->LoadModel(param_.model_in, learner_.get()); @@ -238,11 +238,7 @@ class CLI { LOG(INFO) << "boosting round " << i << ", " << elapsed << " sec elapsed"; learner_->UpdateOneIter(i, dtrain); - if (learner_->AllowLazyCheckPoint()) { - rabit::LazyCheckPoint(learner_.get()); - } else { - rabit::CheckPoint(learner_.get()); - } + rabit::CheckPoint(); version += 1; } CHECK_EQ(version, rabit::VersionNumber()); @@ -262,11 +258,7 @@ class CLI { this->SaveModel(os.str(), learner_.get()); } - if (learner_->AllowLazyCheckPoint()) { - rabit::LazyCheckPoint(learner_.get()); - } else { - rabit::CheckPoint(learner_.get()); - } + rabit::CheckPoint(); version += 1; CHECK_EQ(version, rabit::VersionNumber()); } diff --git a/src/common/device_helpers.cu b/src/common/device_helpers.cu index 4c7b6b90c..5f0e92223 100644 --- a/src/common/device_helpers.cu +++ b/src/common/device_helpers.cu @@ -15,11 +15,10 @@ namespace dh { constexpr std::size_t kUuidLength = sizeof(std::declval().uuid) / sizeof(uint64_t); -void GetCudaUUID(int world_size, int rank, int device_ord, - xgboost::common::Span uuid) { +void GetCudaUUID(int device_ord, xgboost::common::Span uuid) { cudaDeviceProp prob; safe_cuda(cudaGetDeviceProperties(&prob, device_ord)); - std::memcpy(uuid.data(), static_cast(&(prob.uuid)), sizeof(prob.uuid)); + std::memcpy(uuid.data(), static_cast(&(prob.uuid)), sizeof(prob.uuid)); } std::string PrintUUID(xgboost::common::Span uuid) { @@ -38,7 +37,7 @@ void NcclAllReducer::DoInit(int _device_ordinal) { std::vector uuids(world * kUuidLength, 0); auto s_uuid = xgboost::common::Span{uuids.data(), uuids.size()}; auto s_this_uuid = s_uuid.subspan(rank * kUuidLength, kUuidLength); - GetCudaUUID(world, rank, _device_ordinal, s_this_uuid); + GetCudaUUID(_device_ordinal, s_this_uuid); // No allgather yet. rabit::Allreduce(uuids.data(), uuids.size()); @@ -67,7 +66,7 @@ void NcclAllReducer::DoInit(int _device_ordinal) { void NcclAllReducer::DoAllGather(void const *data, size_t length_bytes, std::vector *segments, dh::caching_device_vector *recvbuf) { - size_t world = rabit::GetWorldSize(); + int32_t world = rabit::GetWorldSize(); segments->clear(); segments->resize(world, 0); segments->at(rabit::GetRank()) = length_bytes; diff --git a/src/common/json.cc b/src/common/json.cc index f3421fa9f..92ad11c08 100644 --- a/src/common/json.cc +++ b/src/common/json.cc @@ -246,7 +246,7 @@ std::enable_if_t::value, bool> IsInfMSVCWar(T v) { return std::isinf(v); } template -std::enable_if_t::value, bool> IsInfMSVCWar(T v) { +std::enable_if_t::value, bool> IsInfMSVCWar(T) { return false; } } // namespace @@ -850,9 +850,11 @@ Json UBJReader::Parse() { } case 'D': { LOG(FATAL) << "f64 is not supported."; + break; } case 'H': { LOG(FATAL) << "High precision number is not supported."; + break; } default: Error("Unknown construct"); @@ -968,7 +970,7 @@ void UBJWriter::Visit(JsonInteger const* num) { } } -void UBJWriter::Visit(JsonNull const* null) { stream_->push_back('Z'); } +void UBJWriter::Visit(JsonNull const*) { stream_->push_back('Z'); } void UBJWriter::Visit(JsonString const* str) { stream_->push_back('S'); diff --git a/src/common/quantile.cu b/src/common/quantile.cu index 331795516..5f69eafb3 100644 --- a/src/common/quantile.cu +++ b/src/common/quantile.cu @@ -55,12 +55,10 @@ __device__ SketchEntry BinarySearchQuery(EntryIter beg, EntryIter end, float ran } template -void PruneImpl(int device, - common::Span cuts_ptr, +void PruneImpl(common::Span cuts_ptr, Span sorted_data, Span columns_ptr_in, // could be ptr for data or cuts - Span feature_types, - Span out_cuts, + Span feature_types, Span out_cuts, ToSketchEntry to_sketch_entry) { dh::LaunchN(out_cuts.size(), [=] __device__(size_t idx) { size_t column_id = dh::SegmentId(cuts_ptr, idx); @@ -207,12 +205,8 @@ common::Span> MergePath( // run it in 2 passes to obtain the merge path and then customize the standard merge // algorithm. void MergeImpl(int32_t device, Span const &d_x, - Span const &x_ptr, - Span const &d_y, - Span const &y_ptr, - Span feature_types, - Span out, - Span out_ptr) { + Span const &x_ptr, Span const &d_y, + Span const &y_ptr, Span out, Span out_ptr) { dh::safe_cuda(cudaSetDevice(device)); CHECK_EQ(d_x.size() + d_y.size(), out.size()); CHECK_EQ(x_ptr.size(), out_ptr.size()); @@ -311,6 +305,7 @@ void MergeImpl(int32_t device, Span const &d_x, void SketchContainer::Push(Span entries, Span columns_ptr, common::Span cuts_ptr, size_t total_cuts, Span weights) { + dh::safe_cuda(cudaSetDevice(device_)); Span out; dh::device_vector cuts; bool first_window = this->Current().empty(); @@ -330,8 +325,7 @@ void SketchContainer::Push(Span entries, Span columns_ptr, float rmax = sample_idx + 1; return SketchEntry{rmin, rmax, 1, column[sample_idx].fvalue}; }; // NOLINT - PruneImpl(device_, cuts_ptr, entries, columns_ptr, ft, out, - to_sketch_entry); + PruneImpl(cuts_ptr, entries, columns_ptr, ft, out, to_sketch_entry); } else { auto to_sketch_entry = [weights, columns_ptr] __device__( size_t sample_idx, @@ -345,8 +339,7 @@ void SketchContainer::Push(Span entries, Span columns_ptr, wmin = wmin < 0 ? kRtEps : wmin; // GPU scan can generate floating error. return SketchEntry{rmin, rmax, wmin, column[sample_idx].fvalue}; }; // NOLINT - PruneImpl(device_, cuts_ptr, entries, columns_ptr, ft, out, - to_sketch_entry); + PruneImpl(cuts_ptr, entries, columns_ptr, ft, out, to_sketch_entry); } auto n_uniques = this->ScanInput(out, cuts_ptr); @@ -436,8 +429,7 @@ void SketchContainer::Prune(size_t to) { Span const &entries, size_t) { return entries[sample_idx]; }; // NOLINT auto ft = this->feature_types_.ConstDeviceSpan(); - PruneImpl(device_, d_columns_ptr_out, in, d_columns_ptr_in, ft, - out, no_op); + PruneImpl(d_columns_ptr_out, in, d_columns_ptr_in, ft, out, no_op); this->columns_ptr_.Copy(columns_ptr_b_); this->Alternate(); @@ -466,10 +458,8 @@ void SketchContainer::Merge(Span d_that_columns_ptr, this->Other().resize(this->Current().size() + that.size()); CHECK_EQ(d_that_columns_ptr.size(), this->columns_ptr_.Size()); - auto feature_types = this->FeatureTypes().ConstDeviceSpan(); MergeImpl(device_, this->Data(), this->ColumnsPtr(), that, d_that_columns_ptr, - feature_types, dh::ToSpan(this->Other()), - columns_ptr_b_.DeviceSpan()); + dh::ToSpan(this->Other()), columns_ptr_b_.DeviceSpan()); this->columns_ptr_.Copy(columns_ptr_b_); CHECK_EQ(this->columns_ptr_.Size(), num_columns_ + 1); this->Alternate(); diff --git a/src/data/data.cc b/src/data/data.cc index db952fc3a..600894798 100644 --- a/src/data/data.cc +++ b/src/data/data.cc @@ -965,8 +965,7 @@ template DMatrix *DMatrix::Create -DMatrix* DMatrix::Create(AdapterT* adapter, float missing, int nthread, - const std::string& cache_prefix) { +DMatrix* DMatrix::Create(AdapterT* adapter, float missing, int nthread, const std::string&) { return new data::SimpleDMatrix(adapter, missing, nthread); } diff --git a/src/data/device_adapter.cuh b/src/data/device_adapter.cuh index 145bb56dd..fbe90db14 100644 --- a/src/data/device_adapter.cuh +++ b/src/data/device_adapter.cuh @@ -190,6 +190,7 @@ class CupyAdapter : public detail::SingleBatchDataIter { template size_t GetRowCounts(const AdapterBatchT batch, common::Span offset, int device_idx, float missing) { + dh::safe_cuda(cudaSetDevice(device_idx)); IsValidFunctor is_valid(missing); // Count elements per row dh::LaunchN(batch.Size(), [=] __device__(size_t idx) { diff --git a/src/data/ellpack_page.cu b/src/data/ellpack_page.cu index 82d90eb13..14a1b2bbf 100644 --- a/src/data/ellpack_page.cu +++ b/src/data/ellpack_page.cu @@ -264,12 +264,10 @@ void WriteNullValues(EllpackPageImpl* dst, int device_idx, } template -EllpackPageImpl::EllpackPageImpl(AdapterBatch batch, float missing, int device, - bool is_dense, int nthread, +EllpackPageImpl::EllpackPageImpl(AdapterBatch batch, float missing, int device, bool is_dense, common::Span row_counts_span, - common::Span feature_types, - size_t row_stride, size_t n_rows, size_t n_cols, - common::HistogramCuts const& cuts) { + common::Span feature_types, size_t row_stride, + size_t n_rows, common::HistogramCuts const& cuts) { dh::safe_cuda(cudaSetDevice(device)); *this = EllpackPageImpl(device, cuts, is_dense, row_stride, n_rows); @@ -277,12 +275,11 @@ EllpackPageImpl::EllpackPageImpl(AdapterBatch batch, float missing, int device, WriteNullValues(this, device, row_counts_span); } -#define ELLPACK_BATCH_SPECIALIZE(__BATCH_T) \ - template EllpackPageImpl::EllpackPageImpl( \ - __BATCH_T batch, float missing, int device, bool is_dense, int nthread, \ - common::Span row_counts_span, \ - common::Span feature_types, size_t row_stride, \ - size_t n_rows, size_t n_cols, common::HistogramCuts const &cuts); +#define ELLPACK_BATCH_SPECIALIZE(__BATCH_T) \ + template EllpackPageImpl::EllpackPageImpl( \ + __BATCH_T batch, float missing, int device, bool is_dense, \ + common::Span row_counts_span, common::Span feature_types, \ + size_t row_stride, size_t n_rows, common::HistogramCuts const& cuts); ELLPACK_BATCH_SPECIALIZE(data::CudfAdapterBatch) ELLPACK_BATCH_SPECIALIZE(data::CupyAdapterBatch) diff --git a/src/data/ellpack_page.cuh b/src/data/ellpack_page.cuh index bd7a574d6..7a2020c8b 100644 --- a/src/data/ellpack_page.cuh +++ b/src/data/ellpack_page.cuh @@ -150,12 +150,10 @@ class EllpackPageImpl { explicit EllpackPageImpl(DMatrix* dmat, const BatchParam& parm); template - explicit EllpackPageImpl(AdapterBatch batch, float missing, int device, - bool is_dense, int nthread, + explicit EllpackPageImpl(AdapterBatch batch, float missing, int device, bool is_dense, common::Span row_counts_span, - common::Span feature_types, - size_t row_stride, size_t n_rows, size_t n_cols, - common::HistogramCuts const &cuts); + common::Span feature_types, size_t row_stride, + size_t n_rows, common::HistogramCuts const& cuts); /*! \brief Copy the elements of the given ELLPACK page into this page. * diff --git a/src/data/iterative_device_dmatrix.cu b/src/data/iterative_device_dmatrix.cu index 477247fb6..c5f1894ca 100644 --- a/src/data/iterative_device_dmatrix.cu +++ b/src/data/iterative_device_dmatrix.cu @@ -16,7 +16,7 @@ namespace xgboost { namespace data { -void IterativeDeviceDMatrix::Initialize(DataIterHandle iter_handle, float missing, int nthread) { +void IterativeDeviceDMatrix::Initialize(DataIterHandle iter_handle, float missing) { // A handle passed to external iterator. DMatrixProxy* proxy = MakeProxy(proxy_); CHECK(proxy); @@ -132,10 +132,9 @@ void IterativeDeviceDMatrix::Initialize(DataIterHandle iter_handle, float missin proxy->Info().feature_types.SetDevice(get_device()); auto d_feature_types = proxy->Info().feature_types.ConstDeviceSpan(); - auto new_impl = Dispatch(proxy, [&](auto const &value) { - return EllpackPageImpl(value, missing, get_device(), is_dense, nthread, - row_counts_span, d_feature_types, row_stride, rows, - cols, cuts); + auto new_impl = Dispatch(proxy, [&](auto const& value) { + return EllpackPageImpl(value, missing, get_device(), is_dense, row_counts_span, + d_feature_types, row_stride, rows, cuts); }); size_t num_elements = page_->Impl()->Copy(get_device(), &new_impl, offset); offset += num_elements; @@ -163,6 +162,11 @@ void IterativeDeviceDMatrix::Initialize(DataIterHandle iter_handle, float missin BatchSet IterativeDeviceDMatrix::GetEllpackBatches(const BatchParam& param) { CHECK(page_); + // FIXME(Jiamingy): https://github.com/dmlc/xgboost/issues/7976 + if (param.max_bin != batch_param_.max_bin) { + LOG(WARNING) << "Inconsistent max_bin between Quantile DMatrix and Booster:" << param.max_bin + << " vs. " << batch_param_.max_bin; + } auto begin_iter = BatchIterator(new SimpleBatchIteratorImpl(page_)); return BatchSet(begin_iter); } diff --git a/src/data/iterative_device_dmatrix.h b/src/data/iterative_device_dmatrix.h index 2ae0c4c64..9920891d2 100644 --- a/src/data/iterative_device_dmatrix.h +++ b/src/data/iterative_device_dmatrix.h @@ -30,16 +30,16 @@ class IterativeDeviceDMatrix : public DMatrix { XGDMatrixCallbackNext *next_; public: - void Initialize(DataIterHandle iter, float missing, int nthread); + void Initialize(DataIterHandle iter, float missing); public: explicit IterativeDeviceDMatrix(DataIterHandle iter, DMatrixHandle proxy, - DataIterResetCallback *reset, - XGDMatrixCallbackNext *next, float missing, - int nthread, int max_bin) + DataIterResetCallback *reset, XGDMatrixCallbackNext *next, + float missing, int nthread, int max_bin) : proxy_{proxy}, reset_{reset}, next_{next} { batch_param_ = BatchParam{0, max_bin}; - this->Initialize(iter, missing, nthread); + ctx_.UpdateAllowUnknown(Args{{"nthread", std::to_string(nthread)}}); + this->Initialize(iter, missing); } ~IterativeDeviceDMatrix() override = default; @@ -77,7 +77,7 @@ class IterativeDeviceDMatrix : public DMatrix { }; #if !defined(XGBOOST_USE_CUDA) -inline void IterativeDeviceDMatrix::Initialize(DataIterHandle iter, float missing, int nthread) { +inline void IterativeDeviceDMatrix::Initialize(DataIterHandle iter, float missing) { // silent the warning about unused variables. (void)(proxy_); (void)(reset_); diff --git a/src/data/simple_dmatrix.cu b/src/data/simple_dmatrix.cu index da4000ed1..12f44fb85 100644 --- a/src/data/simple_dmatrix.cu +++ b/src/data/simple_dmatrix.cu @@ -15,7 +15,7 @@ namespace data { // Current implementation assumes a single batch. More batches can // be supported in future. Does not currently support inferring row/column size template -SimpleDMatrix::SimpleDMatrix(AdapterT* adapter, float missing, int nthread) { +SimpleDMatrix::SimpleDMatrix(AdapterT* adapter, float missing, int32_t /*nthread*/) { auto device = (adapter->DeviceIdx() < 0 || adapter->NumRows() == 0) ? dh::CurrentDevice() : adapter->DeviceIdx(); CHECK_GE(device, 0); diff --git a/src/gbm/gblinear.cc b/src/gbm/gblinear.cc index 0e983fe4b..35de4c70d 100644 --- a/src/gbm/gblinear.cc +++ b/src/gbm/gblinear.cc @@ -148,8 +148,8 @@ class GBLinear : public GradientBooster { monitor_.Stop("DoBoost"); } - void PredictBatch(DMatrix *p_fmat, PredictionCacheEntry *predts, - bool training, unsigned layer_begin, unsigned layer_end) override { + void PredictBatch(DMatrix* p_fmat, PredictionCacheEntry* predts, bool /*training*/, + uint32_t layer_begin, uint32_t) override { monitor_.Start("PredictBatch"); LinearCheckLayer(layer_begin); auto* out_preds = &predts->predictions; @@ -157,9 +157,8 @@ class GBLinear : public GradientBooster { monitor_.Stop("PredictBatch"); } // add base margin - void PredictInstance(const SparsePage::Inst &inst, - std::vector *out_preds, - unsigned layer_begin, unsigned layer_end) override { + void PredictInstance(const SparsePage::Inst& inst, std::vector* out_preds, + uint32_t layer_begin, uint32_t) override { LinearCheckLayer(layer_begin); const int ngroup = model_.learner_model_param->num_output_group; for (int gid = 0; gid < ngroup; ++gid) { @@ -172,9 +171,9 @@ class GBLinear : public GradientBooster { LOG(FATAL) << "gblinear does not support prediction of leaf index"; } - void PredictContribution(DMatrix* p_fmat, - HostDeviceVector* out_contribs, - unsigned layer_begin, unsigned layer_end, bool, int, unsigned) override { + void PredictContribution(DMatrix* p_fmat, HostDeviceVector* out_contribs, + uint32_t layer_begin, uint32_t /*layer_end*/, bool, int, + unsigned) override { model_.LazyInitModel(); LinearCheckLayer(layer_begin); auto base_margin = p_fmat->Info().base_margin_.View(GenericParameter::kCpuId); @@ -210,9 +209,9 @@ class GBLinear : public GradientBooster { } } - void PredictInteractionContributions(DMatrix* p_fmat, - HostDeviceVector* out_contribs, - unsigned layer_begin, unsigned layer_end, bool) override { + void PredictInteractionContributions(DMatrix* p_fmat, HostDeviceVector* out_contribs, + unsigned layer_begin, unsigned /*layer_end*/, + bool) override { LinearCheckLayer(layer_begin); std::vector& contribs = out_contribs->HostVector(); diff --git a/src/gbm/gblinear_model.h b/src/gbm/gblinear_model.h index 53121ae84..577494f87 100644 --- a/src/gbm/gblinear_model.h +++ b/src/gbm/gblinear_model.h @@ -34,7 +34,10 @@ struct DeprecatedGBLinearModelParam : public dmlc::Parameternum_output_group == 1; - } - // Number of trees per layer. auto LayerTrees() const { auto n_trees = model_.learner_model_param->num_output_group * model_.param.num_parallel_tree; diff --git a/src/learner.cc b/src/learner.cc index ee115c03c..0ecb1647d 100644 --- a/src/learner.cc +++ b/src/learner.cc @@ -61,11 +61,6 @@ enum class DataSplitMode : int { DECLARE_FIELD_ENUM_CLASS(xgboost::DataSplitMode); namespace xgboost { -// implementation of base learner. -bool Learner::AllowLazyCheckPoint() const { - return gbm_->AllowLazyCheckPoint(); -} - Learner::~Learner() = default; /*! \brief training parameter for regression diff --git a/src/linear/updater_gpu_coordinate.cu b/src/linear/updater_gpu_coordinate.cu index 4d2a8c5b0..ba98f4949 100644 --- a/src/linear/updater_gpu_coordinate.cu +++ b/src/linear/updater_gpu_coordinate.cu @@ -77,8 +77,8 @@ class GPUCoordinateUpdater : public LinearUpdater { // NOLINT auto column_end = std::lower_bound(col.cbegin(), col.cend(), xgboost::Entry(num_row_, 0.0f), cmp); - column_segments.emplace_back( - std::make_pair(column_begin - col.cbegin(), column_end - col.cbegin())); + column_segments.emplace_back(static_cast(column_begin - col.cbegin()), + static_cast(column_end - col.cbegin())); row_ptr_.push_back(row_ptr_.back() + (column_end - column_begin)); } data_.resize(row_ptr_.back()); @@ -109,28 +109,28 @@ class GPUCoordinateUpdater : public LinearUpdater { // NOLINT monitor_.Stop("UpdateGpair"); monitor_.Start("UpdateBias"); - this->UpdateBias(p_fmat, model); + this->UpdateBias(model); monitor_.Stop("UpdateBias"); // prepare for updating the weights selector_->Setup(*model, in_gpair->ConstHostVector(), p_fmat, tparam_.reg_alpha_denorm, tparam_.reg_lambda_denorm, coord_param_.top_k); monitor_.Start("UpdateFeature"); - for (auto group_idx = 0; group_idx < model->learner_model_param->num_output_group; + for (uint32_t group_idx = 0; group_idx < model->learner_model_param->num_output_group; ++group_idx) { for (auto i = 0U; i < model->learner_model_param->num_feature; i++) { auto fidx = selector_->NextFeature( i, *model, group_idx, in_gpair->ConstHostVector(), p_fmat, tparam_.reg_alpha_denorm, tparam_.reg_lambda_denorm); if (fidx < 0) break; - this->UpdateFeature(fidx, group_idx, &in_gpair->HostVector(), model); + this->UpdateFeature(fidx, group_idx, model); } } monitor_.Stop("UpdateFeature"); } - void UpdateBias(DMatrix *p_fmat, gbm::GBLinearModel *model) { - for (int group_idx = 0; group_idx < model->learner_model_param->num_output_group; + void UpdateBias(gbm::GBLinearModel *model) { + for (uint32_t group_idx = 0; group_idx < model->learner_model_param->num_output_group; ++group_idx) { // Get gradient auto grad = GradientPair(0, 0); @@ -150,7 +150,6 @@ class GPUCoordinateUpdater : public LinearUpdater { // NOLINT } void UpdateFeature(int fidx, int group_idx, - std::vector *in_gpair, gbm::GBLinearModel *model) { bst_float &w = (*model)[fidx][group_idx]; // Get gradient diff --git a/src/metric/auc.cu b/src/metric/auc.cu index 6d3373c83..536f6442d 100644 --- a/src/metric/auc.cu +++ b/src/metric/auc.cu @@ -201,8 +201,7 @@ void Transpose(common::Span in, common::Span out, size_t m, }); } -double ScaleClasses(common::Span results, - common::Span local_area, common::Span fp, +double ScaleClasses(common::Span results, common::Span local_area, common::Span tp, common::Span auc, std::shared_ptr cache, size_t n_classes) { dh::XGBDeviceAllocator alloc; @@ -333,10 +332,9 @@ double GPUMultiClassAUCOVR(MetaInfo const &info, int32_t device, common::Span predts, diff --git a/src/metric/elementwise_metric.cu b/src/metric/elementwise_metric.cu index ab5799cff..596894a54 100644 --- a/src/metric/elementwise_metric.cu +++ b/src/metric/elementwise_metric.cu @@ -376,40 +376,40 @@ struct EvalEWiseBase : public Metric { }; XGBOOST_REGISTER_METRIC(RMSE, "rmse") -.describe("Rooted mean square error.") -.set_body([](const char* param) { return new EvalEWiseBase(); }); + .describe("Rooted mean square error.") + .set_body([](const char*) { return new EvalEWiseBase(); }); XGBOOST_REGISTER_METRIC(RMSLE, "rmsle") -.describe("Rooted mean square log error.") -.set_body([](const char* param) { return new EvalEWiseBase(); }); + .describe("Rooted mean square log error.") + .set_body([](const char*) { return new EvalEWiseBase(); }); -XGBOOST_REGISTER_METRIC(MAE, "mae") -.describe("Mean absolute error.") -.set_body([](const char* param) { return new EvalEWiseBase(); }); +XGBOOST_REGISTER_METRIC(MAE, "mae").describe("Mean absolute error.").set_body([](const char*) { + return new EvalEWiseBase(); +}); XGBOOST_REGISTER_METRIC(MAPE, "mape") .describe("Mean absolute percentage error.") - .set_body([](const char* param) { return new EvalEWiseBase(); }); + .set_body([](const char*) { return new EvalEWiseBase(); }); XGBOOST_REGISTER_METRIC(LogLoss, "logloss") -.describe("Negative loglikelihood for logistic regression.") -.set_body([](const char* param) { return new EvalEWiseBase(); }); + .describe("Negative loglikelihood for logistic regression.") + .set_body([](const char*) { return new EvalEWiseBase(); }); XGBOOST_REGISTER_METRIC(PseudoErrorLoss, "mphe") .describe("Mean Pseudo-huber error.") - .set_body([](const char* param) { return new PseudoErrorLoss{}; }); + .set_body([](const char*) { return new PseudoErrorLoss{}; }); XGBOOST_REGISTER_METRIC(PossionNegLoglik, "poisson-nloglik") -.describe("Negative loglikelihood for poisson regression.") -.set_body([](const char* param) { return new EvalEWiseBase(); }); + .describe("Negative loglikelihood for poisson regression.") + .set_body([](const char*) { return new EvalEWiseBase(); }); XGBOOST_REGISTER_METRIC(GammaDeviance, "gamma-deviance") -.describe("Residual deviance for gamma regression.") -.set_body([](const char* param) { return new EvalEWiseBase(); }); + .describe("Residual deviance for gamma regression.") + .set_body([](const char*) { return new EvalEWiseBase(); }); XGBOOST_REGISTER_METRIC(GammaNLogLik, "gamma-nloglik") -.describe("Negative log-likelihood for gamma regression.") -.set_body([](const char* param) { return new EvalEWiseBase(); }); + .describe("Negative log-likelihood for gamma regression.") + .set_body([](const char*) { return new EvalEWiseBase(); }); XGBOOST_REGISTER_METRIC(Error, "error") .describe("Binary classification error.") diff --git a/src/metric/multiclass_metric.cu b/src/metric/multiclass_metric.cu index 601e33b99..3c2ef7d38 100644 --- a/src/metric/multiclass_metric.cu +++ b/src/metric/multiclass_metric.cu @@ -230,9 +230,7 @@ struct EvalMultiLogLoss : public EvalMClassBase { const char* Name() const override { return "mlogloss"; } - XGBOOST_DEVICE static bst_float EvalRow(int label, - const bst_float *pred, - size_t nclass) { + XGBOOST_DEVICE static bst_float EvalRow(int label, const bst_float* pred, size_t /*nclass*/) { const bst_float eps = 1e-16f; auto k = static_cast(label); if (pred[k] > eps) { @@ -244,11 +242,11 @@ struct EvalMultiLogLoss : public EvalMClassBase { }; XGBOOST_REGISTER_METRIC(MatchError, "merror") -.describe("Multiclass classification error.") -.set_body([](const char* param) { return new EvalMatchError(); }); + .describe("Multiclass classification error.") + .set_body([](const char*) { return new EvalMatchError(); }); XGBOOST_REGISTER_METRIC(MultiLogLoss, "mlogloss") -.describe("Multiclass negative loglikelihood.") -.set_body([](const char* param) { return new EvalMultiLogLoss(); }); + .describe("Multiclass negative loglikelihood.") + .set_body([](const char*) { return new EvalMultiLogLoss(); }); } // namespace metric } // namespace xgboost diff --git a/src/metric/survival_metric.cu b/src/metric/survival_metric.cu index 4eaf32b01..296764be0 100644 --- a/src/metric/survival_metric.cu +++ b/src/metric/survival_metric.cu @@ -153,7 +153,7 @@ class ElementWiseSurvivalMetricsReduction { }; struct EvalIntervalRegressionAccuracy { - void Configure(const Args& args) {} + void Configure(const Args&) {} const char* Name() const { return "interval-regression-accuracy"; @@ -277,18 +277,15 @@ struct AFTNLogLikDispatcher : public Metric { std::unique_ptr metric_; }; - XGBOOST_REGISTER_METRIC(AFTNLogLik, "aft-nloglik") -.describe("Negative log likelihood of Accelerated Failure Time model.") -.set_body([](const char* param) { - return new AFTNLogLikDispatcher(); -}); + .describe("Negative log likelihood of Accelerated Failure Time model.") + .set_body([](const char*) { return new AFTNLogLikDispatcher(); }); XGBOOST_REGISTER_METRIC(IntervalRegressionAccuracy, "interval-regression-accuracy") -.describe("") -.set_body([](const char* param) { - return new EvalEWiseSurvivalBase(); -}); + .describe("") + .set_body([](const char*) { + return new EvalEWiseSurvivalBase(); + }); } // namespace metric } // namespace xgboost diff --git a/src/objective/adaptive.cu b/src/objective/adaptive.cu index 42d239acd..aa01370b0 100644 --- a/src/objective/adaptive.cu +++ b/src/objective/adaptive.cu @@ -29,7 +29,7 @@ void EncodeTreeLeafDevice(Context const* ctx, common::Span pos thrust::stable_sort_by_key(thrust::cuda::par(alloc), sorted_position.begin(), sorted_position.begin() + n_samples, p_ridx->begin()); dh::XGBCachingDeviceAllocator caching; - auto beg_pos = + size_t beg_pos = thrust::find_if(thrust::cuda::par(caching), sorted_position.cbegin(), sorted_position.cend(), [] XGBOOST_DEVICE(bst_node_t nidx) { return nidx >= 0; }) - sorted_position.cbegin(); @@ -53,15 +53,15 @@ void EncodeTreeLeafDevice(Context const* ctx, common::Span pos dh::caching_device_vector unique_out(max_n_unique, 0); auto d_unique_out = dh::ToSpan(unique_out); - size_t nbytes; + size_t nbytes{0}; auto begin_it = sorted_position.begin() + beg_pos; - cub::DeviceRunLengthEncode::Encode(nullptr, nbytes, begin_it, unique_out.data().get(), - counts_out.data().get(), d_num_runs_out.data(), - n_samples - beg_pos); + dh::safe_cuda(cub::DeviceRunLengthEncode::Encode(nullptr, nbytes, begin_it, + unique_out.data().get(), counts_out.data().get(), + d_num_runs_out.data(), n_samples - beg_pos)); dh::TemporaryArray temp(nbytes); - cub::DeviceRunLengthEncode::Encode(temp.data().get(), nbytes, begin_it, unique_out.data().get(), - counts_out.data().get(), d_num_runs_out.data(), - n_samples - beg_pos); + dh::safe_cuda(cub::DeviceRunLengthEncode::Encode(temp.data().get(), nbytes, begin_it, + unique_out.data().get(), counts_out.data().get(), + d_num_runs_out.data(), n_samples - beg_pos)); dh::PinnedMemory pinned_pool; auto pinned = pinned_pool.GetSpan(sizeof(size_t) + sizeof(bst_node_t)); diff --git a/src/objective/aft_obj.cu b/src/objective/aft_obj.cu index 5f2306dee..9811529e3 100644 --- a/src/objective/aft_obj.cu +++ b/src/objective/aft_obj.cu @@ -70,9 +70,7 @@ class AFTObj : public ObjFunction { &info.weights_); } - void GetGradient(const HostDeviceVector& preds, - const MetaInfo& info, - int iter, + void GetGradient(const HostDeviceVector& preds, const MetaInfo& info, int /*iter*/, HostDeviceVector* out_gpair) override { const size_t ndata = preds.Size(); CHECK_EQ(info.labels_lower_bound_.Size(), ndata); @@ -115,7 +113,7 @@ class AFTObj : public ObjFunction { .Eval(io_preds); } - void EvalTransform(HostDeviceVector *io_preds) override { + void EvalTransform(HostDeviceVector* /*io_preds*/) override { // do nothing here, since the AFT metric expects untransformed prediction score } diff --git a/src/objective/hinge.cu b/src/objective/hinge.cu index e062b2b48..bff3bc593 100644 --- a/src/objective/hinge.cu +++ b/src/objective/hinge.cu @@ -27,9 +27,7 @@ class HingeObj : public ObjFunction { void Configure(Args const&) override {} ObjInfo Task() const override { return ObjInfo::kRegression; } - void GetGradient(const HostDeviceVector &preds, - const MetaInfo &info, - int iter, + void GetGradient(const HostDeviceVector &preds, const MetaInfo &info, int /*iter*/, HostDeviceVector *out_gpair) override { CHECK_NE(info.labels.Size(), 0U) << "label set cannot be empty"; CHECK_EQ(preds.Size(), info.labels.Size()) @@ -86,7 +84,7 @@ class HingeObj : public ObjFunction { auto& out = *p_out; out["name"] = String("binary:hinge"); } - void LoadConfig(Json const& in) override {} + void LoadConfig(Json const &) override {} }; // register the objective functions diff --git a/src/objective/regression_obj.cu b/src/objective/regression_obj.cu index ad7f37b49..ecd906f69 100644 --- a/src/objective/regression_obj.cu +++ b/src/objective/regression_obj.cu @@ -218,7 +218,7 @@ class PseudoHuberRegression : public ObjFunction { return std::max(static_cast(1), info.labels.Shape(1)); } - void GetGradient(HostDeviceVector const& preds, const MetaInfo& info, int iter, + void GetGradient(HostDeviceVector const& preds, const MetaInfo& info, int /*iter*/, HostDeviceVector* out_gpair) override { CheckRegInputs(info, preds); auto slope = param_.huber_slope; @@ -672,7 +672,7 @@ class MeanAbsoluteError : public ObjFunction { void Configure(Args const&) override {} ObjInfo Task() const override { return {ObjInfo::kRegression, true, true}; } - void GetGradient(HostDeviceVector const& preds, const MetaInfo& info, int iter, + void GetGradient(HostDeviceVector const& preds, const MetaInfo& info, int /*iter*/, HostDeviceVector* out_gpair) override { CheckRegInputs(info, preds); auto labels = info.labels.View(ctx_->gpu_id); @@ -721,7 +721,9 @@ class MeanAbsoluteError : public ObjFunction { out["name"] = String("reg:absoluteerror"); } - void LoadConfig(Json const& in) override {} + void LoadConfig(Json const& in) override { + CHECK_EQ(StringView{get(in["name"])}, StringView{"reg:absoluteerror"}); + } }; XGBOOST_REGISTER_OBJECTIVE(MeanAbsoluteError, "reg:absoluteerror") diff --git a/src/predictor/cpu_predictor.cc b/src/predictor/cpu_predictor.cc index b5dd9b4af..68500be28 100644 --- a/src/predictor/cpu_predictor.cc +++ b/src/predictor/cpu_predictor.cc @@ -244,7 +244,7 @@ void FillNodeMeanValues(RegTree const* tree, std::vector* mean_values) { class CPUPredictor : public Predictor { protected: // init thread buffers - static void InitThreadTemp(int nthread, int num_feature, std::vector* out) { + static void InitThreadTemp(int nthread, std::vector *out) { int prev_thread_temp_size = out->size(); if (prev_thread_temp_size < nthread) { out->resize(nthread, RegTree::FVec()); @@ -263,8 +263,7 @@ class CPUPredictor : public Predictor { bool blocked = density > kDensityThresh; std::vector feat_vecs; - InitThreadTemp(n_threads * (blocked ? kBlockOfRowsSize : 1), - model.learner_model_param->num_feature, &feat_vecs); + InitThreadTemp(n_threads * (blocked ? kBlockOfRowsSize : 1), &feat_vecs); for (auto const &batch : p_fmat->GetBatches()) { CHECK_EQ(out_preds->size(), p_fmat->Info().num_row_ * @@ -320,8 +319,7 @@ class CPUPredictor : public Predictor { std::vector workspace(m->NumColumns() * 8 * n_threads); auto &predictions = out_preds->predictions.HostVector(); std::vector thread_temp; - InitThreadTemp(n_threads * kBlockSize, model.learner_model_param->num_feature, - &thread_temp); + InitThreadTemp(n_threads * kBlockSize, &thread_temp); PredictBatchByBlockOfRowsKernel, kBlockSize>( AdapterView(m.get(), missing, common::Span{workspace}, n_threads), &predictions, model, tree_begin, tree_end, &thread_temp, n_threads); @@ -376,7 +374,7 @@ class CPUPredictor : public Predictor { auto const n_threads = this->ctx_->Threads(); std::vector feat_vecs; const int num_feature = model.learner_model_param->num_feature; - InitThreadTemp(n_threads, num_feature, &feat_vecs); + InitThreadTemp(n_threads, &feat_vecs); const MetaInfo& info = p_fmat->Info(); // number of valid trees if (ntree_limit == 0 || ntree_limit > model.trees.size()) { @@ -417,7 +415,7 @@ class CPUPredictor : public Predictor { auto const n_threads = this->ctx_->Threads(); const int num_feature = model.learner_model_param->num_feature; std::vector feat_vecs; - InitThreadTemp(n_threads, num_feature, &feat_vecs); + InitThreadTemp(n_threads, &feat_vecs); const MetaInfo& info = p_fmat->Info(); // number of valid trees if (ntree_limit == 0 || ntree_limit > model.trees.size()) { diff --git a/src/tree/gpu_hist/feature_groups.cu b/src/tree/gpu_hist/feature_groups.cu index 5a2c8ee6c..27ed9bd91 100644 --- a/src/tree/gpu_hist/feature_groups.cu +++ b/src/tree/gpu_hist/feature_groups.cu @@ -29,7 +29,7 @@ FeatureGroups::FeatureGroups(const common::HistogramCuts& cuts, bool is_dense, bin_segments_h.push_back(0); const std::vector& cut_ptrs = cuts.Ptrs(); - int max_shmem_bins = shm_size / bin_size; + size_t max_shmem_bins = shm_size / bin_size; max_group_bins = 0; for (size_t i = 2; i < cut_ptrs.size(); ++i) { diff --git a/src/tree/gpu_hist/histogram.cu b/src/tree/gpu_hist/histogram.cu index efb08d5e4..a63c6c954 100644 --- a/src/tree/gpu_hist/histogram.cu +++ b/src/tree/gpu_hist/histogram.cu @@ -188,7 +188,7 @@ void BuildGradientHistogram(EllpackDeviceAccessor const& matrix, int device = 0; dh::safe_cuda(cudaGetDevice(&device)); // opt into maximum shared memory for the kernel if necessary - int max_shared_memory = dh::MaxSharedMemoryOptin(device); + size_t max_shared_memory = dh::MaxSharedMemoryOptin(device); size_t smem_size = sizeof(typename HistRounding::SharedSumT) * feature_groups.max_group_bins; diff --git a/src/tree/gpu_hist/row_partitioner.cu b/src/tree/gpu_hist/row_partitioner.cu index 9e002f77b..44b962a96 100644 --- a/src/tree/gpu_hist/row_partitioner.cu +++ b/src/tree/gpu_hist/row_partitioner.cu @@ -79,6 +79,7 @@ void RowPartitioner::SortPosition(common::Span position, void Reset(int device_idx, common::Span ridx, common::Span position) { + dh::safe_cuda(cudaSetDevice(device_idx)); CHECK_EQ(ridx.size(), position.size()); dh::LaunchN(ridx.size(), [=] __device__(size_t idx) { ridx[idx] = idx; @@ -92,7 +93,7 @@ RowPartitioner::RowPartitioner(int device_idx, size_t num_rows) dh::safe_cuda(cudaSetDevice(device_idx_)); ridx_ = dh::DoubleBuffer{&ridx_a_, &ridx_b_}; position_ = dh::DoubleBuffer{&position_a_, &position_b_}; - ridx_segments_.emplace_back(Segment(0, num_rows)); + ridx_segments_.emplace_back(static_cast(0), num_rows); Reset(device_idx, ridx_.CurrentSpan(), position_.CurrentSpan()); left_counts_.resize(256); diff --git a/src/tree/hist/histogram.h b/src/tree/hist/histogram.h index 6b93577a0..70fad741b 100644 --- a/src/tree/hist/histogram.h +++ b/src/tree/hist/histogram.h @@ -140,9 +140,7 @@ class HistogramBuilder { nodes_for_subtraction_trick, starting_index, sync_count); } else { - this->SyncHistogramLocal(p_tree, nodes_for_explicit_hist_build, - nodes_for_subtraction_trick, starting_index, - sync_count); + this->SyncHistogramLocal(p_tree, nodes_for_explicit_hist_build, nodes_for_subtraction_trick); } } /** same as the other build hist but handles only single batch data (in-core) */ @@ -211,11 +209,9 @@ class HistogramBuilder { nodes_for_explicit_hist_build, p_tree); } - void SyncHistogramLocal( - RegTree *p_tree, - std::vector const &nodes_for_explicit_hist_build, - std::vector const &nodes_for_subtraction_trick, - int starting_index, int sync_count) { + void SyncHistogramLocal(RegTree *p_tree, + std::vector const &nodes_for_explicit_hist_build, + std::vector const &nodes_for_subtraction_trick) { const size_t nbins = this->builder_.GetNumBins(); common::BlockedSpace2d space( nodes_for_explicit_hist_build.size(), [&](size_t) { return nbins; }, diff --git a/src/tree/param.cc b/src/tree/param.cc index 6f5080ee2..1a52d9a8b 100644 --- a/src/tree/param.cc +++ b/src/tree/param.cc @@ -92,14 +92,14 @@ void ParseInteractionConstraint( for (size_t i = 0; i < all.size(); ++i) { auto const &set = get(all[i]); for (auto const &v : set) { - if (XGBOOST_EXPECT(IsA(v), true)) { - uint32_t u = static_cast(get(v)); + if (XGBOOST_EXPECT(IsA(v), true)) { + auto u = static_cast(get(v)); out[i].emplace_back(u); } else if (IsA(v)) { double d = get(v); CHECK_EQ(std::floor(d), d) << "Found floating point number in interaction constraints"; - out[i].emplace_back(static_cast(d)); + out[i].emplace_back(static_cast(d)); } else { LOG(FATAL) << "Unknown value type for interaction constraint:" << v.GetValue().TypeStr(); diff --git a/src/tree/tree_model.cc b/src/tree/tree_model.cc index d498c54ed..64f4b777d 100644 --- a/src/tree/tree_model.cc +++ b/src/tree/tree_model.cc @@ -354,10 +354,10 @@ class TextGenerator : public TreeGenerator { }; XGBOOST_REGISTER_TREE_IO(TextGenerator, "text") -.describe("Dump text representation of tree") -.set_body([](FeatureMap const& fmap, std::string const& attrs, bool with_stats) { - return new TextGenerator(fmap, with_stats); - }); + .describe("Dump text representation of tree") + .set_body([](FeatureMap const& fmap, std::string const& /*attrs*/, bool with_stats) { + return new TextGenerator(fmap, with_stats); + }); class JsonGenerator : public TreeGenerator { using SuperT = TreeGenerator; @@ -510,10 +510,10 @@ class JsonGenerator : public TreeGenerator { }; XGBOOST_REGISTER_TREE_IO(JsonGenerator, "json") -.describe("Dump json representation of tree") -.set_body([](FeatureMap const& fmap, std::string const& attrs, bool with_stats) { - return new JsonGenerator(fmap, with_stats); - }); + .describe("Dump json representation of tree") + .set_body([](FeatureMap const& fmap, std::string const& /*attrs*/, bool with_stats) { + return new JsonGenerator(fmap, with_stats); + }); struct GraphvizParam : public XGBoostParameter { std::string yes_color; diff --git a/src/tree/updater_colmaker.cc b/src/tree/updater_colmaker.cc index 7c076daab..f55769cc0 100644 --- a/src/tree/updater_colmaker.cc +++ b/src/tree/updater_colmaker.cc @@ -98,7 +98,7 @@ class ColMaker: public TreeUpdater { } void Update(HostDeviceVector *gpair, DMatrix *dmat, - common::Span> out_position, + common::Span> /*out_position*/, const std::vector &trees) override { if (rabit::IsDistributed()) { LOG(FATAL) << "Updater `grow_colmaker` or `exact` tree method doesn't " diff --git a/src/tree/updater_refresh.cc b/src/tree/updater_refresh.cc index 19bfe7d00..5dd7694b9 100644 --- a/src/tree/updater_refresh.cc +++ b/src/tree/updater_refresh.cc @@ -42,7 +42,7 @@ class TreeRefresher : public TreeUpdater { } // update the tree, do pruning void Update(HostDeviceVector *gpair, DMatrix *p_fmat, - common::Span> out_position, + common::Span> /*out_position*/, const std::vector &trees) override { if (trees.size() == 0) return; const std::vector &gpair_h = gpair->ConstHostVector(); diff --git a/src/tree/updater_sync.cc b/src/tree/updater_sync.cc index 308c7728d..5b89f80ec 100644 --- a/src/tree/updater_sync.cc +++ b/src/tree/updater_sync.cc @@ -33,7 +33,7 @@ class TreeSyncher : public TreeUpdater { } void Update(HostDeviceVector*, DMatrix*, - common::Span> out_position, + common::Span> /*out_position*/, const std::vector& trees) override { if (rabit::GetWorldSize() == 1) return; std::string s_model; diff --git a/tests/cpp/common/test_hist_util.cc b/tests/cpp/common/test_hist_util.cc index 418caab13..a095f6972 100644 --- a/tests/cpp/common/test_hist_util.cc +++ b/tests/cpp/common/test_hist_util.cc @@ -38,15 +38,16 @@ void ParallelGHistBuilderReset() { target_hist[i] = collection[i]; } - common::BlockedSpace2d space(kNodes, [&](size_t node) { return kTasksPerNode; }, 1); + common::BlockedSpace2d space( + kNodes, [&](size_t /* node*/) { return kTasksPerNode; }, 1); hist_builder.Reset(nthreads, kNodes, space, target_hist); - common::ParallelFor2d(space, nthreads, [&](size_t inode, common::Range1d r) { + common::ParallelFor2d(space, nthreads, [&](size_t inode, common::Range1d) { const size_t tid = omp_get_thread_num(); GHistRow hist = hist_builder.GetInitializedHist(tid, inode); // fill hist by some non-null values - for(size_t j = 0; j < kBins; ++j) { + for (size_t j = 0; j < kBins; ++j) { hist[j].Add(kValue, kValue); } }); @@ -56,15 +57,16 @@ void ParallelGHistBuilderReset() { for(size_t i = 0; i < target_hist.size(); ++i) { target_hist[i] = collection[i]; } - common::BlockedSpace2d space2(kNodesExtended, [&](size_t node) { return kTasksPerNode; }, 1); + common::BlockedSpace2d space2( + kNodesExtended, [&](size_t /*node*/) { return kTasksPerNode; }, 1); hist_builder.Reset(nthreads, kNodesExtended, space2, target_hist); - common::ParallelFor2d(space2, nthreads, [&](size_t inode, common::Range1d r) { + common::ParallelFor2d(space2, nthreads, [&](size_t inode, common::Range1d) { const size_t tid = omp_get_thread_num(); GHistRow hist = hist_builder.GetInitializedHist(tid, inode); // fill hist by some non-null values - for(size_t j = 0; j < kBins; ++j) { + for (size_t j = 0; j < kBins; ++j) { ASSERT_EQ(0.0, hist[j].GetGrad()); ASSERT_EQ(0.0, hist[j].GetHess()); } @@ -92,11 +94,12 @@ void ParallelGHistBuilderReduceHist(){ target_hist[i] = collection[i]; } - common::BlockedSpace2d space(kNodes, [&](size_t node) { return kTasksPerNode; }, 1); + common::BlockedSpace2d space( + kNodes, [&](size_t /*node*/) { return kTasksPerNode; }, 1); hist_builder.Reset(nthreads, kNodes, space, target_hist); // Simple analog of BuildHist function, works in parallel for both tree-nodes and data in node - common::ParallelFor2d(space, nthreads, [&](size_t inode, common::Range1d r) { + common::ParallelFor2d(space, nthreads, [&](size_t inode, common::Range1d) { const size_t tid = omp_get_thread_num(); GHistRow hist = hist_builder.GetInitializedHist(tid, inode); @@ -260,8 +263,7 @@ TEST(HistUtil, DenseCutsExternalMemory) { for (auto num_rows : sizes) { auto x = GenerateRandom(num_rows, num_columns); dmlc::TemporaryDirectory tmpdir; - auto dmat = - GetExternalMemoryDMatrixFromData(x, num_rows, num_columns, 50, tmpdir); + auto dmat = GetExternalMemoryDMatrixFromData(x, num_rows, num_columns, tmpdir); for (auto num_bins : bin_sizes) { HistogramCuts cuts = SketchOnDMatrix(dmat.get(), num_bins, common::OmpGetNumThreads(0)); ValidateCuts(cuts, dmat.get(), num_bins); diff --git a/tests/cpp/common/test_hist_util.cu b/tests/cpp/common/test_hist_util.cu index 612f84840..e92e2728e 100644 --- a/tests/cpp/common/test_hist_util.cu +++ b/tests/cpp/common/test_hist_util.cu @@ -252,8 +252,7 @@ TEST(HistUtil, DeviceSketchMultipleColumnsExternal) { for (auto num_rows : sizes) { auto x = GenerateRandom(num_rows, num_columns); dmlc::TemporaryDirectory temp; - auto dmat = - GetExternalMemoryDMatrixFromData(x, num_rows, num_columns, 100, temp); + auto dmat = GetExternalMemoryDMatrixFromData(x, num_rows, num_columns, temp); for (auto num_bins : bin_sizes) { auto cuts = DeviceSketch(0, dmat.get(), num_bins); ValidateCuts(cuts, dmat.get(), num_bins); @@ -269,7 +268,7 @@ TEST(HistUtil, DeviceSketchExternalMemoryWithWeights) { dmlc::TemporaryDirectory temp; for (auto num_rows : sizes) { auto x = GenerateRandom(num_rows, num_columns); - auto dmat = GetExternalMemoryDMatrixFromData(x, num_rows, num_columns, 100, temp); + auto dmat = GetExternalMemoryDMatrixFromData(x, num_rows, num_columns, temp); dmat->Info().weights_.HostVector() = GenerateRandomWeights(num_rows); for (auto num_bins : bin_sizes) { auto cuts = DeviceSketch(0, dmat.get(), num_bins); @@ -284,17 +283,15 @@ auto MakeUnweightedCutsForTest(Adapter adapter, int32_t num_bins, float missing, HostDeviceVector ft; SketchContainer sketch_container(ft, num_bins, adapter.NumColumns(), adapter.NumRows(), 0); MetaInfo info; - AdapterDeviceSketch(adapter.Value(), num_bins, info, std::numeric_limits::quiet_NaN(), - &sketch_container); + AdapterDeviceSketch(adapter.Value(), num_bins, info, missing, &sketch_container, batch_size); sketch_container.MakeCuts(&batched_cuts); return batched_cuts; } template -void ValidateBatchedCuts(Adapter adapter, int num_bins, int num_columns, int num_rows, - DMatrix* dmat, size_t batch_size = 0) { +void ValidateBatchedCuts(Adapter adapter, int num_bins, DMatrix* dmat, size_t batch_size = 0) { common::HistogramCuts batched_cuts = MakeUnweightedCutsForTest( - adapter, num_bins, std::numeric_limits::quiet_NaN()); + adapter, num_bins, std::numeric_limits::quiet_NaN(), batch_size); ValidateCuts(batched_cuts, dmat, num_bins); } @@ -448,8 +445,7 @@ TEST(HistUtil, AdapterDeviceSketchCategorical) { auto dmat = GetDMatrixFromData(x, n, 1); auto x_device = thrust::device_vector(x); auto adapter = AdapterFromData(x_device, n, 1); - ValidateBatchedCuts(adapter, num_bins, adapter.NumColumns(), - adapter.NumRows(), dmat.get()); + ValidateBatchedCuts(adapter, num_bins, dmat.get()); TestCategoricalSketchAdapter(n, num_categories, num_bins, true); TestCategoricalSketchAdapter(n, num_categories, num_bins, false); } @@ -466,7 +462,7 @@ TEST(HistUtil, AdapterDeviceSketchMultipleColumns) { auto x_device = thrust::device_vector(x); for (auto num_bins : bin_sizes) { auto adapter = AdapterFromData(x_device, num_rows, num_columns); - ValidateBatchedCuts(adapter, num_bins, num_columns, num_rows, dmat.get()); + ValidateBatchedCuts(adapter, num_bins, dmat.get()); } } } @@ -481,7 +477,7 @@ TEST(HistUtil, AdapterDeviceSketchBatches) { auto dmat = GetDMatrixFromData(x, num_rows, num_columns); auto x_device = thrust::device_vector(x); auto adapter = AdapterFromData(x_device, num_rows, num_columns); - ValidateBatchedCuts(adapter, num_bins, num_columns, num_rows, dmat.get(), batch_size); + ValidateBatchedCuts(adapter, num_bins, dmat.get(), batch_size); } } @@ -504,7 +500,7 @@ TEST(HistUtil, SketchingEquivalent) { EXPECT_EQ(dmat_cuts.Ptrs(), adapter_cuts.Ptrs()); EXPECT_EQ(dmat_cuts.MinValues(), adapter_cuts.MinValues()); - ValidateBatchedCuts(adapter, num_bins, num_columns, num_rows, dmat.get()); + ValidateBatchedCuts(adapter, num_bins, dmat.get()); } } } diff --git a/tests/cpp/common/test_hist_util.h b/tests/cpp/common/test_hist_util.h index 5b16bd0b1..37a38d1b3 100644 --- a/tests/cpp/common/test_hist_util.h +++ b/tests/cpp/common/test_hist_util.h @@ -74,7 +74,7 @@ GetDMatrixFromData(const std::vector &x, int num_rows, int num_columns) { inline std::shared_ptr GetExternalMemoryDMatrixFromData( const std::vector& x, int num_rows, int num_columns, - size_t page_size, const dmlc::TemporaryDirectory& tempdir) { + const dmlc::TemporaryDirectory& tempdir) { // Create the svm file in a temp dir const std::string tmp_file = tempdir.path + "/temp.libsvm"; std::ofstream fo(tmp_file.c_str()); @@ -92,10 +92,9 @@ inline std::shared_ptr GetExternalMemoryDMatrixFromData( } // Test that elements are approximately equally distributed among bins -inline void TestBinDistribution(const HistogramCuts &cuts, int column_idx, - const std::vector &sorted_column, - const std::vector &sorted_weights, - int num_bins) { +inline void TestBinDistribution(const HistogramCuts& cuts, int column_idx, + const std::vector& sorted_column, + const std::vector& sorted_weights) { std::map bin_weights; for (auto i = 0ull; i < sorted_column.size(); i++) { auto bin_idx = cuts.SearchBin(sorted_column[i], column_idx); @@ -175,7 +174,7 @@ inline void ValidateColumn(const HistogramCuts& cuts, int column_idx, std::copy(cuts.Values().begin() + cuts.Ptrs()[column_idx], cuts.Values().begin() + cuts.Ptrs()[column_idx + 1], column_cuts.begin()); - TestBinDistribution(cuts, column_idx, sorted_column, sorted_weights, num_bins); + TestBinDistribution(cuts, column_idx, sorted_column, sorted_weights); TestRank(column_cuts, sorted_column, sorted_weights); } } diff --git a/tests/cpp/common/test_quantile.cu b/tests/cpp/common/test_quantile.cu index dcb82d29c..a179ab7f9 100644 --- a/tests/cpp/common/test_quantile.cu +++ b/tests/cpp/common/test_quantile.cu @@ -79,6 +79,7 @@ TEST(GPUQuantile, Unique) { // if with_error is true, the test tolerates floating point error void TestQuantileElemRank(int32_t device, Span in, Span d_columns_ptr, bool with_error = false) { + dh::safe_cuda(cudaSetDevice(device)); std::vector h_in(in.size()); dh::CopyDeviceSpanToVector(&h_in, in); std::vector h_columns_ptr(d_columns_ptr.size()); @@ -478,7 +479,7 @@ TEST(GPUQuantile, SameOnAllWorkers) { dh::CopyDeviceSpanToVector(&h_base_line, base_line); size_t offset = 0; - for (size_t i = 0; i < world; ++i) { + for (decltype(world) i = 0; i < world; ++i) { auto comp = dh::ToSpan(all_workers).subspan(offset, size_as_float); std::vector h_comp(comp.size()); dh::CopyDeviceSpanToVector(&h_comp, comp); diff --git a/tests/cpp/common/test_span.h b/tests/cpp/common/test_span.h index 8f5e9fc76..11a67caab 100644 --- a/tests/cpp/common/test_span.h +++ b/tests/cpp/common/test_span.h @@ -248,7 +248,7 @@ struct TestIterCompare { XGBOOST_DEVICE void operator()() { this->operator()(0); } - XGBOOST_DEVICE void operator()(int _idx) { + XGBOOST_DEVICE void operator()(size_t) { // size_t for CUDA index float arr[16]; InitializeRange(arr, arr + 16); Span s (arr); diff --git a/tests/cpp/common/test_threading_utils.cc b/tests/cpp/common/test_threading_utils.cc index 8867b5f7d..5607e6d05 100644 --- a/tests/cpp/common/test_threading_utils.cc +++ b/tests/cpp/common/test_threading_utils.cc @@ -12,9 +12,8 @@ TEST(CreateBlockedSpace2d, Test) { constexpr size_t kDim2 = 3; constexpr size_t kGrainSize = 1; - BlockedSpace2d space(kDim1, [&](size_t i) { - return kDim2; - }, kGrainSize); + BlockedSpace2d space( + kDim1, [&](size_t) { return kDim2; }, kGrainSize); ASSERT_EQ(kDim1 * kDim2, space.Size()); diff --git a/tests/cpp/helpers.cc b/tests/cpp/helpers.cc index 736c43ef7..00e3c447c 100644 --- a/tests/cpp/helpers.cc +++ b/tests/cpp/helpers.cc @@ -651,7 +651,7 @@ RMMAllocatorPtr SetUpRMMResourceForCppTests(int argc, char** argv) { #else // defined(XGBOOST_USE_RMM) && XGBOOST_USE_RMM == 1 class RMMAllocator {}; -void DeleteRMMResource(RMMAllocator* r) {} +void DeleteRMMResource(RMMAllocator*) {} RMMAllocatorPtr SetUpRMMResourceForCppTests(int, char**) { return {nullptr, DeleteRMMResource}; } #endif // !defined(XGBOOST_USE_RMM) || XGBOOST_USE_RMM != 1 diff --git a/tests/cpp/predictor/test_gpu_predictor.cu b/tests/cpp/predictor/test_gpu_predictor.cu index 56ad28d46..fa849cf51 100644 --- a/tests/cpp/predictor/test_gpu_predictor.cu +++ b/tests/cpp/predictor/test_gpu_predictor.cu @@ -56,7 +56,7 @@ TEST(GPUPredictor, Basic) { std::vector& gpu_out_predictions_h = gpu_out_predictions.predictions.HostVector(); std::vector& cpu_out_predictions_h = cpu_out_predictions.predictions.HostVector(); float abs_tolerance = 0.001; - for (int j = 0; j < gpu_out_predictions.predictions.Size(); j++) { + for (size_t j = 0; j < gpu_out_predictions.predictions.Size(); j++) { ASSERT_NEAR(gpu_out_predictions_h[j], cpu_out_predictions_h[j], abs_tolerance); } } @@ -118,7 +118,7 @@ TEST(GPUPredictor, ExternalMemoryTest) { gpu_predictor->PredictBatch(dmat.get(), &out_predictions, model, 0); EXPECT_EQ(out_predictions.predictions.Size(), dmat->Info().num_row_ * n_classes); const std::vector &host_vector = out_predictions.predictions.ConstHostVector(); - for (int i = 0; i < host_vector.size() / n_classes; i++) { + for (size_t i = 0; i < host_vector.size() / n_classes; i++) { ASSERT_EQ(host_vector[i * n_classes], 2.0); ASSERT_EQ(host_vector[i * n_classes + 1], 0.5); ASSERT_EQ(host_vector[i * n_classes + 2], 0.5); diff --git a/tests/cpp/predictor/test_predictor.cc b/tests/cpp/predictor/test_predictor.cc index 832d2cf4c..71eee8bb3 100644 --- a/tests/cpp/predictor/test_predictor.cc +++ b/tests/cpp/predictor/test_predictor.cc @@ -45,7 +45,7 @@ void TestTrainingPrediction(size_t rows, size_t bins, size_t constexpr kIters = 3; std::unique_ptr learner; - auto train = [&](std::string predictor, HostDeviceVector *out) { + auto train = [&](std::string predictor) { p_hist->Info().labels.Reshape(rows, 1); auto &h_label = p_hist->Info().labels.Data()->HostVector(); @@ -59,6 +59,7 @@ void TestTrainingPrediction(size_t rows, size_t bins, learner->SetParam("num_feature", std::to_string(kCols)); learner->SetParam("num_class", std::to_string(kClasses)); learner->SetParam("max_bin", std::to_string(bins)); + learner->SetParam("predictor", predictor); learner->Configure(); for (size_t i = 0; i < kIters; ++i) { @@ -77,11 +78,11 @@ void TestTrainingPrediction(size_t rows, size_t bins, } }; - HostDeviceVector predictions_0; - train("cpu_predictor", &predictions_0); - - HostDeviceVector predictions_1; - train("gpu_predictor", &predictions_1); + if (tree_method == "gpu_hist") { + train("gpu_predictor"); + } else { + train("cpu_predictor"); + } } void TestInplacePrediction(std::shared_ptr x, std::string predictor, bst_row_t rows, diff --git a/tests/cpp/tree/gpu_hist/test_histogram.cu b/tests/cpp/tree/gpu_hist/test_histogram.cu index 75d97b681..a24bc1e1f 100644 --- a/tests/cpp/tree/gpu_hist/test_histogram.cu +++ b/tests/cpp/tree/gpu_hist/test_histogram.cu @@ -143,7 +143,6 @@ void TestGPUHistogramCategorical(size_t num_categories) { std::vector h_cat_hist(cat_hist.size()); thrust::copy(cat_hist.begin(), cat_hist.end(), h_cat_hist.begin()); - auto cat_sum = std::accumulate(h_cat_hist.begin(), h_cat_hist.end(), GradientPairPrecise{}); std::vector h_encode_hist(encode_hist.size()); thrust::copy(encode_hist.begin(), encode_hist.end(), h_encode_hist.begin()); diff --git a/tests/cpp/tree/gpu_hist/test_row_partitioner.cu b/tests/cpp/tree/gpu_hist/test_row_partitioner.cu index c8aaf82dc..cf1710699 100644 --- a/tests/cpp/tree/gpu_hist/test_row_partitioner.cu +++ b/tests/cpp/tree/gpu_hist/test_row_partitioner.cu @@ -119,7 +119,7 @@ void TestFinalise() { rp.FinalisePosition( &ctx, task, &position, [=] __device__(RowPartitioner::RowIndexT ridx, int position) { return 7; }, - [] XGBOOST_DEVICE(size_t idx) { return false; }); + [] XGBOOST_DEVICE(size_t) { return false; }); auto position = rp.GetPositionHost(); for (auto p : position) { diff --git a/tests/cpp/tree/hist/test_histogram.cc b/tests/cpp/tree/hist/test_histogram.cc index d20c3d0d8..3ce6c9989 100644 --- a/tests/cpp/tree/hist/test_histogram.cc +++ b/tests/cpp/tree/hist/test_histogram.cc @@ -181,8 +181,7 @@ void TestSyncHist(bool is_distributed) { starting_index, sync_count); } else { histogram.SyncHistogramLocal(&tree, nodes_for_explicit_hist_build_, - nodes_for_subtraction_trick_, starting_index, - sync_count); + nodes_for_subtraction_trick_); } using GHistRowT = common::GHistRow;