Make HostDeviceVector single gpu only (#4773)

* Make HostDeviceVector single gpu only
This commit is contained in:
Rong Ou
2019-08-25 14:51:13 -07:00
committed by Rory Mitchell
parent 41227d1933
commit 38ab79f889
54 changed files with 641 additions and 1621 deletions

View File

@@ -6,7 +6,7 @@
#include "../helpers.h"
TEST(Metric, DeclareUnifiedTest(RMSE)) {
auto lparam = xgboost::CreateEmptyGenericParam(0, NGPUS);
auto lparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("rmse", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "rmse");
@@ -20,7 +20,7 @@ TEST(Metric, DeclareUnifiedTest(RMSE)) {
}
TEST(Metric, DeclareUnifiedTest(RMSLE)) {
auto lparam = xgboost::CreateEmptyGenericParam(0, NGPUS);
auto lparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("rmsle", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "rmsle");
@@ -32,7 +32,7 @@ TEST(Metric, DeclareUnifiedTest(RMSLE)) {
}
TEST(Metric, DeclareUnifiedTest(MAE)) {
auto lparam = xgboost::CreateEmptyGenericParam(0, NGPUS);
auto lparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("mae", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "mae");
@@ -45,7 +45,7 @@ TEST(Metric, DeclareUnifiedTest(MAE)) {
}
TEST(Metric, DeclareUnifiedTest(LogLoss)) {
auto lparam = xgboost::CreateEmptyGenericParam(0, NGPUS);
auto lparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("logloss", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "logloss");
@@ -58,7 +58,7 @@ TEST(Metric, DeclareUnifiedTest(LogLoss)) {
}
TEST(Metric, DeclareUnifiedTest(Error)) {
auto lparam = xgboost::CreateEmptyGenericParam(0, NGPUS);
auto lparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("error", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "error");
@@ -90,7 +90,7 @@ TEST(Metric, DeclareUnifiedTest(Error)) {
}
TEST(Metric, DeclareUnifiedTest(PoissionNegLogLik)) {
auto lparam = xgboost::CreateEmptyGenericParam(0, NGPUS);
auto lparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("poisson-nloglik", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "poisson-nloglik");

View File

@@ -4,7 +4,7 @@
#include "../helpers.h"
TEST(Metric, UnknownMetric) {
auto tparam = xgboost::CreateEmptyGenericParam(0, 0);
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = nullptr;
EXPECT_ANY_THROW(metric = xgboost::Metric::Create("unknown_name", &tparam));
EXPECT_NO_THROW(metric = xgboost::Metric::Create("rmse", &tparam));

View File

@@ -4,10 +4,9 @@
#include "../helpers.h"
inline void TestMultiClassError(xgboost::GPUSet const& devices) {
auto lparam = xgboost::CreateEmptyGenericParam(0, NGPUS);
lparam.gpu_id = *devices.begin();
lparam.n_gpus = devices.Size();
inline void TestMultiClassError(int device) {
auto lparam = xgboost::CreateEmptyGenericParam(device);
lparam.gpu_id = device;
xgboost::Metric * metric = xgboost::Metric::Create("merror", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "merror");
@@ -23,14 +22,12 @@ inline void TestMultiClassError(xgboost::GPUSet const& devices) {
}
TEST(Metric, DeclareUnifiedTest(MultiClassError)) {
auto devices = xgboost::GPUSet::Range(0, NGPUS);
TestMultiClassError(devices);
TestMultiClassError(GPUIDX);
}
inline void TestMultiClassLogLoss(xgboost::GPUSet const& devices) {
auto lparam = xgboost::CreateEmptyGenericParam(0, NGPUS);
lparam.gpu_id = *devices.begin();
lparam.n_gpus = devices.Size();
inline void TestMultiClassLogLoss(int device) {
auto lparam = xgboost::CreateEmptyGenericParam(device);
lparam.gpu_id = device;
xgboost::Metric * metric = xgboost::Metric::Create("mlogloss", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "mlogloss");
@@ -46,27 +43,31 @@ inline void TestMultiClassLogLoss(xgboost::GPUSet const& devices) {
}
TEST(Metric, DeclareUnifiedTest(MultiClassLogLoss)) {
auto devices = xgboost::GPUSet::Range(0, NGPUS);
TestMultiClassLogLoss(devices);
TestMultiClassLogLoss(GPUIDX);
}
#if defined(XGBOOST_USE_NCCL) && defined(__CUDACC__)
namespace xgboost {
namespace common {
TEST(Metric, MGPU_MultiClassError) {
if (AllVisibleGPUs() < 2) {
LOG(WARNING) << "Not testing in multi-gpu environment.";
return;
}
{
auto devices = xgboost::GPUSet::All(0, -1);
TestMultiClassError(devices);
TestMultiClassError(0);
}
{
auto devices = xgboost::GPUSet::All(1, -1);
TestMultiClassError(devices);
TestMultiClassError(1);
}
{
auto devices = xgboost::GPUSet::All(0, -1);
TestMultiClassLogLoss(devices);
TestMultiClassLogLoss(0);
}
{
auto devices = xgboost::GPUSet::All(1, -1);
TestMultiClassLogLoss(devices);
TestMultiClassLogLoss(1);
}
}
} // namespace common
} // namespace xgboost
#endif // defined(XGBOOST_USE_NCCL)

View File

@@ -4,7 +4,7 @@
#include "../helpers.h"
TEST(Metric, AMS) {
auto tparam = xgboost::CreateEmptyGenericParam(0, 0);
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
EXPECT_ANY_THROW(xgboost::Metric::Create("ams", &tparam));
xgboost::Metric * metric = xgboost::Metric::Create("ams@0.5f", &tparam);
ASSERT_STREQ(metric->Name(), "ams@0.5");
@@ -23,7 +23,7 @@ TEST(Metric, AMS) {
}
TEST(Metric, AUC) {
auto tparam = xgboost::CreateEmptyGenericParam(0, 0);
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("auc", &tparam);
ASSERT_STREQ(metric->Name(), "auc");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 1, 1e-10);
@@ -38,7 +38,7 @@ TEST(Metric, AUC) {
}
TEST(Metric, AUCPR) {
auto tparam = xgboost::CreateEmptyGenericParam(0, 0);
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric *metric = xgboost::Metric::Create("aucpr", &tparam);
ASSERT_STREQ(metric->Name(), "aucpr");
EXPECT_NEAR(GetMetricEval(metric, {0, 0, 1, 1}, {0, 0, 1, 1}), 1, 1e-10);
@@ -65,7 +65,7 @@ TEST(Metric, Precision) {
// When the limit for precision is not given, it takes the limit at
// std::numeric_limits<unsigned>::max(); hence all values are very small
// NOTE(AbdealiJK): Maybe this should be fixed to be num_row by default.
auto tparam = xgboost::CreateEmptyGenericParam(0, 0);
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("pre", &tparam);
ASSERT_STREQ(metric->Name(), "pre");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 0, 1e-7);
@@ -89,7 +89,7 @@ TEST(Metric, Precision) {
}
TEST(Metric, NDCG) {
auto tparam = xgboost::CreateEmptyGenericParam(0, 0);
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("ndcg", &tparam);
ASSERT_STREQ(metric->Name(), "ndcg");
EXPECT_ANY_THROW(GetMetricEval(metric, {0, 1}, {}));
@@ -147,7 +147,7 @@ TEST(Metric, NDCG) {
}
TEST(Metric, MAP) {
auto tparam = xgboost::CreateEmptyGenericParam(0, 0);
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("map", &tparam);
ASSERT_STREQ(metric->Name(), "map");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 1, 1e-10);