-
Notifications
You must be signed in to change notification settings - Fork 5
/
onetbb-2021.2-e2k.patch
146 lines (134 loc) · 6.04 KB
/
onetbb-2021.2-e2k.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From e3a57bd6bd8ecc9dacaab54578aac1912cc6a0d4 Mon Sep 17 00:00:00 2001
From: Ilya Kurdyukov <jpegqs@gmail.com>
Date: Mon, 1 Feb 2021 16:48:48 +0700
Subject: [PATCH] oneTBB-2021.2 e2k support
---
cmake/compilers/GNU.cmake | 5 +++++
include/oneapi/tbb/detail/_config.h | 2 +-
src/tbb/allocator.cpp | 6 ++++++
src/tbb/co_context.h | 9 +++++++++
src/tbb/tools_api/ittnotify_config.h | 7 +++++++
test/tbb/test_openmp.cpp | 5 +++++
6 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/cmake/compilers/GNU.cmake b/cmake/compilers/GNU.cmake
index d9c0759..717e977 100644
--- a/cmake/compilers/GNU.cmake
+++ b/cmake/compilers/GNU.cmake
@@ -39,6 +39,11 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "mips")
set(TBB_TEST_COMPILE_FLAGS ${TBB_TEST_COMPILE_FLAGS} -DTBB_TEST_LOW_WORKLOAD)
endif()
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL e2k)
+ set(TBB_COMMON_COMPILE_FLAGS -mno-avx -Wno-reduced-alignment -Wno-sign-compare)
+ set(TBB_TEST_COMPILE_FLAGS ${TBB_TEST_COMPILE_FLAGS} -DTBB_TEST_LOW_WORKLOAD)
+endif()
+
# TBB malloc settings
set(TBBMALLOC_LIB_COMPILE_FLAGS -fno-rtti -fno-exceptions)
set(TBB_OPENMP_FLAG -fopenmp)
diff --git a/include/oneapi/tbb/detail/_config.h b/include/oneapi/tbb/detail/_config.h
index e591b80..ea7d40b 100644
--- a/include/oneapi/tbb/detail/_config.h
+++ b/include/oneapi/tbb/detail/_config.h
@@ -193,7 +193,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 ( !_WIN32 && !__APPLE__ && !__sun && !__e2k__ && (__TBB_GCC_VERSION >= 40000 || __INTEL_COMPILER ) )
#endif
/** Presence of compiler features **/
diff --git a/src/tbb/allocator.cpp b/src/tbb/allocator.cpp
index 6bf5a0b..b52fe58 100644
--- a/src/tbb/allocator.cpp
+++ b/src/tbb/allocator.cpp
@@ -109,7 +109,13 @@ static const dynamic_link_descriptor MallocLinkTable[] = {
If that allocator is not found, it links to malloc and free. */
void initialize_handler_pointers() {
__TBB_ASSERT(allocate_handler == &initialize_allocate_handler, NULL);
+#ifdef __e2k__
+ // FIXME: many tests failing, first one is "conformance_join_node"
+ // internalPoolFree -> assert isMallocInitialized()
+ bool success = false;
+#else
bool success = dynamic_link(MALLOCLIB_NAME, MallocLinkTable, 4);
+#endif
if(!success) {
// If unsuccessful, set the handlers to the default routines.
// This must be done now, and not before FillDynamicLinks runs, because if other
diff --git a/src/tbb/co_context.h b/src/tbb/co_context.h
index 552dec3..6d9ab1e 100644
--- a/src/tbb/co_context.h
+++ b/src/tbb/co_context.h
@@ -180,7 +180,12 @@ inline void create_coroutine(coroutine_type& c, std::size_t stack_size, void* ar
c.my_context.uc_stack.ss_flags = 0;
typedef void(*coroutine_func_t)();
+#ifdef __e2k__
+ err = makecontext_e2k(&c.my_context, (coroutine_func_t)co_local_wait_for_all, sizeof(arg) / sizeof(int), arg);
+ __TBB_ASSERT_EX(err >= 0, NULL);
+#else
makecontext(&c.my_context, (coroutine_func_t)co_local_wait_for_all, sizeof(arg) / sizeof(int), arg);
+#endif
}
inline void current_coroutine(coroutine_type& c) {
@@ -200,6 +205,10 @@ inline void destroy_coroutine(coroutine_type& c) {
// Clear the stack state afterwards
c.my_stack = NULL;
c.my_stack_size = 0;
+#ifdef __e2k__
+ c.my_context.uc_stack.ss_sp = NULL;
+ freecontext_e2k(&c.my_context);
+#endif
}
#if __APPLE__
diff --git a/src/tbb/tools_api/ittnotify_config.h b/src/tbb/tools_api/ittnotify_config.h
index c25730d..cd2bf5b 100644
--- a/src/tbb/tools_api/ittnotify_config.h
+++ b/src/tbb/tools_api/ittnotify_config.h
@@ -330,6 +330,9 @@ ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
#elif ITT_ARCH==ITT_ARCH_ARM || ITT_ARCH==ITT_ARCH_PPC64
#define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
#endif /* ITT_ARCH==ITT_ARCH_IA64 */
+#ifdef __e2k__
+#define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
+#endif
#ifndef ITT_SIMPLE_INIT
ITT_INLINE long
__itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
@@ -339,11 +342,14 @@ ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
}
#endif /* ITT_SIMPLE_INIT */
+#ifndef __e2k__
void* dlopen(const char*, int) __attribute__((weak));
void* dlsym(void*, const char*) __attribute__((weak));
int dlclose(void*) __attribute__((weak));
+#endif
#define DL_SYMBOLS (dlopen && dlsym && dlclose)
+#ifndef __e2k__
int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __attribute__((weak));
int pthread_mutex_lock(pthread_mutex_t*) __attribute__((weak));
int pthread_mutex_unlock(pthread_mutex_t*) __attribute__((weak));
@@ -352,6 +358,7 @@ int pthread_mutexattr_init(pthread_mutexattr_t*) __attribute__((weak));
int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __attribute__((weak));
int pthread_mutexattr_destroy(pthread_mutexattr_t*) __attribute__((weak));
pthread_t pthread_self(void) __attribute__((weak));
+#endif
#define PTHREAD_SYMBOLS (pthread_mutex_init && pthread_mutex_lock && pthread_mutex_unlock && pthread_mutex_destroy && pthread_mutexattr_init && pthread_mutexattr_settype && pthread_mutexattr_destroy && pthread_self)
#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
diff --git a/test/tbb/test_openmp.cpp b/test/tbb/test_openmp.cpp
index d3727dc..e564a6a 100644
--- a/test/tbb/test_openmp.cpp
+++ b/test/tbb/test_openmp.cpp
@@ -103,7 +103,12 @@ public:
int start = i < n ? 0 : i - n + 1;
int finish = i < m ? i + 1 : m;
data_type sum = 0;
+#ifdef __e2k__ /* compiler bug workaround */
+ int num = p; (void)num;
+#pragma omp parallel for reduction(+:sum) num_threads(num)
+#else
#pragma omp parallel for reduction(+:sum) num_threads(p)
+#endif
for (int j = start; j < finish; ++j)
sum += my_a[j] * my_b[i - j];
my_c[i] = sum;
--
2.17.1