Fine tune OpenMP some more

This commit is contained in:
Justine Tunney 2024-01-30 04:38:11 -08:00
parent 369aebfc48
commit 616717fa82
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 45 additions and 48 deletions

View file

@ -142,6 +142,9 @@ libc/isystem/nsync_once.h \
libc/isystem/nsync_time.h \
libc/isystem/nsync_waiter.h \
libc/isystem/numeric \
libc/isystem/omp-tools.h \
libc/isystem/omp.h \
libc/isystem/ompx.h \
libc/isystem/optional \
libc/isystem/ostream \
libc/isystem/paths.h \
@ -274,6 +277,8 @@ LIBC_INCS = $(filter %.inc,$(LIBC_FILES))
LIBC_CHECKS = $(LIBC_HDRS_H:%=o/$(MODE)/%.ok)
LIBC_FILES := $(wildcard libc/*)
o/$(MODE)/libc/isystem/ompx.h.ok: private CPPFLAGS += -Wno-unknown-pragmas
.PHONY: o/$(MODE)/libc
o/$(MODE)/libc: o/$(MODE)/libc/calls \
o/$(MODE)/libc/crt \

3
libc/isystem/omp-tools.h Normal file
View file

@ -0,0 +1,3 @@
#ifndef _OMP_TOOLS_H
#include "third_party/openmp/omp-tools.h"
#endif /* _OMP_TOOLS_H */

3
libc/isystem/omp.h Normal file
View file

@ -0,0 +1,3 @@
#ifndef _OMP_H
#include "third_party/openmp/omp.h"
#endif /* _OMP_H */

3
libc/isystem/ompx.h Normal file
View file

@ -0,0 +1,3 @@
#ifndef _OMPX_H
#include "third_party/openmp/ompx.h"
#endif /* _OMPX_H */

View file

@ -58,10 +58,11 @@ $(THIRD_PARTY_OPENMP_A_OBJS): private \
-ffunction-sections \
-Wno-maybe-uninitialized \
-Wno-stringop-truncation \
-Wno-class-memaccess \
-Wno-unused-but-set-variable \
-Wno-class-memaccess \
-fno-strict-aliasing \
-Wno-frame-address \
-fno-strict-aliasing
-Wno-sign-compare
o/$(MODE)/third_party/openmp/util1.o: private COPTS += -fportcosmo

View file

@ -13,5 +13,8 @@ LOCAL CHANGES
- Use Cosmo's gettid() function
- Ran third_party/openmp/generate.sh
- Removed usage of syscall() function
- Only enable hidden helper on GNU/Systemd
- Made __kmp_get_load_balance() portable at runtime
- Made __kmp_affinity_get_offline_cpus() portable at runtime
- Turned off quad floating point support (why does openmp have it?)
- Remove bloat for checking if multiple OpenMP libraries are linked

View file

@ -1547,7 +1547,6 @@ kmp_affin_mask_t *__kmp_affinity_get_offline_cpus() {
kmp_affin_mask_t *offline;
KMP_CPU_ALLOC(offline);
KMP_CPU_ZERO(offline);
#if KMP_OS_LINUX
int n, begin_cpu, end_cpu;
kmp_safe_raii_file_t offline_file;
auto skip_ws = [](FILE *f) {
@ -1595,7 +1594,6 @@ kmp_affin_mask_t *__kmp_affinity_get_offline_cpus() {
KMP_CPU_SET(cpu, offline);
}
}
#endif
return offline;
}

View file

@ -22,7 +22,6 @@
#define KMP_DEBUG 1
#endif
#define KMP_USE_FUTEX 0
#define KMP_FTN_ENTRIES KMP_FTN_PLAIN
#define syscall {{openmp_shall_not_use_syscall}}
@ -63,9 +62,9 @@
#define OMPX_TASKGRAPH LIBOMP_OMPX_TASKGRAPH
#define LIBOMP_PROFILING_SUPPORT 0
#define OMP_PROFILING_SUPPORT LIBOMP_PROFILING_SUPPORT
#define LIBOMP_OMPT_OPTIONAL 0
#define LIBOMP_OMPT_OPTIONAL 1
#define OMPT_OPTIONAL LIBOMP_OMPT_OPTIONAL
#define LIBOMP_USE_ADAPTIVE_LOCKS 0
#define LIBOMP_USE_ADAPTIVE_LOCKS 1
#define KMP_USE_ADAPTIVE_LOCKS LIBOMP_USE_ADAPTIVE_LOCKS
#define KMP_DEBUG_ADAPTIVE_LOCKS 0
#define LIBOMP_USE_INTERNODE_ALIGNMENT 0

View file

@ -1,32 +0,0 @@
/*
* kmp_ftn_stdcall.cpp -- Fortran __stdcall linkage support for OpenMP.
*/
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "kmp.h"
// Note: This string is not printed when KMP_VERSION=1.
char const __kmp_version_ftnstdcall[] =
KMP_VERSION_PREFIX "Fortran __stdcall OMP support: "
#ifdef USE_FTN_STDCALL
"yes";
#else
"no";
#endif
#ifdef USE_FTN_STDCALL
#define FTN_STDCALL KMP_STDCALL
#define KMP_FTN_ENTRIES USE_FTN_STDCALL
#include "kmp_ftn_entry.h"
#include "kmp_ftn_os.h"
#endif /* USE_FTN_STDCALL */

View file

@ -22,6 +22,9 @@
#include "kmp_wrapper_getpid.h"
#if KMP_USE_FUTEX
#ifdef __COSMOPOLITAN__
#include "third_party/nsync/futex.internal.h"
#else
#include <sys/syscall.h>
#include <unistd.h>
// We should really include <futex.h>, but that causes compatibility problems on
@ -36,6 +39,7 @@
#define FUTEX_WAKE 1
#endif
#endif
#endif
/* Implement spin locks for internal library use. */
/* The algorithm implemented is Lamport's bakery lock [1974]. */
@ -375,8 +379,12 @@ __kmp_acquire_futex_lock_timed_template(kmp_futex_lock_t *lck, kmp_int32 gtid) {
lck, gtid, poll_val));
long rc;
#ifdef __COSMOPOLITAN__
if ((rc = nsync_futex_wait_(&(lck->lk.poll), poll_val, false, NULL)) != 0) {
#else
if ((rc = syscall(__NR_futex, &(lck->lk.poll), FUTEX_WAIT, poll_val, NULL,
NULL, 0)) != 0) {
#endif
KA_TRACE(1000, ("__kmp_acquire_futex_lock: lck:%p, T#%d futex_wait(0x%x) "
"failed (rc=%ld errno=%d)\n",
lck, gtid, poll_val, rc, errno));
@ -453,8 +461,12 @@ int __kmp_release_futex_lock(kmp_futex_lock_t *lck, kmp_int32 gtid) {
KA_TRACE(1000,
("__kmp_release_futex_lock: lck:%p, T#%d futex_wake 1 thread\n",
lck, gtid));
#ifdef __COSMOPOLITAN__
nsync_futex_wake_(&(lck->lk.poll), 1, false);
#else
syscall(__NR_futex, &(lck->lk.poll), FUTEX_WAKE, KMP_LOCK_BUSY(1, futex),
NULL, NULL, 0);
#endif
}
KMP_MB(); /* Flush all pending memory write invalidates. */

View file

@ -9202,7 +9202,7 @@ kmp_info_t *__kmp_hidden_helper_main_thread;
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;
kmp_int32 __kmp_enable_hidden_helper = IsLinux();
#else
kmp_int32 __kmp_hidden_helper_threads_num = 0;
kmp_int32 __kmp_enable_hidden_helper = FALSE;

View file

@ -2236,15 +2236,12 @@ int __kmp_is_address_mapped(void *addr) {
#ifdef USE_LOAD_BALANCE
#if KMP_OS_DARWIN || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
KMP_OS_OPENBSD || KMP_OS_SOLARIS
// The function returns the rounded value of the system load average
// during given time interval which depends on the value of
// __kmp_load_balance_interval variable (default is 60 sec, other values
// may be 300 sec or 900 sec).
// It returns -1 in case of error.
int __kmp_get_load_balance(int max) {
static int __kmp_get_load_balance_getloadavg(int max) {
double averages[3];
int ret_avg = 0;
@ -2268,13 +2265,11 @@ int __kmp_get_load_balance(int max) {
return ret_avg;
}
#else // Linux* OS
// The function returns number of running (not sleeping) threads, or -1 in case
// of error. Error could be reported if Linux* OS kernel too old (without
// "/proc" support). Counting running threads stops if max running threads
// encountered.
int __kmp_get_load_balance(int max) {
static int __kmp_get_load_balance_linux(int max) {
static int permanent_error = 0;
static int glb_running_threads = 0; // Saved count of the running threads for
// the thread balance algorithm
@ -2495,9 +2490,16 @@ finish: // Clean up and exit.
return running_threads;
} // __kmp_get_load_balance
} // __kmp_get_load_balance_linux
int __kmp_get_load_balance(int max) {
#if KMP_OS_DARWIN || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
KMP_OS_OPENBSD || KMP_OS_SOLARIS
return __kmp_get_load_balance_getloadavg(max);
#else // Linux* OS
return __kmp_get_load_balance_linux(max);
#endif // KMP_OS_DARWIN
} // __kmp_get_load_balance
#endif // USE_LOAD_BALANCE