Fix gpu devices. (#3693)
* Fix gpu_set normalized and unnormalized. * Fix DeviceSpan.
This commit is contained in:
committed by
Rory Mitchell
parent
0f99cdfe0e
commit
9119f9e369
@@ -1,8 +1,7 @@
|
||||
#include "../../../src/common/gpu_set.h"
|
||||
#include "../../../src/common/common.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace xgboost {
|
||||
|
||||
TEST(GPUSet, Basic) {
|
||||
GPUSet devices = GPUSet::Empty();
|
||||
ASSERT_TRUE(devices.IsEmpty());
|
||||
@@ -28,10 +27,16 @@ TEST(GPUSet, Basic) {
|
||||
|
||||
devices = GPUSet::Range(2, 8);
|
||||
EXPECT_EQ(devices.Size(), 8);
|
||||
EXPECT_ANY_THROW(devices[8]);
|
||||
EXPECT_ANY_THROW(devices.Index(0));
|
||||
|
||||
devices = devices.Unnormalised();
|
||||
|
||||
EXPECT_EQ(*devices.begin(), 0);
|
||||
EXPECT_EQ(*devices.end(), devices.Size());
|
||||
#ifndef XGBOOST_USE_CUDA
|
||||
EXPECT_EQ(GPUSet::AllVisible(), GPUSet::Empty());
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace xgboost
|
||||
|
||||
44
tests/cpp/common/test_common.cu
Normal file
44
tests/cpp/common/test_common.cu
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "../../../src/common/common.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace xgboost {
|
||||
|
||||
TEST(GPUSet, GPUBasic) {
|
||||
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());
|
||||
EXPECT_EQ(8, devices.Size());
|
||||
|
||||
ASSERT_NO_THROW(GPUSet::AllVisible());
|
||||
devices = GPUSet::AllVisible();
|
||||
if (devices.IsEmpty()) {
|
||||
LOG(WARNING) << "Empty devices.";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace xgboost
|
||||
Reference in New Issue
Block a user