Skip to content

Conversation

kaz7
Copy link
Contributor

@kaz7 kaz7 commented Sep 19, 2023

VE supports up to 64 threads per a VE process. So, we limit the number of threads defined by KMP_MAX_NTH. We also modify the __kmp_sys_max_nth initialization to use KMP_MAX_NTH as a limit.

@kaz7 kaz7 requested review from shiltian and a team September 19, 2023 02:00
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2023

@llvm/pr-subscribers-openmp

Changes

VE supports up to 64 threads per a VE process. So, we limit the number of threads defined by KMP_MAX_NTH. We also modify the __kmp_sys_max_nth initialization to use KMP_MAX_NTH as a limit.


Full diff: https://github.com/llvm/llvm-project/pull/66729.diff

2 Files Affected:

  • (modified) openmp/runtime/src/kmp.h (+7)
  • (modified) openmp/runtime/src/z_Linux_util.cpp (+8)
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index b931b7ba66416ec..f26311f28516539 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1153,8 +1153,15 @@ extern void __kmp_init_target_task();
 #if defined(PTHREAD_THREADS_MAX) && PTHREAD_THREADS_MAX < INT_MAX
 #define KMP_MAX_NTH PTHREAD_THREADS_MAX
 #else
+#ifdef __ve__
+// VE's pthread supports only up to 64 threads per a VE process.
+//   https://sxauroratsubasa.sakura.ne.jp/documents/veos/en/VEOS_high_level_design.pdf
+//   p. 14 Maximum number of threads per VE process is 64.
+#define KMP_MAX_NTH 64
+#else
 #define KMP_MAX_NTH INT_MAX
 #endif
+#endif
 #endif /* KMP_MAX_NTH */
 
 #ifdef PTHREAD_STACK_MIN
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp
index 42488eb6be5dc87..478c09baa1beefe 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/runtime/src/z_Linux_util.cpp
@@ -1894,6 +1894,13 @@ void __kmp_runtime_initialize(void) {
 
     /* Query the maximum number of threads */
     __kmp_type_convert(sysconf(_SC_THREAD_THREADS_MAX), &(__kmp_sys_max_nth));
+#ifdef __ve__
+    if (__kmp_sys_max_nth == -1) {
+      // VE's pthread supports only up to 64 threads per a VE process.
+      // So we use that KMP_MAX_NTH (predefined as 64) here.
+      __kmp_sys_max_nth = KMP_MAX_NTH;
+    }
+#else
     if (__kmp_sys_max_nth == -1) {
       /* Unlimited threads for NPTL */
       __kmp_sys_max_nth = INT_MAX;
@@ -1901,6 +1908,7 @@ void __kmp_runtime_initialize(void) {
       /* Can't tell, just use PTHREAD_THREADS_MAX */
       __kmp_sys_max_nth = KMP_MAX_NTH;
     }
+#endif
 
     /* Query the minimum stack size */
     __kmp_sys_min_stksize = sysconf(_SC_THREAD_STACK_MIN);

Copy link
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one nit

VE supports up to 64 threads per a VE process.  So, we limit the number
of threads defined by KMP_MAX_NTH.  We also modify the __kmp_sys_max_nth
initialization to use KMP_MAX_NTH as a limit.
@kaz7 kaz7 merged commit 7b8130c into llvm:main Sep 20, 2023
@kaz7 kaz7 deleted the main-openmp-reduce-num-threads branch September 20, 2023 08:44
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants