Skip to content

Commit d7b2b02

Browse files
committed
Set NTHREADS to utils_get_num_cores() at minimum
Set NTHREADS to utils_get_num_cores() at minimum and rename NTHREADS to numThreads. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 1faa557 commit d7b2b02

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

test/ipcFixtures.hpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct umfIpcTest : umf_test::test,
9393
providerParamsDestroy = provider_params_destroy;
9494
memAccessor = accessor;
9595
openedIpcCacheSize = getOpenedIpcCacheSize();
96+
numThreads = std::max(10, (int)utils_get_num_cores());
9697
}
9798

9899
void TearDown() override { test::TearDown(); }
@@ -162,7 +163,8 @@ struct umfIpcTest : umf_test::test,
162163
closeCount(0) {}
163164
};
164165

165-
static constexpr int NTHREADS = 10;
166+
unsigned int numThreads;
167+
static constexpr int CNTHREADS = 10;
166168
stats_type stat;
167169
MemoryAccessor *memAccessor = nullptr;
168170

@@ -188,9 +190,9 @@ struct umfIpcTest : umf_test::test,
188190
ptrs.push_back(ptr);
189191
}
190192

191-
std::array<std::vector<umf_ipc_handle_t>, NTHREADS> ipcHandles;
193+
std::array<std::vector<umf_ipc_handle_t>, CNTHREADS> ipcHandles;
192194

193-
umf_test::syncthreads_barrier syncthreads(NTHREADS);
195+
umf_test::syncthreads_barrier syncthreads(numThreads);
194196

195197
auto getHandlesFn = [shuffle, &ipcHandles, &ptrs,
196198
&syncthreads](size_t tid) {
@@ -212,7 +214,7 @@ struct umfIpcTest : umf_test::test,
212214
}
213215
};
214216

215-
umf_test::parallel_exec(NTHREADS, getHandlesFn);
217+
umf_test::parallel_exec(numThreads, getHandlesFn);
216218

217219
auto putHandlesFn = [&ipcHandles, &syncthreads](size_t tid) {
218220
syncthreads();
@@ -222,7 +224,7 @@ struct umfIpcTest : umf_test::test,
222224
}
223225
};
224226

225-
umf_test::parallel_exec(NTHREADS, putHandlesFn);
227+
umf_test::parallel_exec(numThreads, putHandlesFn);
226228

227229
for (void *ptr : ptrs) {
228230
umf_result_t ret = umfPoolFree(pool.get(), ptr);
@@ -246,7 +248,7 @@ struct umfIpcTest : umf_test::test,
246248
ptrs.push_back(ptr);
247249
}
248250

249-
umf_test::syncthreads_barrier syncthreads(NTHREADS);
251+
umf_test::syncthreads_barrier syncthreads(numThreads);
250252

251253
auto getPutHandlesFn = [shuffle, &ptrs, &syncthreads](size_t) {
252254
// Each thread gets a copy of the pointers to shuffle them
@@ -268,7 +270,7 @@ struct umfIpcTest : umf_test::test,
268270
}
269271
};
270272

271-
umf_test::parallel_exec(NTHREADS, getPutHandlesFn);
273+
umf_test::parallel_exec(numThreads, getPutHandlesFn);
272274

273275
for (void *ptr : ptrs) {
274276
umf_result_t ret = umfPoolFree(pool.get(), ptr);
@@ -302,13 +304,13 @@ struct umfIpcTest : umf_test::test,
302304
ipcHandles.push_back(ipcHandle);
303305
}
304306

305-
std::array<std::vector<void *>, NTHREADS> openedIpcHandles;
307+
std::array<std::vector<void *>, CNTHREADS> openedIpcHandles;
306308
umf_ipc_handler_handle_t ipcHandler = nullptr;
307309
ret = umfPoolGetIPCHandler(pool.get(), &ipcHandler);
308310
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
309311
ASSERT_NE(ipcHandler, nullptr);
310312

311-
umf_test::syncthreads_barrier syncthreads(NTHREADS);
313+
umf_test::syncthreads_barrier syncthreads(numThreads);
312314

313315
auto openHandlesFn = [shuffle, &ipcHandles, &openedIpcHandles,
314316
&syncthreads, ipcHandler](size_t tid) {
@@ -329,7 +331,7 @@ struct umfIpcTest : umf_test::test,
329331
}
330332
};
331333

332-
umf_test::parallel_exec(NTHREADS, openHandlesFn);
334+
umf_test::parallel_exec(numThreads, openHandlesFn);
333335

334336
auto closeHandlesFn = [&openedIpcHandles, &syncthreads](size_t tid) {
335337
syncthreads();
@@ -339,7 +341,7 @@ struct umfIpcTest : umf_test::test,
339341
}
340342
};
341343

342-
umf_test::parallel_exec(NTHREADS, closeHandlesFn);
344+
umf_test::parallel_exec(numThreads, closeHandlesFn);
343345

344346
for (auto ipcHandle : ipcHandles) {
345347
ret = umfPutIPCHandle(ipcHandle);
@@ -386,7 +388,7 @@ struct umfIpcTest : umf_test::test,
386388
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
387389
ASSERT_NE(ipcHandler, nullptr);
388390

389-
umf_test::syncthreads_barrier syncthreads(NTHREADS);
391+
umf_test::syncthreads_barrier syncthreads(numThreads);
390392

391393
auto openCloseHandlesFn = [shuffle, &ipcHandles, &syncthreads,
392394
ipcHandler](size_t) {
@@ -408,7 +410,7 @@ struct umfIpcTest : umf_test::test,
408410
}
409411
};
410412

