Remove internal use of gpu_id. (#9568)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user