gcc/libgomp
Jakub Jelinek 48d7327f2a openmp: Add support for 2 argument num_teams clause
In OpenMP 5.1, num_teams clause can accept either one expression as before,
but it in that case changed meaning, rather than create <= expression
teams it is now create == expression teams.  Or it accepts two expressions
separated by :, with the meaning that the first is low bound and second upper
bound on how many teams should be created.  The other ways to set number of
teams are upper bounds with lower bound of 1.

The following patch does parsing of this for C/C++.  For host teams, we
actually don't need to do anything further right now, we always create
(pretend to create) exactly the requested number of teams, so we can just
evaluate and throw away the lower bound for now.
For teams nested in target, we don't guarantee that though and further
work will be needed.
In particular, omplower now turns the teams part of:
struct S { S (); S (const S &); ~S (); int s; };
void bar (S &, S &);
int baz ();
_Pragma ("omp declare target to (baz)");

void
foo (void)
{
  S a, b;
  #pragma omp target private (a) map (b)
  {
    #pragma omp teams firstprivate (b) num_teams (baz ())
    {
      bar (a, b);
    }
  }
}
into:
  retval.0 = baz ();
  retval.1 = retval.0;
  {
    unsigned int retval.3;
    struct S * D.2549;
    struct S b;

    retval.3 = (unsigned int) retval.1;
    D.2549 = .omp_data_i->b;
    S::S (&b, D.2549);
    #pragma omp teams num_teams(retval.1) firstprivate(b) shared(a)
    __builtin_GOMP_teams (retval.3, 0);
    {
      bar (&a, &b);
    }
    S::~S (&b);
    #pragma omp return(nowait)
  }
IMHO we want a new API, say GOMP_teams3 which will take 3 arguments
instead of 2 (the lower and upper bounds from num_teams and thread_limit)
and will return a bool whether it should do the teams body or not.
And, we should add right before outermost {} above
while (__builtin_GOMP_teams3 ((unsigned) retval.1, (unsigned) retval.1, 0))
and remove the __builtin_GOMP_teams call.  The current function performs
exit equivalent (at least on NVPTX) which seems bad because that means
the destructors of e.g. private variables on target aren't invoked, and
at the current placement neither destructors of the already constructed
privatized variables in teams.
I'll do this next on the compiler side, but I'm afraid I'll need help
with the nvptx and amdgcn implementations.  E.g. for nvptx, we won't be
able to use %ctaid.x .  I think ideal would be to use a .shared
integer variable for the omp_get_team_num value, but I don't have any
experience with that, are .shared variables zero initialized by default,
or do they have random value at start?  PTX docs say they aren't initializable.

2021-11-11  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* tree.h (OMP_CLAUSE_NUM_TEAMS_EXPR): Rename to ...
	(OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR): ... this.
	(OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR): Define.
	* tree.c (omp_clause_num_ops): Increase num ops for
	OMP_CLAUSE_NUM_TEAMS to 2.
	* tree-pretty-print.c (dump_omp_clause): Print optional lower bound
	for OMP_CLAUSE_NUM_TEAMS.
	* gimplify.c (gimplify_scan_omp_clauses): Gimplify
	OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR if non-NULL.
	(optimize_target_teams): Use OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR instead
	of OMP_CLAUSE_NUM_TEAMS_EXPR.  Handle OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR.
	* omp-low.c (lower_omp_teams): Use OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR
	instead of OMP_CLAUSE_NUM_TEAMS_EXPR.
	* omp-expand.c (expand_teams_call, get_target_arguments): Likewise.
gcc/c/
	* c-parser.c (c_parser_omp_clause_num_teams): Parse optional
	lower-bound and store it into OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR.
	Use OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR instead of
	OMP_CLAUSE_NUM_TEAMS_EXPR.
	(c_parser_omp_target): For OMP_CLAUSE_NUM_TEAMS evaluate before
	combined target teams even lower-bound expression.
gcc/cp/
	* parser.c (cp_parser_omp_clause_num_teams): Parse optional
	lower-bound and store it into OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR.
	Use OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR instead of
	OMP_CLAUSE_NUM_TEAMS_EXPR.
	(cp_parser_omp_target): For OMP_CLAUSE_NUM_TEAMS evaluate before
	combined target teams even lower-bound expression.
	* semantics.c (finish_omp_clauses): Handle
	OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR of OMP_CLAUSE_NUM_TEAMS clause.
	* pt.c (tsubst_omp_clauses): Likewise.
	(tsubst_expr): For OMP_CLAUSE_NUM_TEAMS evaluate before
	combined target teams even lower-bound expression.
