Skip to content

Commit 171ca93

Browse files
committed
[OpenMP] Initialize runtime in the forked child process
This patch enables serial initialization in the forked child process to fix unstable runtime behavior when used with Python-based AI tools. Differential Revision: https://reviews.llvm.org/D93230
1 parent 5186eda commit 171ca93

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,15 +1272,16 @@ static void __kmp_atfork_prepare(void) {
12721272
}
12731273

12741274
static void __kmp_atfork_parent(void) {
1275-
__kmp_release_bootstrap_lock(&__kmp_initz_lock);
12761275
__kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
1276+
__kmp_release_bootstrap_lock(&__kmp_initz_lock);
12771277
}
12781278

12791279
/* Reset the library so execution in the child starts "all over again" with
12801280
clean data structures in initial states. Don't worry about freeing memory
12811281
allocated by parent, just abandon it to be safe. */
12821282
static void __kmp_atfork_child(void) {
12831283
__kmp_release_bootstrap_lock(&__kmp_forkjoin_lock);
1284+
__kmp_release_bootstrap_lock(&__kmp_initz_lock);
12841285
/* TODO make sure this is done right for nested/sibling */
12851286
// ATT: Memory leaks are here? TODO: Check it and fix.
12861287
/* KMP_ASSERT( 0 ); */
@@ -1302,7 +1303,6 @@ static void __kmp_atfork_child(void) {
13021303
}
13031304
#endif // KMP_AFFINITY_SUPPORTED
13041305

1305-
__kmp_init_runtime = FALSE;
13061306
#if KMP_USE_MONITOR
13071307
__kmp_init_monitor = 0;
13081308
#endif
@@ -1355,6 +1355,8 @@ static void __kmp_atfork_child(void) {
13551355
__kmp_itt_reset(); // reset ITT's global state
13561356
#endif /* USE_ITT_BUILD */
13571357

1358+
__kmp_serial_initialize();
1359+
13581360
/* This is necessary to make sure no stale data is left around */
13591361
/* AC: customers complain that we use unsafe routines in the atfork
13601362
handler. Mathworks: dlsym() is unsafe. We call dlsym and dlopen

0 commit comments

Comments
 (0)