Skip to content
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
3 changes: 3 additions & 0 deletions include/xgboost/host_device_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class HostDeviceVector {
const T* DevicePointer() const { return ConstDevicePointer(); }

T* HostPointer() { return HostVector().data(); }
common::Span<T> HostSpan() { return common::Span<T>{HostVector()}; }
common::Span<T const> HostSpan() const { return common::Span<T const>{HostVector()}; }
common::Span<T const> ConstHostSpan() const { return HostSpan(); }
const T* ConstHostPointer() const { return ConstHostVector().data(); }
const T* HostPointer() const { return ConstHostPointer(); }

Expand Down
9 changes: 9 additions & 0 deletions tests/cpp/common/test_host_device_vector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ TEST(HostDeviceVector, Span) {
auto const_span = vec.ConstDeviceSpan();
ASSERT_EQ(vec.Size(), const_span.size());
ASSERT_EQ(vec.ConstDevicePointer(), const_span.data());

auto h_span = vec.ConstHostSpan();
ASSERT_TRUE(vec.HostCanRead());
ASSERT_FALSE(vec.HostCanWrite());
ASSERT_EQ(h_span.size(), vec.Size());
ASSERT_EQ(h_span.data(), vec.ConstHostPointer());

h_span = vec.HostSpan();
ASSERT_TRUE(vec.HostCanWrite());
}

TEST(HostDeviceVector, MGPU_Basic) {
Expand Down