-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix device dispatch for linear updater. (#9507)
- Loading branch information
1 parent
302bbdc
commit 3c09399
Showing
6 changed files
with
80 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright 2023, XGBoost Contributors | ||
*/ | ||
#include <gtest/gtest.h> | ||
#include <xgboost/global_config.h> // for GlobalConfigThreadLocalStore | ||
#include <xgboost/json.h> // for Json, Object | ||
#include <xgboost/learner.h> // for Learner | ||
|
||
#include <algorithm> // for transform | ||
#include <string> // for string | ||
#include <utility> // for swap | ||
|
||
#include "../helpers.h" // for RandomDataGenerator | ||
|
||
namespace xgboost { | ||
TEST(GBlinear, DispatchUpdater) { | ||
auto verbosity = 3; | ||
std::swap(GlobalConfigThreadLocalStore::Get()->verbosity, verbosity); | ||
|
||
auto test = [](std::string device) { | ||
auto p_fmat = RandomDataGenerator{10, 10, 0.0f}.GenerateDMatrix(true); | ||
std::unique_ptr<Learner> learner{Learner::Create({p_fmat})}; | ||
learner->SetParams( | ||
Args{{"booster", "gblinear"}, {"updater", "coord_descent"}, {"device", device}}); | ||
learner->Configure(); | ||
for (std::int32_t iter = 0; iter < 3; ++iter) { | ||
learner->UpdateOneIter(iter, p_fmat); | ||
} | ||
Json config{Object{}}; | ||
::testing::internal::CaptureStderr(); | ||
learner->SaveConfig(&config); | ||
auto str = ::testing::internal::GetCapturedStderr(); | ||
std::transform(device.cbegin(), device.cend(), device.begin(), | ||
[](char c) { return std::toupper(c); }); | ||
ASSERT_NE(str.find(device), std::string::npos); | ||
}; | ||
test("cpu"); | ||
test("gpu"); | ||
|
||
std::swap(GlobalConfigThreadLocalStore::Get()->verbosity, verbosity); | ||
} | ||
} // namespace xgboost |