Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify CPU hist sketching #5880

Merged
merged 5 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions amalgamation/xgboost-all0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include "../src/common/common.cc"
#include "../src/common/charconv.cc"
#include "../src/common/timer.cc"
#include "../src/common/quantile.cc"
#include "../src/common/host_device_vector.cc"
#include "../src/common/hist_util.cc"
#include "../src/common/json.cc"
Expand Down
20 changes: 20 additions & 0 deletions include/xgboost/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ struct BatchParam {
}
};

struct HostSparsePageView {
using Inst = common::Span<Entry const>;

common::Span<bst_row_t const> offset;
common::Span<Entry const> data;

Inst operator[](size_t i) const {
auto size = *(offset.data() + i + 1) - *(offset.data() + i);
return {data.data() + *(offset.data() + i),
static_cast<Inst::index_type>(size)};
}

size_t Size() const { return offset.size() == 0 ? 0 : offset.size() - 1; }
};

/*!
* \brief In-memory storage unit of sparse batch, stored in CSR format.
*/
Expand Down Expand Up @@ -270,6 +285,11 @@ class SparsePage {
static_cast<Inst::index_type>(size)};
}

HostSparsePageView GetView() const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to fix operator[] instead of creating a whole new class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RAMitchell If you want to call operator[] without first calling HostVector twice, then I don't think so.

return {offset.ConstHostSpan(), data.ConstHostSpan()};
}


/*! \brief constructor */
SparsePage() {
this->Clear();
Expand Down
Loading