summaryrefslogtreecommitdiff
path: root/openmp/runtime/src/kmp_csupport.cpp
AgeCommit message (Collapse)Author
2025-06-25[OpenMP] Fix various alignment issues (#142376)Rainer Orth
When running the `openmp` testsuite on 32-bit SPARC, several tests `FAIL` apparently randomly, but always with the same kind of error: ``` # error: command failed with exit status: -11 ``` The tests die with `SIGBUS`, as can be seen in `truss` output: ``` 26461/1: Incurred fault #5, FLTACCESS %pc = 0x00010EAC 26461/1: siginfo: SIGBUS BUS_ADRALN addr=0x0013D12C 26461/1: Received signal #10, SIGBUS [default] 26461/1: siginfo: SIGBUS BUS_ADRALN addr=0x0013D12C ``` i.e. the code is trying an unaligned access which cannot work on SPARC, a strict-alignment target which enforces natural alignment on access. This explains the apparent randomness of the failures: if the memory happens to be aligned appropriately, the tests work, but fail if not. A `Debug` build reveals much more: - `__kmp_alloc` currently aligns to `sizeof(void *)`, which isn't enough on strict-alignment targets when the data are accessed as types requiring larger alignment. Therefore, this patch increases `alignment` to `SizeQuant`. - 32-bit Solaris/sparc `libc` guarantees 8-byte alignment from `malloc`, so this patch adjusts `SizeQuant` to match. - There's a `SIGBUS` in ``` __kmpc_fork_teams (loc=0x112f8, argc=0, microtask=0x16cc8 <__omp_offloading_ffbc020a_4b1abe_main_l9_debug__.omp_outlined>) at openmp/runtime/src/kmp_csupport.cpp:573 573 *(kmp_int64 *)(&this_thr->th.th_teams_size) = 0L; ``` Casting to a pointer to a type requiring 64-bit alignment when that isn't guaranteed is wrong. Instead, this patch uses `memset` instead. - There's another `SIGBUS` in ``` 0xfef8cb9c in __kmp_taskloop_recur (loc=0x10cb8, gtid=0, task=0x23cd00, lb=0x23cd18, ub=0x23cd20, st=1, ub_glob=499, num_tasks=100, grainsize=5, extras=0, last_chunk=0, tc=500, num_t_min=20, codeptr_ra=0xfef8dbc8 <__kmpc_taskloop(ident_t*, int, kmp_task_t*, int, kmp_uint64*, kmp_uint64*, kmp_int64, int, int, kmp_uint64, void*)+240>, task_dup=0x0) at openmp/runtime/src/kmp_tasking.cpp:5147 5147 p->st = st; ``` `p->st` doesn't currently guarantee the 8-byte alignment required by `kmp_int64 st`. `p` is set in ``` __taskloop_params_t *p = (__taskloop_params_t *)new_task->shareds; ``` but `shareds_offset` is currently aligned to `sizeof(void *)` only. Increasing it to `sizeof(kmp_uint64)` to match its use fixes the `SIGBUS`. With these fixes I get clean `openmp` test results on 32-bit SPARC (both Solaris and Linux), with one unrelated exception. Tested on `sparc-sun-solaris2.11`, `sparcv9-sun-solaris2.11`, `sparc-unknown-linux-gnu`, `sparc64-unknown-linux-gnu`, `i386-pc-solaris2.11`, `amd64-pc-solaris2.11`, `i686-pc-linux-gnu`, and `x86_64-pc-linux-gnu`.
2024-08-15[OpenMP] Miscellaneous small code improvements (#95603)Hansang Bae
Removes a few uninitialized variables, possible resource leaks, and redundant code.
2024-07-03[OpenMP][OMPT] Indicate loop schedule for worksharing-loop events (#97429)Joachim
Use more specific values from `ompt_work_t` to allow the tool identify the schedule of a worksharing-loop. With this patch, the runtime will report the schedule chosen by the runtime rather than necessarily the schedule literally requested by the clause. E.g., for guided + just one iteration per thread, the runtime would choose and report static. Fixes issue #63904
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-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-03-27[NFC][OpenMP] Use `SimpleVLA` to replace variable length arrays in C++Shilei Tian
2024-02-13[OpenMP][AIX]Define struct kmp_base_tas_lock with the order of two members ↵Xing Xue
swapped for big-endian (#79188) The direct lock data structure has bit `0` (the least significant bit) of the first 32-bit word set to `1` to indicate it is a direct lock. On the other hand, the first word (in 32-bit mode) or first two words (in 64-bit mode) of an indirect lock are the address of the entry allocated from the indirect lock table. The runtime checks bit `0` of the first 32-bit word to tell if this is a direct or an indirect lock. This works fine for 32-bit and 64-bit little-endian because its memory layout of a 64-bit address is (`low word`, `high word`). However, this causes problems for big-endian where the memory layout of a 64-bit address is (`high word`, `low word`). If an address of the indirect lock table entry is something like `0x110035300`, i.e., (`0x1`, `0x10035300`), it is treated as a direct lock. This patch defines `struct kmp_base_tas_lock` with the ordering of the two 32-bit members flipped for big-endian PPC64 so that when checking/setting tags in member `poll`, the second word (the low word) is used. This patch also changes places where `poll` is not already explicitly specified for checking/setting tags.
2023-09-06[OpenMP] Fix build issue with `libomp` when OMPT is disabledShilei Tian
2023-09-06[OpenMP] Fix issue of indirect function call in `__kmpc_fork_call_if` (#65436)Shilei Tian
The outlined function is typically invoked by using `__kmp_invoke_microtask`, which is written in asm. D138495 introduces a new interface function for parallel region for OpenMPIRBuilder, where the outlined function is called via the function pointer. For some reason, it works perfectly well on x86 and x86-64 system, but doesn't work on Apple Silicon. The 3rd argument in the callee is always `nullptr`, even if it is not in caller. It appears `x2` always contains `0x0`. This patch adopts the typical method to invoke the function pointer. It works on my M2 Ultra Mac. Fix #63194.
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-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-07[OpenMP][OMPT] Change OMPT kind for OpenMP test lock functionsJoachim Jenke
The OpenMP specification mentions that omp_test_lock and omp_test_nest_lock dispatch OMPT callbacks with ompt_mutex_test_lock and ompt_mutex_test_nest_lock for their kind respectively. Previously, the values ompt_mutex_lock and ompt_mutex_nest_lock were used. This could cause issues in application relying on the kind to correctly determine lock states. This commit changes the kind to the expected ones. Also update callback.h and OMPT tests to reflect this change. Patch prepared by Thyre Differential Review: https://reviews.llvm.org/D153028 Differential Review: https://reviews.llvm.org/D153031 Differential Review: https://reviews.llvm.org/D153032
2023-01-16[OpenMP] Fix the wrong format string used in `__kmpc_error`Shilei Tian
This patch fixes the wrong format string used in `__kmpc_error`, which could cause segment fault at runtime. Reviewed By: jlpeyton Differential Revision: https://reviews.llvm.org/D141889
2022-12-09[openmp][mlir] Lower parallel if to new fork_call_if function.David Truby
This patch adds a new runtime function `fork_call_if` and uses that to lower parallel if statements when going through OpenMPIRBuilder. This fixes an issue where the OpenMPIRBuilder passes all arguments to fork_call as a struct but this struct is not filled corretly in the non-if branch by handling the fork inside the runtime. Differential Revision: https://reviews.llvm.org/D138495
2022-10-28[OpenMP][libomp] Parameterize affinity functionsJonathan Peyton
This patch parameterizes the affinity initialization code to allow multiple affinity settings. Almost all global affinity settings are consolidated and put into a structure kmp_affinity_t. This is in anticipation of the addition of hidden helper affinity which will have the same syntax and semantics as KMP_AFFINITY only for the hidden helper team. Differential Revision: https://reviews.llvm.org/D135109
2022-09-08[OpenMP][libomp] Cleanup __kmpc_flush() codeJonathan Peyton
Have it be simple KMP_MFENCE() which incorporates x86-specific logic and reduces to KMP_MB() for other architectures. Differential Revision: https://reviews.llvm.org/D130928
2022-07-19[OpenMP][libomp] Allow reset affinity mask after parallelAndreyChurbanov
Added control to reset affinity of primary thread after outermost parallel region to initial affinity encountered before OpenMP runtime was initialized. KMP_AFFINITY environment variable reset/noreset modifier introduced. Default behavior is unchanged. Differential Revision: https://reviews.llvm.org/D125993
2022-07-05[OpenMP] add 4 custom APIs supporting MSVC OMP codegenVadim Paretsky
This check-in adds 4 APIs to support MSVC, specifically: * 3 APIs (__kmpc_sections_init, __kmpc_next_section, __kmpc_end_sections) to support the dynamic scheduling of OMP sections. * 1 API (__kmpc_copyprivate_light, a light-weight version of __kmpc_copyrprivate) to support the OMP single copyprivate clause. Differential Revision: https://reviews.llvm.org/D128403
2022-04-12[OpenMP][libomp] Fix some Doxygen issuesJonathan Peyton
Fix spelling of variable names and remove accidental references (#) in Doxygen comments.
2022-02-14[OpenMP][libomp] Introduce oneAPI compiler supportJonathan Peyton
Introduce KMP_COMPILER_ICX macro to represent compilation with oneAPI compiler. Fixup flag detection and compiler ID detection in CMake. Older CMake's detect IntelLLVM as Clang. Fix compiler warnings. Fixup many of the tests to have non-empty parallel regions as they are elided by oneAPI compiler.
2021-12-29[OpenMP] Add missing `tt_hidden_helper_task_encountered` along with ↵Shilei Tian
`tt_found_proxy_tasks` In most cases, hidden helper task behave similar as detached tasks. That means, for example, if we have to wait for detached tasks, we have to do the same thing for hidden helper tasks as well. This patch adds the missing condition for hidden helper task accordingly along with detached task. Reviewed By: AndreyChurbanov Differential Revision: https://reviews.llvm.org/D107316
2021-10-25[OpenMP][OMPT][clang] task frame support fixed in __kmpc_fork_callVladimir Inđić
__kmp_fork_call sets the enter_frame of the active task (th_curren_task) before new parallel region begins. After the region is finished, the enter_frame is cleared. The old implementation of __kmpc_fork_call didn’t clear the enter_frame of active task. Also, the way of initializing the enter_frame of the active task was wrong. Consider the following two OpenMP programs. The first program: Let R1 be the serialized parallel region that encloses another serialized parallel region R2. Assume that thread that executes R2 is going to create a new serialized parallel region R3 by executing __kmpc_fork_call. This thread is responsible to set enter_frame of R2's implicit task. Note that the information about R2's implicit task is present inside master_th->th.th_current_task at this moment, while lwt represents the information about R1's implicit task. The old implementation uses lwt and resets enter_frame of R1's implicit task instead of R2's implicit task. The new implementation uses master_th->th.th_current_task instead. The second program: Consider the OpenMP program that contains parallel region R1 which encloses an explicit task T. Assume that thread should create another parallel region R2 during the execution of the T. The __kmpc_fork_call is responsible to create R2 and set enter frame of T whose information is present inside the master_th->th.th_current_task. Old implementation tries to set the frame of parent_team->t.t_implicit_task_taskdata[tid] which corresponds to the implicit task of the R1, instead of T. Differential Revision: https://reviews.llvm.org/D112419
2021-10-11[OpenMP] libomp: add OpenMP 5.1 memory allocation routines.AndreyChurbanov
Aligned allocation routines added. Fortran interfaces added for all allocation routines. Differential Revision: https://reviews.llvm.org/D110923
2021-10-01[OpenMP][host runtime] Introduce kmp_cpuinfo_flags_t to replace integer flagsPeyton, Jonathan L
Store CPUID support flags as bits instead of using entire integers. Differential Revision: https://reviews.llvm.org/D110091
2021-09-07[OpenMP] Add interface for 5.1 scope constructHansang Bae
The new interface only marks begin/end of a scope construct for corresponding OMPT events, and we can use existing interfaces for reduction operations. Differential Revision: https://reviews.llvm.org/D108062
2021-08-20[OpenMP][OMPD]Code movement required for OMPDVignesh Balasubramanian
These changes don't come under OMPD guard as it is a movement of existing code to capture parallel behavior correctly. "Runtime Entry Points for OMPD" like "ompd_bp_parallel_begin" and "ompd_bp_parallel_begin" should be placed at the correct execution point for the debugging tool to access proper handles/data. Without the below changes, in certain cases, debugging tool will pick the wrong parallel and task handle. Reviewed By: @hbae Differential Revision: https://reviews.llvm.org/D100366
2021-06-16[OpenMP] Remove unused variables from libomp codeJoachim Protze
Several variables were left unused as a result of different patches removing their use. Two variables have some use: `poll_count` is used by the KMP_BLOCKING macro only under certain conditions. Adding (void) to tell the compiler to ignore the unused variable. `padding` is a dummy stack allocation with no intent to be used. Also adding (void) to make the compiler ignore the unused variable. Differential Revision: https://reviews.llvm.org/D104303
2021-06-15[OpenMP] Add GOMP 5.0 version symbols to APIPeyton, Jonathan L
* Add GOMP versioned pause functions * Add GOMP versioned affinity format functions To do the affinity format functions, only attach versioned symbols to the APPEND Fortran entries (e.g., omp_set_affinity_format_) since GOMP only exports two symbols (one for Fortran, one for C). Our affinity format functions have three symbols. e.g., with omp_set_affinity_format: 1) omp_set_affinity_format (Fortran interface) 2) omp_set_affinity_format_ (Fortran interface) 3) ompc_set_affinity_format (C interface) Have the GOMP version of the C symbol alias the ompc_* 3) version instead of the Fortran unappended version 1). Differential Revision: https://reviews.llvm.org/D103647
2021-06-15[OpenMP] Lazily assign root affinityPeyton, Jonathan L
Lazily set affinity for root threads. Previously, the root thread executing middle initialization would attempt to assign affinity to other existing root threads. This was not working properly as the set_system_affinity() function wasn't setting the affinity for the target thread. Instead, the middle init thread was resetting the its own affinity using the target thread's affinity mask. Differential Revision: https://reviews.llvm.org/D103625
2021-06-08[OpenMP][OMPD] Implementation of OMPD debugging library - libompd.Vignesh Balasubramanian
This is the first of seven patches that implements OMPD, a debugging interface to support debugging of OpenMP programs. It contains support code required in "openmp/runtime" for OMPD implementation. Reviewed By: @hbae Differential Revision: https://reviews.llvm.org/D100181
2021-05-24[OpenMP] Fix crashing critical section with hint clauseHansang Bae
Runtime was using the default lock type without using the hint. Differential Revision: https://reviews.llvm.org/D102955
2021-03-16[OpenMP] Add runtime interface for OpenMP 5.1 error directiveHansang Bae
The proposed new interface is for supporting `at(execution)` clause in the error directive. Differential Revision: https://reviews.llvm.org/D98448
2021-03-05Added API for "masked" construct via two entrypoints: __kmpc_masked,tlwilmar
and __kmpc_end_masked. The "master" construct is deprecated. Changed proc-bind keyword from "master" to "primary". Use of both master construct and master as proc-bind keyword is still allowed, but deprecated. Remove references to "master" in comments and strings, and replace with "primary" or "primary thread". Function names and variables were not touched, nor were references to deprecated master construct. These can be updated over time. No new code should refer to master.
2021-02-22[OpenMP] Limit number of dispatch buffersPeyton, Jonathan L
This patch limits the number of dispatch buffers (used for loop worksharing construct) to between 1 and 4096. Differential Revision: https://reviews.llvm.org/D96749
2021-02-20[OpenMP][NFC] clang-format the whole openmp projectShilei Tian
Same script as D95318. Test files are excluded. Reviewed By: AndreyChurbanov Differential Revision: https://reviews.llvm.org/D97088
2021-02-10[OpenMP] Add lower and upper bound in num_teams clauseNawrin Sultana
This patch adds lower-bound and upper-bound to num_teams clause according to OpenMP 5.1 specification. The initial number of teams created is implementation defined, but it will be greater than or equal to lower-bound and less than or equal to upper-bound. If num_teams clause is not specified, the number of teams created is implementation defined, but it will be greater or equal to 1. Differential Revision: https://reviews.llvm.org/D95820
2020-12-31[OpenMP] libomp: Handle implicit conversion warningsTerry Wilmarth
This patch partially prepares the runtime source code to be built with -Wconversion, which should trigger warnings if any implicit conversions can possibly change a value. For builds done with icc or gcc, all such warnings are handled in this patch. clang gives a much longer list of warnings, particularly for sign conversions, which the other compilers don't report. The -Wconversion flag is commented into cmake files, but I'm not going to turn it on. If someone thinks it is important, and wants to fix all the clang warnings, they are welcome to. Types of changes made here involve either improving the consistency of types used so that no conversion is needed, or else performing careful explicit conversions, when we're sure a problem won't arise. Patch is a combination of changes by Terry Wilmarth and Johnny Peyton. Differential Revision: https://reviews.llvm.org/D92942
2020-12-09[OpenMP] Use RTM lock for OMP lock with synchronization hintHansang Bae
This patch introduces a new RTM lock type based on spin lock which is used for OMP lock with speculative hint on supported architecture. Differential Revision: https://reviews.llvm.org/D92615
2020-11-25[OpenMP][OMPT] Introduce a guard to handle OMPT return addressJoachim Protze
This is an alternative approach to address inconsistencies pointed out in: D90078 This patch makes sure that the return address is reset, when leaving the scope. In some cases, I had to move the macro out of an if-statement to have it in the right scope, in some cases I added an additional block to restrict the scope. This patch does not handle inconsistencies, which might occur if the return address is still set when we call into the application. Test case (repeated_calls.c) provided by @hbae Differential Revision: https://reviews.llvm.org/D91692
2020-11-17[OpenMP] Add omp_realloc implementationNawrin Sultana
This patch adds omp_realloc function implementation according to OpenMP 5.1 specification. Differential Revision: https://reviews.llvm.org/D90971
2020-11-17[OpenMP][stats] reset serial state when re-entering serial regionPeyton, Jonathan L
Differential Revision: https://reviews.llvm.org/D90867
2020-11-13[OpenMP] Add omp_calloc implementationNawrin Sultana
This patch adds omp_calloc implementation according to OpenMP 5.1 specification. Differential Revision: https://reviews.llvm.org/D90967
2020-11-11[OpenMP][OMPT] Update the omp-tools header file to reflect 5.1 changesJoachim Protze
This doesn't add functionality, but just adds the new types and renames the master callback to masked callback. Differential Revision: https://reviews.llvm.org/D90752
2020-08-24Move special va_list handling to kmp_os.hDimitry Andric
Instead of copying and pasting the same `#ifdef` expressions in multiple places, define a type and a pair of macros in `kmp_os.h`, to handle whether `va_list` is pointer-like or not: * `kmp_va_list` is the type to use for `__kmp_fork_call()` * `kmp_va_deref()` dereferences a `va_list`, if necessary * `kmp_va_addr_of()` takes the address of a `va_list`, if necessary Also add FreeBSD to the list of OSes that has a non pointer-like va_list. This can now be easily extended to other OSes too. Reviewed By: AndreyChurbanov Differential Revision: https://reviews.llvm.org/D86397
2020-07-28Re-land "[PowerPC] Remove QPX/A2Q BGQ/BGP CNK support"Jinsong Ji
This reverts commit bf544fa1c3cb80f24d85e84559fb11193846259f. Fixed the typo in PPCInstrInfo.cpp.
2020-07-27Revert "[PowerPC] Remove QPX/A2Q BGQ/BGP CNK support"Jinsong Ji
This reverts commit adffce71538e219aab4eeb024819baa7687262ff. This is breaking test-suite, revert while investigation.
2020-07-27[PowerPC] Remove QPX/A2Q BGQ/BGP CNK supportJinsong Ji
Per RFC http://lists.llvm.org/pipermail/llvm-dev/2020-April/141295.html no one is making use of QPX/A2Q/BGQ/BGP CNK anymore. This patch remove the support of QPX/A2Q in llvm, BGQ/BGP in clang, CNK support in openmp/polly. Reviewed By: hfinkel Differential Revision: https://reviews.llvm.org/D83915
2020-07-20[OpenMP] libomp cleanup: add check of input global tid parameterAndreyChurbanov
Add check of negative gtid before indexing __kmp_threads. This makes static analyzers happier. This is the first part of the patch split in two parts. Differential Revision: https://reviews.llvm.org/D84062
2020-06-16[OpenMP][OMPT] Add callbacks for doacross loopsJoachim Protze
Adds the callbacks for ordered with source/sink dependencies. The test for task dependencies changed, because callbach.h now actually prints the passed dependencies and the test also checks for the address. Reviewed by: hbae Differential Revision: https://reviews.llvm.org/D81807
2020-04-04[OpenMP] NFC: Fix trivial typoKazuaki Ishizaki
Differential Revision: https://reviews.llvm.org/D77430