Merge generic device helper functions into gpu set. (#3626)

* Remove the use of old NDevices* functions.
* Use GPUSet in timer.h.
This commit is contained in:
trivialfis
2018-08-26 14:14:23 +08:00
committed by Rory Mitchell
parent 3261002099
commit 60787ecebc
12 changed files with 299 additions and 199 deletions

View File

@@ -0,0 +1,37 @@
#include "../../../src/common/gpu_set.h"
#include <gtest/gtest.h>
namespace xgboost {
TEST(GPUSet, Basic) {
GPUSet devices = GPUSet::Empty();
ASSERT_TRUE(devices.IsEmpty());
devices = GPUSet{0, 1};
ASSERT_TRUE(devices != GPUSet::Empty());
EXPECT_EQ(devices.Size(), 1);
EXPECT_ANY_THROW(devices.Index(1));
EXPECT_ANY_THROW(devices.Index(-1));
devices = GPUSet::Range(1, 0);
EXPECT_EQ(devices, GPUSet::Empty());
EXPECT_EQ(devices.Size(), 0);
EXPECT_TRUE(devices.IsEmpty());
EXPECT_FALSE(devices.Contains(1));
devices = GPUSet::Range(2, -1);
EXPECT_EQ(devices, GPUSet::Empty());
EXPECT_EQ(devices.Size(), 0);
EXPECT_TRUE(devices.IsEmpty());
devices = GPUSet::Range(2, 8);
EXPECT_EQ(devices.Size(), 8);
devices = devices.Unnormalised();
EXPECT_EQ(*devices.begin(), 0);
EXPECT_EQ(*devices.end(), devices.Size());
}
} // namespace xgboost