Medial Code Documentation
Loading...
Searching...
No Matches
sparse_page_writer.h
Go to the documentation of this file.
1
6#ifndef XGBOOST_DATA_SPARSE_PAGE_WRITER_H_
7#define XGBOOST_DATA_SPARSE_PAGE_WRITER_H_
8
9#include <functional> // for function
10#include <string> // for string
11
12#include "../common/io.h" // for AlignedResourceReadStream, AlignedFileWriteStream
13#include "dmlc/io.h" // for Stream
14#include "dmlc/registry.h" // for Registry, FunctionRegEntryBase
15#include "xgboost/data.h" // for SparsePage,CSCPage,SortedCSCPage,EllpackPage ...
16
17namespace xgboost::data {
18template<typename T>
19struct SparsePageFormatReg;
20
24template <typename T>
26 public:
27 virtual ~SparsePageFormat() = default;
35 virtual bool Read(T* page, common::AlignedResourceReadStream* fi) = 0;
41 virtual size_t Write(const T& page, common::AlignedFileWriteStream* fo) = 0;
42};
43
48template<typename T>
49inline SparsePageFormat<T>* CreatePageFormat(const std::string& name) {
50 auto *e = ::dmlc::Registry<SparsePageFormatReg<T>>::Get()->Find(name);
51 if (e == nullptr) {
52 LOG(FATAL) << "Unknown format type " << name;
53 return nullptr;
54 }
55 return (e->body)();
56}
57
61template<typename T>
63 : public dmlc::FunctionRegEntryBase<SparsePageFormatReg<T>,
64 std::function<SparsePageFormat<T>* ()>> {
65};
66
79#define SparsePageFmt SparsePageFormat<SparsePage>
80#define XGBOOST_REGISTER_SPARSE_PAGE_FORMAT(Name) \
81 DMLC_REGISTRY_REGISTER(SparsePageFormatReg<SparsePage>, SparsePageFmt, Name)
82
83#define CSCPageFmt SparsePageFormat<CSCPage>
84#define XGBOOST_REGISTER_CSC_PAGE_FORMAT(Name) \
85 DMLC_REGISTRY_REGISTER(SparsePageFormatReg<CSCPage>, CSCPageFmt, Name)
86
87#define SortedCSCPageFmt SparsePageFormat<SortedCSCPage>
88#define XGBOOST_REGISTER_SORTED_CSC_PAGE_FORMAT(Name) \
89 DMLC_REGISTRY_REGISTER(SparsePageFormatReg<SortedCSCPage>, SortedCSCPageFmt, Name)
90
91#define EllpackPageFmt SparsePageFormat<EllpackPage>
92#define XGBOOST_REGISTER_ELLPACK_PAGE_FORMAT(Name) \
93 DMLC_REGISTRY_REGISTER(SparsePageFormatReg<EllpackPage>, EllpackPageFmt, Name)
94
95#define GHistIndexPageFmt SparsePageFormat<GHistIndexMatrix>
96#define XGBOOST_REGISTER_GHIST_INDEX_PAGE_FORMAT(Name) \
97 DMLC_REGISTRY_REGISTER(SparsePageFormatReg<GHistIndexMatrix>, \
98 GHistIndexPageFmt, Name)
99
100} // namespace xgboost::data
101#endif // XGBOOST_DATA_SPARSE_PAGE_WRITER_H_
Common base class for function registry.
Definition registry.h:151
Registry class. Registry can be used to register global singletons. The most commonly use case are fa...
Definition registry.h:27
static const EntryType * Find(const std::string &name)
Find the entry with corresponding name.
Definition registry.h:48
Output stream backed by a file.
Definition io.h:426
Wrap resource into a dmlc stream.
Definition io.h:282
Format specification of various data formats like SparsePage.
Definition sparse_page_writer.h:25
virtual size_t Write(const T &page, common::AlignedFileWriteStream *fo)=0
save the data to fo, when a page was written.
virtual bool Read(T *page, common::AlignedResourceReadStream *fi)=0
Load all the segments into page, advance fi to end of the block.
defines serializable interface of dmlc
Copyright 2015-2023 by XGBoost Contributors.
Copyright 2019-2023, XGBoost Contributors.
Definition data.py:1
SparsePageFormat< T > * CreatePageFormat(const std::string &name)
Create sparse page of format.
Definition sparse_page_writer.h:49
Registry utility that helps to build registry singletons.
Registry entry for sparse page format.
Definition sparse_page_writer.h:64