mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-24 03:14:08 +08:00
18c8b56c7d
OMP_TARGET_OFFLOAD=mandatory handling was before inconsistent. Hence, in OpenMP 5.2 it was clarified/extended by having implications on the default-device-var; additionally, omp_initial_device and omp_invalid_device enum values/PARAMETERs were added; support for it was added in r13-1066-g1158fe43407568 including aborting for omp_invalid_device and non-conforming device numbers. Only the mandatory handling was missing. Namely, while the default-device-var is usually initialized to value 0, with 'mandatory' it must have the value 'omp_invalid_device' if and only if zero non-host devices are available. (The OMP_DEFAULT_DEVICE env var overrides this as it comes semantically after the initialization.) To achieve this, default-device-var is now initialized to MIN_INT. If there is no 'mandatory', it is set to 0 directly after env var parsing. Otherwise, it is updated in gomp_target_init to either 0 or omp_invalid_device. To ensure INT_MIN is never seen by the user, both the omp_get_default_device API routine and omp_display_env (user call and OMP_DISPLAY_ENV env var) call gomp_init_targets_once() in that case. libgomp/ChangeLog: * env.c (gomp_default_icv_values): Init default_device_var to an nonconforming value - INT_MIN. (initialize_env): After env-var parsing, set default_device_var to device 0 unless OMP_TARGET_OFFLOAD=mandatory. (omp_display_env): If default_device_var is INT_MIN, call gomp_init_targets_once. * icv-device.c (omp_get_default_device): Likewise. * libgomp.texi (OMP_DEFAULT_DEVICE): Update init description. (OpenMP 5.2 Impl. Status): Mark OMP_TARGET_OFFLOAD=mandatory as 'Y'. * target.c (resolve_device): Improve error message device-num < 0 with 'mandatory' and no no-host devices available. (gomp_target_init): Set default-device-var if INT_MIN. * testsuite/libgomp.c/target-48.c: New test. * testsuite/libgomp.c/target-49.c: New test. * testsuite/libgomp.c/target-50.c: New test. * testsuite/libgomp.c/target-50a.c: New test. * testsuite/libgomp.c/target-51.c: New test. * testsuite/libgomp.c/target-52.c: New test. * testsuite/libgomp.c/target-53.c: New test. * testsuite/libgomp.c/target-54.c: New test.
121 lines
2.7 KiB
C
121 lines
2.7 KiB
C
/* Copyright (C) 2005-2023 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 OpenMP API entry points that accelerator targets are
|
|
expected to replace. */
|
|
|
|
#include "libgomp.h"
|
|
#include <limits.h>
|
|
|
|
void
|
|
omp_set_default_device (int device_num)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (true);
|
|
icv->default_device_var = device_num;
|
|
}
|
|
|
|
ialias (omp_set_default_device)
|
|
|
|
int
|
|
omp_get_default_device (void)
|
|
{
|
|
struct gomp_task_icv *icv = gomp_icv (false);
|
|
if (icv->default_device_var == INT_MIN)
|
|
/* This implies OMP_TARGET_OFFLOAD=mandatory. */
|
|
gomp_init_targets_once ();
|
|
return icv->default_device_var;
|
|
}
|
|
|
|
ialias (omp_get_default_device)
|
|
|
|
int
|
|
omp_get_initial_device (void)
|
|
{
|
|
return gomp_get_num_devices ();
|
|
}
|
|
|
|
ialias (omp_get_initial_device)
|
|
|
|
int
|
|
omp_get_num_devices (void)
|
|
{
|
|
return gomp_get_num_devices ();
|
|
}
|
|
|
|
ialias (omp_get_num_devices)
|
|
|
|
int
|
|
omp_is_initial_device (void)
|
|
{
|
|
/* Hardcoded to 1 on host, should be 0 on MIC, HSAIL, PTX. */
|
|
return 1;
|
|
}
|
|
|
|
ialias (omp_is_initial_device)
|
|
|
|
int
|
|
omp_get_device_num (void)
|
|
{
|
|
/* By specification, this is equivalent to omp_get_initial_device
|
|
on the host. */
|
|
return ialias_call (omp_get_initial_device) ();
|
|
}
|
|
|
|
ialias (omp_get_device_num)
|
|
|
|
int
|
|
omp_get_max_teams (void)
|
|
{
|
|
return gomp_nteams_var;
|
|
}
|
|
|
|
ialias (omp_get_max_teams)
|
|
|
|
void
|
|
omp_set_num_teams (int num_teams)
|
|
{
|
|
if (num_teams >= 0)
|
|
gomp_nteams_var = num_teams;
|
|
}
|
|
|
|
ialias (omp_set_num_teams)
|
|
|
|
int
|
|
omp_get_teams_thread_limit (void)
|
|
{
|
|
return gomp_teams_thread_limit_var;
|
|
}
|
|
|
|
ialias (omp_get_teams_thread_limit)
|
|
|
|
void
|
|
omp_set_teams_thread_limit (int thread_limit)
|
|
{
|
|
if (thread_limit >= 0)
|
|
gomp_teams_thread_limit_var = thread_limit;
|
|
}
|
|
|
|
ialias (omp_set_teams_thread_limit)
|