Fix compiler warnings. (#7974)

- Remove unused parameters. There are still many warnings that are not yet
addressed. Currently, the warnings in dmlc-core dominate the error log.
- Remove `distributed` parameter from metric.
- Fixes some warnings about signed comparison.
This commit is contained in:
Jiaming Yuan
2022-06-06 22:56:25 +08:00
committed by GitHub
parent d48123d23b
commit 1a33b50a0d
46 changed files with 149 additions and 189 deletions

View File

@@ -254,8 +254,7 @@ std::pair<double, uint32_t> RankingAUC(std::vector<float> const &predts,
template <typename Curve>
class EvalAUC : public Metric {
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info,
bool distributed) override {
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info) override {
double auc {0};
if (tparam_->gpu_id != GenericParameter::kCpuId) {
preds.SetDevice(tparam_->gpu_id);

View File

@@ -312,10 +312,8 @@ void SegmentedReduceAUC(common::Span<size_t const> d_unique_idx,
* up each class in all kernels.
*/
template <bool scale, typename Fn>
double GPUMultiClassAUCOVR(common::Span<float const> predts,
MetaInfo const &info, int32_t device,
common::Span<uint32_t> d_class_ptr, size_t n_classes,
std::shared_ptr<DeviceAUCCache> cache, Fn area_fn) {
double GPUMultiClassAUCOVR(MetaInfo const &info, int32_t device, common::Span<uint32_t> d_class_ptr,
size_t n_classes, std::shared_ptr<DeviceAUCCache> cache, Fn area_fn) {
dh::safe_cuda(cudaSetDevice(device));
/**
* Sorted idx
@@ -478,8 +476,7 @@ double GPUMultiClassROCAUC(common::Span<float const> predts,
double tp, size_t /*class_id*/) {
return TrapezoidArea(fp_prev, fp, tp_prev, tp);
};
return GPUMultiClassAUCOVR<true>(predts, info, device, dh::ToSpan(class_ptr),
n_classes, cache, fn);
return GPUMultiClassAUCOVR<true>(info, device, dh::ToSpan(class_ptr), n_classes, cache, fn);
}
namespace {
@@ -704,8 +701,7 @@ double GPUMultiClassPRAUC(common::Span<float const> predts,
return detail::CalcDeltaPRAUC(fp_prev, fp, tp_prev, tp,
d_totals[class_id].first);
};
return GPUMultiClassAUCOVR<false>(predts, info, device, d_class_ptr,
n_classes, cache, fn);
return GPUMultiClassAUCOVR<false>(info, device, d_class_ptr, n_classes, cache, fn);
}
template <typename Fn>

View File

@@ -178,8 +178,7 @@ class PseudoErrorLoss : public Metric {
out["pseudo_huber_param"] = ToJson(param_);
}
double Eval(const HostDeviceVector<bst_float>& preds, const MetaInfo& info,
bool distributed) override {
double Eval(const HostDeviceVector<bst_float>& preds, const MetaInfo& info) override {
CHECK_EQ(info.labels.Shape(0), info.num_row_);
auto labels = info.labels.View(tparam_->gpu_id);
preds.SetDevice(tparam_->gpu_id);
@@ -197,7 +196,7 @@ class PseudoErrorLoss : public Metric {
return std::make_tuple(v, wt);
});
double dat[2]{result.Residue(), result.Weights()};
if (distributed) {
if (rabit::IsDistributed()) {
rabit::Allreduce<rabit::op::Sum>(dat, 2);
}
return EvalRowMAPE::GetFinal(dat[0], dat[1]);
@@ -342,8 +341,7 @@ struct EvalEWiseBase : public Metric {
EvalEWiseBase() = default;
explicit EvalEWiseBase(char const* policy_param) : policy_{policy_param} {}
double Eval(HostDeviceVector<bst_float> const& preds, const MetaInfo& info,
bool distributed) override {
double Eval(HostDeviceVector<bst_float> const& preds, const MetaInfo& info) override {
CHECK_EQ(preds.Size(), info.labels.Size())
<< "label and prediction size not match, "
<< "hint: use merror or mlogloss for multi-class classification";
@@ -367,10 +365,7 @@ struct EvalEWiseBase : public Metric {
});
double dat[2]{result.Residue(), result.Weights()};
if (distributed) {
rabit::Allreduce<rabit::op::Sum>(dat, 2);
}
rabit::Allreduce<rabit::op::Sum>(dat, 2);
return Policy::GetFinal(dat[0], dat[1]);
}

View File

@@ -167,8 +167,7 @@ class MultiClassMetricsReduction {
*/
template<typename Derived>
struct EvalMClassBase : public Metric {
double Eval(const HostDeviceVector<float> &preds, const MetaInfo &info,
bool distributed) override {
double Eval(const HostDeviceVector<float> &preds, const MetaInfo &info) override {
if (info.labels.Size() == 0) {
CHECK_EQ(preds.Size(), 0);
} else {
@@ -186,9 +185,7 @@ struct EvalMClassBase : public Metric {
dat[0] = result.Residue();
dat[1] = result.Weights();
}
if (distributed) {
rabit::Allreduce<rabit::op::Sum>(dat, 2);
}
rabit::Allreduce<rabit::op::Sum>(dat, 2);
return Derived::GetFinal(dat[0], dat[1]);
}
/*!

View File

@@ -102,9 +102,8 @@ struct EvalAMS : public Metric {
name_ = os.str();
}
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info,
bool distributed) override {
CHECK(!distributed) << "metric AMS do not support distributed evaluation";
double Eval(const HostDeviceVector<bst_float>& preds, const MetaInfo& info) override {
CHECK(!rabit::IsDistributed()) << "metric AMS do not support distributed evaluation";
using namespace std; // NOLINT(*)
const auto ndata = static_cast<bst_omp_uint>(info.labels.Size());
@@ -161,8 +160,7 @@ struct EvalRank : public Metric, public EvalRankConfig {
std::unique_ptr<xgboost::Metric> rank_gpu_;
public:
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info,
bool distributed) override {
double Eval(const HostDeviceVector<bst_float>& preds, const MetaInfo& info) override {
CHECK_EQ(preds.Size(), info.labels.Size())
<< "label size predict size not match";
@@ -185,7 +183,7 @@ struct EvalRank : public Metric, public EvalRankConfig {
rank_gpu_.reset(GPUMetric::CreateGPUMetric(this->Name(), tparam_));
}
if (rank_gpu_) {
sum_metric = rank_gpu_->Eval(preds, info, distributed);
sum_metric = rank_gpu_->Eval(preds, info);
}
}
@@ -218,7 +216,7 @@ struct EvalRank : public Metric, public EvalRankConfig {
exc.Rethrow();
}
if (distributed) {
if (rabit::IsDistributed()) {
double dat[2]{sum_metric, static_cast<double>(ngroups)};
// approximately estimate the metric using mean
rabit::Allreduce<rabit::op::Sum>(dat, 2);
@@ -342,9 +340,8 @@ struct EvalMAP : public EvalRank {
struct EvalCox : public Metric {
public:
EvalCox() = default;
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info,
bool distributed) override {
CHECK(!distributed) << "Cox metric does not support distributed evaluation";
double Eval(const HostDeviceVector<bst_float>& preds, const MetaInfo& info) override {
CHECK(!rabit::IsDistributed()) << "Cox metric does not support distributed evaluation";
using namespace std; // NOLINT(*)
const auto ndata = static_cast<bst_omp_uint>(info.labels.Size());

View File

@@ -29,8 +29,7 @@ DMLC_REGISTRY_FILE_TAG(rank_metric_gpu);
template <typename EvalMetricT>
struct EvalRankGpu : public GPUMetric, public EvalRankConfig {
public:
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info,
bool distributed) override {
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info) override {
// Sanity check is done by the caller
std::vector<unsigned> tgptr(2, 0);
tgptr[1] = static_cast<unsigned>(preds.Size());

View File

@@ -206,20 +206,15 @@ template <typename Policy> struct EvalEWiseSurvivalBase : public Metric {
CHECK(tparam_);
}
double Eval(const HostDeviceVector<float> &preds, const MetaInfo &info,
bool distributed) override {
double Eval(const HostDeviceVector<float>& preds, const MetaInfo& info) override {
CHECK_EQ(preds.Size(), info.labels_lower_bound_.Size());
CHECK_EQ(preds.Size(), info.labels_upper_bound_.Size());
CHECK(tparam_);
auto result =
reducer_.Reduce(*tparam_, info.weights_, info.labels_lower_bound_,
info.labels_upper_bound_, preds);
auto result = reducer_.Reduce(*tparam_, info.weights_, info.labels_lower_bound_,
info.labels_upper_bound_, preds);
double dat[2] {result.Residue(), result.Weights()};
if (distributed) {
rabit::Allreduce<rabit::op::Sum>(dat, 2);
}
double dat[2]{result.Residue(), result.Weights()};
rabit::Allreduce<rabit::op::Sum>(dat, 2);
return Policy::GetFinal(dat[0], dat[1]);
}
@@ -240,10 +235,9 @@ struct AFTNLogLikDispatcher : public Metric {
return "aft-nloglik";
}
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info,
bool distributed) override {
double Eval(const HostDeviceVector<bst_float>& preds, const MetaInfo& info) override {
CHECK(metric_) << "AFT metric must be configured first, with distribution type and scale";
return metric_->Eval(preds, info, distributed);
return metric_->Eval(preds, info);
}
void Configure(const Args& args) override {