From baba3e9eb045bdcdddd2ce46951a2e3831239d95 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Wed, 10 Jul 2024 13:01:47 +0800 Subject: [PATCH] Fix empty partition. (#10559) --- src/common/hist_util.cc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/common/hist_util.cc b/src/common/hist_util.cc index 9b703a3fa..7107cb2de 100644 --- a/src/common/hist_util.cc +++ b/src/common/hist_util.cc @@ -201,7 +201,7 @@ void RowsWiseBuildHistKernel(Span gpair, auto const &row_ptr = gmat.row_ptr.data(); auto base_rowid = gmat.base_rowid; - uint32_t const *offsets = gmat.index.Offset(); + std::uint32_t const *offsets = gmat.index.Offset(); // There's no feature-based compression if missing value is present. if (kAnyMissing) { CHECK(!offsets); @@ -212,8 +212,11 @@ void RowsWiseBuildHistKernel(Span gpair, auto get_row_ptr = [&](bst_idx_t ridx) { return kFirstPage ? row_ptr[ridx] : row_ptr[ridx - base_rowid]; }; - auto get_rid = [&](bst_idx_t ridx) { return kFirstPage ? ridx : (ridx - base_rowid); }; + auto get_rid = [&](bst_idx_t ridx) { + return kFirstPage ? ridx : (ridx - base_rowid); + }; + CHECK_NE(row_indices.Size(), 0); const size_t n_features = get_row_ptr(row_indices.begin[0] + 1) - get_row_ptr(row_indices.begin[0]); auto hist_data = reinterpret_cast(hist.data()); @@ -325,16 +328,20 @@ void BuildHistDispatch(Span gpair, const RowSetCollection::E if (contiguousBlock) { // contiguous memory access, built-in HW prefetching is enough + if (row_indices.Size() == 0) { + return; + } RowsWiseBuildHistKernel(gpair, row_indices, gmat, hist); } else { - const RowSetCollection::Elem span1(row_indices.begin, - row_indices.end - no_prefetch_size); - const RowSetCollection::Elem span2(row_indices.end - no_prefetch_size, - row_indices.end); - - RowsWiseBuildHistKernel(gpair, span1, gmat, hist); + const RowSetCollection::Elem span1(row_indices.begin, row_indices.end - no_prefetch_size); + if (span1.Size() != 0) { + RowsWiseBuildHistKernel(gpair, span1, gmat, hist); + } // no prefetching to avoid loading extra memory - RowsWiseBuildHistKernel(gpair, span2, gmat, hist); + const RowSetCollection::Elem span2(row_indices.end - no_prefetch_size, row_indices.end); + if (span2.Size() != 0) { + RowsWiseBuildHistKernel(gpair, span2, gmat, hist); + } } } }