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

Function TestHistogramExternalMemory

tests/cpp/tree/hist/test_histogram.cc:410–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408}
409namespace {
410void TestHistogramExternalMemory(Context const *ctx, BatchParam batch_param, bool is_approx,
411 bool force_read_by_column) {
412 size_t constexpr kEntries = 1 << 16;
413 auto m =
414 RandomDataGenerator{kEntries / 8, 8, 0.0f}.Batches(4).GenerateSparsePageDMatrix("temp", true);
415
416 std::vector<float> hess(m->Info().num_row_, 1.0);
417 if (is_approx) {
418 batch_param.hess = hess;
419 }
420
421 std::vector<bst_idx_t> partition_size(1, 0);
422 bst_bin_t total_bins{0};
423 bst_idx_t n_samples{0};
424
425 auto gpair = GenerateRandomGradients(m->Info().num_row_, 0.0, 1.0);
426 auto const &h_gpair = gpair.HostVector();
427
428 RegTree tree;
429 std::vector<bst_node_t> nodes{RegTree::kRoot};
430 common::BlockedSpace2d space{
431 1, [&](std::size_t nidx_in_set) { return partition_size.at(nidx_in_set); }, 256};
432
433 common::GHistRow multi_page;
434 HistogramBuilder multi_build;
435 HistMakerTrainParam hist_param;
436 std::vector<bst_node_t> dummy_sub;
437 {
438 /**
439 * Multi page
440 */
441 std::vector<common::RowSetCollection> rows_set;
442 for (auto const &page : m->GetBatches<GHistIndexMatrix>(ctx, batch_param)) {
443 CHECK_LT(page.base_rowid, m->Info().num_row_);
444 auto n_rows_in_node = page.Size();
445 partition_size[0] = std::max(partition_size[0], n_rows_in_node);
446 total_bins = page.cut.TotalBins();
447 n_samples += n_rows_in_node;
448
449 rows_set.emplace_back();
450 InitRowPartitionForTest(&rows_set.back(), n_rows_in_node, page.base_rowid);
451 }
452 ASSERT_EQ(n_samples, m->Info().num_row_);
453
454 multi_build.Reset(ctx, total_bins, batch_param, false, false, &hist_param);
455 multi_build.AddHistRows(tree.HostScView(), &nodes, &dummy_sub, false);
456 std::size_t page_idx{0};
457 for (auto const &page : m->GetBatches<GHistIndexMatrix>(ctx, batch_param)) {
458 multi_build.BuildHist(page_idx, space, page, rows_set[page_idx], nodes,
459 linalg::MakeTensorView(ctx, h_gpair, h_gpair.size()),
460 force_read_by_column);
461 ++page_idx;
462 }
463 multi_build.SyncHistogram(ctx, tree.HostScView(), nodes, {});
464
465 multi_page = multi_build.Histogram()[RegTree::kRoot];
466 }
467

Callers 1

TESTFunction · 0.85

Calls 15

GenerateRandomGradientsFunction · 0.85
InitRowPartitionForTestFunction · 0.85
MakeTensorViewFunction · 0.85
SketchOnDMatrixFunction · 0.85
BatchesMethod · 0.80
HostScViewMethod · 0.80
SyncHistogramMethod · 0.80
GetGradMethod · 0.80
GetHessMethod · 0.80
InfoMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected