Skip to content
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

Enable WASM on oneTBB #1006

Merged
merged 15 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ endif()

# -------------------------------------------------------------------
# Common dependencies
#force -pthread during compilation for Emscripten
if (EMSCRIPTEN)
set(THREADS_HAVE_PTHREAD_ARG TRUE)
JhaShweta1 marked this conversation as resolved.
Show resolved Hide resolved
endif()

set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
# -------------------------------------------------------------------
Expand Down
11 changes: 9 additions & 2 deletions cmake/compilers/Clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if(EMSCRIPTEN)
JhaShweta1 marked this conversation as resolved.
Show resolved Hide resolved
set(TBB_EMSCRIPTEN 1)
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -fexceptions)
isaevil marked this conversation as resolved.
Show resolved Hide resolved
set(TBB_TEST_LINK_FLAGS ${TBB_COMMON_LINK_FLAGS} -fexceptions -sINITIAL_MEMORY=65536000 -sALLOW_MEMORY_GROWTH=1 -sEXIT_RUNTIME=1)
JhaShweta1 marked this conversation as resolved.
Show resolved Hide resolved
set_property(TARGET Threads::Threads PROPERTY INTERFACE_LINK_LIBRARIES "-pthread")
endif()

if (MINGW)
set(TBB_LINK_DEF_FILE_FLAG "")
set(TBB_DEF_FILE_PREFIX "")
Expand Down Expand Up @@ -50,8 +57,8 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)")
endif()

# Clang flags to prevent compiler from optimizing out security checks
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security
-fstack-protector-strong -fPIC)
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -fPIC $<$<NOT:$<IF:${EMSCRIPTEN},1,0>>:-fstack-protector-strong>)
JhaShweta1 marked this conversation as resolved.
Show resolved Hide resolved

# -z switch is not supported on MacOS
if (NOT APPLE)
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now)
Expand Down
4 changes: 2 additions & 2 deletions include/oneapi/tbb/detail/_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

/** __TBB_DYNAMIC_LOAD_ENABLED describes the system possibility to load shared libraries at run time **/
#ifndef __TBB_DYNAMIC_LOAD_ENABLED
#define __TBB_DYNAMIC_LOAD_ENABLED 1
#define __TBB_DYNAMIC_LOAD_ENABLED (!__EMSCRIPTEN__)
#endif

/** __TBB_WIN8UI_SUPPORT enables support of Windows* Store Apps and limit a possibility to load
Expand All @@ -201,7 +201,7 @@

/** __TBB_WEAK_SYMBOLS_PRESENT denotes that the system supports the weak symbol mechanism **/
#ifndef __TBB_WEAK_SYMBOLS_PRESENT
#define __TBB_WEAK_SYMBOLS_PRESENT ( !_WIN32 && !__APPLE__ && !__sun && (__TBB_GCC_VERSION >= 40000 || __INTEL_COMPILER ) )
#define __TBB_WEAK_SYMBOLS_PRESENT ( !__EMSCRIPTEN__ && !_WIN32 && !__APPLE__ && !__sun && (__TBB_GCC_VERSION >= 40000 || __INTEL_COMPILER ) )
#endif

/** Presence of compiler features **/
Expand Down
51 changes: 29 additions & 22 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,11 @@ if (TARGET TBB::tbb)
)

# HWLOC related test
tbb_add_tbbbind_test(SUBDIR tbb NAME test_arena_constraints)
if (NOT TBB_EMSCRIPTEN)
tbb_add_tbbbind_test(SUBDIR tbb NAME test_arena_constraints)
endif()

if (NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "mips")
if ((NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "mips") AND (NOT TBB_EMSCRIPTEN))
# TODO: Fix for MIPS
tbb_add_test(SUBDIR tbb NAME test_tbb_fork DEPENDENCIES TBB::tbb)
endif()
JhaShweta1 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -533,7 +535,9 @@ if (TARGET TBB::tbb)
tbb_add_test(SUBDIR conformance NAME conformance_graph DEPENDENCIES TBB::tbb)

# HWLOC related conformance
if (NOT TBB_EMSCRIPTEN)
tbb_add_tbbbind_test(SUBDIR conformance NAME conformance_arena_constraints)
endif()
JhaShweta1 marked this conversation as resolved.
Show resolved Hide resolved

