Skip to content

Commit

Permalink
Add workaround for incorrect soft limit initialization (uxlfoundation…
Browse files Browse the repository at this point in the history
…#512)

Signed-off-by: pavelkumbrasev <[email protected]>
  • Loading branch information
pavelkumbrasev authored Jul 30, 2021
1 parent 34c7d17 commit 552f342
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/tbb/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ void __TBB_EXPORTED_FUNC enqueue(d1::task& t, d1::task_group_context& ctx, d1::t
}

void task_arena_impl::initialize(d1::task_arena_base& ta) {
governor::one_time_init();
// Enforce global market initialization to properly initialize soft limit
(void)governor::get_thread_data();
if (ta.my_max_concurrency < 1) {
#if __TBB_ARENA_BINDING

Expand Down
10 changes: 6 additions & 4 deletions test/tbb/test_arena_priorities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "common/spin_barrier.h"
#include "common/utils.h"
#include "common/utils_concurrency_limit.h"

#include <cstddef>
#include <algorithm>
Expand Down Expand Up @@ -177,13 +178,14 @@ void wait_work_completion(

void test() {

const std::size_t max_num_threads = tbb::global_control::active_value(
tbb::global_control::max_allowed_parallelism
);
const std::size_t max_num_threads = utils::get_platform_max_threads();

tbb::global_control control(tbb::global_control::max_allowed_parallelism, max_num_threads + 1);
concurrency_type signed_max_num_threads = static_cast<int>(max_num_threads);
if( 1 == max_num_threads )
if (1 == max_num_threads) {
// Skipping workerless case
return;
}

INFO( "max_num_threads = " << max_num_threads );
// TODO: iterate over threads to see that the work is going on in low priority arena.
Expand Down
2 changes: 2 additions & 0 deletions test/tbb/test_buffer_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "common/config.h"

#include "tbb/flow_graph.h"
#include "tbb/global_control.h"

#include "common/test.h"
#include "common/utils.h"
Expand Down Expand Up @@ -460,6 +461,7 @@ void test_deduction_guides() {
//! \brief \ref requirement \ref error_guessing
TEST_CASE("Serial and parallel test"){
for (int p = 2; p <= 4; ++p) {
tbb::global_control thread_limit(tbb::global_control::max_allowed_parallelism, p);
tbb::task_arena arena(p);
arena.execute(
[&]() {
Expand Down
2 changes: 2 additions & 0 deletions test/tbb/test_eh_flow_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "tbb/task_scheduler_observer.h"
#endif
#include "tbb/flow_graph.h"
#include "tbb/global_control.h"

#include "common/test.h"

Expand Down Expand Up @@ -2029,6 +2030,7 @@ void TestOneThreadNum(int nThread) {
TEST_CASE("Testing several threads"){
// reverse order of tests
for(unsigned int nThread=utils::MaxThread; nThread >= utils::MinThread; --nThread) {
tbb::global_control thread_limit(tbb::global_control::max_allowed_parallelism, nThread);
TestOneThreadNum(nThread);
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/tbb/test_priority_queue_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "common/config.h"

#include "tbb/flow_graph.h"
#include "tbb/global_control.h"

#include "common/test.h"
#include "common/utils.h"
Expand Down Expand Up @@ -381,6 +382,7 @@ void test_deduction_guides() {
//! \brief \ref requirement \ref error_guessing
TEST_CASE("Serial, parallel and reservation tests"){
for (int p = 2; p <= 4; ++p) {
tbb::global_control thread_limit(tbb::global_control::max_allowed_parallelism, p);
tbb::task_arena arena(p);
arena.execute(
[&]() {
Expand Down
2 changes: 2 additions & 0 deletions test/tbb/test_queue_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "common/config.h"

#include "tbb/flow_graph.h"
#include "tbb/global_control.h"

#include "common/test.h"
#include "common/utils.h"
Expand Down Expand Up @@ -497,6 +498,7 @@ void test_deduction_guides() {
//! \brief \ref requirement \ref error_guessing
TEST_CASE("Parallel, serial test"){
for (int p = 2; p <= 4; ++p) {
tbb::global_control thread_limit(tbb::global_control::max_allowed_parallelism, p);
tbb::task_arena arena(p);
arena.execute(
[&]() {
Expand Down
2 changes: 2 additions & 0 deletions test/tbb/test_sequencer_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "common/config.h"

#include "tbb/flow_graph.h"
#include "tbb/global_control.h"

#include "common/test.h"
#include "common/utils.h"
Expand Down Expand Up @@ -440,6 +441,7 @@ void test_deduction_guides() {
//! \brief \ref requirement \ref error_guessing
TEST_CASE("Serial and parallel test"){
for (int p = 2; p <= 4; ++p) {
tbb::global_control thread_limit(tbb::global_control::max_allowed_parallelism, p);
tbb::task_arena arena(p);
arena.execute(
[&]() {
Expand Down
17 changes: 17 additions & 0 deletions test/tbb/test_task_arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,23 @@ struct enqueue_test_helper {
};

//--------------------------------------------------//

// This test should be first
//! \brief \ref requirement
TEST_CASE("task_arena initialize soft limit ignoring affinity mask") {
tbb::enumerable_thread_specific<int> ets;

tbb::task_arena arena(int(utils::get_platform_max_threads() * 2));
arena.execute([&ets] {
tbb::parallel_for(0, 10000000, [&ets](int){
ets.local() = 1;
utils::doDummyWork(100);
});
});

CHECK(ets.combine(std::plus<int>{}) <= int(utils::get_platform_max_threads()));
}

//! Test for task arena in concurrent cases
//! \brief \ref requirement
TEST_CASE("Test for concurrent functionality") {
Expand Down

0 comments on commit 552f342

Please sign in to comment.