Implement host span. (#5459)

This commit is contained in:
Jiaming Yuan 2020-04-03 10:37:51 +08:00 committed by GitHub
parent 459b175dc6
commit 86beb68ce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -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(); }

View File

@ -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) {