if (MSVC AND BUILD_SHARED_LIBS AND CMAKE_VERSION VERSION_GREATER 3.13) # LINK_OPTIONS property first appeared in 3.13
# version of the CMake
Expand All @@ -551,27 +555,28 @@ endif()
if (TARGET TBB::tbbmalloc)
# TBB allocator tests
if (NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "mips")
# Define TBB malloc tests
tbb_add_test(SUBDIR tbbmalloc NAME test_scalable_allocator DEPENDENCIES TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_pools DEPENDENCIES TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_init_shutdown DEPENDENCIES TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_regression DEPENDENCIES TBB::tbbmalloc)
if (TARGET TBB::tbb)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_shutdown_hang DEPENDENCIES TBB::tbb TBB::tbbmalloc)
endif()

if (NOT (WINDOWS_STORE OR TBB_WINDOWS_DRIVER))
# TODO: Consider adding following tests on WINDOWS_STORE and TBB_WINDOWS_DRIVER platforms
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_compliance DEPENDENCIES TBB::tbbmalloc)
tbb_add_lib_test(SUBDIR tbbmalloc NAME test_malloc_used_by_lib DEPENDENCIES TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_used_by_lib DEPENDENCIES _test_malloc_used_by_lib)
tbb_add_lib_test(SUBDIR tbbmalloc NAME test_malloc_lib_unload)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_lib_unload DEPENDENCIES _test_malloc_lib_unload)
endif()
if (NOT TBB_EMSCRIPTEN)
# Define TBB malloc tests
tbb_add_test(SUBDIR tbbmalloc NAME test_scalable_allocator DEPENDENCIES TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_pools DEPENDENCIES TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_init_shutdown DEPENDENCIES TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_regression DEPENDENCIES TBB::tbbmalloc)
if (TARGET TBB::tbb)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_shutdown_hang DEPENDENCIES TBB::tbb TBB::tbbmalloc)
endif()

enable_language(C)
tbb_add_c_test(SUBDIR tbbmalloc NAME test_malloc_pure_c DEPENDENCIES TBB::tbbmalloc)
if (NOT (WINDOWS_STORE OR TBB_WINDOWS_DRIVER))
# TODO: Consider adding following tests on WINDOWS_STORE and TBB_WINDOWS_DRIVER platforms
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_compliance DEPENDENCIES TBB::tbbmalloc)
tbb_add_lib_test(SUBDIR tbbmalloc NAME test_malloc_used_by_lib DEPENDENCIES TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_used_by_lib DEPENDENCIES _test_malloc_used_by_lib)
tbb_add_lib_test(SUBDIR tbbmalloc NAME test_malloc_lib_unload)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_lib_unload DEPENDENCIES _test_malloc_lib_unload)
endif()

enable_language(C)
tbb_add_c_test(SUBDIR tbbmalloc NAME test_malloc_pure_c DEPENDENCIES TBB::tbbmalloc)
endif()
# ----------------------------------------------------------------------------------------
# Whitebox testing

