From 3fc1046fd3917b928e7dfa4c9a951627c444c470 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Tue, 29 Nov 2022 00:04:16 +0800 Subject: [PATCH] Reduce compiler warnings on CPU-only build. (#8483) --- include/xgboost/data.h | 2 +- src/data/data.cc | 4 +--- src/data/ellpack_page.cc | 4 ++-- src/data/ellpack_page.cu | 2 +- src/data/ellpack_page.cuh | 2 +- src/data/sparse_page_dmatrix.cc | 6 +++--- src/data/sparse_page_source.cu | 4 ++-- src/gbm/gbtree.cc | 14 ++++++------ src/learner.cc | 1 + src/metric/auc.cc | 37 +++++++++++++------------------- src/metric/auc.cu | 38 ++++++++++++++++----------------- src/metric/auc.h | 38 ++++++++++++++++----------------- 12 files changed, 69 insertions(+), 83 deletions(-) diff --git a/include/xgboost/data.h b/include/xgboost/data.h index 91976a48d..9fb643541 100644 --- a/include/xgboost/data.h +++ b/include/xgboost/data.h @@ -417,7 +417,7 @@ class EllpackPage { size_t Size() const; /*! \brief Set the base row id for this page. */ - void SetBaseRowId(size_t row_id); + void SetBaseRowId(std::size_t row_id); const EllpackPageImpl* Impl() const { return impl_.get(); } EllpackPageImpl* Impl() { return impl_.get(); } diff --git a/src/data/data.cc b/src/data/data.cc index a4293d7b5..fb46b487b 100644 --- a/src/data/data.cc +++ b/src/data/data.cc @@ -734,9 +734,7 @@ void MetaInfo::Validate(int32_t device) const { } #if !defined(XGBOOST_USE_CUDA) -void MetaInfo::SetInfoFromCUDA(Context const& ctx, StringView key, Json arr) { - common::AssertGPUSupport(); -} +void MetaInfo::SetInfoFromCUDA(Context const&, StringView, Json) { common::AssertGPUSupport(); } #endif // !defined(XGBOOST_USE_CUDA) using DMatrixThreadLocal = diff --git a/src/data/ellpack_page.cc b/src/data/ellpack_page.cc index 2784ddefd..b1f24506e 100644 --- a/src/data/ellpack_page.cc +++ b/src/data/ellpack_page.cc @@ -12,7 +12,7 @@ class EllpackPageImpl {}; EllpackPage::EllpackPage() = default; -EllpackPage::EllpackPage(DMatrix* dmat, const BatchParam& param) { +EllpackPage::EllpackPage(DMatrix*, const BatchParam&) { LOG(FATAL) << "Internal Error: XGBoost is not compiled with CUDA but " "EllpackPage is required"; } @@ -22,7 +22,7 @@ EllpackPage::~EllpackPage() { "EllpackPage is required"; } -void EllpackPage::SetBaseRowId(size_t row_id) { +void EllpackPage::SetBaseRowId(std::size_t) { LOG(FATAL) << "Internal Error: XGBoost is not compiled with CUDA but " "EllpackPage is required"; } diff --git a/src/data/ellpack_page.cu b/src/data/ellpack_page.cu index 11de33d8f..076b8ed4b 100644 --- a/src/data/ellpack_page.cu +++ b/src/data/ellpack_page.cu @@ -25,7 +25,7 @@ EllpackPage::EllpackPage(EllpackPage&& that) { std::swap(impl_, that.impl_); } size_t EllpackPage::Size() const { return impl_->Size(); } -void EllpackPage::SetBaseRowId(size_t row_id) { impl_->SetBaseRowId(row_id); } +void EllpackPage::SetBaseRowId(std::size_t row_id) { impl_->SetBaseRowId(row_id); } // Bin each input data entry, store the bin indices in compressed form. __global__ void CompressBinEllpackKernel( diff --git a/src/data/ellpack_page.cuh b/src/data/ellpack_page.cuh index 16e2f13b3..faf44b3b6 100644 --- a/src/data/ellpack_page.cuh +++ b/src/data/ellpack_page.cuh @@ -190,7 +190,7 @@ class EllpackPageImpl { size_t Size() const; /*! \brief Set the base row id for this page. */ - void SetBaseRowId(size_t row_id) { + void SetBaseRowId(std::size_t row_id) { base_rowid = row_id; } diff --git a/src/data/sparse_page_dmatrix.cc b/src/data/sparse_page_dmatrix.cc index df9d99fdd..7881c62d2 100644 --- a/src/data/sparse_page_dmatrix.cc +++ b/src/data/sparse_page_dmatrix.cc @@ -19,7 +19,7 @@ const MetaInfo &SparsePageDMatrix::Info() const { return info_; } namespace detail { // Use device dispatch -size_t NSamplesDevice(DMatrixProxy *proxy) +std::size_t NSamplesDevice(DMatrixProxy *) #if defined(XGBOOST_USE_CUDA) ; // NOLINT #else @@ -28,7 +28,7 @@ size_t NSamplesDevice(DMatrixProxy *proxy) return 0; } #endif -size_t NFeaturesDevice(DMatrixProxy *proxy) +std::size_t NFeaturesDevice(DMatrixProxy *) #if defined(XGBOOST_USE_CUDA) ; // NOLINT #else @@ -189,7 +189,7 @@ BatchSet SparsePageDMatrix::GetGradientIndex(const BatchParam } #if !defined(XGBOOST_USE_CUDA) -BatchSet SparsePageDMatrix::GetEllpackBatches(const BatchParam& param) { +BatchSet SparsePageDMatrix::GetEllpackBatches(const BatchParam &) { common::AssertGPUSupport(); auto begin_iter = BatchIterator(ellpack_page_source_); return BatchSet(BatchIterator(begin_iter)); diff --git a/src/data/sparse_page_source.cu b/src/data/sparse_page_source.cu index bcadffaff..41d4f3584 100644 --- a/src/data/sparse_page_source.cu +++ b/src/data/sparse_page_source.cu @@ -9,11 +9,11 @@ namespace xgboost { namespace data { namespace detail { -size_t NSamplesDevice(DMatrixProxy *proxy) { +std::size_t NSamplesDevice(DMatrixProxy *proxy) { return Dispatch(proxy, [](auto const &value) { return value.NumRows(); }); } -size_t NFeaturesDevice(DMatrixProxy *proxy) { +std::size_t NFeaturesDevice(DMatrixProxy *proxy) { return Dispatch(proxy, [](auto const &value) { return value.NumCols(); }); } } // namespace detail diff --git a/src/gbm/gbtree.cc b/src/gbm/gbtree.cc index e9e888a98..c7b916e38 100644 --- a/src/gbm/gbtree.cc +++ b/src/gbm/gbtree.cc @@ -191,11 +191,10 @@ void GBTree::ConfigureUpdaters() { } } -void GPUCopyGradient(HostDeviceVector const *in_gpair, - bst_group_t n_groups, bst_group_t group_id, - HostDeviceVector *out_gpair) +void GPUCopyGradient(HostDeviceVector const*, bst_group_t, bst_group_t, + HostDeviceVector*) #if defined(XGBOOST_USE_CUDA) -; // NOLINT + ; // NOLINT #else { common::AssertGPUSupport(); @@ -627,11 +626,10 @@ GBTree::GetPredictor(HostDeviceVector const *out_pred, * \param predts Prediction for current tree. * \param tree_w Tree weight. */ -void GPUDartPredictInc(common::Span out_predts, - common::Span predts, float tree_w, size_t n_rows, - bst_group_t n_groups, bst_group_t group) +void GPUDartPredictInc(common::Span, common::Span, float, size_t, bst_group_t, + bst_group_t) #if defined(XGBOOST_USE_CUDA) -; // NOLINT + ; // NOLINT #else { common::AssertGPUSupport(); diff --git a/src/learner.cc b/src/learner.cc index 7a8d9a4e1..3d3d18535 100644 --- a/src/learner.cc +++ b/src/learner.cc @@ -343,6 +343,7 @@ void GenericParameter::ConfigureGpuId(bool require_gpu) { #else // Just set it to CPU, don't think about it. this->UpdateAllowUnknown(Args{{"gpu_id", std::to_string(kCpuId)}}); + (void)(require_gpu); #endif // defined(XGBOOST_USE_CUDA) common::SetDevice(this->gpu_id); diff --git a/src/metric/auc.cc b/src/metric/auc.cc index 2cda80f06..318a3d4aa 100644 --- a/src/metric/auc.cc +++ b/src/metric/auc.cc @@ -390,24 +390,21 @@ XGBOOST_REGISTER_METRIC(EvalAUC, "auc") .set_body([](const char*) { return new EvalROCAUC(); }); #if !defined(XGBOOST_USE_CUDA) -std::tuple -GPUBinaryROCAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache) { +std::tuple GPUBinaryROCAUC(common::Span, MetaInfo const &, + std::int32_t, + std::shared_ptr *) { common::AssertGPUSupport(); return {}; } -double GPUMultiClassROCAUC(common::Span predts, - MetaInfo const &info, int32_t device, - std::shared_ptr *cache, - size_t n_classes) { +double GPUMultiClassROCAUC(common::Span, MetaInfo const &, std::int32_t, + std::shared_ptr *, std::size_t) { common::AssertGPUSupport(); return 0.0; } -std::pair -GPURankingAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache) { +std::pair GPURankingAUC(common::Span, MetaInfo const &, + std::int32_t, std::shared_ptr *) { common::AssertGPUSupport(); return {}; } @@ -432,8 +429,8 @@ class EvalPRAUC : public EvalAUC { return std::make_tuple(pr, re, auc); } - double EvalMultiClass(HostDeviceVector const &predts, - MetaInfo const &info, size_t n_classes) { + double EvalMultiClass(HostDeviceVector const &predts, MetaInfo const &info, + size_t n_classes) { if (tparam_->gpu_id == GenericParameter::kCpuId) { auto n_threads = this->tparam_->Threads(); return MultiClassOVR(predts.ConstHostSpan(), info, n_classes, n_threads, @@ -472,24 +469,20 @@ XGBOOST_REGISTER_METRIC(AUCPR, "aucpr") .set_body([](char const *) { return new EvalPRAUC{}; }); #if !defined(XGBOOST_USE_CUDA) -std::tuple -GPUBinaryPRAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache) { +std::tuple GPUBinaryPRAUC(common::Span, MetaInfo const &, + std::int32_t, std::shared_ptr *) { common::AssertGPUSupport(); return {}; } -double GPUMultiClassPRAUC(common::Span predts, - MetaInfo const &info, int32_t device, - std::shared_ptr *cache, - size_t n_classes) { +double GPUMultiClassPRAUC(common::Span, MetaInfo const &, std::int32_t, + std::shared_ptr *, std::size_t) { common::AssertGPUSupport(); return {}; } -std::pair -GPURankingPRAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *cache) { +std::pair GPURankingPRAUC(common::Span, MetaInfo const &, + std::int32_t, std::shared_ptr *) { common::AssertGPUSupport(); return {}; } diff --git a/src/metric/auc.cu b/src/metric/auc.cu index 0c5e9612d..646e670b6 100644 --- a/src/metric/auc.cu +++ b/src/metric/auc.cu @@ -162,9 +162,9 @@ GPUBinaryAUC(common::Span predts, MetaInfo const &info, return std::make_tuple(last.first, last.second, auc); } -std::tuple -GPUBinaryROCAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache) { +std::tuple GPUBinaryROCAUC(common::Span predts, + MetaInfo const &info, std::int32_t device, + std::shared_ptr *p_cache) { auto &cache = *p_cache; InitCacheOnce(predts, p_cache); @@ -451,10 +451,9 @@ void MultiClassSortedIdx(common::Span predts, dh::SegmentedArgSort(d_predts_t, d_class_ptr, d_sorted_idx); } -double GPUMultiClassROCAUC(common::Span predts, - MetaInfo const &info, int32_t device, - std::shared_ptr *p_cache, - size_t n_classes) { +double GPUMultiClassROCAUC(common::Span predts, MetaInfo const &info, + std::int32_t device, std::shared_ptr *p_cache, + std::size_t n_classes) { auto& cache = *p_cache; InitCacheOnce(predts, p_cache); @@ -480,9 +479,9 @@ struct RankScanItem { }; } // anonymous namespace -std::pair -GPURankingAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache) { +std::pair GPURankingAUC(common::Span predts, + MetaInfo const &info, std::int32_t device, + std::shared_ptr *p_cache) { auto& cache = *p_cache; InitCacheOnce(predts, p_cache); @@ -600,9 +599,9 @@ GPURankingAUC(common::Span predts, MetaInfo const &info, return std::make_pair(auc, n_valid); } -std::tuple -GPUBinaryPRAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache) { +std::tuple GPUBinaryPRAUC(common::Span predts, + MetaInfo const &info, std::int32_t device, + std::shared_ptr *p_cache) { auto& cache = *p_cache; InitCacheOnce(predts, p_cache); @@ -640,10 +639,9 @@ GPUBinaryPRAUC(common::Span predts, MetaInfo const &info, return std::make_tuple(1.0, 1.0, auc); } -double GPUMultiClassPRAUC(common::Span predts, - MetaInfo const &info, int32_t device, - std::shared_ptr *p_cache, - size_t n_classes) { +double GPUMultiClassPRAUC(common::Span predts, MetaInfo const &info, + std::int32_t device, std::shared_ptr *p_cache, + std::size_t n_classes) { auto& cache = *p_cache; InitCacheOnce(predts, p_cache); @@ -816,9 +814,9 @@ GPURankingPRAUCImpl(common::Span predts, MetaInfo const &info, return std::make_pair(auc, n_groups - invalid_groups); } -std::pair -GPURankingPRAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache) { +std::pair GPURankingPRAUC(common::Span predts, + MetaInfo const &info, std::int32_t device, + std::shared_ptr *p_cache) { dh::safe_cuda(cudaSetDevice(device)); if (predts.empty()) { return std::make_pair(0.0, static_cast(0)); diff --git a/src/metric/auc.h b/src/metric/auc.h index ab205bf7e..b92188068 100644 --- a/src/metric/auc.h +++ b/src/metric/auc.h @@ -29,34 +29,32 @@ XGBOOST_DEVICE inline double TrapezoidArea(double x0, double x1, double y0, doub struct DeviceAUCCache; -std::tuple -GPUBinaryROCAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache); +std::tuple GPUBinaryROCAUC(common::Span predts, + MetaInfo const &info, std::int32_t device, + std::shared_ptr *p_cache); -double GPUMultiClassROCAUC(common::Span predts, - MetaInfo const &info, int32_t device, - std::shared_ptr *cache, - size_t n_classes); +double GPUMultiClassROCAUC(common::Span predts, MetaInfo const &info, + std::int32_t device, std::shared_ptr *cache, + std::size_t n_classes); -std::pair -GPURankingAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *cache); +std::pair GPURankingAUC(common::Span predts, + MetaInfo const &info, std::int32_t device, + std::shared_ptr *cache); /********** * PR AUC * **********/ -std::tuple -GPUBinaryPRAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *p_cache); +std::tuple GPUBinaryPRAUC(common::Span predts, + MetaInfo const &info, std::int32_t device, + std::shared_ptr *p_cache); -double GPUMultiClassPRAUC(common::Span predts, - MetaInfo const &info, int32_t device, - std::shared_ptr *cache, - size_t n_classes); +double GPUMultiClassPRAUC(common::Span predts, MetaInfo const &info, + std::int32_t device, std::shared_ptr *cache, + std::size_t n_classes); -std::pair -GPURankingPRAUC(common::Span predts, MetaInfo const &info, - int32_t device, std::shared_ptr *cache); +std::pair GPURankingPRAUC(common::Span predts, + MetaInfo const &info, std::int32_t device, + std::shared_ptr *cache); namespace detail { XGBOOST_DEVICE inline double CalcH(double fp_a, double fp_b, double tp_a,