Skip to content

[OpenMP] Add support for Haiku #133034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openmp/runtime/src/kmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion openmp/runtime/src/kmp_ftn_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
14 changes: 10 additions & 4 deletions openmp/runtime/src/kmp_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions openmp/runtime/src/kmp_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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

Expand Down
5 changes: 4 additions & 1 deletion openmp/runtime/src/kmp_wrapper_getpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down
21 changes: 14 additions & 7 deletions openmp/runtime/src/z_Linux_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -2515,7 +2520,9 @@ 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

Expand Down
12 changes: 8 additions & 4 deletions openmp/runtime/test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ':'
Expand Down Expand Up @@ -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 = [ ]
Expand Down
2 changes: 2 additions & 0 deletions openmp/tools/multiplex/ompt-multiplex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down