summaryrefslogtreecommitdiff
path: root/openmp/runtime/src/kmp_taskdeps.cpp
AgeCommit message (Collapse)Author
2025-04-25[OpenMP] Fix taskgraph dependency tracking, memory access, and ↵Josep Pinot
initialization (#136837) This commit resolves multiple issues in the OpenMP taskgraph implementation: - Fix a potential use of uninitialized is_taskgraph and tdg fields when a task is created outside of a taskgraph construct. - Fix use of task ID field when accessing the taskgraph’s record_map. - Fix resizing and copying of the successors array when its capacity is exceeded. Fixes memory management flaws, invalid memory accesses, and uninitialized data risks in taskgraph operations.
2025-03-12[OpenMP] [Taskgraph] Differentiating task ids from the taskgraph and from ↵Rémy Neveu
the debugger (#130660) This PR creates a new member for task data, which is used to identify the task in its taskgraph (when ompx taskgraph is enabled). It aims to remove the overloading of the td_task_id member, which was used both by the debugger and the taskgraph. This resulted in the identifier's non-unicity in the case of multiple taskgraphs. Co-authored-by: Rémy Neveu <rem2007@free.fr>
2025-03-03[OpenMP][runtime] Fix comparison of integer expressions of different ↵foxtran
signedness (#128204) This PR fixes warning which occurs if one compiles OpenMP runtime with GCC: ``` warning: comparison of integer expressions of different signedness: 'kmp_intptr_t' {aka 'long int'} and 'long unsigned int' [-Wsign-compare] ```
2025-02-14[OpenMP] Fix crash with task stealing and task dependencies (#126049)Julian Brown
This patch series demonstrates and fixes a bug that causes crashes with OpenMP 'taskwait' directives in heavily multi-threaded scenarios. TLDR: The early return from __kmpc_omp_taskwait_deps_51 missed the synchronization mechanism in place for the late return. Additional debug assertions check for the implied invariants of the code. @jpeyton52 found the timing hole as this sequence of events: > > 1. THREAD 1: A regular task with dependences is created, call it T1 > 2. THREAD 1: Call into `__kmpc_omp_taskwait_deps_51()` and create a stack based depnode (`NULL` task), call it T2 (stack) > 3. THREAD 2: Steals task T1 and executes it getting to `__kmp_release_deps()` region. > 4. THREAD 1: During processing of dependences for T2 (stack) (within `__kmp_check_deps()` region), a link is created T1 -> T2. This increases T2's (stack) `nrefs` count. > 5. THREAD 2: Iterates through the successors list: decrement the T2's (stack) npredecessor count. BUT HASN'T YET `__kmp_node_deref()`-ed it. > 6. THREAD 1: Now when finished with `__kmp_check_deps()`, it returns false because npredecessor count is 0, but T2's (stack) `nrefs` count is 2 because THREAD 2 still references it! > 7. THREAD 1: Because `__kmp_check_deps()` returns false, early exit. > _Now the stack based depnode is invalid, but THREAD 2 still references it._ > > We've reached improper stack referencing behavior. Varied results/crashes/ asserts can occur if THREAD 1 comes back and recreates the exact same depnode in the exact same stack address during the same time THREAD 2 calls `__kmp_node_deref()`.
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-03-28[OpenMP] Fix node destruction race in __kmpc_omp_taskwait_deps_51 (#86130)Ulrich Weigand
The __kmpc_omp_taskwait_deps_51 allocates a kmp_depnode_t node on its stack, and there is currently a race condition where another thread might still be accessing that node after the function has returned and its stack frame was released. While the function does wait until the node's npredecessors count has reached zero before exiting, there is still a window where the function that last decremented the npredecessors count assumes the node is still accessible. For heap-allocated kmp_depnode_t nodes, this normally works via a separate ndeps count that only reaches zero at the point where no accesses to the node are expected at all; in fact, at this point the heap allocation will be freed. For this case of a stack-allocated kmp_depnode_t node, it therefore makes sense to similarly respect the ndeps count; we need to wait until this reaches 1 (not 0, because it is not heap-allocated so there's always one extra count to prevent it from being freed), before we can safely deallocate our stack frame. As this is expected to be a short race window of only a few instructions, it should be fine to just use a busy wait loop checking the ndeps count. Fixes: https://github.com/llvm/llvm-project/issues/85963
2023-11-21[OpenMP] Optimized trivial multiple edges from task dependency graphJoachim Jenke
From "3.1 Reducing the number of edges" of this [[ https://hal.science/hal-04136674v1/ | paper ]] - Optimization (b) Task (dependency) nodes have a `successors` list built upon passed dependency. Given the following code, B will be added to A's successors list building the graph `A` -> `B` ``` // A # pragma omp task depend(out: x) {} // B # pragma omp task depend(in: x) {} ``` In the following code, B is currently added twice to A's successor list ``` // A # pragma omp task depend(out: x, y) {} // B # pragma omp task depend(in: x, y) {} ``` This patch removes such dupplicates by checking lastly inserted task in `A` successor list. Authored by: Romain Pereira (rpereira-dev) Differential Revision: https://reviews.llvm.org/D158544
2023-07-07[OpenMP] Add OMPT support for omp_all_memory task dependenceJoachim Jenke
omp_all_memory currently has no representation in OMPT. Adding new dependency flags as suggested by omp-lang issue #3007. Differential Revision: https://reviews.llvm.org/D111788
2023-05-15[OpenMP] Implement task record and replay mechanismChenle Yu
This patch implements the "task record and replay" mechanism. The idea is to be able to store tasks and their dependencies in the runtime so that we do not pay the cost of task creation and dependency resolution for future executions. The objective is to improve fine-grained task performance, both for those from "omp task" and "taskloop". The entry point of the recording phase is __kmpc_start_record_task, and the end of record is triggered by __kmpc_end_record_task. Tasks encapsulated between a record start and a record end are saved, meaning that the runtime stores their dependencies and structures, referred to as TDG, in order to replay them in subsequent executions. In these TDG replays, we start the execution by scheduling all root tasks (tasks that do not have input dependencies), and there will be no involvement of a hash table to track the dependencies, yet tasks do not need to be created again. At the beginning of __kmpc_start_record_task, we must check if a TDG has already been recorded. If yes, the function returns 0 and starts to replay the TDG by calling __kmp_exec_tdg; if not, we start to record, and the function returns 1. An integer uniquely identifies TDGs. Currently, this identifier needs to be incremented manually in the source code. Still, depending on how this feature would eventually be used in the library, the caller function must do it; also, the caller function needs to implement a mechanism to skip the associated region, according to the return value of __kmpc_start_record_task. Reviewed By: tianshilei1992 Differential Revision: https://reviews.llvm.org/D146642
2023-02-24[OpenMP] Remove uses of ATOMIC_VAR_INITFangrui Song
ATOMIC_VAR_INIT has a trivial definition `#define ATOMIC_VAR_INIT(value) (value)`, is deprecated in C17/C++20, and will be removed in newer standards in newer GCC/Clang (e.g. https://reviews.llvm.org/D144196).
2022-12-20[OpenMP] Clang Support for taskwait nowait clauseSunil Kuravinakop
Support for taskwait nowait clause with placeholder for runtime changes. Reviewed By: cchen, ABataev Differential Revision: https://reviews.llvm.org/D131830
2022-12-09Revert "[OpenMP] Clang Support for taskwait nowait clause"Chi Chun Chen
This reverts commit 100dfe7a8ad3789a98df623482b88d9a3a02e176.
2022-12-08[OpenMP] Clang Support for taskwait nowait clauseSunil K
Support for taskwait nowait clause with placeholder for runtime changes. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D131830
2022-05-05[OpenMP] libomp: Add itt notifications to sync dependent tasks.AndreyChurbanov
Intel Inspector uses itt notifications to analyze code execution, and it reports race conditions in dependent tasks. This patch fixes the issue notifying Inspector on tasks dependency synchronizations. Differential Revision: https://reviews.llvm.org/D123042
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-09-17[OpenMP] NFC: add type casts to silence gcc warningsAndreyChurbanov
2021-09-08[OpenMP] libomp: runtime part of omp_all_memory task dependence implementation.AndreyChurbanov
New omp_all_memory task dependence type is implemented. Library recognizes the new type via either (dependence_address == NULL && dependence_flag == 0x80) or (dependence_address == SIZE_MAX). A task with new dependence type depends on each preceding task with any dependence type (kind of a dependence barrier). Differential Revision: https://reviews.llvm.org/D108574
2021-08-03[OpenMP] libomp: taskwait depend implementation fixed.AndreyChurbanov
Fix for https://bugs.llvm.org/show_bug.cgi?id=49723. Eliminated references from task dependency hash to node allocated on stack, thus eliminated accesses to stale memory. So the node now never freed. Uncommented assertion which triggered when stale memory accessed. Removed unneeded ref count increment for stack allocated node. Differential Revision: https://reviews.llvm.org/D106705
2021-06-16[OpenMP] libomp: fixed implementation of OMP 5.1 inoutset task dependence typeAndreyChurbanov
Refactored code of dependence processing and added new inoutset dependence type. Compiler can set dependence flag to 0x8 when call __kmpc_omp_task_with_deps. All dependence flags library gets so far and corresponding dependence types: 1 - IN, 2 - OUT, 3 - INOUT, 4 - MUTEXINOUTSET, 8 - INOUTSET. Differential Revision: https://reviews.llvm.org/D97085
2021-06-09Revert "[OpenMP] libomp: implement OpenMP 5.1 inoutset task dependence type"AndreyChurbanov
This reverts commit a1f550e052543f75acac9089b760cbc61729131f. Revert in order to fix backwards compatibility breakage caused by type size change for task dependence flag.
2021-06-07[OpenMP] libomp: implement OpenMP 5.1 inoutset task dependence typeAndreyChurbanov
Refactored code of dependence processing and added new inoutset dependence type. Compiler can set dependence flag to 0x8 when call __kmpc_omp_task_with_deps. Size of type of the dependence flag changed from 1 to 4 bytes in clang. All dependence flags library gets so far and corresponding dependence types: 1 - IN, 2 - OUT, 3 - INOUT, 4 - MUTEXINOUTSET, 8 - INOUTSET. Differential Revision: https://reviews.llvm.org/D97085
2021-06-02[OpenMP] Use new task type/flag for taskwait depend events.Hansang Bae
Differential Revision: https://reviews.llvm.org/D103464
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-18[OpenMP][NFC] replaced 'dependencies' with 'dependences' in comments and ↵AndreyChurbanov
debug prints
2021-01-25[OpenMP] Added the support for hidden helper task in RTLShilei Tian
The basic design is to create an outer-most parallel team. It is not a regular team because it is only created when the first hidden helper task is encountered, and is only responsible for the execution of hidden helper tasks. We first use `pthread_create` to create a new thread, let's call it the initial and also the main thread of the hidden helper team. This initial thread then initializes a new root, just like what RTL does in initialization. After that, it directly calls `__kmpc_fork_call`. It is like the initial thread encounters a parallel region. The wrapped function for this team is, for main thread, which is the initial thread that we create via `pthread_create` on Linux, waits on a condition variable. The condition variable can only be signaled when RTL is being destroyed. For other work threads, they just do nothing. The reason that main thread needs to wait there is, in current implementation, once the main thread finishes the wrapped function of this team, it starts to free the team which is not what we want. Two environment variables, `LIBOMP_NUM_HIDDEN_HELPER_THREADS` and `LIBOMP_USE_HIDDEN_HELPER_TASK`, are also set to configure the number of threads and enable/disable this feature. By default, the number of hidden helper threads is 8. Here are some open issues to be discussed: 1. The main thread goes to sleeping when the initialization is finished. As Andrey mentioned, we might need it to be awaken from time to time to do some stuffs. What kind of update/check should be put here? Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D77609
2021-01-22[OpenMP] Remove unnecessary pointer checks in a few locationsHansang Bae
Also, return NULL from unsuccessful OMPT function lookup. Differential Revision: https://reviews.llvm.org/D95277
2021-01-22[OpenMP] libomp: properly initialize buckets in __kmp_dephash_extendJoseph Schuchart
The buckets are initialized in __kmp_dephash_create but when they are extended the memory is allocated but not NULL'd, potentially leaving some buckets uninitialized after all entries have been copied into the new allocation. This commit makes sure the buckets are properly initialized with NULL before copying the entries. Differential Revision: https://reviews.llvm.org/D95167
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-01[OpenMP] Add support for Intel's umonitor/umwaitTerry Wilmarth
These changes add support for Intel's umonitor/umwait usage in wait code, for architectures that support those intrinsic functions. Usage of umonitor/umwait is off by default, but can be turned on by setting the KMP_USER_LEVEL_MWAIT environment variable. Differential Revision: https://reviews.llvm.org/D91189
2020-11-20Revert "[OpenMP] Add support for Intel's umonitor/umwait"AndreyChurbanov
This reverts commit 9cfad5f9c5bfd985f1bc8b0954f58013c5236e58.
2020-11-19[OpenMP] Add support for Intel's umonitor/umwaitAndreyChurbanov
Patch by tlwilmar (Terry Wilmarth) Differential Revision: https://reviews.llvm.org/D91189
2020-10-01[OpenMP][OMPT] Update OMPT tests for newly added GOMP interface patchesJoachim Protze
This patch updates the expected results for the GOMP interface patches: D87267, D87269, and D87271. The taskwait-depend test is changed to really use taskwait-depend and copied to an task_if0-depend test. To pass the tests, the handling of the return address was fixed. Differential Revision: https://reviews.llvm.org/D87680
2020-08-14[OpenMP] Fix releasing of stack memoryJoachim Protze
Starting with 787eb0c637b I got spurious segmentation faults for some testcases. I could nail it down to `brel` trying to release the "memory" of the node allocated on the stack of __kmpc_omp_wait_deps. With this patch, you will see the assertion triggering for some of the tests in the test suite. My proposed solution for the issue is to just patch __kmpc_omp_wait_deps: ``` __kmp_init_node(&node); - node.dn.on_stack = 1; + // the stack owns the node + __kmp_node_ref(&node); ``` What do you think? Reviewed By: AndreyChurbanov Differential Revision: https://reviews.llvm.org/D84472
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-07-05[OpenMP][OMPT] Fix ifdefs for OMPT codeJoachim Protze
Fixes build with LIBOMP_OMPT_SUPPORT=off Reported by: Jason Edson Reviewed by: Hahnfeld Differential Revision: https://reviews.llvm.org/D83171
2020-07-03[OpenMP][OMPT]Add event callbacks for taskwait with dependJoachim Protze
This adds the missing event callbacks to express dependencies on included tasks and taskwait with depend clause. The test fails for GCC, see bug report: https://bugs.llvm.org/show_bug.cgi?id=46573 Reviewed by: hbae Differential Revision: https://reviews.llvm.org/D81891
2020-06-19[OpenMP][OMPT] Pass mutexinoutset to the toolJoachim Protze
Adds OMPT support for the mutexinoutset dependency Reviewed by: hbae Differential Revision: https://reviews.llvm.org/D81890
2020-04-04[OpenMP] NFC: Fix trivial typoKazuaki Ishizaki
Differential Revision: https://reviews.llvm.org/D77430
2020-01-07[OpenMP] NFC: Fix trivial typos in commentsKazuaki Ishizaki
Reviewers: jdoerfert, Jim Reviewed By: Jim Subscribers: Jim, mgorny, guansong, jfb, openmp-commits Tags: #openmp Differential Revision: https://reviews.llvm.org/D72285
2019-10-25OpenMP Tasks dependencies hash re-sizing fixed.AndreyChurbanov
Details: - nconflicts field initialized; - formatting fix (moved declaration out of the long line); - count conflicts in new hash as opposed to old one. Differential Revision: https://reviews.llvm.org/D68036
2019-09-25Enable tasks dependencies hashmaps resizing.Andrey Churbanov
Patch by viroulep (Philippe Virouleau) Differential Revision: https://reviews.llvm.org/D67447 llvm-svn: 372879
2019-07-12[OpenMP] Remove OMP spec versioningJonathan Peyton
Remove all older OMP spec versioning from the runtime and build system. Patch by Terry Wilmarth Differential Revision: https://reviews.llvm.org/D64534 llvm-svn: 365963
2019-01-19Update more file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. These used slightly different spellings that defeated my regular expressions. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351648
2019-01-15[OMPT] Second chunk of final OMPT 5.0 interface updatesJoachim Protze
The omp-tools.h file is generated from the OpenMP spec to ensure that the interface is implemented as specified. The other changes are necessary to update the interface implementation to the final version as published in 5.0. The omp-tools.h header was previously called ompt.h, currently a copy under this name is installed for legacy tools. Patch partially perpared by @sconvent Reviewers: AndreyChurbanov, hbae, Hahnfeld Reviewed By: hbae Tags: #openmp, #ompt Differential Revision: https://reviews.llvm.org/D55579 llvm-svn: 351197
2018-12-18[OMPT] First chunk of final OMPT 5.0 interface updatesJoachim Protze
This patch updates the implementation of the ompt_frame_t, ompt_wait_id_t and ompt_state_t. The final version of the OpenMP 5.0 spec added the "t" for these types. Furthermore the structure for ompt_frame_t changed and allows to specify that the reenter frame belongs to the runtime. Patch partially prepared by Simon Convent Reviewers: hbae llvm-svn: 349458
2018-11-07Implementation of OpenMP 5.0 mutexinoutset task dependency type.Andrey Churbanov
Differential Revision: https://reviews.llvm.org/D53380 llvm-svn: 346307
2018-09-26[OpenMP] Fix performance issue from 376.kdtreeJonathan Peyton
This change improves the performance of 376.kdtree by giving the compiler an opportunity to do inlining and other optimizations for the call path, __kmpc_omp_task_complete_if0()->__kmp_task_finish(), which is one of the hot paths in the program; some functions in kmp_taskdeps.cpp were moved to the new header file, kmp_taskdeps.h to achieve this. Patch by Hansang Bae Differential Revision: https://reviews.llvm.org/D51889 llvm-svn: 343138
2018-09-10[OMPT] Update types according to TR7Joachim Protze
Some types and callback signatures have changed from TR6 to TR7. Major changes (only adding signatures and stubs): (-remove idle callback) done by D48362 -add reduction and dispatch callback -add get_task_memory and finalize_tool runtime entry points -ompt_invoker_t becomes ompt_parallel_flag_t -more types of sync_regions Patch provided by Simon Convent Reviewers: hbae, protze.joachim Differential Revision: https://reviews.llvm.org/D50774 llvm-svn: 341834
2018-07-09[OpenMP] Fix a few formatting issuesJonathan Peyton
llvm-svn: 336575
2018-07-09[OpenMP] Use C++11 Atomics - barrier, tasking, and lock codeJonathan Peyton
These are preliminary changes that attempt to use C++11 Atomics in the runtime. We are expecting better portability with this change across architectures/OSes. Here is the summary of the changes. Most variables that need synchronization operation were converted to generic atomic variables (std::atomic<T>). Variables that are updated with combined CAS are packed into a single atomic variable, and partial read/write is done through unpacking/packing Patch by Hansang Bae Differential Revision: https://reviews.llvm.org/D47903 llvm-svn: 336563