[Openmp-commits] [PATCH] D93230: [OpenMP] Initialize runtime in the forked child process

Hansang Bae via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Dec 14 09:06:13 PST 2020


hbae created this revision.
hbae added reviewers: AndreyChurbanov, jlpeyton.
hbae added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
hbae requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

This patch enables serial initialization in the forked child process
to fix unstable runtime behavior when used with Python-based AI tools.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93230

Files:
  openmp/runtime/src/z_Linux_util.cpp


Index: openmp/runtime/src/z_Linux_util.cpp
===================================================================
--- openmp/runtime/src/z_Linux_util.cpp
+++ openmp/runtime/src/z_Linux_util.cpp
@@ -1272,8 +1272,8 @@
 }
 
 static void __kmp_atfork_parent(void) {
-  __kmp_release_bootstrap_lock(&__kmp_initz_lock);
   __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
+  __kmp_release_bootstrap_lock(&__kmp_initz_lock);
 }
 
 /* Reset the library so execution in the child starts "all over again" with
@@ -1281,6 +1281,7 @@
    allocated by parent, just abandon it to be safe. */
 static void __kmp_atfork_child(void) {
   __kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
+  __kmp_release_bootstrap_lock(&__kmp_initz_lock);
   /* TODO make sure this is done right for nested/sibling */
   // ATT:  Memory leaks are here? TODO: Check it and fix.
   /* KMP_ASSERT( 0 ); */
@@ -1302,7 +1303,6 @@
   }
 #endif // KMP_AFFINITY_SUPPORTED
 
-  __kmp_init_runtime = FALSE;
 #if KMP_USE_MONITOR
   __kmp_init_monitor = 0;
 #endif
@@ -1355,6 +1355,8 @@
   __kmp_itt_reset(); // reset ITT's global state
 #endif /* USE_ITT_BUILD */
 
+  __kmp_serial_initialize();
+
   /* This is necessary to make sure no stale data is left around */
   /* AC: customers complain that we use unsafe routines in the atfork
      handler. Mathworks: dlsym() is unsafe. We call dlsym and dlopen


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93230.311615.patch
Type: text/x-patch
Size: 1366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20201214/128cf558/attachment-0001.bin>


More information about the Openmp-commits mailing list