Expand Down Expand Up @@ -624,7 +629,9 @@ if (TARGET TBB::tbbmalloc)
if (BUILD_SHARED_LIBS AND NOT TBB_SANITIZE MATCHES "thread" AND TBBMALLOC_PROXY_BUILD AND NOT MSVC_CXX_ARCHITECTURE_ID MATCHES "ARM64")
# Define TBB malloc proxy tests
tbb_add_lib_test(SUBDIR tbbmalloc NAME test_malloc_atexit DEPENDENCIES TBB::tbbmalloc_proxy TBB::tbbmalloc)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_atexit DEPENDENCIES TBB::tbbmalloc_proxy TBB::tbbmalloc _test_malloc_atexit)
if (NOT TBB_EMSCRIPTEN)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_atexit DEPENDENCIES TBB::tbbmalloc_proxy TBB::tbbmalloc _test_malloc_atexit)
endif()
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_overload DEPENDENCIES TBB::tbbmalloc_proxy)
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_overload_disable DEPENDENCIES TBB::tbbmalloc_proxy TBB::tbbmalloc) # safer_msize call need to be available
tbb_add_test(SUBDIR tbbmalloc NAME test_malloc_new_handler DEPENDENCIES TBB::tbbmalloc_proxy)
Expand Down
2 changes: 1 addition & 1 deletion test/conformance/conformance_global_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ TEST_CASE("simple prolong lifetime 3") {

// The test cannot work correctly with statically linked runtime.
// TODO: investigate a failure in debug with MSVC
#if !_MSC_VER || (defined(_DLL) && !defined(_DEBUG))
#if (!_MSC_VER || (defined(_DLL) && !defined(_DEBUG))) && !EMSCRIPTEN
#include <csetjmp>

// Overall, the test case is not safe because the dtors might not be called during long jump.
Expand Down
4 changes: 3 additions & 1 deletion test/tbb/test_parallel_invoke.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020-2021 Intel Corporation
Copyright (c) 2020-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,7 @@
//! \file test_parallel_invoke.cpp
//! \brief Test for [algorithms.parallel_invoke]

#if !EMSCRIPTEN
//! Testing parallel_invoke memory usage
//! \brief \ref resource_usage \ref stress
TEST_CASE("Test memory leaks") {
Expand Down Expand Up @@ -56,6 +57,7 @@ TEST_CASE("Test memory leaks") {
}
REQUIRE_MESSAGE(false, "Seems like we get memory leak here.");
}
#endif

template<typename Body>
void test_from_2_to_10_arguments(const Body& body, const std::atomic<std::size_t>& counter) {
Expand Down
4 changes: 3 additions & 1 deletion test/tbb/test_partitioner.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2021-2022 Intel Corporation
Copyright (c) 2021-2023 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -143,7 +143,9 @@ void strict_test() {
//! \brief \ref error_guessing
TEST_CASE("Threads respect task affinity") {
task_affinity_retention::relaxed_test();
#if !EMSCRIPTEN
task_affinity_retention::strict_test();
#endif
}

template <typename Range>
Expand Down
8 changes: 8 additions & 0 deletions test/tbb/test_task_arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,11 +1831,13 @@ TEST_CASE("Test for concurrent functionality") {
TestConcurrentFunctionality();
}

#if !EMSCRIPTEN
//! Test for arena entry consistency
//! \brief \ref requirement \ref error_guessing
TEST_CASE("Test for task arena entry consistency") {
TestArenaEntryConsistency();
}
#endif

//! Test for task arena attach functionality
//! \brief \ref requirement \ref interface
Expand Down Expand Up @@ -1867,6 +1869,7 @@ TEST_CASE("Delegated spawn wait") {
TestDelegatedSpawnWait();
}

#if !EMSCRIPTEN
//! Test task arena isolation functionality
//! \brief \ref requirement \ref interface
TEST_CASE("Isolated execute") {
Expand All @@ -1875,6 +1878,7 @@ TEST_CASE("Isolated execute") {
TestIsolatedExecute();
}
}
#endif

//! Test for TBB Workers creation limits
//! \brief \ref requirement
Expand All @@ -1888,11 +1892,13 @@ TEST_CASE("Arena workers migration") {
TestArenaWorkersMigration();
}

#if !EMSCRIPTEN
//! Test for multiple waits, threads should not block each other
//! \brief \ref requirement
TEST_CASE("Multiple waits") {
TestMultipleWaits();
}
#endif

//! Test for small stack size settings and arena initialization
//! \brief \ref error_guessing
Expand Down Expand Up @@ -1983,6 +1989,7 @@ TEST_CASE("Empty task_handle cannot be scheduled"
}
#endif

#if !EMSCRIPTEN
//! \brief \ref error_guessing
TEST_CASE("Test threads sleep") {
for (auto concurrency_level : utils::concurrency_range()) {
Expand All @@ -1993,6 +2000,7 @@ TEST_CASE("Test threads sleep") {
test_threads_sleep(conc, conc);
}
}
#endif

#if __TBB_PREVIEW_TASK_GROUP_EXTENSIONS

Expand Down
4 changes: 2 additions & 2 deletions test/tbb/test_task_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ namespace TestIsolationNS {
//! Test for thread safety for the task_group
//! \brief \ref error_guessing \ref resource_usage
TEST_CASE("Memory leaks test is not applicable under ASAN\n" * doctest::skip(true)) {}
#else
#elif !EMSCRIPTEN
//! Test for thread safety for the task_group
//! \brief \ref error_guessing \ref resource_usage
TEST_CASE("Thread safety test for the task group") {
Expand Down Expand Up @@ -823,7 +823,7 @@ TEST_CASE("Move semantics test for the task group") {
//! Test for thread safety for the isolated_task_group
//! \brief \ref error_guessing
TEST_CASE("Memory leaks test is not applicable under ASAN\n" * doctest::skip(true)) {}
#else
#elif !EMSCRIPTEN
//! Test for thread safety for the isolated_task_group
//! \brief \ref error_guessing
TEST_CASE("Thread safety test for the isolated task group") {
Expand Down