gcc/libgomp/testsuite
Jakub Jelinek f25a6767ec openmp: Implement doacross(sink: omp_cur_iteration - 1)
This patch implements doacross(sink: omp_cur_iteration - 1) that the
previous patchset emitted a sorry on during omp expansion.
It can be implemented with existing library functions.

To recap, depend(source)/doacross(source:)/doacross(source:omp_cur_iteration)
is implemented calling GOMP_doacross_post or GOMP_doacross_ull_post,
called with an array of long or unsigned long long elements, one for
all collapsed loops together and one for each further ordered loop if any.
We initialize that array in each thread when grabbing further set of iterations
and update it at the end of loops, so that it represents the current iteration
(as 0 based counters).  When the worksharing loop is created, we tell the
library through another similar array the counts (the loop needs to be
rectangular) in each dimension, first element is count of all logical iterations
in the collapsed loops.

depend(sink:v1 op N1, v2 op N2, ...) is then implemented by conditionally calling
GOMP_doacross_wait/GOMP_doacross_ull_wait.  For N? of 0 there is no check,
otherwise if it wants to wait in a particular dimension for a previous iteration,
we check that the corresponding iterator isn't the first one (or first few),
where the previous iterator in that dimension would be out of range, and similarly
for checking of next iteration in a dimension that it isn't the last one (or last few)
where it would be similarly out of bounds.  Then the collapsed loop counters are
folded into a single 0 based counter (first argument) and then other 0 based
iterations counters on what iteration it should wait for.

Now, doacross(sink: omp_cur_iteration - 1) is supposed to wait for the previous
logical iteration in the combined iteration space of all ordered loops.
For the very first iteration in that combined iteration space it does nothing,
there is no previous iteration.  And similarly it does nothing if there
are more ordered loops than collapsed loop and it isn't the first logical
iteration of the combined loops inside of the collapsed loops, because as implemented
we know the previous iteration in that case is always executed by the same thread
as the current one.
In the implementation, we use the same value as is stored in the first element
of the array for GOMP_doacross_post/GOMP_doacross_ull_post, if that value is 0,
we do nothing.  The rest is different based on if ordered argument is equal to
collapse or not.  If it is, then we otherwise call
GOMP_doacross_wait/GOMP_doacross_ull_wait with a single argument, one less than
that counter we compare against 0.
If ordered argument is bigger than collapse, we add a per-thread boolean variable
.first.N, which we set to true at the start of the outermost ordered loop inside
of the collapsed set of loops and set to false at the end of the innermost
ordered loop.  If .first.N is false, we don't do anything (we know the previous
iteration was handled by the current thread and by my reading of the spec we don't
need to emit even a memory barrier in that case, because it is just synchronization
with the same thread), otherwise we call GOMP_doacross_wait/GOMP_doacross_ull_wait
with the first argument one less than the counter we compare against 0, and then
one less than 2nd and following counts if iterations we pass to the workshare
initialization.  If say .counts.N passed to the workshare initialization is
{ 256, 13, 5, 2 } for collapse(3) ordered(6) loop, then
GOMP_doacross_post/GOMP_doacross_ull_post is called with arguments equal to
.ordereda.N[0] - 1, 12, 4, 1.

2022-09-08  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* omp-expand.cc (expand_omp_ordered_sink): Add CONT_BB argument.
	Add doacross(sink:omp_cur_iteration-1) support.
	(expand_omp_ordered_source_sink): Clear counts[fd->ordered + 1].
	Adjust expand_omp_ordered_sink caller.
	(expand_omp_for_ordered_loops): If counts[fd->ordered + 1] is
	non-NULL, set that variable to true at the start of outermost
	non-collapsed loop and set it to false at the end of innermost
	ordered loop.
	(expand_omp_for_generic): If fd->ordered, allocate
	1 + (fd->ordered - fd->collapse) further elements in counts array.
	Copy to counts + 2 + fd->ordered the counts of fd->collapse ..
	fd->ordered - 1 loop if any.
gcc/testsuite/
	* c-c++-common/gomp/doacross-7.c: New test.
libgomp/
	* libgomp.texi (OpenMP 5.2): Mention that omp_cur_iteration is now
	fully supported.
	* testsuite/libgomp.c/doacross-4.c: New test.
	* testsuite/libgomp.c/doacross-5.c: New test.
	* testsuite/libgomp.c/doacross-6.c: New test.
	* testsuite/libgomp.c/doacross-7.c: New test.
2022-09-08 13:32:51 +02:00
..
config Update copyright years. 2022-01-03 10:42:10 +01:00
lib Fix Intel MIC 'mkoffload' for OpenMP 'requires' 2022-07-07 12:38:51 +02:00
libgomp.c openmp: Implement doacross(sink: omp_cur_iteration - 1) 2022-09-08 13:32:51 +02:00
libgomp.c-c++-common OpenMP: Support reverse offload (middle end part) 2022-08-26 12:12:25 +02:00
libgomp.c++ OpenMP, C++: Add template support for the has_device_addr clause. 2022-05-16 01:02:50 -07:00
libgomp.fortran OpenMP: Support reverse offload (middle end part) 2022-08-26 12:12:25 +02:00
libgomp.graphite Update copyright years. 2022-01-03 10:42:10 +01:00
libgomp.oacc-c [testsuite] Unset 'offload_target' after use 2020-07-24 14:00:43 +02:00
libgomp.oacc-c-c++-common XFAIL 'offloading_enabled' diagnostics issue in 'libgomp.oacc-c-c++-common/reduction-5.c' [PR101551] 2022-07-12 08:28:00 +02:00
libgomp.oacc-c++ nvptx: update fix for -Wformat-diag 2022-01-19 08:27:00 +01:00
libgomp.oacc-fortran Fix up 'libgomp.oacc-fortran/print-1.f90' GCN offloading compilation [PR104717] 2022-04-28 15:15:29 +02:00
libgomp-site-extra.exp.in libgomp/test: Remove a build sysroot fix regression 2020-04-06 23:32:45 +01:00
libgomp-test-support.exp.in libgomp nvptx plugin: Remove '--with-cuda-driver=[...]' etc. configuration option 2022-06-10 17:08:57 +02:00
Makefile.am libgomp/test: Remove a build sysroot fix regression 2020-04-06 23:32:45 +01:00
Makefile.in libgomp nvptx plugin: Remove '--with-cuda-driver=[...]' etc. configuration option 2022-06-10 17:08:57 +02:00