diff --git a/test/ipcFixtures.hpp b/test/ipcFixtures.hpp index 0edf6cefe..c2f33efae 100644 --- a/test/ipcFixtures.hpp +++ b/test/ipcFixtures.hpp @@ -93,6 +93,7 @@ struct umfIpcTest : umf_test::test, providerParamsDestroy = provider_params_destroy; memAccessor = accessor; openedIpcCacheSize = getOpenedIpcCacheSize(); + numThreads = std::max(10, (int)utils_get_num_cores()); } void TearDown() override { test::TearDown(); } @@ -162,7 +163,8 @@ struct umfIpcTest : umf_test::test, closeCount(0) {} }; - static constexpr int NTHREADS = 10; + unsigned int numThreads; + static constexpr int CNTHREADS = 10; stats_type stat; MemoryAccessor *memAccessor = nullptr; @@ -188,9 +190,9 @@ struct umfIpcTest : umf_test::test, ptrs.push_back(ptr); } - std::array, NTHREADS> ipcHandles; + std::array, CNTHREADS> ipcHandles; - umf_test::syncthreads_barrier syncthreads(NTHREADS); + umf_test::syncthreads_barrier syncthreads(numThreads); auto getHandlesFn = [shuffle, &ipcHandles, &ptrs, &syncthreads](size_t tid) { @@ -212,7 +214,7 @@ struct umfIpcTest : umf_test::test, } }; - umf_test::parallel_exec(NTHREADS, getHandlesFn); + umf_test::parallel_exec(numThreads, getHandlesFn); auto putHandlesFn = [&ipcHandles, &syncthreads](size_t tid) { syncthreads(); @@ -222,7 +224,7 @@ struct umfIpcTest : umf_test::test, } }; - umf_test::parallel_exec(NTHREADS, putHandlesFn); + umf_test::parallel_exec(numThreads, putHandlesFn); for (void *ptr : ptrs) { umf_result_t ret = umfPoolFree(pool.get(), ptr); @@ -246,7 +248,7 @@ struct umfIpcTest : umf_test::test, ptrs.push_back(ptr); } - umf_test::syncthreads_barrier syncthreads(NTHREADS); + umf_test::syncthreads_barrier syncthreads(numThreads); auto getPutHandlesFn = [shuffle, &ptrs, &syncthreads](size_t) { // Each thread gets a copy of the pointers to shuffle them @@ -268,7 +270,7 @@ struct umfIpcTest : umf_test::test, } }; - umf_test::parallel_exec(NTHREADS, getPutHandlesFn); + umf_test::parallel_exec(numThreads, getPutHandlesFn); for (void *ptr : ptrs) { umf_result_t ret = umfPoolFree(pool.get(), ptr); @@ -302,13 +304,13 @@ struct umfIpcTest : umf_test::test, ipcHandles.push_back(ipcHandle); } - std::array, NTHREADS> openedIpcHandles; + std::array, CNTHREADS> openedIpcHandles; umf_ipc_handler_handle_t ipcHandler = nullptr; ret = umfPoolGetIPCHandler(pool.get(), &ipcHandler); ASSERT_EQ(ret, UMF_RESULT_SUCCESS); ASSERT_NE(ipcHandler, nullptr); - umf_test::syncthreads_barrier syncthreads(NTHREADS); + umf_test::syncthreads_barrier syncthreads(numThreads); auto openHandlesFn = [shuffle, &ipcHandles, &openedIpcHandles, &syncthreads, ipcHandler](size_t tid) { @@ -329,7 +331,7 @@ struct umfIpcTest : umf_test::test, } }; - umf_test::parallel_exec(NTHREADS, openHandlesFn); + umf_test::parallel_exec(numThreads, openHandlesFn); auto closeHandlesFn = [&openedIpcHandles, &syncthreads](size_t tid) { syncthreads(); @@ -339,7 +341,7 @@ struct umfIpcTest : umf_test::test, } }; - umf_test::parallel_exec(NTHREADS, closeHandlesFn); + umf_test::parallel_exec(numThreads, closeHandlesFn); for (auto ipcHandle : ipcHandles) { ret = umfPutIPCHandle(ipcHandle); @@ -386,7 +388,7 @@ struct umfIpcTest : umf_test::test, ASSERT_EQ(ret, UMF_RESULT_SUCCESS); ASSERT_NE(ipcHandler, nullptr); - umf_test::syncthreads_barrier syncthreads(NTHREADS); + umf_test::syncthreads_barrier syncthreads(numThreads); auto openCloseHandlesFn = [shuffle, &ipcHandles, &syncthreads, ipcHandler](size_t) { @@ -408,7 +410,7 @@ struct umfIpcTest : umf_test::test, } }; - umf_test::parallel_exec(NTHREADS, openCloseHandlesFn); + umf_test::parallel_exec(numThreads, openCloseHandlesFn); for (auto ipcHandle : ipcHandles) { ret = umfPutIPCHandle(ipcHandle); diff --git a/test/poolFixtures.hpp b/test/poolFixtures.hpp index 870596c91..a27f2ad63 100644 --- a/test/poolFixtures.hpp +++ b/test/poolFixtures.hpp @@ -5,6 +5,7 @@ #ifndef UMF_TEST_POOL_FIXTURES_HPP #define UMF_TEST_POOL_FIXTURES_HPP 1 +#include #include #include #include @@ -82,13 +83,15 @@ struct umfPoolTest : umf_test::test, test::SetUp(); pool = poolCreateExtUnique(this->GetParam()); +#undef max + numThreads = std::max(5, (int)utils_get_num_cores()); } void TearDown() override { test::TearDown(); } umf_test::pool_unique_handle_t pool; - static constexpr int NTHREADS = 5; + int numThreads; static constexpr std::array nonAlignedAllocSizes = {5, 7, 23, 55, 80, 119, 247}; }; @@ -281,7 +284,7 @@ TEST_P(umfPoolTest, multiThreadedMallocFree) { }; std::vector threads; - for (int i = 0; i < NTHREADS; i++) { + for (int i = 0; i < numThreads; i++) { threads.emplace_back(poolMalloc, allocSize, pool.get()); } @@ -300,7 +303,7 @@ TEST_P(umfPoolTest, multiThreadedpow2AlignedAlloc) { }; std::vector threads; - for (int i = 0; i < NTHREADS; i++) { + for (int i = 0; i < numThreads; i++) { threads.emplace_back(poolpow2AlignedAlloc, pool.get()); } @@ -335,7 +338,7 @@ TEST_P(umfPoolTest, multiThreadedReallocFree) { }; std::vector threads; - for (int i = 0; i < NTHREADS; i++) { + for (int i = 0; i < numThreads; i++) { threads.emplace_back(poolRealloc, allocSize, multiplier, pool.get()); } @@ -366,7 +369,7 @@ TEST_P(umfPoolTest, multiThreadedCallocFree) { }; std::vector threads; - for (int i = 0; i < NTHREADS; i++) { + for (int i = 0; i < numThreads; i++) { threads.emplace_back(poolCalloc, num, sizeof(int), pool.get()); } @@ -392,7 +395,7 @@ TEST_P(umfPoolTest, multiThreadedMallocFreeRandomSizes) { }; std::vector threads; - for (int i = 0; i < NTHREADS; i++) { + for (int i = 0; i < numThreads; i++) { threads.emplace_back(poolMalloc, (rand() % 16) * 8, pool.get()); } diff --git a/test/test_base_alloc.cpp b/test/test_base_alloc.cpp index 80bc67541..0781d139e 100644 --- a/test/test_base_alloc.cpp +++ b/test/test_base_alloc.cpp @@ -1,10 +1,11 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include #include #include @@ -17,9 +18,9 @@ using umf_test::test; TEST_F(test, baseAllocMultiThreadedAllocMemset) { - static constexpr int NTHREADS = 10; static constexpr int ITERATIONS = 1000; static constexpr int ALLOCATION_SIZE = 16; + int numThreads = std::max(10, (int)utils_get_num_cores()); auto pool = std::shared_ptr(umf_ba_create(ALLOCATION_SIZE), umf_ba_destroy); @@ -43,7 +44,7 @@ TEST_F(test, baseAllocMultiThreadedAllocMemset) { }; std::vector threads; - for (int i = 0; i < NTHREADS; i++) { + for (int i = 0; i < numThreads; i++) { threads.emplace_back(poolAlloc, i, pool.get()); } diff --git a/test/test_base_alloc_linear.cpp b/test/test_base_alloc_linear.cpp index 3f8371d8d..a6029d6b2 100644 --- a/test/test_base_alloc_linear.cpp +++ b/test/test_base_alloc_linear.cpp @@ -1,10 +1,11 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include #include #include @@ -50,9 +51,9 @@ TEST_F(test, baseAllocLinearPoolContainsPointer) { } TEST_F(test, baseAllocLinearMultiThreadedAllocMemset) { - static constexpr int NTHREADS = 10; static constexpr int ITERATIONS = 1000; static constexpr int MAX_ALLOCATION_SIZE = 1024; + int numThreads = std::max(10, (int)utils_get_num_cores()); srand(0); @@ -94,7 +95,7 @@ TEST_F(test, baseAllocLinearMultiThreadedAllocMemset) { }; std::vector threads; - for (int i = 0; i < NTHREADS; i++) { + for (int i = 0; i < numThreads; i++) { threads.emplace_back(poolAlloc, i, pool.get()); }