Skip to content

Repro of issue: ConcurrentOpenConcurrentCloseHandles and ConcurrentGetConcurrentPutHandles tests fail when NTHREADS == utils_get_num_cores() #1315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions test/ipcFixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -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;

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

std::array<std::vector<umf_ipc_handle_t>, NTHREADS> ipcHandles;
std::array<std::vector<umf_ipc_handle_t>, CNTHREADS> ipcHandles;

umf_test::syncthreads_barrier syncthreads(NTHREADS);
umf_test::syncthreads_barrier syncthreads(numThreads);

auto getHandlesFn = [shuffle, &ipcHandles, &ptrs,
&syncthreads](size_t tid) {
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -302,13 +304,13 @@ struct umfIpcTest : umf_test::test,
ipcHandles.push_back(ipcHandle);
}

std::array<std::vector<void *>, NTHREADS> openedIpcHandles;
std::array<std::vector<void *>, 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) {
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions test/poolFixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef UMF_TEST_POOL_FIXTURES_HPP
#define UMF_TEST_POOL_FIXTURES_HPP 1

#include <algorithm>
#include <array>
#include <cstring>
#include <functional>
Expand Down Expand Up @@ -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<int, 7> nonAlignedAllocSizes = {5, 7, 23, 55,
80, 119, 247};
};
Expand Down Expand Up @@ -281,7 +284,7 @@ TEST_P(umfPoolTest, multiThreadedMallocFree) {
};

std::vector<std::thread> threads;
for (int i = 0; i < NTHREADS; i++) {
for (int i = 0; i < numThreads; i++) {
threads.emplace_back(poolMalloc, allocSize, pool.get());
}

Expand All @@ -300,7 +303,7 @@ TEST_P(umfPoolTest, multiThreadedpow2AlignedAlloc) {
};

std::vector<std::thread> threads;
for (int i = 0; i < NTHREADS; i++) {
for (int i = 0; i < numThreads; i++) {
threads.emplace_back(poolpow2AlignedAlloc, pool.get());
}

Expand Down Expand Up @@ -335,7 +338,7 @@ TEST_P(umfPoolTest, multiThreadedReallocFree) {
};

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

Expand Down Expand Up @@ -366,7 +369,7 @@ TEST_P(umfPoolTest, multiThreadedCallocFree) {
};

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

Expand All @@ -392,7 +395,7 @@ TEST_P(umfPoolTest, multiThreadedMallocFreeRandomSizes) {
};

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

Expand Down
7 changes: 4 additions & 3 deletions test/test_base_alloc.cpp
Original file line number Diff line number Diff line change
@@ -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 <algorithm>
#include <cstdio>
#include <cstdlib>
#include <thread>
Expand All @@ -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_pool_t>(umf_ba_create(ALLOCATION_SIZE),
umf_ba_destroy);
Expand All @@ -43,7 +44,7 @@ TEST_F(test, baseAllocMultiThreadedAllocMemset) {
};

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

Expand Down
7 changes: 4 additions & 3 deletions test/test_base_alloc_linear.cpp
Original file line number Diff line number Diff line change
@@ -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 <algorithm>
#include <cstdio>
#include <cstdlib>
#include <thread>
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -94,7 +95,7 @@ TEST_F(test, baseAllocLinearMultiThreadedAllocMemset) {
};

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

Expand Down
Loading