[Openmp-commits] [openmp] f1b9ce2 - [OpenMP] Fix a few issues with hidden helper task
Hansang Bae via Openmp-commits
openmp-commits at lists.llvm.org
Thu Jul 1 15:10:51 PDT 2021
Author: Hansang Bae
Date: 2021-07-01T17:10:32-05:00
New Revision: f1b9ce2736d826df2ff4cbd67116864f0856334f
URL: https://github.com/llvm/llvm-project/commit/f1b9ce2736d826df2ff4cbd67116864f0856334f
DIFF: https://github.com/llvm/llvm-project/commit/f1b9ce2736d826df2ff4cbd67116864f0856334f.diff
LOG: [OpenMP] Fix a few issues with hidden helper task
This patch includes the following changes to address a few issues when
using hidden helper task.
- Assertion is triggered when there are inadvertent calls to hidden
helper functions on non-Linux OS
- Added deinit code in __kmp_internal_end_library function to fix random
shutdown crashes
- Moved task data access into the lock-guarded region in __kmp_push_task
Differential Revision: https://reviews.llvm.org/D105308
Added:
Modified:
openmp/runtime/src/kmp_runtime.cpp
openmp/runtime/src/kmp_tasking.cpp
openmp/runtime/src/z_Linux_util.cpp
Removed:
################################################################################
diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index 414e9ba4e36d7..f6a53825f2d10 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -6204,6 +6204,16 @@ void __kmp_internal_end_library(int gtid_req) {
return;
}
+ // If hidden helper team has been initialized, we need to deinit it
+ if (TCR_4(__kmp_init_hidden_helper) &&
+ !TCR_4(__kmp_hidden_helper_team_done)) {
+ TCW_SYNC_4(__kmp_hidden_helper_team_done, TRUE);
+ // First release the main thread to let it continue its work
+ __kmp_hidden_helper_main_thread_release();
+ // Wait until the hidden helper team has been destroyed
+ __kmp_hidden_helper_threads_deinitz_wait();
+ }
+
KMP_MB(); /* Flush all pending memory write invalidates. */
/* find out who we are and what we should do */
{
@@ -6317,7 +6327,8 @@ void __kmp_internal_end_thread(int gtid_req) {
}
// If hidden helper team has been initialized, we need to deinit it
- if (TCR_4(__kmp_init_hidden_helper)) {
+ if (TCR_4(__kmp_init_hidden_helper) &&
+ !TCR_4(__kmp_hidden_helper_team_done)) {
TCW_SYNC_4(__kmp_hidden_helper_team_done, TRUE);
// First release the main thread to let it continue its work
__kmp_hidden_helper_main_thread_release();
@@ -8697,11 +8708,12 @@ void __kmp_omp_display_env(int verbose) {
// Globals and functions for hidden helper task
kmp_info_t **__kmp_hidden_helper_threads;
kmp_info_t *__kmp_hidden_helper_main_thread;
-kmp_int32 __kmp_hidden_helper_threads_num = 8;
std::atomic<kmp_int32> __kmp_unexecuted_hidden_helper_tasks;
#if KMP_OS_LINUX
+kmp_int32 __kmp_hidden_helper_threads_num = 8;
kmp_int32 __kmp_enable_hidden_helper = TRUE;
#else
+kmp_int32 __kmp_hidden_helper_threads_num = 0;
kmp_int32 __kmp_enable_hidden_helper = FALSE;
#endif
diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 62f0bdca4be93..7dfd256801b5a 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -436,10 +436,12 @@ static kmp_int32 __kmp_push_task(kmp_int32 gtid, kmp_task_t *task) {
gtid, taskdata, thread_data->td.td_deque_ntasks,
thread_data->td.td_deque_head, thread_data->td.td_deque_tail));
+ auto hidden_helper = taskdata->td_flags.hidden_helper;
+
__kmp_release_bootstrap_lock(&thread_data->td.td_deque_lock);
// Signal one worker thread to execute the task
- if (taskdata->td_flags.hidden_helper) {
+ if (UNLIKELY(hidden_helper)) {
// Wake hidden helper threads up if they're sleeping
__kmp_hidden_helper_worker_thread_signal();
}
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp
index bd50987a857ac..5c2486904a76e 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/runtime/src/z_Linux_util.cpp
@@ -25,7 +25,9 @@
#include <alloca.h>
#endif
#include <math.h> // HUGE_VAL.
+#if KMP_OS_LINUX
#include <semaphore.h>
+#endif // KMP_OS_LINUX
#include <sys/resource.h>
#include <sys/syscall.h>
#include <sys/time.h>
@@ -2468,6 +2470,7 @@ int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int tid, int argc,
#endif
+#if KMP_OS_LINUX
// Functions for hidden helper task
namespace {
// Condition variable for initializing hidden helper team
@@ -2628,5 +2631,42 @@ void __kmp_hidden_helper_threads_deinitz_release() {
status = pthread_mutex_unlock(&hidden_helper_threads_deinitz_lock);
KMP_CHECK_SYSFAIL("pthread_mutex_unlock", status);
}
+#else // KMP_OS_LINUX
+void __kmp_hidden_helper_worker_thread_wait() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+
+void __kmp_do_initialize_hidden_helper_threads() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+
+void __kmp_hidden_helper_threads_initz_wait() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+
+void __kmp_hidden_helper_initz_release() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+
+void __kmp_hidden_helper_main_thread_wait() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+
+void __kmp_hidden_helper_main_thread_release() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+
+void __kmp_hidden_helper_worker_thread_signal() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+
+void __kmp_hidden_helper_threads_deinitz_wait() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+
+void __kmp_hidden_helper_threads_deinitz_release() {
+ KMP_ASSERT(0 && "Hidden helper task is not supported on this OS");
+}
+#endif // KMP_OS_LINUX
// end of file //
More information about the Openmp-commits
mailing list