Skip to content

Commit 086ca69

Browse files
authored
[backport]Fix empty partition. (dmlc#10559) (dmlc#10579)
1 parent 644e001 commit 086ca69

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/common/hist_util.cc

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void RowsWiseBuildHistKernel(Span<GradientPair const> gpair,
201201

202202
auto const &row_ptr = gmat.row_ptr.data();
203203
auto base_rowid = gmat.base_rowid;
204-
uint32_t const *offsets = gmat.index.Offset();
204+
std::uint32_t const *offsets = gmat.index.Offset();
205205
// There's no feature-based compression if missing value is present.
206206
if (kAnyMissing) {
207207
CHECK(!offsets);
@@ -212,8 +212,11 @@ void RowsWiseBuildHistKernel(Span<GradientPair const> gpair,
212212
auto get_row_ptr = [&](bst_idx_t ridx) {
213213
return kFirstPage ? row_ptr[ridx] : row_ptr[ridx - base_rowid];
214214
};
215-
auto get_rid = [&](bst_idx_t ridx) { return kFirstPage ? ridx : (ridx - base_rowid); };
215+
auto get_rid = [&](bst_idx_t ridx) {
216+
return kFirstPage ? ridx : (ridx - base_rowid);
217+
};
216218

219+
CHECK_NE(row_indices.Size(), 0);
217220
const size_t n_features =
218221
get_row_ptr(row_indices.begin[0] + 1) - get_row_ptr(row_indices.begin[0]);
219222
auto hist_data = reinterpret_cast<double *>(hist.data());
@@ -325,16 +328,20 @@ void BuildHistDispatch(Span<GradientPair const> gpair, const RowSetCollection::E
325328

326329
if (contiguousBlock) {
327330
// contiguous memory access, built-in HW prefetching is enough
331+
if (row_indices.Size() == 0) {
332+
return;
333+
}
328334
RowsWiseBuildHistKernel<false, BuildingManager>(gpair, row_indices, gmat, hist);
329335
} else {
330-
const RowSetCollection::Elem span1(row_indices.begin,
331-
row_indices.end - no_prefetch_size);
332-
const RowSetCollection::Elem span2(row_indices.end - no_prefetch_size,
333-
row_indices.end);
334-
335-
RowsWiseBuildHistKernel<true, BuildingManager>(gpair, span1, gmat, hist);
336+
const RowSetCollection::Elem span1(row_indices.begin, row_indices.end - no_prefetch_size);
337+
if (span1.Size() != 0) {
338+
RowsWiseBuildHistKernel<true, BuildingManager>(gpair, span1, gmat, hist);
339+
}
336340
// no prefetching to avoid loading extra memory
337-
RowsWiseBuildHistKernel<false, BuildingManager>(gpair, span2, gmat, hist);
341+
const RowSetCollection::Elem span2(row_indices.end - no_prefetch_size, row_indices.end);
342+
if (span2.Size() != 0) {
343+
RowsWiseBuildHistKernel<false, BuildingManager>(gpair, span2, gmat, hist);
344+
}
338345
}
339346
}
340347
}

0 commit comments

Comments
 (0)