Rename and extract Context. (#8528)
* Rename `GenericParameter` to `Context`. * Rename header file to reflect the change. * Rename all references.
This commit is contained in:
@@ -79,14 +79,14 @@ double MultiClassOVR(common::Span<float const> predts, MetaInfo const &info,
|
||||
size_t n_classes, int32_t n_threads,
|
||||
BinaryAUC &&binary_auc) {
|
||||
CHECK_NE(n_classes, 0);
|
||||
auto const labels = info.labels.View(GenericParameter::kCpuId);
|
||||
auto const labels = info.labels.View(Context::kCpuId);
|
||||
if (labels.Shape(0) != 0) {
|
||||
CHECK_EQ(labels.Shape(1), 1) << "AUC doesn't support multi-target model.";
|
||||
}
|
||||
|
||||
std::vector<double> results_storage(n_classes * 3, 0);
|
||||
linalg::TensorView<double, 2> results(results_storage, {n_classes, static_cast<size_t>(3)},
|
||||
GenericParameter::kCpuId);
|
||||
Context::kCpuId);
|
||||
auto local_area = results.Slice(linalg::All(), 0);
|
||||
auto tp = results.Slice(linalg::All(), 1);
|
||||
auto auc = results.Slice(linalg::All(), 2);
|
||||
@@ -94,7 +94,7 @@ double MultiClassOVR(common::Span<float const> predts, MetaInfo const &info,
|
||||
auto weights = common::OptionalWeights{info.weights_.ConstHostSpan()};
|
||||
auto predts_t = linalg::TensorView<float const, 2>(
|
||||
predts, {static_cast<size_t>(info.num_row_), n_classes},
|
||||
GenericParameter::kCpuId);
|
||||
Context::kCpuId);
|
||||
|
||||
if (info.labels.Size() != 0) {
|
||||
common::ParallelFor(n_classes, n_threads, [&](auto c) {
|
||||
@@ -215,7 +215,7 @@ std::pair<double, uint32_t> RankingAUC(std::vector<float> const &predts,
|
||||
CHECK_GE(info.group_ptr_.size(), 2);
|
||||
uint32_t n_groups = info.group_ptr_.size() - 1;
|
||||
auto s_predts = common::Span<float const>{predts};
|
||||
auto labels = info.labels.View(GenericParameter::kCpuId);
|
||||
auto labels = info.labels.View(Context::kCpuId);
|
||||
auto s_weights = info.weights_.ConstHostSpan();
|
||||
|
||||
std::atomic<uint32_t> invalid_groups{0};
|
||||
@@ -255,7 +255,7 @@ template <typename Curve>
|
||||
class EvalAUC : public Metric {
|
||||
double Eval(const HostDeviceVector<bst_float> &preds, const MetaInfo &info) override {
|
||||
double auc {0};
|
||||
if (tparam_->gpu_id != GenericParameter::kCpuId) {
|
||||
if (tparam_->gpu_id != Context::kCpuId) {
|
||||
preds.SetDevice(tparam_->gpu_id);
|
||||
info.labels.SetDevice(tparam_->gpu_id);
|
||||
info.weights_.SetDevice(tparam_->gpu_id);
|
||||
@@ -340,7 +340,7 @@ class EvalROCAUC : public EvalAUC<EvalROCAUC> {
|
||||
double auc{0};
|
||||
uint32_t valid_groups = 0;
|
||||
auto n_threads = tparam_->Threads();
|
||||
if (tparam_->gpu_id == GenericParameter::kCpuId) {
|
||||
if (tparam_->gpu_id == Context::kCpuId) {
|
||||
std::tie(auc, valid_groups) =
|
||||
RankingAUC<true>(predts.ConstHostVector(), info, n_threads);
|
||||
} else {
|
||||
@@ -355,7 +355,7 @@ class EvalROCAUC : public EvalAUC<EvalROCAUC> {
|
||||
double auc{0};
|
||||
auto n_threads = tparam_->Threads();
|
||||
CHECK_NE(n_classes, 0);
|
||||
if (tparam_->gpu_id == GenericParameter::kCpuId) {
|
||||
if (tparam_->gpu_id == Context::kCpuId) {
|
||||
auc = MultiClassOVR(predts.ConstHostVector(), info, n_classes, n_threads,
|
||||
BinaryROCAUC);
|
||||
} else {
|
||||
@@ -368,7 +368,7 @@ class EvalROCAUC : public EvalAUC<EvalROCAUC> {
|
||||
std::tuple<double, double, double>
|
||||
EvalBinary(HostDeviceVector<float> const &predts, MetaInfo const &info) {
|
||||
double fp, tp, auc;
|
||||
if (tparam_->gpu_id == GenericParameter::kCpuId) {
|
||||
if (tparam_->gpu_id == Context::kCpuId) {
|
||||
std::tie(fp, tp, auc) =
|
||||
BinaryROCAUC(predts.ConstHostVector(), info.labels.HostView().Slice(linalg::All(), 0),
|
||||
common::OptionalWeights{info.weights_.ConstHostSpan()});
|
||||
@@ -418,7 +418,7 @@ class EvalPRAUC : public EvalAUC<EvalPRAUC> {
|
||||
std::tuple<double, double, double>
|
||||
EvalBinary(HostDeviceVector<float> const &predts, MetaInfo const &info) {
|
||||
double pr, re, auc;
|
||||
if (tparam_->gpu_id == GenericParameter::kCpuId) {
|
||||
if (tparam_->gpu_id == Context::kCpuId) {
|
||||
std::tie(pr, re, auc) =
|
||||
BinaryPRAUC(predts.ConstHostSpan(), info.labels.HostView().Slice(linalg::All(), 0),
|
||||
common::OptionalWeights{info.weights_.ConstHostSpan()});
|
||||
@@ -431,7 +431,7 @@ class EvalPRAUC : public EvalAUC<EvalPRAUC> {
|
||||
|
||||
double EvalMultiClass(HostDeviceVector<float> const &predts, MetaInfo const &info,
|
||||
size_t n_classes) {
|
||||
if (tparam_->gpu_id == GenericParameter::kCpuId) {
|
||||
if (tparam_->gpu_id == Context::kCpuId) {
|
||||
auto n_threads = this->tparam_->Threads();
|
||||
return MultiClassOVR(predts.ConstHostSpan(), info, n_classes, n_threads,
|
||||
BinaryPRAUC);
|
||||
@@ -446,7 +446,7 @@ class EvalPRAUC : public EvalAUC<EvalPRAUC> {
|
||||
double auc{0};
|
||||
uint32_t valid_groups = 0;
|
||||
auto n_threads = tparam_->Threads();
|
||||
if (tparam_->gpu_id == GenericParameter::kCpuId) {
|
||||
if (tparam_->gpu_id == Context::kCpuId) {
|
||||
auto labels = info.labels.Data()->ConstHostSpan();
|
||||
if (std::any_of(labels.cbegin(), labels.cend(), PRAUCLabelInvalid{})) {
|
||||
InvalidLabels();
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace {
|
||||
* applying the weights. A tuple of {error_i, weight_i} is expected as return.
|
||||
*/
|
||||
template <typename Fn>
|
||||
PackedReduceResult Reduce(GenericParameter const* ctx, MetaInfo const& info, Fn&& loss) {
|
||||
PackedReduceResult Reduce(Context const* ctx, MetaInfo const& info, Fn&& loss) {
|
||||
PackedReduceResult result;
|
||||
auto labels = info.labels.View(ctx->gpu_id);
|
||||
if (ctx->IsCPU()) {
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* \brief Registry of objective functions.
|
||||
*/
|
||||
#include <dmlc/registry.h>
|
||||
#include <xgboost/context.h>
|
||||
#include <xgboost/metric.h>
|
||||
#include <xgboost/generic_parameters.h>
|
||||
|
||||
#include "metric_common.h"
|
||||
|
||||
@@ -43,7 +43,7 @@ Metric* CreateMetricImpl(const std::string& name) {
|
||||
}
|
||||
|
||||
Metric *
|
||||
Metric::Create(const std::string& name, GenericParameter const* tparam) {
|
||||
Metric::Create(const std::string& name, Context const* tparam) {
|
||||
auto metric = CreateMetricImpl<MetricReg>(name);
|
||||
if (metric == nullptr) {
|
||||
LOG(FATAL) << "Unknown metric function " << name;
|
||||
@@ -54,7 +54,7 @@ Metric::Create(const std::string& name, GenericParameter const* tparam) {
|
||||
}
|
||||
|
||||
Metric *
|
||||
GPUMetric::CreateGPUMetric(const std::string& name, GenericParameter const* tparam) {
|
||||
GPUMetric::CreateGPUMetric(const std::string& name, Context const* tparam) {
|
||||
auto metric = CreateMetricImpl<MetricGPUReg>(name);
|
||||
if (metric == nullptr) {
|
||||
LOG(WARNING) << "Cannot find a GPU metric builder for metric " << name
|
||||
|
||||
@@ -12,12 +12,13 @@
|
||||
#include "xgboost/metric.h"
|
||||
|
||||
namespace xgboost {
|
||||
struct Context;
|
||||
|
||||
// This creates a GPU metric instance dynamically and adds it to the GPU metric registry, if not
|
||||
// present already. This is created when there is a device ordinal present and if xgboost
|
||||
// is compiled with CUDA support
|
||||
struct GPUMetric : Metric {
|
||||
static Metric *CreateGPUMetric(const std::string& name, GenericParameter const* tparam);
|
||||
static Metric *CreateGPUMetric(const std::string &name, Context const *tparam);
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
@@ -126,13 +126,10 @@ class MultiClassMetricsReduction {
|
||||
|
||||
#endif // XGBOOST_USE_CUDA
|
||||
|
||||
PackedReduceResult Reduce(
|
||||
const GenericParameter &tparam,
|
||||
int device,
|
||||
size_t n_class,
|
||||
const HostDeviceVector<bst_float>& weights,
|
||||
const HostDeviceVector<bst_float>& labels,
|
||||
const HostDeviceVector<bst_float>& preds) {
|
||||
PackedReduceResult Reduce(const Context& tparam, int device, size_t n_class,
|
||||
const HostDeviceVector<bst_float>& weights,
|
||||
const HostDeviceVector<bst_float>& labels,
|
||||
const HostDeviceVector<bst_float>& preds) {
|
||||
PackedReduceResult result;
|
||||
|
||||
if (device < 0) {
|
||||
|
||||
@@ -118,7 +118,7 @@ struct EvalAMS : public Metric {
|
||||
const double br = 10.0;
|
||||
unsigned thresindex = 0;
|
||||
double s_tp = 0.0, b_fp = 0.0, tams = 0.0;
|
||||
const auto& labels = info.labels.View(GenericParameter::kCpuId);
|
||||
const auto& labels = info.labels.View(Context::kCpuId);
|
||||
for (unsigned i = 0; i < static_cast<unsigned>(ndata-1) && i < ntop; ++i) {
|
||||
const unsigned ridx = rec[i].second;
|
||||
const bst_float wt = info.GetWeight(ridx);
|
||||
@@ -191,7 +191,7 @@ struct EvalRank : public Metric, public EvalRankConfig {
|
||||
std::vector<double> sum_tloc(tparam_->Threads(), 0.0);
|
||||
|
||||
if (!rank_gpu_ || tparam_->gpu_id < 0) {
|
||||
const auto& labels = info.labels.View(GenericParameter::kCpuId);
|
||||
const auto& labels = info.labels.View(Context::kCpuId);
|
||||
const auto &h_preds = preds.ConstHostVector();
|
||||
|
||||
dmlc::OMPException exc;
|
||||
|
||||
@@ -123,7 +123,7 @@ class ElementWiseSurvivalMetricsReduction {
|
||||
#endif // XGBOOST_USE_CUDA
|
||||
|
||||
PackedReduceResult Reduce(
|
||||
const GenericParameter &ctx,
|
||||
const Context &ctx,
|
||||
const HostDeviceVector<bst_float>& weights,
|
||||
const HostDeviceVector<bst_float>& labels_lower_bound,
|
||||
const HostDeviceVector<bst_float>& labels_upper_bound,
|
||||
@@ -195,7 +195,7 @@ struct EvalAFTNLogLik {
|
||||
};
|
||||
|
||||
template <typename Policy> struct EvalEWiseSurvivalBase : public Metric {
|
||||
explicit EvalEWiseSurvivalBase(GenericParameter const *ctx) {
|
||||
explicit EvalEWiseSurvivalBase(Context const *ctx) {
|
||||
tparam_ = ctx;
|
||||
}
|
||||
EvalEWiseSurvivalBase() = default;
|
||||
|
||||
Reference in New Issue
Block a user