Implement Empty method for host device vector. (#5781)
* Fix accessing nullptr.
This commit is contained in:
parent
306e38ff31
commit
1fa84b61c1
@ -95,6 +95,7 @@ class HostDeviceVector {
|
|||||||
HostDeviceVector<T>& operator=(const HostDeviceVector<T>&) = delete;
|
HostDeviceVector<T>& operator=(const HostDeviceVector<T>&) = delete;
|
||||||
HostDeviceVector<T>& operator=(HostDeviceVector<T>&&);
|
HostDeviceVector<T>& operator=(HostDeviceVector<T>&&);
|
||||||
|
|
||||||
|
bool Empty() const { return Size() == 0; }
|
||||||
size_t Size() const;
|
size_t Size() const;
|
||||||
int DeviceIdx() const;
|
int DeviceIdx() const;
|
||||||
common::Span<T> DeviceSpan();
|
common::Span<T> DeviceSpan();
|
||||||
|
|||||||
@ -59,7 +59,9 @@ class HostDeviceVectorImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Size() const { return HostCanRead() ? data_h_.size() : data_d_->size(); }
|
size_t Size() const {
|
||||||
|
return HostCanRead() ? data_h_.size() : data_d_ ? data_d_->size() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
int DeviceIdx() const { return device_; }
|
int DeviceIdx() const { return device_; }
|
||||||
|
|
||||||
|
|||||||
@ -176,6 +176,13 @@ TEST(HostDeviceVector, Span) {
|
|||||||
ASSERT_TRUE(vec.HostCanWrite());
|
ASSERT_TRUE(vec.HostCanWrite());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(HostDeviceVector, Empty) {
|
||||||
|
HostDeviceVector<float> vec {1.0f, 2.0f, 3.0f, 4.0f};
|
||||||
|
HostDeviceVector<float> another { std::move(vec) };
|
||||||
|
ASSERT_FALSE(another.Empty());
|
||||||
|
ASSERT_TRUE(vec.Empty());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(HostDeviceVector, MGPU_Basic) { // NOLINT
|
TEST(HostDeviceVector, MGPU_Basic) { // NOLINT
|
||||||
if (AllVisibleGPUs() < 2) {
|
if (AllVisibleGPUs() < 2) {
|
||||||
LOG(WARNING) << "Not testing in multi-gpu environment.";
|
LOG(WARNING) << "Not testing in multi-gpu environment.";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user