Medial Code Documentation
Loading...
Searching...
No Matches
iterative_dmatrix.h
Go to the documentation of this file.
1
7#ifndef XGBOOST_DATA_ITERATIVE_DMATRIX_H_
8#define XGBOOST_DATA_ITERATIVE_DMATRIX_H_
9
10#include <memory>
11#include <string>
12#include <utility>
13#include <vector>
14
15#include "../common/error_msg.h"
16#include "proxy_dmatrix.h"
17#include "simple_batch_iterator.h"
18#include "xgboost/base.h"
19#include "xgboost/c_api.h"
20#include "xgboost/context.h" // for Context
21#include "xgboost/data.h"
22
23namespace xgboost {
24namespace common {
25class HistogramCuts;
26}
27
28namespace data {
48class IterativeDMatrix : public DMatrix {
49 MetaInfo info_;
50 std::shared_ptr<EllpackPage> ellpack_;
51 std::shared_ptr<GHistIndexMatrix> ghist_;
52 BatchParam batch_;
53
54 DMatrixHandle proxy_;
57 Context fmat_ctx_;
58
59 void CheckParam(BatchParam const &param) {
60 CHECK_EQ(param.max_bin, batch_.max_bin) << error::InconsistentMaxBin();
61 CHECK(!param.regen && param.hess.empty())
62 << "Only `hist` and `gpu_hist` tree method can use `QuantileDMatrix`.";
63 }
64
65 template <typename Page>
66 static auto InvalidTreeMethod() {
67 LOG(FATAL) << "Only `hist` and `gpu_hist` tree method can use `QuantileDMatrix`.";
68 return BatchSet<Page>(BatchIterator<Page>(nullptr));
69 }
70
71 void InitFromCUDA(Context const *ctx, BatchParam const &p, DataIterHandle iter_handle,
72 float missing, std::shared_ptr<DMatrix> ref);
73 void InitFromCPU(Context const *ctx, BatchParam const &p, DataIterHandle iter_handle,
74 float missing, std::shared_ptr<DMatrix> ref);
75
76 public:
77 explicit IterativeDMatrix(DataIterHandle iter_handle, DMatrixHandle proxy,
78 std::shared_ptr<DMatrix> ref, DataIterResetCallback *reset,
79 XGDMatrixCallbackNext *next, float missing, int nthread,
80 bst_bin_t max_bin);
81 ~IterativeDMatrix() override = default;
82
83 bool EllpackExists() const override { return static_cast<bool>(ellpack_); }
84 bool GHistIndexExists() const override { return static_cast<bool>(ghist_); }
85 bool SparsePageExists() const override { return false; }
86
87 DMatrix *Slice(common::Span<int32_t const>) override {
88 LOG(FATAL) << "Slicing DMatrix is not supported for Quantile DMatrix.";
89 return nullptr;
90 }
91 DMatrix *SliceCol(int, int) override {
92 LOG(FATAL) << "Slicing DMatrix columns is not supported for Quantile DMatrix.";
93 return nullptr;
94 }
95 BatchSet<SparsePage> GetRowBatches() override {
96 LOG(FATAL) << "Not implemented.";
98 }
99 BatchSet<CSCPage> GetColumnBatches(Context const *) override {
100 return InvalidTreeMethod<CSCPage>();
101 }
102 BatchSet<SortedCSCPage> GetSortedColumnBatches(Context const *) override {
103 return InvalidTreeMethod<SortedCSCPage>();
104 }
105 BatchSet<GHistIndexMatrix> GetGradientIndex(Context const *ctx, BatchParam const &param) override;
106
107 BatchSet<EllpackPage> GetEllpackBatches(Context const *ctx, const BatchParam &param) override;
108 BatchSet<ExtSparsePage> GetExtBatches(Context const *ctx, BatchParam const &param) override;
109
110 bool SingleColBlock() const override { return true; }
111
112 MetaInfo &Info() override { return info_; }
113 MetaInfo const &Info() const override { return info_; }
114
115 Context const *Ctx() const override { return &fmat_ctx_; }
116};
117
127void GetCutsFromRef(Context const *ctx, std::shared_ptr<DMatrix> ref, bst_feature_t n_features,
133} // namespace data
134} // namespace xgboost
135
136#endif // XGBOOST_DATA_ITERATIVE_DMATRIX_H_
Definition data.h:458
Definition data.h:494
A page stored in ELLPACK format.
Definition ellpack_page.h:21
Meta information about dataset, always sit in memory.
Definition data.h:48
Definition hist_util.h:37
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition span.h:424
Definition core.py:748
DMatrix type for QuantileDMatrix, the naming IterativeDMatix is due to its construction process.
Definition iterative_dmatrix.h:48
Copyright 2014-2023, XGBoost Contributors.
XGB_EXTERN_C typedef int XGDMatrixCallbackNext(DataIterHandle iter)
Callback function prototype for getting next batch of data.
XGB_EXTERN_C typedef void DataIterResetCallback(DataIterHandle handle)
Callback function prototype for resetting external iterator.
Copyright 2015-2023 by XGBoost Contributors.
Copyright 2015-2023 by XGBoost Contributors.
void GetCutsFromRef(Context const *ctx, std::shared_ptr< DMatrix > ref, bst_feature_t n_features, BatchParam p, common::HistogramCuts *p_cuts)
Get quantile cuts from reference (Quantile)DMatrix.
Definition iterative_dmatrix.cc:54
void GetCutsFromEllpack(EllpackPage const &, common::HistogramCuts *)
Get quantile cuts from ellpack page.
Definition iterative_dmatrix.cc:377
namespace of xgboost
Definition base.h:90
uint32_t bst_feature_t
Type for data column (feature) index.
Definition base.h:101
int32_t bst_bin_t
Type for histogram bin index.
Definition base.h:103
Parameters for constructing histogram index batches.
Definition data.h:244
bst_bin_t max_bin
Maximum number of bins per feature for histograms.
Definition data.h:248
Runtime context for XGBoost.
Definition context.h:84
Copyright 2015~2023 by XGBoost Contributors.