[Openmp-commits] [openmp] [OpenMP] Add support for Haiku (PR #133034)
Brad Smith via Openmp-commits
openmp-commits at lists.llvm.org
Tue Mar 25 21:56:30 PDT 2025
https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/133034
None
>From 4dac82cb7d071570c09660e7bcbec11e684df68a Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Sun, 15 Dec 2024 10:26:32 +0000
Subject: [PATCH] [OpenMP] Add support for Haiku
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Jérôme Duval <jerome.duval at gmail.com>
---
openmp/runtime/src/kmp.h | 4 ++++
openmp/runtime/src/kmp_ftn_entry.h | 3 ++-
openmp/runtime/src/kmp_platform.h | 14 ++++++++++----
openmp/runtime/src/kmp_runtime.cpp | 12 ++++++------
openmp/runtime/src/kmp_wrapper_getpid.h | 5 ++++-
openmp/runtime/src/z_Linux_util.cpp | 21 +++++++++++++++------
openmp/runtime/test/lit.cfg | 12 ++++++++----
openmp/tools/multiplex/ompt-multiplex.h | 2 ++
8 files changed, 51 insertions(+), 22 deletions(-)
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 9b8c6102dbee2..3d34513491154 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1354,6 +1354,10 @@ extern kmp_uint64 __kmp_now_nsec();
/* TODO: tune for KMP_OS_OPENBSD */
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
+#elif KMP_OS_HAIKU
+/* TODO: tune for KMP_OS_HAIKU */
+#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
+#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
#elif KMP_OS_HURD
/* TODO: tune for KMP_OS_HURD */
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h
index 9bd3ac973b352..9c8be5f953d35 100644
--- a/openmp/runtime/src/kmp_ftn_entry.h
+++ b/openmp/runtime/src/kmp_ftn_entry.h
@@ -582,7 +582,8 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_THREAD_NUM)(void) {
int gtid;
#if KMP_OS_DARWIN || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || \
+ KMP_OS_AIX
gtid = __kmp_entry_gtid();
#elif KMP_OS_WINDOWS
if (!__kmp_init_parallel ||
diff --git a/openmp/runtime/src/kmp_platform.h b/openmp/runtime/src/kmp_platform.h
index 2f47efd3e85ff..9ed14159376cc 100644
--- a/openmp/runtime/src/kmp_platform.h
+++ b/openmp/runtime/src/kmp_platform.h
@@ -22,6 +22,7 @@
#define KMP_OS_OPENBSD 0
#define KMP_OS_DARWIN 0
#define KMP_OS_WINDOWS 0
+#define KMP_OS_HAIKU 0
#define KMP_OS_HURD 0
#define KMP_OS_SOLARIS 0
#define KMP_OS_WASI 0
@@ -73,6 +74,11 @@
#define KMP_OS_OPENBSD 1
#endif
+#if (defined __HAIKU__)
+#undef KMP_OS_HAIKU
+#define KMP_OS_HAIKU 1
+#endif
+
#if (defined __GNU__)
#undef KMP_OS_HURD
#define KMP_OS_HURD 1
@@ -94,14 +100,14 @@
#endif
#if (1 != KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD + \
- KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD + \
- KMP_OS_SOLARIS + KMP_OS_WASI + KMP_OS_AIX)
+ KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HAIKU + \
+ KMP_OS_HURD + KMP_OS_SOLARIS + KMP_OS_WASI + KMP_OS_AIX)
#error Unknown OS
#endif
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS || \
- KMP_OS_WASI || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HAIKU || KMP_OS_HURD || \
+ KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
#undef KMP_OS_UNIX
#define KMP_OS_UNIX 1
#endif
diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index 3e5d671cb7a48..64548b1397c34 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -8949,8 +8949,8 @@ __kmp_determine_reduction_method(
KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_WASM
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD || \
- KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HAIKU || \
+ KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
int teamsize_cutoff = 4;
@@ -8974,15 +8974,15 @@ __kmp_determine_reduction_method(
#else
#error "Unknown or unsupported OS"
#endif // KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD ||
- // KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD ||
- // KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
+ // KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HAIKU ||
+ // KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
#elif KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_AARCH || KMP_ARCH_MIPS || \
KMP_ARCH_WASM || KMP_ARCH_PPC || KMP_ARCH_AARCH64_32
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_HURD || KMP_OS_SOLARIS || \
- KMP_OS_WASI || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_HAIKU || KMP_OS_HURD || \
+ KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
// basic tuning
diff --git a/openmp/runtime/src/kmp_wrapper_getpid.h b/openmp/runtime/src/kmp_wrapper_getpid.h
index d31c6e80f75df..6b41dfcc20880 100644
--- a/openmp/runtime/src/kmp_wrapper_getpid.h
+++ b/openmp/runtime/src/kmp_wrapper_getpid.h
@@ -17,7 +17,7 @@
// On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard
// headers.
-#if !defined(KMP_OS_AIX)
+#if !defined(KMP_OS_AIX) && !defined(KMP_OS_HAIKU)
#include <sys/syscall.h>
#endif
#include <sys/types.h>
@@ -36,6 +36,9 @@
#elif KMP_OS_AIX
#include <pthread.h>
#define __kmp_gettid() pthread_self()
+#elif KMP_OS_HAIKU
+#include <OS.h>
+#define __kmp_gettid() find_thread(NULL)
#elif defined(SYS_gettid)
// Hopefully other Unix systems define SYS_gettid syscall for getting os thread
// id
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp
index bdb7a12cef5e9..44ead49599a90 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/runtime/src/z_Linux_util.cpp
@@ -32,7 +32,7 @@
#if KMP_OS_AIX
#include <sys/ldr.h>
#include <libperfstat.h>
-#else
+#elif !KMP_OS_HAIKU
#include <sys/syscall.h>
#endif
#include <sys/time.h>
@@ -465,7 +465,7 @@ void __kmp_terminate_thread(int gtid) {
static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
int stack_data;
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
+ KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
int status;
size_t size = 0;
void *addr = 0;
@@ -517,7 +517,7 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
return TRUE;
}
#endif /* KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD \
- || KMP_OS_HURD || KMP_OS_SOLARIS */
+ || KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS */
/* Use incremental refinement starting from initial conservative estimate */
TCW_PTR(th->th.th_info.ds.ds_stacksize, 0);
TCW_PTR(th->th.th_info.ds.ds_stackbase, &stack_data);
@@ -532,7 +532,8 @@ static void *__kmp_launch_worker(void *thr) {
#endif /* KMP_BLOCK_SIGNALS */
void *exit_val;
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || \
+ KMP_OS_AIX
void *volatile padding = 0;
#endif
int gtid;
@@ -581,7 +582,8 @@ static void *__kmp_launch_worker(void *thr) {
#endif /* KMP_BLOCK_SIGNALS */
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || \
+ KMP_OS_AIX
if (__kmp_stkoffset > 0 && gtid > 0) {
padding = KMP_ALLOCA(gtid * __kmp_stkoffset);
(void)padding;
@@ -1902,7 +1904,7 @@ static int __kmp_get_xproc(void) {
__kmp_type_convert(sysconf(_SC_NPROCESSORS_CONF), &(r));
#elif KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_OPENBSD || \
- KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
+ KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
__kmp_type_convert(sysconf(_SC_NPROCESSORS_ONLN), &(r));
@@ -2400,6 +2402,9 @@ int __kmp_is_address_mapped(void *addr) {
}
KMP_INTERNAL_FREE(loadQueryBuf);
+#elif KMP_OS_HAIKU
+
+ found = 1;
#else
#error "Unknown or unsupported OS"
@@ -2515,6 +2520,10 @@ int __kmp_get_load_balance(int max) {
glb_running_threads = running_threads;
return running_threads;
+#elif KMP_OS_HAIKU
+
+int __kmp_get_load_balance(int max) {
+ return -1;
}
#else // Linux* OS
diff --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg
index 2a9ae05f97552..cfbd2c5d418b5 100644
--- a/openmp/runtime/test/lit.cfg
+++ b/openmp/runtime/test/lit.cfg
@@ -19,6 +19,9 @@ def prepend_dynamic_library_path(path):
elif config.operating_system == 'Darwin':
name = 'DYLD_LIBRARY_PATH'
sep = ':'
+ elif config.operating_system == 'Haiku':
+ name = 'LIBRARY_PATH'
+ sep = ':'
elif target_arch == 've':
name = 'VE_LD_LIBRARY_PATH'
sep = ':'
@@ -60,10 +63,11 @@ config.test_flags_use_compiler_omp_h = flags
# extra libraries
libs = ""
-if config.has_libm:
- libs += " -lm"
-if config.has_libatomic:
- libs += " -latomic"
+if config.operating_system != 'Haiku':
+ if config.has_libm:
+ libs += " -lm"
+ if config.has_libatomic:
+ libs += " -latomic"
# Allow REQUIRES / UNSUPPORTED / XFAIL to work
config.target_triple = [ ]
diff --git a/openmp/tools/multiplex/ompt-multiplex.h b/openmp/tools/multiplex/ompt-multiplex.h
index a73f2b375852d..4c17802a3769e 100644
--- a/openmp/tools/multiplex/ompt-multiplex.h
+++ b/openmp/tools/multiplex/ompt-multiplex.h
@@ -21,7 +21,9 @@
#endif
#include <dlfcn.h>
#include <errno.h>
+#ifndef __HAIKU__
#include <execinfo.h>
+#endif
#include <inttypes.h>
#include <omp-tools.h>
#include <omp.h>
More information about the Openmp-commits
mailing list