gcc/fortran/
	* trans-openmp.c (gfc_trans_omp_clauses): Use
	OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR instead of OMP_CLAUSE_NUM_TEAMS_EXPR.
gcc/testsuite/
	* c-c++-common/gomp/clauses-1.c (bar): Supply lower-bound expression
	to half of the num_teams clauses.
	* c-c++-common/gomp/num-teams-1.c: New test.
	* c-c++-common/gomp/num-teams-2.c: New test.
	* g++.dg/gomp/attrs-1.C (bar): Supply lower-bound expression
	to half of the num_teams clauses.
	* g++.dg/gomp/attrs-2.C (bar): Likewise.
	* g++.dg/gomp/num-teams-1.C: New test.
	* g++.dg/gomp/num-teams-2.C: New test.
libgomp/
	* testsuite/libgomp.c-c++-common/teams-1.c: New test.
2021-11-11 09:42:47 +01:00
..
config openmp: Fix handling of numa_domains(1) 2021-10-18 15:00:46 +02:00
plugin amdgcn: Enable OpenACC worker partitioning for AMD GCN 2021-08-09 15:08:44 +02:00
testsuite openmp: Add support for 2 argument num_teams clause 2021-11-11 09:42:47 +01:00
.gitattributes libgomp: Fixes + cleanup for OpenACC's Fortran module + openacc_lib.h 2020-02-19 09:13:44 +01:00
ChangeLog Daily bump. 2021-11-10 00:16:28 +00:00
ChangeLog.graphite Add forgotten ChangeLog entries. 2010-03-08 17:49:42 +00:00
Makefile.am openmp: Implement OpenMP 5.1 scope construct 2021-08-17 09:30:09 +02:00
Makefile.in openmp: Implement OpenMP 5.1 scope construct 2021-08-17 09:30:09 +02:00
acc_prof.h Update copyright years. 2021-01-04 10:26:59 +01:00
acinclude.m4 re PR other/79543 (Inappropriate "ld --version" checking) 2019-09-03 14:10:26 +00:00
aclocal.m4 libgomp: Regenerate configure files with automake 1.15.1 2020-10-02 12:08:47 +02:00
affinity-fmt.c openmp: Avoid PLT relocations for omp_* symbols in libgomp 2021-10-01 10:42:07 +02:00
affinity.c Update copyright years. 2021-01-04 10:26:59 +01:00
alloc.c Update copyright years. 2021-01-04 10:26:59 +01:00
allocator.c libgomp: Add tests for omp_atv_serialized and deprecate omp_atv_sequential. 2021-10-11 04:34:51 -07:00
atomic.c Update copyright years. 2021-01-04 10:26:59 +01:00
barrier.c Update copyright years. 2021-01-04 10:26:59 +01:00
config.h.in offload-defaulted: Config option to silently ignore uninstalled offload compilers 2021-04-28 18:46:47 +02:00
configure libgomp: Only check for 2*sizeof(void*) int type with Fortran [PR96661] 2021-09-28 15:15:47 +02:00
configure.ac libgomp: Only check for 2*sizeof(void*) int type with Fortran [PR96661] 2021-09-28 15:15:47 +02:00
configure.tgt [gcn] Work-around libgomp 'error: array subscript 0 is outside array bounds of ‘__lds struct gomp_thread * __lds[0]’ [-Werror=array-bounds]' some more [PR101484] 2021-07-20 09:14:28 +02:00
critical.c Update copyright years. 2021-01-04 10:26:59 +01:00
env.c Restore 'GOMP_OPENACC_DIM' environment variable parsing 2021-11-09 16:51:57 +01:00
error.c openmp: Implement the error directive 2021-08-20 11:36:52 +02:00
fortran.c openmp: Add omp_set_num_teams, omp_get_max_teams, omp_[gs]et_teams_thread_limit 2021-10-11 12:20:22 +02:00
hashtab.h libgomp: Structure element mapping for OpenMP 5.0 2021-06-17 21:34:59 +08:00
icv-device.c openmp: Avoid PLT relocations for omp_* symbols in libgomp 2021-10-01 10:42:07 +02:00
icv.c openmp: Add omp_set_num_teams, omp_get_max_teams, omp_[gs]et_teams_thread_limit 2021-10-11 12:20:22 +02:00
iter.c Update copyright years. 2021-01-04 10:26:59 +01:00
iter_ull.c Update copyright years. 2021-01-04 10:26:59 +01:00
libgomp-plugin.c Update copyright years. 2021-01-04 10:26:59 +01:00
libgomp-plugin.h openmp: Implement omp_get_device_num routine 2021-08-05 23:29:03 +08:00
libgomp.h openmp: Fix up struct gomp_work_share handling [PR102838] 2021-10-20 09:34:51 +02:00
libgomp.map openmp: Add omp_set_num_teams, omp_get_max_teams, omp_[gs]et_teams_thread_limit 2021-10-11 12:20:22 +02:00
libgomp.spec.in Generally link to libgomp for -ftree-parallelize-loops=*. 2013-11-07 16:07:34 +01:00
libgomp.texi openmp: Document that non-rect loops are not supported in Fortran yet 2021-10-27 09:24:46 +02:00
libgomp_f.h.in Update copyright years. 2021-01-04 10:26:59 +01:00
libgomp_g.h openmp: Implement the error directive 2021-08-20 11:36:52 +02:00
lock.c Update copyright years. 2021-01-04 10:26:59 +01:00
loop.c Update copyright years. 2021-01-04 10:26:59 +01:00
loop_ull.c Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-async.c Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-cuda.c Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-host.c Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-init.c Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-int.h Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-mem.c Fix OpenACC "ephemeral" asynchronous host-to-device copies 2021-07-27 11:16:27 +02:00
oacc-parallel.c libgomp: Structure element mapping for OpenMP 5.0 2021-06-17 21:34:59 +08:00
oacc-plugin.c Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-plugin.h Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-profiling.c Update copyright years. 2021-01-04 10:26:59 +01:00
oacc-target.c GCN libgomp port 2019-11-13 12:38:04 +00:00
omp.h.in libgomp: Add tests for omp_atv_serialized and deprecate omp_atv_sequential. 2021-10-11 04:34:51 -07:00
omp_lib.f90.in libgomp: Add tests for omp_atv_serialized and deprecate omp_atv_sequential. 2021-10-11 04:34:51 -07:00
omp_lib.h.in openmp: Add omp_set_num_teams, omp_get_max_teams, omp_[gs]et_teams_thread_limit 2021-10-11 12:20:22 +02:00
openacc.f90 Update copyright years. 2021-01-04 10:26:59 +01:00
openacc.h Update copyright years. 2021-01-04 10:26:59 +01:00
openacc_lib.h Update copyright years. 2021-01-04 10:26:59 +01:00
ordered.c Update copyright years. 2021-01-04 10:26:59 +01:00
parallel.c Update copyright years. 2021-01-04 10:26:59 +01:00
priority_queue.c openmp: Add support for the OpenMP 5.0 task detach clause 2021-01-16 12:58:13 -08:00
priority_queue.h openmp: Add support for the OpenMP 5.0 task detach clause 2021-01-16 12:58:13 -08:00
scope.c openmp: Implement OpenMP 5.1 scope construct 2021-08-17 09:30:09 +02:00
sections.c Update copyright years. 2021-01-04 10:26:59 +01:00
secure_getenv.h Update copyright years. 2021-01-04 10:26:59 +01:00
single.c Update copyright years. 2021-01-04 10:26:59 +01:00
splay-tree.c Update copyright years. 2021-01-04 10:26:59 +01:00
splay-tree.h Update copyright years. 2021-01-04 10:26:59 +01:00
target.c libgomp: Release device lock on cbuf error path 2021-10-12 06:50:26 -07:00
task.c openmp: Notify team barrier of pending tasks in omp_fulfill_event 2021-05-17 13:15:08 -07:00
taskloop.c openmp: Add support for strict modifier on grainsize/num_tasks clauses 2021-08-23 10:16:24 +02:00
team.c Replace VRP threader with a hybrid forward threader. 2021-09-27 17:39:51 +02:00
teams.c openmp: Add omp_set_num_teams, omp_get_max_teams, omp_[gs]et_teams_thread_limit 2021-10-11 12:20:22 +02:00
work.c openmp: Fix up struct gomp_work_share handling [PR102838] 2021-10-20 09:34:51 +02:00