summaryrefslogtreecommitdiff
path: root/openmp/runtime/src/kmp_runtime.cpp
AgeCommit message (Collapse)Author
2025-08-06[OFFLOAD][OPENMP] 6.0 compatible interop interface (#143491)Alex Duran
The following patch introduces a new interop interface implementation with the following characteristics: * It supports the new 6.0 prefer_type specification * It supports both explicit objects (from interop constructs) and implicit objects (from variant calls). * Implements a per-thread reuse mechanism for implicit objects to reduce overheads. * It provides a plugin interface that allows selecting the supported interop types, and managing all the backend related interop operations (init, sync, ...). * It enables cooperation with the OpenMP runtime to allow progress on OpenMP synchronizations. * It cleanups some vendor/fr_id mismatchs from the current query routines. * It supports extension to define interop callbacks for library cleanup.
2025-07-21[OpenMP] Fixup bugs found during fuzz testing (#143455)Jonathan Peyton
A lot of these only trip when using sanitizers with the library. * Insert forgotten free()s * Change (-1) << amount to 0xffffffffu as left shifting a negative is UB * Fixup integer parser to return INT_MAX when parsing huge string of digits. e.g., 452523423423423423 returns INT_MAX * Fixup range parsing for affinity mask so integer overflow does not occur * Don't assert when branch bits are 0, instead warn user that is invalid and use the default value. * Fixup kmp_set_defaults() so the C version only uses null terminated strings and the Fortran version uses the string + size version. * Make sure the KMP_ALIGN_ALLOC is power of two, otherwise use CACHE_LINE. * Disallow ability to set KMP_TASKING=1 (task barrier) this doesn't work and hasn't worked for a long time. * Limit KMP_HOT_TEAMS_MAX_LEVEL to 1024, an array is allocated based on this value. * Remove integer values for OMP_PROC_BIND. The specification only allows strings and CSV of strings. * Fix setting KMP_AFFINITY=disabled + OMP_DISPLAY_AFFINITY=TRUE
2025-07-21[OpenMP] [NFC] Remove KMP_NESTED_HOT_TEAMS macro (#143584)Jonathan Peyton
The feature was introduced back in 2014 and has been on ever since. Leave the feature in place. Removing only the macro.
2025-07-08Reland: [OpenMP][clang] 6.0: num_threads strict (part 1: host runtime) (#147532)Robert Imschweiler
OpenMP 6.0 12.1.2 specifies the behavior of the strict modifier for the num_threads clause on parallel directives, along with the message and severity clauses. This commit implements necessary host runtime changes. Reland https://github.com/llvm/llvm-project/pull/146403. After manual testing on a gfx90a machine, I could not reproduce the failing test, which makes it even more likely that the test has just been flaky. (Or at least that it's not an issue related to this patch.)
2025-07-07Revert "[OpenMP][clang] 6.0: num_threads strict (part 1: host runtime)" ↵Robert Imschweiler
(#147379) Reverts llvm/llvm-project#146403
2025-07-07[OpenMP][clang] 6.0: num_threads strict (part 1: host runtime) (#146403)Robert Imschweiler
OpenMP 6.0 12.1.2 specifies the behavior of the strict modifier for the num_threads clause on parallel directives, along with the message and severity clauses. This commit implements necessary host runtime changes.
2025-04-02[OpenMP] 6.0 (TR11) Memory Management Update (#97106)Hansang Bae
TR11 introduced changes to support target memory management in a unified way by defining a series of API routines and additional traits. Host runtime is oblivious to how actual memory resources are mapped when using the new API routines, so it can only support how the composed memory space is maintained, and the offload backend must handle which memory resources are actually used to allocate memory from the memory space. Here is summary of the implementation. * Implemented 12 API routines to get/mainpulate memory space/allocator. * Memory space composed with a list of devices has a state with resource description, and runtime is responsible for maintaining the allocated memory space objects. * Defined interface with offload runtime to access memory resource list, and to redirect calls to omp_alloc/omp_free since it requires backend-specific information. * Value of omp_default_mem_space changed from 0 to 99, and omp_null_mem_space took the value 0 as defined in the language. * New allocator traits were introduced, but how to use them is up to the offload backend. * Added basic tests for the new API routines.
2025-04-01[OpenMP] allow openmp build for sparc (#133239)Petr Sumbera
2025-03-26[OpenMP] Add support for Haiku (#133034)Brad Smith
Co-authored-by: Jérôme Duval <jerome.duval@gmail.com>
2025-02-20[OpenMP][NFC] Remove unused debug lock (#127928)Jonathan Peyton
2025-02-19[OpenMP][NFC] Remove unused __kmp_dispatch_lock global (#127686)Jonathan Peyton
2024-08-15[OpenMP] Add support for pause with omp_pause_stop_tool (#97100)Hansang Bae
This patch adds support for pause resource with a new enumerator omp_pause_stop_tool. The expected behavior of this enumerator is * omp_pause_resource: not allowed * omp_pause_resource_all: equivalent to omp_pause_hard
2024-08-15[OpenMP] Miscellaneous small code improvements (#95603)Hansang Bae
Removes a few uninitialized variables, possible resource leaks, and redundant code.
2024-07-16[OpenMP] Use new OMPT state and sync kinds for barrier events (#95602)Hansang Bae
This change makes the runtime use new OMPT state and sync kinds introduced in OpenMP 5.1 in place of the deprecated implicit state and sync kinds. Events from implicit barriers use different enumerators for workshare, parallel, and teams.
2024-06-24[OpenMP] Add num_threads clause list format and strict modifier support (#85466)Terry Wilmarth
Add support to the runtime for 6.0 spec features that allow num_threads clause to take a list, and also make use of the strict modifier. Provides new compiler interface functions for these features.
2024-06-04[OpenMP][OMPT] Add missing callbacks for asynchronous target tasks (#93472)Joachim
- The first hidden-helper-thread did not trigger thread-begin - The "detaching" from a target-task when waiting for completion missed to call task-switch - Target tasks identified themself as explicit task Co-authored-by: Kaloyan Ignatov <kaloyan.ignatov@rwth-aachen.de>
2024-05-07[OpenMP] Fix task state and taskteams for serial teams (#86859)Jonathan Peyton
* Serial teams now use a stack (similar to dispatch buffers) * Serial teams always use `t_task_team[0]` as the task team and the second pointer is a next pointer for the stack `t_task_team[1]` is interpreted as a stack of task teams where each level is a nested level ``` inner serial team outer serial team [ t_task_team[0] ] -> (task_team) [ t_task_team[0] ] -> (task_team) [ next ] ----------------> [ next ] -> ... ``` * Remove the task state memo stack from thread structure. * Instead of a thread-private stack, use team structure to store th_task_state of the primary thread. When coming out of a parallel, restore the primary thread's task state. The new field in the team structure doesn't cause sizeof(team) to change and is in the cache line which is only read/written by the primary thread. Fixes: #50602 Fixes: #69368 Fixes: #69733 Fixes: #79416
2024-04-02[OpenMP] arm64_32 port for Apple WatchOS (#87246)nihui
detect `aarch64_32` with compiler defined macro `__ARM64_ARCH_8_32__` reuse ARM `__kmp_unnamed_critical_addr` and add `KMP_PREFIX_UNDERSCORE` macro like AARCH64 reuse AARCH64 `__kmp_invoke_microtask` build log for watchos armv7k + arm64_32 and watchos simulator x86_64 + arm64 https://github.com/nihui/action-protobuf/actions/runs/8520684611/job/23337305030
2024-03-29[OpenMP] Have hidden helper team allocate new OS threads only (#87119)Jonathan Peyton
The hidden helper team pre-allocates the gtid space [1, num_hidden_helpers] (inclusive). If regular host threads are allocated, then put back in the thread pool, then the hidden helper team is initialized, the hidden helper team tries to allocate the threads from the thread pool with gtids higher than [1, num_hidden_helpers]. Instead, have the hidden helper team fork OS threads so the correct gtid range used for hidden helper threads. Fixes: #87117
2024-03-27[OpenMP] Close up permissions on /tmp files (#85469)Terry Wilmarth
The SHM or /tmp files that might be created during library registration don't need to have such open permissions, so this change fixes that.
2024-03-11[OpenMP] Remove unnecessary check of ap (#83303)Jonathan Peyton
2024-03-10[openmp] adding affinity support to DragonFlyBSD. (#84672)David CARLIER
2024-03-09[openmp] porting affinity feature to netbsd. (#84618)David CARLIER
netbsd supports the portable hwloc's layer as well. for a hardware with 4 cpus, a cpu set is 4 and maxcpus is 256.
2024-02-27[OpenMP] Fix distributed barrier hang for OMP_WAIT_POLICY=passive (#83058)Jonathan Peyton
The resume thread logic inside __kmp_free_team() is faulty. Only checking b_go for sleep status doesn't wake up distributed barrier. Change to generic check for th_sleep_loc and calling __kmp_null_resume_wrapper(). Fixes: #80664
2024-01-08[openmp][AIX]Initial changes for porting to AIX (#76841)Xing Xue
This PR contains initial changes for building and testing libomp on AIX. More changes will follow. - `KMP_OS_AIX` is defined for the AIX platform - `KMP_ARCH_PPC` is defined for 32-bit PPC - `KMP_ARCH_PPC_XCOFF` and `KMP_ARCH_PPC64_XCOFF` are for 32- and 64-bit XCOFF object formats respectively - Assembly file `z_AIX_asm.S` is used for AIX specific assembly code and will be added in a separate PR - The target library is disabled because AIX does not have the device support - OMPT is temporarily disabled
2023-12-15[OpenMP] Use simple VLA implementation to replace uses of actual VLAShilei Tian
Use of VLA can cause compile warning that was introduced in D156565. This patch implements a simple stack/heap-based VLA that can miminc the behavior of an actual VLA and prevent the warning. By default the stack accomodates the elements. If the number of emelements is greater than N, which by default is 8, a heap buffer will be allocated and used to acccomodate the elements.
2023-12-14[openmp][wasm] Allow compiling OpenMP to WebAssembly (#71297)Andrew Brown
This change allows building the static OpenMP runtime, `libomp.a`, as WebAssembly. It builds on the work done in [D142593] but goes further in several ways: - it makes the OpenMP CMake files more WebAssembly-aware - it conditions much more code (or code that had been refactored since [D142593]) for `KMP_ARCH_WASM` and `KMP_OS_WASI` - it fixes a Clang crash due to unimplemented common symbols in WebAssembly The commit messages have more details. Please understand this PR as a start, not the completed work, for WebAssembly support in OpenMP. Getting the tests running somehow would be a good next step, e.g.; but what is contained here works, at least with recent versions of [wasi-sdk] and engines that support [wasi-threads]. I suspect the same is true for Emscripten and browsers, but I have not tested that workflow. [D142593]: https://reviews.llvm.org/D142593 [wasi-sdk]: https://github.com/WebAssembly/wasi-sdk [wasi-threads]: https://github.com/WebAssembly/wasi-threads --------- Co-authored-by: Atanas Atanasov <atanas.atanasov@intel.com>
2023-11-30Revert "[OpenMP] Use simple VLA implementation to replace uses of actual VLA"Shilei Tian
This reverts commit 97e16da450e94c92456fa5a74768ec1b22fe6b63 because it causes build error on i386 system.
2023-11-28[OpenMP] Use simple VLA implementation to replace uses of actual VLAShilei Tian
Use of VLA can cause compile warning that was introduced in D156565. This patch implements a simple stack/heap-based VLA that can miminc the behavior of an actual VLA and prevent the warning. By default the stack accomodates the elements. If the number of emelements is greater than N, which by default is 8, a heap buffer will be allocated and used to acccomodate the elements.
2023-11-28Revert "[OpenMP] Use simple VLA implementation to replace uses of actual VLA"Shilei Tian
This reverts commit d46f63553ab9ee041884b5306527afefaf00e144.
2023-11-28[OpenMP] Use simple VLA implementation to replace uses of actual VLAShilei Tian
Use of VLA can cause compile warning that was introduced in D156565. This patch implements a simple stack/heap-based VLA that can miminc the behavior of an actual VLA and prevent the warning. By default the stack accomodates the elements. If the number of emelements is greater than N, which by default is 8, a heap buffer will be allocated and used to acccomodate the elements.
2023-11-28Revert "[OpenMP] Use simple VLA implementation to replace uses of actual VLA ↵Shilei Tian
(#71412)" This reverts commit eaab947a8aa39002e8bdaa82be08cbc31e116a11 because it causes link error.
2023-11-28[OpenMP] Use simple VLA implementation to replace uses of actual VLA (#71412)Shilei Tian
Use of VLA can cause compile warning that was introduced in D156565. This patch implements a simple stack/heap-based VLA that can miminc the behavior of an actual VLA and prevent the warning. By default the stack accomodates the elements. If the number of emelements is greater than N, which by default is 8, a heap buffer will be allocated and used to acccomodate the elements.
2023-11-03Add openmp support to System z (#66081)Neale Ferguson
* openmp/README.rst - Add s390x to those platforms supported * openmp/libomptarget/plugins-nextgen/CMakeLists.txt - Add s390x subdirectory * openmp/libomptarget/plugins-nextgen/s390x/CMakeLists.txt - Add s390x definitions * openmp/runtime/CMakeLists.txt - Add s390x to those platforms supported * openmp/runtime/cmake/LibompGetArchitecture.cmake - Define s390x ARCHITECTURE * openmp/runtime/cmake/LibompMicroTests.cmake - Add dependencies for System z (aka s390x) * openmp/runtime/cmake/LibompUtils.cmake - Add S390X to the mix * openmp/runtime/cmake/config-ix.cmake - Add s390x as a supported LIPOMP_ARCH * openmp/runtime/src/kmp_affinity.h - Define __NR_sched_[get|set]addinity for s390x * openmp/runtime/src/kmp_config.h.cmake - Define CACHE_LINE for s390x * openmp/runtime/src/kmp_os.h - Add KMP_ARCH_S390X to support checks * openmp/runtime/src/kmp_platform.h - Define KMP_ARCH_S390X * openmp/runtime/src/kmp_runtime.cpp - Generate code when KMP_ARCH_S390X is defined * openmp/runtime/src/kmp_tasking.cpp - Generate code when KMP_ARCH_S390X is defined * openmp/runtime/src/thirdparty/ittnotify/ittnotify_config.h - Define ITT_ARCH_S390X * openmp/runtime/src/z_Linux_asm.S - Instantiate __kmp_invoke_microtask for s390x * openmp/runtime/src/z_Linux_util.cpp - Generate code when KMP_ARCH_S390X is defined * openmp/runtime/test/ompt/callback.h - Define print_possible_return_addresses for s390x * openmp/runtime/tools/lib/Platform.pm - Return s390x as platform and host architecture * openmp/runtime/tools/lib/Uname.pm - Set hardware platform value for s390x
2023-11-02[OpenMP] Add support for Solaris/x86_64 (#70593)Brad Smith
Tested on `amd64-pc-solaris2.11`.
2023-10-27[OpenMP] Fix building for 32-bit DragonFly, NetBSD, OpenBSD (#70527)Brad Smith
Fixing ```#error "Unknown or unsupported OS"```
2023-09-13Fix /tmp approach, and add environment variable method as third fallback ↵Terry Wilmarth
during library registration The /tmp fallback for /dev/shm did not write to a fixed filename, so multiple instances of the runtime would not be able to detect each other. Now, we create the /tmp file in much the same way as the /dev/shm file was created, since mkstemp approach would not work to create a file that other instances of the runtime would detect. Also, add the environment variable method as a third fallback to /dev/shm and /tmp for library registration, as some systems do not have either. Also, add ability to fallback to a subsequent method should a failure occur during any part of the registration process. When unregistering, it is assumed that the method chosen during registration should work, so errors at that point are ignored. This also avoids a problem with multiple threads trying to unregister the library.
2023-09-10[OpenMP][VE] Support OpenMP runtime on VEKazushi (Jam) Marukawa
Support OpenMP runtime library on VE. This patch makes OpenMP compilable for VE architecture. Almost all tests run correctly on VE. Reviewed By: tianshilei1992 Differential Revision: https://reviews.llvm.org/D159401
2023-09-06[OpenMP] Fix a wrong assertion in `__kmp_get_global_thread_id`Shilei Tian
The function assumes that `__kmp_gtid_get_specific` always returns a valid gtid. That is not always true, because when creating the key for thread-specific data, a destructor is assigned. The dtor will be called at thread exit. However, before the dtor is called, the thread-specific data will be reset to NULL first (https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_key_create.html): > At thread exit, if a key value has a non-NULL destructor pointer, and the thread > has a non-NULL value associated with that key, the value of the key is set to NULL. This will lead to that `__kmp_gtid_get_specific` returns `KMP_GTID_DNE`. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D159369
2023-08-31[OpenMP] Fix a segment fault in __kmp_get_global_thread_idShilei Tian
In `__kmp_get_global_thread_id`, if the gtid mode is 1, after getting the gtid from TLS, it will store the gtid value to the thread stack maintained in the thread descriptor. However, `__kmp_get_global_thread_id` can be called when the library is destructed, after the corresponding thread info has been release. This will cause a segment fault. This can happen on an Intel-based Mac. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D159324
2023-08-26[OpenMP] Codegen support for thread_limit on target directive for hostSandeep Kosuri
offloading - This patch adds support for thread_limit clause on target directive according to OpenMP 51 [2.14.5] - The idea is to create an outer task for target region, when there is a thread_limit clause, and manipulate the thread_limit of task instead. This way, thread_limit will be applied to all the relevant constructs enclosed by the target region. Differential Revision: https://reviews.llvm.org/D152054
2023-08-22[OpenMP] Let primary thread gather topology info for each worker threadJonathan Peyton
This change has the primary thread create each thread's initial mask and topology information so it is available immediately after forking. The setting of mask/topology information is decoupled from the actual binding. Also add this setting of topology information inside the __kmp_partition_places mechanism for OMP_PLACES+OMP_PROC_BIND. Without this, there could be a timing window after the primary thread signals the workers to fork where worker threads have not yet established their affinity mask or topology information. Each worker thread will then bind to the location the primary thread sets. Differential Revision: https://reviews.llvm.org/D156727
2023-08-18[OpenMP] Add option to use different units for blocktimeTerry Wilmarth
This change adds the option of using different units for blocktimes specified via the KMP_BLOCKTIME environment variable. The parsing of the environment now recognizes units suffixes: ms and us. If a units suffix is not specified, the default unit is ms. Thus default behavior is still the same, and any previous usage still works the same. Internally, blocktime is now converted to microseconds everywhere, so settings that exceed INT_MAX in microseconds are considered "infinite". kmp_set/get_blocktime are updated to use the units the user specified with KMP_BLOCKTIME, and if not specified, ms are used. Added better range checking and inform messages for the two time units. Large values of blocktime for default (ms) case (beyond INT_MAX/1000) are no longer allowed, but will autocorrect with an INFORM message. The delay for determining ticks per usec was lowered. It is now 1 million ticks which was calculated as ~450us based on 2.2GHz clock which is pretty typical base clock frequency on X86: (1e6 Ticks) / (2.2e9 Ticks/sec) * (1e6 usec/sec) = 454 usec Really short benchmarks can be affected by longer delay. Update KMP_BLOCKTIME docs. Portions of this commit were authored by Johnny Peyton. Differential Revision: https://reviews.llvm.org/D157646
2023-07-24[OpenMP] Move KMP_VERSION printout logic to post-serial-initJonathan Peyton
Get the KMP_VERSION printout logic out of environment variable file (kmp_settings.cpp) and move to end of serial initialization where KMP_SETTINGS and OMP_DISPLAY_ENV are. Differential Revision: https://reviews.llvm.org/D154652
2023-07-24[OpenMP] Restore comment accidently deleted in D154650Jonathan Peyton
2023-07-24[OpenMP] Re-use affinity raii class in worker spawningJonathan Peyton
Get rid of explicit mask alloc, getthreadaffinity, set temp affinity, reset to old affinity, dealloc steps in favor of existing kmp_affinity_raii_t to push/pop a temporary affinity. Differential Revision: https://reviews.llvm.org/D154650
2023-07-06[OpenMP] Remove gcc-12 warnings from libompJonathan Peyton
2023-07-05[OpenMP] Minor improvement in error msg and fixes few coverity reported issuesNawrin Sultana
Differential Revision: https://reviews.llvm.org/D152289
2023-06-14[OpenMP] Fix the issue where `num_threads` still takes effect incorrectlyShilei Tian
This patch fixes the issue that, if we have a compile-time serialized parallel region (such as `if (0)`) with `num_threads`, followed by a regular parallel region, the regular parallel region will pick up the value set in the serialized parallel region incorrectly. The reason is, in the front end, if we can prove a parallel region has to serialized, instead of emitting `__kmpc_fork_call`, the front end directly emits `__kmpc_serialized_parallel`, body, and `__kmpc_end_serialized_parallel`. However, this "optimization" doesn't consider the case where `num_threads` is used such that `__kmpc_push_num_threads` is still emitted. Since we don't reset the value in `__kmpc_serialized_parallel`, it will affect the next parallel region followed by it. Fix #63197. Reviewed By: tlwilmar Differential Revision: https://reviews.llvm.org/D152883
2023-05-12[OpenMP] remove an erroneous assert on the location argumentVadim Paretsky
The 'loc' argument is optional, and some compilers (e.g. MSVC) do no supply it. Differential Revision: https://reviews.llvm.org/D148393