Skip to content

Commit

Permalink
remove preserve parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rongou committed Apr 30, 2019
1 parent 80e8fa1 commit f375e85
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/common/host_device_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ template <typename T>
void HostDeviceVector<T>::Shard(GPUSet devices) const { }

template <typename T>
void Reshard(const GPUDistribution &distribution, bool preserve) { }
void Reshard(const GPUDistribution &distribution) { }

// explicit instantiations are required, as HostDeviceVector isn't header-only
template class HostDeviceVector<bst_float>;
Expand Down
11 changes: 4 additions & 7 deletions src/common/host_device_vector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,11 @@ struct HostDeviceVectorImpl {
Shard(GPUDistribution::Block(new_devices));
}

void Reshard(const GPUDistribution &distribution, bool preserve) {
void Reshard(const GPUDistribution &distribution) {
if (distribution_ == distribution) { return; }
if (preserve) {
LazySyncHost(GPUAccess::kWrite);
}
LazySyncHost(GPUAccess::kWrite);
distribution_ = distribution;
shards_.clear();
perm_h_.Grant(kWrite);
InitShards();
}

Expand Down Expand Up @@ -604,8 +601,8 @@ void HostDeviceVector<T>::Shard(const GPUDistribution &distribution) const {
}

template <typename T>
void HostDeviceVector<T>::Reshard(const GPUDistribution &distribution, bool preserve) {
impl_->Reshard(distribution, preserve);
void HostDeviceVector<T>::Reshard(const GPUDistribution &distribution) {
impl_->Reshard(distribution);
}

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion src/common/host_device_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class HostDeviceVector {
/*!
* \brief Change memory distribution.
*/
void Reshard(const GPUDistribution &distribution, bool preserve = true);
void Reshard(const GPUDistribution &distribution);

void Resize(size_t new_size, T v = T());

Expand Down
36 changes: 0 additions & 36 deletions tests/cpp/common/test_host_device_vector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ TEST(HostDeviceVector, Reshard) {
auto span = vec.DeviceSpan(0); // sync to device
PlusOne(&vec);

// GPU data is preserved.
vec.Reshard(GPUDistribution::Empty());
ASSERT_EQ(vec.Size(), h_vec.size());
ASSERT_TRUE(vec.Devices().IsEmpty());
Expand All @@ -222,20 +221,6 @@ TEST(HostDeviceVector, Reshard) {
for (size_t i = 0; i < h_vec_1.size(); ++i) {
ASSERT_EQ(h_vec_1.at(i), i + 1);
}

vec.Reshard(GPUDistribution::Block(devices));
span = vec.DeviceSpan(0); // sync to device
PlusOne(&vec);

vec.Reshard(GPUDistribution::Empty(), /*preserve=*/false);
ASSERT_EQ(vec.Size(), h_vec.size());
ASSERT_TRUE(vec.Devices().IsEmpty());

auto h_vec_2 = vec.HostVector();
for (size_t i = 0; i < h_vec_2.size(); ++i) {
// The second `PlusOne()` has no effect.
ASSERT_EQ(h_vec_2.at(i), i + 1);
}
}

TEST(HostDeviceVector, Span) {
Expand Down Expand Up @@ -334,27 +319,6 @@ TEST(HostDeviceVector, MGPU_Reshard) {
for (size_t i = 0; i < h_vec_1.size(); ++i) {
ASSERT_EQ(h_vec_1.at(i), i + 1);
}

for (size_t i = 0; i < devices.Size(); ++i) {
auto span = vec.DeviceSpan(i); // sync to device
}
PlusOne(&vec);

vec.Reshard(GPUDistribution::Overlap(devices, 11), /*preserve=*/false);
total_size = 0;
for (size_t i = 0; i < devices.Size(); ++i) {
total_size += vec.DeviceSize(i);
devices_size[i] = vec.DeviceSize(i);
}
overlap = 11 * (devices.Size() - 1);
ASSERT_EQ(total_size, h_vec.size() + overlap);
ASSERT_EQ(total_size, vec.Size() + overlap);

auto h_vec_2 = vec.HostVector();
for (size_t i = 0; i < h_vec_2.size(); ++i) {
// The second `PlusOne()` has no effect.
ASSERT_EQ(h_vec_2.at(i), i + 1);
}
}
#endif

Expand Down

0 comments on commit f375e85

Please sign in to comment.