Remove internal use of gpu_id. (#9568)

This commit is contained in:
Jiaming Yuan
2023-09-20 23:29:51 +08:00
committed by GitHub
parent 38ac52dd87
commit 8c676c889d
121 changed files with 1012 additions and 1044 deletions

View File

@@ -5,11 +5,13 @@
#include <xgboost/base.h>
#include <xgboost/context.h>
#include <sstream>
namespace xgboost {
TEST(Context, CPU) {
Context ctx;
ASSERT_EQ(ctx.Device(), DeviceOrd::CPU());
ASSERT_EQ(ctx.Ordinal(), Context::kCpuId);
ASSERT_EQ(ctx.Ordinal(), DeviceOrd::CPUOrdinal());
std::int32_t flag{0};
ctx.DispatchDevice([&] { flag = -1; }, [&] { flag = 1; });
@@ -27,5 +29,20 @@ TEST(Context, CPU) {
ASSERT_THROW(ctx.UpdateAllowUnknown(Args{{"device", ":gpu"}}), dmlc::Error);
ASSERT_THROW(ctx.UpdateAllowUnknown(Args{{"device", ":0"}}), dmlc::Error);
ASSERT_THROW(ctx.UpdateAllowUnknown(Args{{"device", ""}}), dmlc::Error);
std::stringstream ss;
ss << ctx.Device();
ASSERT_EQ(ss.str(), "cpu");
}
TEST(Context, ErrorInit) {
Context ctx;
ASSERT_THROW({ ctx.Init({{"foo", "bar"}}); }, dmlc::Error);
try {
ctx.Init({{"foo", "bar"}});
} catch (dmlc::Error const& e) {
auto msg = std::string{e.what()};
ASSERT_NE(msg.find("foo"), std::string::npos);
}
}
} // namespace xgboost