411-
umf_test::parallel_exec(NTHREADS, openCloseHandlesFn);
413+
umf_test::parallel_exec(numThreads, openCloseHandlesFn);
412414

413415
for (auto ipcHandle : ipcHandles) {
414416
ret = umfPutIPCHandle(ipcHandle);

test/poolFixtures.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ struct umfPoolTest : umf_test::test,
8282
test::SetUp();
8383

8484
pool = poolCreateExtUnique(this->GetParam());
85+
numThreads = std::max(5, (int)utils_get_num_cores());
8586
}
8687

8788
void TearDown() override { test::TearDown(); }
8889

8990
umf_test::pool_unique_handle_t pool;
9091

91-
static constexpr int NTHREADS = 5;
92+
int numThreads;
9293
static constexpr std::array<int, 7> nonAlignedAllocSizes = {5, 7, 23, 55,
9394
80, 119, 247};
9495
};
@@ -281,7 +282,7 @@ TEST_P(umfPoolTest, multiThreadedMallocFree) {
281282
};
282283

283284
std::vector<std::thread> threads;
284-
for (int i = 0; i < NTHREADS; i++) {
285+
for (int i = 0; i < numThreads; i++) {
285286
threads.emplace_back(poolMalloc, allocSize, pool.get());
286287
}
287288

@@ -300,7 +301,7 @@ TEST_P(umfPoolTest, multiThreadedpow2AlignedAlloc) {
300301
};
301302

302303
std::vector<std::thread> threads;
303-
for (int i = 0; i < NTHREADS; i++) {
304+
for (int i = 0; i < numThreads; i++) {
304305
threads.emplace_back(poolpow2AlignedAlloc, pool.get());
305306
}
306307

@@ -335,7 +336,7 @@ TEST_P(umfPoolTest, multiThreadedReallocFree) {
335336
};
336337

337338
std::vector<std::thread> threads;
338-
for (int i = 0; i < NTHREADS; i++) {
339+
for (int i = 0; i < numThreads; i++) {
339340
threads.emplace_back(poolRealloc, allocSize, multiplier, pool.get());
340341
}
341342

@@ -366,7 +367,7 @@ TEST_P(umfPoolTest, multiThreadedCallocFree) {
366367
};
367368

368369
std::vector<std::thread> threads;
369-
for (int i = 0; i < NTHREADS; i++) {
370+
for (int i = 0; i < numThreads; i++) {
370371
threads.emplace_back(poolCalloc, num, sizeof(int), pool.get());
371372
}
372373

@@ -392,7 +393,7 @@ TEST_P(umfPoolTest, multiThreadedMallocFreeRandomSizes) {
392393
};
393394

394395
std::vector<std::thread> threads;
395-
for (int i = 0; i < NTHREADS; i++) {
396+
for (int i = 0; i < numThreads; i++) {
396397
threads.emplace_back(poolMalloc, (rand() % 16) * 8, pool.get());
397398
}
398399

test/test_base_alloc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -17,9 +17,9 @@
1717
using umf_test::test;
1818

1919
TEST_F(test, baseAllocMultiThreadedAllocMemset) {
20-
static constexpr int NTHREADS = 10;
2120
static constexpr int ITERATIONS = 1000;
2221
static constexpr int ALLOCATION_SIZE = 16;
22+
int numThreads = std::max(10, (int)utils_get_num_cores());
2323

2424
auto pool = std::shared_ptr<umf_ba_pool_t>(umf_ba_create(ALLOCATION_SIZE),
2525
umf_ba_destroy);
@@ -43,7 +43,7 @@ TEST_F(test, baseAllocMultiThreadedAllocMemset) {
4343
};
4444

4545
std::vector<std::thread> threads;
46-
for (int i = 0; i < NTHREADS; i++) {
46+
for (int i = 0; i < numThreads; i++) {
4747
threads.emplace_back(poolAlloc, i, pool.get());
4848
}
4949

test/test_base_alloc_linear.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Intel Corporation
2+
* Copyright (C) 2024-2025 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -50,9 +50,9 @@ TEST_F(test, baseAllocLinearPoolContainsPointer) {
5050
}
5151

5252
TEST_F(test, baseAllocLinearMultiThreadedAllocMemset) {
53-
static constexpr int NTHREADS = 10;
5453
static constexpr int ITERATIONS = 1000;
5554
static constexpr int MAX_ALLOCATION_SIZE = 1024;
55+
int numThreads = std::max(10, (int)utils_get_num_cores());
5656

5757
srand(0);
5858

@@ -94,7 +94,7 @@ TEST_F(test, baseAllocLinearMultiThreadedAllocMemset) {
9494
};
9595

9696
std::vector<std::thread> threads;
97-
for (int i = 0; i < NTHREADS; i++) {
97+
for (int i = 0; i < numThreads; i++) {
9898
threads.emplace_back(poolAlloc, i, pool.get());
9999
}
100100

0 commit comments

Comments
 (0)