mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-12-13 22:03:43 +08:00
07dd3bcda1
OpenMP 5.1 adds env vars and functions to set and query new ICVs used as fallback if thread_limit or num_teams clauses aren't specified on teams construct. The following patch implements those, though further work will be needed: 1) OpenMP 5.1 also changed the num_teams clause, so that it can specify both lower and upper limit for how many teams should be created and changed the meaning when only one expression is provided, instead of num_teams(expr) in 5.0 meaning num_teams(1:expr) in 5.1, it now means num_teams(expr:expr), i.e. while previously we could create 1 to expr teams, in 5.1 we have some low limit by default equal to the single expression provided and may not create fewer teams. For host teams (which we don't currently implement efficiently for NUMA hosts) we trivially satisfy it now by always honoring what the user asked for, but for the offloading teams I think we'll need to rethink the APIs; currently teams construct is just a call that returns and possibly lowers the number of teams; and whenever possible we try to evaluate num_teams/thread_limit already on the target construct and the GOMP_teams call just sets the number of teams to the minimum of provided and requested teams; for some cases e.g. where target is not combined with teams and num_teams expression calls some functions etc., we need to call those functions in the target region and so it is late to figure number of teams, but also hw could just limit what it is willing to create; in that case I'm afraid we need to run the target body multiple times and arrange for omp_get_team_num () returning the right values 2) we need to finally implement the NUMA handling for GOMP_teams_reg 3) I now realize I haven't added some testcase coverage, will do that incrementally 4) libgomp.texi needs updates for these new APIs, but also others like the allocator 2021-10-11 Jakub Jelinek <jakub@redhat.com> gcc/ * omp-low.c (omp_runtime_api_call): Handle omp_get_max_teams, omp_[sg]et_teams_thread_limit and omp_set_num_teams. libgomp/ * omp.h.in (omp_set_num_teams, omp_get_max_teams, omp_set_teams_thread_limit, omp_get_teams_thread_limit): Declare. * omp_lib.f90.in (omp_set_num_teams, omp_get_max_teams, omp_set_teams_thread_limit, omp_get_teams_thread_limit): Declare. * omp_lib.h.in (omp_set_num_teams, omp_get_max_teams, omp_set_teams_thread_limit, omp_get_teams_thread_limit): Declare. * libgomp.h (gomp_nteams_var, gomp_teams_thread_limit_var): Declare. * libgomp.map (OMP_5.1): Export omp_get_max_teams{,_}, omp_get_teams_thread_limit{,_}, omp_set_num_teams{,_,_8_} and omp_set_teams_thread_limit{,_,_8_}. * icv.c (omp_set_num_teams, omp_get_max_teams, omp_set_teams_thread_limit, omp_get_teams_thread_limit): New functions. * env.c (gomp_nteams_var, gomp_teams_thread_limit_var): Define. (omp_display_env): Print OMP_NUM_TEAMS and OMP_TEAMS_THREAD_LIMIT. (initialize_env): Handle OMP_NUM_TEAMS and OMP_TEAMS_THREAD_LIMIT env vars. * teams.c (GOMP_teams_reg): If thread_limit is not specified, use gomp_teams_thread_limit_var as fallback if not zero. If num_teams is not specified, use gomp_nteams_var. * fortran.c (omp_set_num_teams, omp_get_max_teams, omp_set_teams_thread_limit, omp_get_teams_thread_limit): Add ialias_redirect. (omp_set_num_teams_, omp_set_num_teams_8_, omp_get_max_teams_, omp_set_teams_thread_limit_, omp_set_teams_thread_limit_8_, omp_get_teams_thread_limit_): New functions.
290 lines
6.4 KiB
C
290 lines
6.4 KiB
C
/* Copyright (C) 2005-2021 Free Software Foundation, Inc.
|
|
Contributed by Richard Henderson <rth@redhat.com>.
|
|
|
|
This file is part of the GNU Offloading and Multi Processing Library
|
|
(libgomp).
|
|
|
|
Libgomp is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
more details.
|
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
/* This file defines the OpenMP API entry points that operate on internal
|
|
control variables. */
|
|
|
|
#include "libgomp.h"
|
|
#include "gomp-constants.h"
|
|
#include <limits.h>
|
|
|
|
ialias_redirect (omp_get_active_level)
|
|
|
|
void
|
|
omp_set_num_threads (int n)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (true);
|
|
icv->nthreads_var = (n > 0 ? n : 1);
|
|
}
|
|
|
|
void
|
|
omp_set_dynamic (int val)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (true);
|
|
icv->dyn_var = val;
|
|
}
|
|
|
|
int
|
|
omp_get_dynamic (void)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (false);
|
|
return icv->dyn_var;
|
|
}
|
|
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
void
|
|
omp_set_nested (int val)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (true);
|
|
if (val)
|
|
icv->max_active_levels_var = gomp_supported_active_levels;
|
|
else if (icv->max_active_levels_var > 1)
|
|
icv->max_active_levels_var = 1;
|
|
}
|
|
|
|
int
|
|
omp_get_nested (void)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (false);
|
|
return (icv->max_active_levels_var > 1
|
|
&& icv->max_active_levels_var > omp_get_active_level ());
|
|
}
|
|
#pragma GCC diagnostic pop
|
|
|
|
void
|
|
omp_set_schedule (omp_sched_t kind, int chunk_size)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (true);
|
|
switch (kind & ~omp_sched_monotonic)
|
|
{
|
|
case omp_sched_static:
|
|
if (chunk_size < 1)
|
|
chunk_size = 0;
|
|
icv->run_sched_chunk_size = chunk_size;
|
|
break;
|
|
case omp_sched_dynamic:
|
|
case omp_sched_guided:
|
|
if (chunk_size < 1)
|
|
chunk_size = 1;
|
|
icv->run_sched_chunk_size = chunk_size;
|
|
break;
|
|
case omp_sched_auto:
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
icv->run_sched_var = kind;
|
|
}
|
|
|
|
void
|
|
omp_get_schedule (omp_sched_t *kind, int *chunk_size)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (false);
|
|
*kind = icv->run_sched_var;
|
|
*chunk_size = icv->run_sched_chunk_size;
|
|
}
|
|
|
|
int
|
|
omp_get_max_threads (void)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (false);
|
|
return icv->nthreads_var;
|
|
}
|
|
|
|
int
|
|
omp_get_thread_limit (void)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (false);
|
|
return icv->thread_limit_var > INT_MAX ? INT_MAX : icv->thread_limit_var;
|
|
}
|
|
|
|
void
|
|
omp_set_max_active_levels (int max_levels)
|
|
{
|
|
if (max_levels >= 0)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (true);
|
|
|
|
if (max_levels <= gomp_supported_active_levels)
|
|
icv->max_active_levels_var = max_levels;
|
|
else
|
|
icv->max_active_levels_var = gomp_supported_active_levels;
|
|
}
|
|
}
|
|
|
|
int
|
|
omp_get_max_active_levels (void)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (false);
|
|
return icv->max_active_levels_var;
|
|
}
|
|
|
|
int
|
|
omp_get_supported_active_levels (void)
|
|
{
|
|
return gomp_supported_active_levels;
|
|
}
|
|
|
|
void
|
|
omp_set_num_teams (int num_teams)
|
|
{
|
|
if (num_teams >= 0)
|
|
gomp_nteams_var = num_teams;
|
|
}
|
|
|
|
int
|
|
omp_get_max_teams (void)
|
|
{
|
|
return gomp_nteams_var;
|
|
}
|
|
|
|
void
|
|
omp_set_teams_thread_limit (int thread_limit)
|
|
{
|
|
if (thread_limit >= 0)
|
|
gomp_teams_thread_limit_var = thread_limit;
|
|
}
|
|
|
|
int
|
|
omp_get_teams_thread_limit (void)
|
|
{
|
|
return gomp_teams_thread_limit_var;
|
|
}
|
|
|
|
int
|
|
omp_get_cancellation (void)
|
|
{
|
|
return gomp_cancel_var;
|
|
}
|
|
|
|
int
|
|
omp_get_max_task_priority (void)
|
|
{
|
|
return gomp_max_task_priority_var;
|
|
}
|
|
|
|
omp_proc_bind_t
|
|
omp_get_proc_bind (void)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (false);
|
|
return icv->bind_var;
|
|
}
|
|
|
|
int
|
|
omp_get_num_places (void)
|
|
{
|
|
return gomp_places_list_len;
|
|
}
|
|
|
|
int
|
|
omp_get_place_num (void)
|
|
{
|
|
if (gomp_places_list == NULL)
|
|
return -1;
|
|
|
|
struct gomp_thread *thr = gomp_thread ();
|
|
if (thr->place == 0)
|
|
gomp_init_affinity ();
|
|
|
|
return (int) thr->place - 1;
|
|
}
|
|
|
|
int
|
|
omp_get_partition_num_places (void)
|
|
{
|
|
if (gomp_places_list == NULL)
|
|
return 0;
|
|
|
|
struct gomp_thread *thr = gomp_thread ();
|
|
if (thr->place == 0)
|
|
gomp_init_affinity ();
|
|
|
|
return thr->ts.place_partition_len;
|
|
}
|
|
|
|
void
|
|
omp_get_partition_place_nums (int *place_nums)
|
|
{
|
|
if (gomp_places_list == NULL)
|
|
return;
|
|
|
|
struct gomp_thread *thr = gomp_thread ();
|
|
if (thr->place == 0)
|
|
gomp_init_affinity ();
|
|
|
|
unsigned int i;
|
|
for (i = 0; i < thr->ts.place_partition_len; i++)
|
|
*place_nums++ = thr->ts.place_partition_off + i;
|
|
}
|
|
|
|
void
|
|
omp_set_default_allocator (omp_allocator_handle_t allocator)
|
|
{
|
|
struct gomp_thread *thr = gomp_thread ();
|
|
if (allocator == omp_null_allocator)
|
|
allocator = omp_default_mem_alloc;
|
|
thr->ts.def_allocator = (uintptr_t) allocator;
|
|
}
|
|
|
|
omp_allocator_handle_t
|
|
omp_get_default_allocator (void)
|
|
{
|
|
struct gomp_thread *thr = gomp_thread ();
|
|
if (thr->ts.def_allocator == omp_null_allocator)
|
|
return (omp_allocator_handle_t) gomp_def_allocator;
|
|
else
|
|
return (omp_allocator_handle_t) thr->ts.def_allocator;
|
|
}
|
|
|
|
ialias (omp_set_dynamic)
|
|
ialias (omp_get_dynamic)
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
ialias (omp_set_nested)
|
|
ialias (omp_get_nested)
|
|
#pragma GCC diagnostic pop
|
|
ialias (omp_set_num_threads)
|
|
ialias (omp_set_schedule)
|
|
ialias (omp_get_schedule)
|
|
ialias (omp_get_max_threads)
|
|
ialias (omp_get_thread_limit)
|
|
ialias (omp_set_max_active_levels)
|
|
ialias (omp_get_max_active_levels)
|
|
ialias (omp_get_supported_active_levels)
|
|
ialias (omp_set_num_teams)
|
|
ialias (omp_get_max_teams)
|
|
ialias (omp_set_teams_thread_limit)
|
|
ialias (omp_get_teams_thread_limit)
|
|
ialias (omp_get_cancellation)
|
|
ialias (omp_get_proc_bind)
|
|
ialias (omp_get_max_task_priority)
|
|
ialias (omp_get_num_places)
|
|
ialias (omp_get_place_num)
|
|
ialias (omp_get_partition_num_places)
|
|
ialias (omp_get_partition_place_nums)
|
|
ialias (omp_set_default_allocator)
|
|
ialias (omp_get_default_allocator)
|