Fix build and C++ tests for FreeBSD (#10480)

This commit is contained in:
Philip Hyunsu Cho
2024-06-28 01:47:55 -07:00
committed by GitHub
parent e8a962575a
commit 09d32f1f2b
8 changed files with 79 additions and 11 deletions

View File

@@ -105,7 +105,7 @@ inline Json MakeTrackerConfig(std::string host, std::int32_t n_workers,
config["port"] = Integer{0};
config["n_workers"] = Integer{n_workers};
config["sortby"] = Integer{static_cast<std::int32_t>(Tracker::SortBy::kHost)};
config["timeout"] = timeout.count();
config["timeout"] = static_cast<std::int64_t>(timeout.count());
return config;
}

View File

@@ -68,14 +68,20 @@ TEST(ColumnSampler, GPUTest) {
// Test if different threads using the same seed produce the same result
TEST(ColumnSampler, ThreadSynchronisation) {
Context ctx;
const int64_t num_threads = 100;
// NOLINTBEGIN(clang-analyzer-deadcode.DeadStores)
#if defined(__linux__)
std::int64_t const n_threads = std::thread::hardware_concurrency() * 128;
#else
std::int64_t const n_threads = std::thread::hardware_concurrency();
#endif
// NOLINTEND(clang-analyzer-deadcode.DeadStores)
int n = 128;
size_t iterations = 10;
size_t levels = 5;
std::vector<bst_feature_t> reference_result;
std::vector<float> feature_weights;
bool success = true; // Cannot use google test asserts in multithreaded region
#pragma omp parallel num_threads(num_threads)
#pragma omp parallel num_threads(n_threads)
{
for (auto j = 0ull; j < iterations; j++) {
ColumnSampler cs(j);

View File

@@ -59,7 +59,11 @@ TEST(DMatrixCache, MultiThread) {
std::size_t constexpr kRows = 2, kCols = 1, kCacheSize = 3;
auto p_fmat = RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix();
auto n = std::thread::hardware_concurrency() * 128u;
#if defined(__linux__)
auto const n = std::thread::hardware_concurrency() * 128;
#else
auto const n = std::thread::hardware_concurrency();
#endif
CHECK_NE(n, 0);
std::vector<std::shared_ptr<CacheForTest>> results(n);

View File

@@ -267,8 +267,14 @@ TEST(Learner, MultiThreadedPredict) {
learner->Configure();
std::vector<std::thread> threads;
for (uint32_t thread_id = 0;
thread_id < 2 * std::thread::hardware_concurrency(); ++thread_id) {
#if defined(__linux__)
auto n_threads = std::thread::hardware_concurrency() * 4u;
#else
auto n_threads = std::thread::hardware_concurrency();
#endif
for (decltype(n_threads) thread_id = 0; thread_id < n_threads; ++thread_id) {
threads.emplace_back([learner, p_data] {
size_t constexpr kIters = 10;
auto &entry = learner->GetThreadLocal().prediction_entry;