[Openmp-commits] [PATCH] D119586: [OpenMP][libomp] Fix crash when LIBOMP_NUM_HIDDEN_HELPER_THREADS=1.
Andrey Churbanov via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Fri Feb 11 13:45:30 PST 2022
AndreyChurbanov updated this revision to Diff 408040.
AndreyChurbanov added a comment.
Addressed Ravi's comment.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119586/new/
https://reviews.llvm.org/D119586
Files:
openmp/runtime/src/kmp_settings.cpp
openmp/runtime/test/tasking/hidden_helper_task/single_helper_thread.c
Index: openmp/runtime/test/tasking/hidden_helper_task/single_helper_thread.c
===================================================================
--- /dev/null
+++ openmp/runtime/test/tasking/hidden_helper_task/single_helper_thread.c
@@ -0,0 +1,21 @@
+// RUN: %libomp-compile && env LIBOMP_NUM_HIDDEN_HELPER_THREADS=1 %libomp-run
+
+// The test checks that "devide-by-0" bug fixed in runtime.
+// The fix is to increment number of threads by 1 if positive,
+// so that operation
+// (gtid) % (__kmp_hidden_helper_threads_num - 1)
+// does not cause crash.
+
+#include <stdio.h>
+#include <omp.h>
+
+int main(){
+#pragma omp target nowait
+ {
+ printf("----- in target region\n");
+ }
+ printf("------ before taskwait\n");
+#pragma omp taskwait
+ printf("passed\n");
+ return 0;
+}
Index: openmp/runtime/src/kmp_settings.cpp
===================================================================
--- openmp/runtime/src/kmp_settings.cpp
+++ openmp/runtime/src/kmp_settings.cpp
@@ -1245,13 +1245,25 @@
// task
if (__kmp_hidden_helper_threads_num == 0) {
__kmp_enable_hidden_helper = FALSE;
+ } else {
+ // Since the main thread of hidden helper team dooes not participate
+ // in tasks execution let's increment the number of threads by one
+ // so that requested number of threads do actual job.
+ __kmp_hidden_helper_threads_num++;
}
} // __kmp_stg_parse_num_hidden_helper_threads
static void __kmp_stg_print_num_hidden_helper_threads(kmp_str_buf_t *buffer,
char const *name,
void *data) {
- __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
+ if (__kmp_hidden_helper_threads_num == 0) {
+ __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num);
+ } else {
+ KMP_DEBUG_ASSERT(__kmp_hidden_helper_threads_num > 1);
+ // Let's exclude the main thread of hidden helper team and print
+ // number of worker threads those do actual job.
+ __kmp_stg_print_int(buffer, name, __kmp_hidden_helper_threads_num - 1);
+ }
} // __kmp_stg_print_num_hidden_helper_threads
static void __kmp_stg_parse_use_hidden_helper(char const *name,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119586.408040.patch
Type: text/x-patch
Size: 2225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220211/636c87cb/attachment-0001.bin>
More information about the Openmp-commits
mailing list