summaryrefslogtreecommitdiff
path: root/openmp/runtime/src/kmp_dispatch.cpp
AgeCommit message (Collapse)Author
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-07-01[OpenMP][offload] Fix dynamic schedule tracking (#97065)Gheorghe-Teodor Bercea
This patch fixes the dynamic schedule tracking.
2024-04-16[OpenMP] Use a memory fence before incrementing the dispatch buffer index ↵Xing Xue
(#87995) This patch uses a memory fence in function `__kmp_dispatch_next()` to flush pending memory write invalidates before incrementing the `volatile` variable `buffer_index` to fix intermittent time-outs of OpenMP runtime LIT test cases `env/kmp_set_dispatch_buf.c` and `worksharing/for/kmp_set_dispatch_buf.c`, noting that the same is needed for incrementing `buffer_index` in function `__kmpc_next_section()` (line 2600 of `kmp_dispatch.cpp`).
2023-11-08[OpenMP] Add skewed iteration distribution on hybrid systems (#69946)Jonathan Peyton
This commit adds skewed distribution of iterations in nonmonotonic:dynamic schedule (static steal) for hybrid systems when thread affinity is assigned. Currently, it distributes the iterations at 60:40 ratio. Consider this loop with dynamic schedule type, for (int i = 0; i < 100; ++i). In a hybrid system with 20 hardware threads (16 CORE and 4 ATOM core), 88 iterations will be assigned to performance cores and 12 iterations will be assigned to efficient cores. Each thread with CORE core will process 5 iterations + extras and with ATOM core will process 3 iterations. Differential Revision: https://reviews.llvm.org/D152955
2023-01-18[OpenMP][libomp] Fix stats-gathering for new MSVC sections APIJonathan Peyton
Differential Revision: https://reviews.llvm.org/D139867
2023-01-12[OpenMP] Fix dynamic schedule assertion failure on AArch64Nawrin Sultana
This patch fixes assertion failure in dynamic schedule with 8 byte induction variable. It uses acquire load instead of relaxed to ensure that steal_lock pointer is not NULL. Differential Revision: https://reviews.llvm.org/D139373
2022-08-02[OpenMP] Fix warnings about unused expressions when OMPT_LOOP_DISPATCH is a ↵Martin Storsjö
no-op. NFC. This fixes warnings like these: ../runtime/src/kmp_dispatch.cpp:2159:24: warning: left operand of comma operator has no effect [-Wunused-value] OMPT_LOOP_DISPATCH(*p_lb, *p_ub, pr->u.p.st, status); ^~~~~ ../runtime/src/kmp_dispatch.cpp:2159:31: warning: left operand of comma operator has no effect [-Wunused-value] OMPT_LOOP_DISPATCH(*p_lb, *p_ub, pr->u.p.st, status); ^~~~~ ../runtime/src/kmp_dispatch.cpp:2159:46: warning: left operand of comma operator has no effect [-Wunused-value] OMPT_LOOP_DISPATCH(*p_lb, *p_ub, pr->u.p.st, status); ~~~~~~~ ^~ ../runtime/src/kmp_dispatch.cpp:2159:50: warning: expression result unused [-Wunused-value] OMPT_LOOP_DISPATCH(*p_lb, *p_ub, pr->u.p.st, status); ^~~~~~
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-06[OpenMP] Add support for ompt_callback_dispatchHansang Bae
This change adds support for ompt_callback_dispatch with the new dispatch chunk type introduced in 5.2. Definitions of the new ompt_work_loop types were also added in the header file. Differential Revision: https://reviews.llvm.org/D122107
2022-01-18[OpenMP] Add use of TPAUSETerry Wilmarth
Add use of TPAUSE (from WAITPKG) to the runtime for Intel hardware, with an envirable to turn it on in a particular C-state. Always uses TPAUSE if it is selected and enabled by Intel hardware and presence of WAITPKG, and if not, falls back to old way of checking __kmp_use_yield, etc. Differential Revision: https://reviews.llvm.org/D115758
2021-09-07[OpenMP] Change monotonicity of dynamic scheduleNawrin Sultana
This patch changes the default monotonicity of dynamic schedule from monotonic to non-monotonic when no modifier is specified. Differential Revision: https://reviews.llvm.org/D109026
2021-08-16[OpenMP] Add a few small fixesPeyton, Jonathan L
* Add comment to help ensure new construct data are added in two places * Check for division by zero in the loop worksharing code * Check for syntax errors in parrange parsing Differential Revision: https://reviews.llvm.org/D105929
2021-08-16[OpenMP] libomp: cleanup: minor fixes to silence static analyzer.AndreyChurbanov
Added couple more checks to silence KlocWork static code analyzer. Differential Revision: https://reviews.llvm.org/D107348
2021-06-25[OpenMP][NFC] libomp: fix wrong debug assertion.AndreyChurbanov
Normalized bounds of chunk of iterations to steal from are inclusive, so upper bound should not be decremented in expression to check. Problem was in attempt to steal iterations 0:0, that caused assertion after wrong decrement. Reported in comment to https://reviews.llvm.org/D103648. Differential Revision: https://reviews.llvm.org/D104880
2021-06-22[OpenMP] libomp: fix dynamic loop dispatcherAndreyChurbanov
Restructured dynamic loop dispatcher code. Fixed use of dispatch buffers for nonmonotonic dynamic (static_steal) schedule: - eliminated possibility of stealing iterations of the wrong loop when victim thread changed its buffer to work on another loop; - fixed race when victim thread changed its buffer to work in nested parallel; - eliminated "static" property of the schedule, that is now a single thread can execute whole loop. Differential Revision: https://reviews.llvm.org/D103648
2021-06-07[OpenMP] Check loc for NULL before dereferencing itBryan Chan
The ident_t * argument in __kmp_get_monotonicity was being used without a customary NULL check, causing the function to crash in a Debug build. Release builds were not affected thanks to dead store elimination.
2021-03-23[OpenMP] Misc. changes that add or remove pointer/bound checksHansang Bae
-- Added or moved checks to appropriate places. -- Removed ineffective null check where the pointer is already being dereferenced around the code. -- Initialized variables that can be used without definitions. -- Added call to dlclose/FreeLibrary in OMPT tool activation. -- Added a new build compiler definition. Differential Revision: https://reviews.llvm.org/D98584
2021-03-08[OpenMP] Fix potential integer overflow in dynamic schedule codePeyton, Jonathan L
Restrict the chunk_size * chunk_num to only occur for valid chunk_nums and reimplement calculating the limit to avoid overflow. Differential Revision: https://reviews.llvm.org/D96747
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] Help static loop code avoid over/underflowPeyton, Jonathan L
This code alleviates some pathological loop parameters (lower, upper, stride) within calculations involved in the static loop code. It bounds the chunk size to the trip count if it is greater than the trip count and also minimizes problematic code for when trip count < nth. Differential Revision: https://reviews.llvm.org/D96426
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-01-29[OpenMP] Add environment variable to force monotonic dynamic schedulingJonathan Peyton
This patch introduces a new environment variable to force monotonic behavior for users that absolutely need it. This is in anticipation of 5.0 change that uses non-monotonic behavior for dynamic scheduling by default. Fixes for that and the actual switch are coming soon. Differential Revision: https://reviews.llvm.org/D95263
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-11-05[OpenMP] Add ident_t flags for compiler OpenMP versionPeyton, Jonathan L
This patch adds the mask and ident_t function to get the openmp version. It also adds logic to force monotonic:dynamic behavior when OpenMP version less than 5.0. The OpenMP version is stored in the format: major*10+minor e.g., OpenMP 5.0 = 50 Differential Revision: https://reviews.llvm.org/D90632
2020-10-29[OpenMP] Add NULL check in dispatcher debug outputPeyton, Jonathan L
Patch by Nawrin Sultana Differential Revision: https://reviews.llvm.org/D90403
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-04[openmp] Fixed nonmonotonic schedule implementation.AndreyChurbanov
Differential Revision: https://reviews.llvm.org/D80942
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-11-27[openmp] Fixed nonmonotonic schedule when #threads > #chunks in a loop.AndreyChurbanov
Differential Revision: https://reviews.llvm.org/D70713
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-04-30[OpenMP] Add OpenMP 5.0 nonmonotonic codeJonathan Peyton
This patch adds: * New omp_sched_monotonic flag to omp_sched_t which is handled within the runtime * Parsing of monotonic/nonmonotonic in OMP_SCHEDULE * Tests for the monotonic flag and envirable parsing * Logic to force monotonic when hierarchical scheduling is used Differential Revision: https://reviews.llvm.org/D60979 llvm-svn: 359601
2019-04-03[OpenMP][Stats] Fix stats gathering for distribute and team clauseJonathan Peyton
The distribute clause needs an explicit push of a timer. The teams clause needs a timer added and also, similarly to parallel, exchanged with the serial timer when encountered so that serial regions are counted properly. Differential Revision: https://reviews.llvm.org/D59801 llvm-svn: 357621
2019-02-28[OpenMP] Make use of sched_yield optional in runtimeJonathan Peyton
This patch cleans up the yielding code and makes it optional. An environment variable, KMP_USE_YIELD, was added. Yielding is still on by default (KMP_USE_YIELD=1), but can be turned off completely (KMP_USE_YIELD=0), or turned on only when oversubscription is detected (KMP_USE_YIELD=2). Note that oversubscription cannot always be detected by the runtime (for example, when the runtime is initialized and the process forks, oversubscription cannot be detected currently over multiple instances of the runtime). Because yielding can be controlled by user now, the library mode settings (from KMP_LIBRARY) for throughput and turnaround have been adjusted by altering blocktime, unless that was also explicitly set. In the original code, there were a number of places where a double yield might have been done under oversubscription. This version checks oversubscription and if that's not going to yield, then it does the spin check. Patch by Terry Wilmarth Differential Revision: https://reviews.llvm.org/D58148 llvm-svn: 355120
2019-02-04[OMPT] Make sure that OMPT is enabled when accessing internals of the runtimeJoachim Protze
The three switch fallthrough generate a warning with -Wimplicit-fallthrough. Two are documented as fallthrough, one is not, but I think the intention is to also fallthrough in kmp_tasking.cpp. Not sure whether kmp.h is the best place to define the macro. Reviewers: jlpeyton, AndreyChurbanov, Hahnfeld Reviewed By: jlpeyton Tags: #openmp Differential Revision: https://reviews.llvm.org/D56397 llvm-svn: 353052
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-16[OpenMP] Add omp_pause_resource* APIJonathan Peyton
Add omp_pause_resource and omp_pause_resource_all API and enum, plus stub for internal implementation. Implemented callable helper function to do local pause, and added basic functionality for hard and soft pause. Patch by Terry Wilmarth Differential Revision: https://reviews.llvm.org/D55078 llvm-svn: 351372
2018-12-10Support clang compiling under windows-gnu and windows-msvcAndrey Churbanov
Patch by Peiyuan Song <squallatf@gmail.com> Differential Revision: https://reviews.llvm.org/D53422 llvm-svn: 348756
2018-09-26[OpenMP][OMPT] A few improvementsJonathan Peyton
This change includes miscellaneous improvements as follows: 1) Added ompt_get_proc_id() implementation for Windows 2) Added parser and print tool for omp-tool-var, just in case it needs to be printed (OMP_DISPLAY_ENV) 3) omp_control_tool is exported on Windows Patch by Hansang Bae Differential Revision: https://reviews.llvm.org/D50538 llvm-svn: 343137
2018-08-09[OpenMP] Cleanup codeJonathan Peyton
This patch cleans up unused functions, variables, sign compare issues, and addresses some -Warning flags which are now enabled including -Wcast-qual. Not all the warning flags in LibompHandleFlags.cmake are enabled, but some are with this patch. Some __kmp_gtid_from_* macros in kmp.h are switched to static inline functions which allows us to remove the awkward definition of KMP_DEBUG_ASSERT() and KMP_ASSERT() macros which used the comma operator. This had to be done for the innumerable -Wunused-value warnings related to KMP_DEBUG_ASSERT() Differential Revision: https://reviews.llvm.org/D49105 llvm-svn: 339393
2018-07-30[OpenMP][Stats] Cleanup stats gathering codeJonathan Peyton
1) Remove unnecessary data from list node structure 2) Remove timerPair in favor of pushing/popping explicitTimers. This way, nested timers will work properly. 3) Fix #pragma omp critical timers 4) Add histogram capability 5) Add KMP_STATS_FILE formatting capability 6) Have time partitioned into serial & parallel by introducing partitionedTimers::exchange(). This also counts the number of serial regions in the executable. 7) Fix up the timers around OMP loops so that scheduling overhead and work are both counted correctly. 8) Fix up the iterations statistics so they count the number of iterations the thread receives at each loop scheduling event 9) Change timers so there is only one RDTSC read per event change 10) Fix up the outdated comments for the timers Differential Revision: https://reviews.llvm.org/D49699 llvm-svn: 338276
2018-07-09[OpenMP] Introduce hierarchical schedulingJonathan Peyton
This patch introduces the logic implementing hierarchical scheduling. First and foremost, hierarchical scheduling is off by default To enable, use -DLIBOMP_USE_HIER_SCHED=On during CMake's configure stage. This work is based off if the IWOMP paper: "Workstealing and Nested Parallelism in SMP Systems" Hierarchical scheduling is the layering of OpenMP schedules for different layers of the memory hierarchy. One can have multiple layers between the threads and the global iterations space. The threads will go up the hierarchy to grab iterations, using possibly a different schedule & chunk for each layer. [ Global iteration space (0-999) ] (use static) [ L1 | L1 | L1 | L1 ] (use dynamic,1) [ T0 T1 | T2 T3 | T4 T5 | T6 T7 ] In the example shown above, there are 8 threads and 4 L1 caches begin targeted. If the topology indicates that there are two threads per core, then two consecutive threads will share the data of one L1 cache unit. This example would have the iteration space (0-999) split statically across the four L1 caches (so the first L1 would get (0-249), the second would get (250-499), etc). Then the threads will use a dynamic,1 schedule to grab iterations from the L1 cache units. There are currently four supported layers: L1, L2, L3, NUMA OMP_SCHEDULE can now read a hierarchical schedule with this syntax: OMP_SCHEDULE='EXPERIMENTAL LAYER,SCHED[,CHUNK][:LAYER,SCHED[,CHUNK]...]:SCHED,CHUNK And OMP_SCHEDULE can still read the normal SCHED,CHUNK syntax from before I've kept most of the hierarchical scheduling logic inside kmp_dispatch_hier.h to try to keep it separate from the rest of the code. Differential Revision: https://reviews.llvm.org/D47962 llvm-svn: 336571
2018-07-09[OpenMP] Restructure loop code for hierarchical schedulingJonathan Peyton
This patch reorganizes the loop scheduling code in order to allow hierarchical scheduling to use it more effectively. In particular, the goal of this patch is to separate the algorithmic parts of the scheduling from the thread logistics code. Moves declarations & structures to kmp_dispatch.h for easier access in other files. Extracts the algorithmic part of __kmp_dispatch_init() and __kmp_dispatch_next() into __kmp_dispatch_init_algorithm() and __kmp_dispatch_next_algorithm(). The thread bookkeeping logic is still kept in __kmp_dispatch_init() and __kmp_dispatch_next(). This is done because the hierarchical scheduler needs to access the scheduling logic without the bookkeeping logic. To prepare for new pointer in dispatch_private_info_t, a new flags variable is created which stores the ordered and nomerge flags instead of them being in two separate variables. This will keep the dispatch_private_info_t structure the same size. Differential Revision: https://reviews.llvm.org/D47961 llvm-svn: 336568
2018-01-04Fix some comments and formatting in kmp_dispatch.cppJonathan Peyton
llvm-svn: 321831
2017-11-09Remove const from variables with dynamic memoryJonas Hahnfeld
Allocated memory is typically not 'const' if it needs to be freed. This patch removes around 50 wrong const attributes, modifies the corresponding functions and finally gets rid of some const_casts. These have especially been strange for __kmp_str_fname_free() that added a 'const' to call __kmp_str_free() which removed it again. Two minor cleanups that I performed in this process: * __kmp_tool_libraries now lives in kmp_settings.cpp as it is used nowhere else. * __kmp_msg_empty was removed as it was never used and Clang now complained that it was assigned a string literal that is 'const char *'. Differential Revision: https://reviews.llvm.org/D39755 llvm-svn: 317797
2017-11-03Revert "Updating implementation of OMPT as specified in OpenMP 5.0 Preview 2 ↵Jonas Hahnfeld
(TR6)" This reverts commit r317339 which discarded some recent commits. llvm-svn: 317346
2017-11-03Updating implementation of OMPT as specified in OpenMP 5.0 Preview 2 (TR6)Joachim Protze
The TR6 document is expected to be publically released around November 15. This patch does not implement OMPT for libomptarget. Patch by Simon Convent and Joachim Protze Differential Revision: https://reviews.llvm.org/D39182 llvm-svn: 317339
2017-11-01Update implementation of OMPT to the specification OpenMP 5.0 Preview 1 (TR4).Joachim Protze
The code is tested to work with latest clang, GNU and Intel compiler. The implementation is optimized for low overhead when no tool is attached shifting the cost to execution with tool attached. This patch does not implement OMPT for libomptarget. Patch by Simon Convent and Joachim Protze Differential Revision: https://reviews.llvm.org/D38185 llvm-svn: 317085
2017-10-20Apply formatting changesJonathan Peyton
.clang-format's comments are removed and a (hopefully) final set of formatting changes are applied. Differential Revision: https://reviews.llvm.org/D38837 Differential Revision: https://reviews.llvm.org/D38920 llvm-svn: 316227
2017-09-27Remove unnecessary semicolonsJonathan Peyton
Removes semicolons after if {} blocks, function definitions, etc. I was able to apply the large OMPT patch cleanly on top of this one with no conflicts. llvm-svn: 314340