diff options
author | Kwok Cheung Yeung <kcy@codesourcery.com> | 2020-10-20 04:15:59 -0700 |
---|---|---|
committer | Kwok Cheung Yeung <kcy@codesourcery.com> | 2020-10-20 04:16:26 -0700 |
commit | 1bfc07d150790fae93184a79a7cce897655cb37b (patch) | |
tree | 6e596730698b9ed4a72930de00b3ed632e124436 /libgomp/env.c | |
parent | 94fd05f1f76faca9dc9033b55d44c960155d38e9 (diff) | |
download | gcc-1bfc07d150790fae93184a79a7cce897655cb37b.zip gcc-1bfc07d150790fae93184a79a7cce897655cb37b.tar.gz gcc-1bfc07d150790fae93184a79a7cce897655cb37b.tar.bz2 |
openmp: Implement support for OMP_TARGET_OFFLOAD environment variable
This implements support for the OMP_TARGET_OFFLOAD environment variable
introduced in the OpenMP 5.0 standard, which controls how offloading
is handled. It may be set to MANDATORY (abort if offloading cannot be
performed), DISABLED (no offloading to devices) or DEFAULT (offload to
device if possible, fall back to host if not).
2020-10-20 Kwok Cheung Yeung <kcy@codesourcery.com>
libgomp/
* env.c (gomp_target_offload_var): New.
(parse_target_offload): New.
(handle_omp_display_env): Print value of OMP_TARGET_OFFLOAD.
(initialize_env): Parse OMP_TARGET_OFFLOAD.
* libgomp.h (gomp_target_offload_t): New.
(gomp_target_offload_var): New.
* libgomp.texi (OMP_TARGET_OFFLOAD): New section.
* target.c (resolve_device): Generate error if device not found and
offloading is mandatory.
(gomp_target_fallback): Generate error if offloading is mandatory.
(GOMP_target): Add argument in call to gomp_target_fallback.
(GOMP_target_ext): Likewise.
(gomp_target_data_fallback): Generate error if offloading is mandatory.
(GOMP_target_data): Add argument in call to gomp_target_data_fallback.
(GOMP_target_data_ext): Likewise.
(gomp_target_task_fn): Add argument in call to gomp_target_fallback.
(gomp_target_init): Return early if offloading is disabled.
Diffstat (limited to 'libgomp/env.c')
-rw-r--r-- | libgomp/env.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/libgomp/env.c b/libgomp/env.c index d730c48..f305b14 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -75,6 +75,8 @@ struct gomp_task_icv gomp_global_icv = { unsigned long gomp_max_active_levels_var = gomp_supported_active_levels; bool gomp_cancel_var = false; +enum gomp_target_offload_t gomp_target_offload_var + = GOMP_TARGET_OFFLOAD_DEFAULT; int gomp_max_task_priority_var = 0; #ifndef HAVE_SYNC_BUILTINS gomp_mutex_t gomp_managed_threads_lock; @@ -374,6 +376,48 @@ parse_unsigned_long_list (const char *name, unsigned long *p1stvalue, return false; } +static void +parse_target_offload (const char *name, enum gomp_target_offload_t *offload) +{ + const char *env; + bool found = false; + enum gomp_target_offload_t new_offload; + + env = getenv (name); + if (env == NULL) + return; + + while (isspace ((unsigned char) *env)) + ++env; + if (strncasecmp (env, "default", 7) == 0) + { + env += 7; + found = true; + new_offload = GOMP_TARGET_OFFLOAD_DEFAULT; + } + else if (strncasecmp (env, "mandatory", 9) == 0) + { + env += 9; + found = true; + new_offload = GOMP_TARGET_OFFLOAD_MANDATORY; + } + else if (strncasecmp (env, "disabled", 8) == 0) + { + env += 8; + found = true; + new_offload = GOMP_TARGET_OFFLOAD_DISABLED; + } + while (isspace ((unsigned char) *env)) + ++env; + if (found && *env == '\0') + { + *offload = new_offload; + return; + } + + gomp_error ("Invalid value for environment variable OMP_TARGET_OFFLOAD"); +} + /* Parse environment variable set to a boolean or list of omp_proc_bind_t enum values. Return true if one was present and it was successfully parsed. */ @@ -1334,6 +1378,21 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy) } fputs ("'\n", stderr); + fputs (" OMP_TARGET_OFFLOAD = '", stderr); + switch (gomp_target_offload_var) + { + case GOMP_TARGET_OFFLOAD_DEFAULT: + fputs ("DEFAULT", stderr); + break; + case GOMP_TARGET_OFFLOAD_MANDATORY: + fputs ("MANDATORY", stderr); + break; + case GOMP_TARGET_OFFLOAD_DISABLED: + fputs ("DISABLED", stderr); + break; + } + fputs ("'\n", stderr); + if (verbose) { fputs (" GOMP_CPU_AFFINITY = ''\n", stderr); @@ -1366,6 +1425,7 @@ initialize_env (void) parse_boolean ("OMP_CANCELLATION", &gomp_cancel_var); parse_boolean ("OMP_DISPLAY_AFFINITY", &gomp_display_affinity_var); parse_int ("OMP_DEFAULT_DEVICE", &gomp_global_icv.default_device_var, true); + parse_target_offload ("OMP_TARGET_OFFLOAD", &gomp_target_offload_var); parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var, true); parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var, true); |