MCPcopy Create free account
hub / github.com/dmlc/xgboost / SparsePageDMatrix

Method SparsePageDMatrix

src/data/sparse_page_dmatrix.cc:27–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25const MetaInfo &SparsePageDMatrix::Info() const { return info_; }
26
27SparsePageDMatrix::SparsePageDMatrix(DataIterHandle iter_handle, DMatrixHandle proxy_handle,
28 DataIterResetCallback *reset, XGDMatrixCallbackNext *next,
29 ExtMemConfig const &config)
30 : proxy_{proxy_handle},
31 iter_{iter_handle},
32 reset_{reset},
33 next_{next},
34 missing_{config.missing},
35 cache_prefix_{config.cache},
36 on_host_{config.on_host},
37 cache_host_ratio_{config.cache_host_ratio},
38 min_cache_page_bytes_{config.min_cache_page_bytes} {
39 CHECK(detail::HostRatioIsAuto(config.cache_host_ratio)) << error::CacheHostRatioNotImpl();
40 Context ctx;
41 ctx.Init(Args{{"nthread", std::to_string(config.n_threads)}});
42 cache_prefix_ = MakeCachePrefix(cache_prefix_);
43
44 DMatrixProxy *proxy = MakeProxy(proxy_);
45 auto iter = DataIterProxy<DataIterResetCallback, XGDMatrixCallbackNext>{iter_, reset_, next_};
46
47 auto get_cats = [](DMatrixProxy const *proxy) {
48 if (proxy->Ctx()->IsCPU()) {
49 return std::make_shared<CatContainer>(cpu_impl::BatchCats(proxy), BatchCatsIsRef(proxy));
50 } else {
51#if defined(XGBOOST_USE_CUDA)
52 return std::make_shared<CatContainer>(proxy->Ctx(), cuda_impl::BatchCats(proxy),
53 BatchCatsIsRef(proxy));
54#else
55 common::AssertGPUSupport();
56 return std::make_shared<CatContainer>();
57#endif
58 }
59 };
60
61 // The proxy is iterated together with the sparse page source so we can obtain all
62 // information in 1 pass.
63 for (auto const &page : this->GetRowBatchesImpl(&ctx)) {
64 this->info_.Extend(std::move(proxy->Info()), false, false);
65 ext_info_.n_features =
66 std::max(static_cast<bst_feature_t>(ext_info_.n_features), BatchColumns(proxy));
67 ext_info_.accumulated_rows += BatchSamples(proxy);
68 ext_info_.nnz += page.data.Size();
69 ext_info_.n_batches++;
70 ext_info_.base_rowids.push_back(page.Size());
71 ext_info_.batch_nnz.push_back(page.data.Size());
72 if (!ext_info_.cats) {
73 ext_info_.cats = get_cats(proxy);
74 } else {
75 CHECK_EQ(ext_info_.cats->NumCatsTotal(), get_cats(proxy)->NumCatsTotal())
76 << error::InconsistentCategories();
77 }
78 }
79 std::partial_sum(ext_info_.base_rowids.cbegin(), ext_info_.base_rowids.cend(),
80 ext_info_.base_rowids.begin());
81
82 iter.Reset();
83
84 ext_info_.SetInfo(&ctx, true, &this->info_);

Callers

nothing calls this directly

Calls 15

GetRowBatchesImplMethod · 0.95
HostRatioIsAutoFunction · 0.85
CacheHostRatioNotImplFunction · 0.85
MakeCachePrefixFunction · 0.85
MakeProxyFunction · 0.85
BatchCatsFunction · 0.85
BatchCatsIsRefFunction · 0.85
AssertGPUSupportFunction · 0.85
InconsistentCategoriesFunction · 0.85
SyncCategoriesFunction · 0.85
NumCatsTotalMethod · 0.80
BatchColumnsFunction · 0.70

Tested by

no test coverage detected