From e25ce4d65f69cefd36f625ebabf13c0b41638954 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 14 Apr 2025 16:38:55 +0000 Subject: Default compute dimensions (compile time) This patch was previously combined with an unrelated change and testcases that was upstreamed separately ("Add '-Wopenacc-parallelism'", 22cff118f7526bec195ed6e41452980820fdf3a8). gcc/ChangeLog * doc/invoke.texi (fopenacc-dim): Document syntax for using runtime value from environment variable. * omp-offload.cc (oacc_parse_default_dims): Implement it. libgomp/ChangeLog * testsuite/libgomp.oacc-c-c++-common/loop-default-compile.c: New. Co-Authored-By: Tom de Vries Co-Authored-By: Thomas Schwinge Co-Authored-By: Julian Brown --- gcc/doc/invoke.texi | 6 +++++- gcc/omp-offload.cc | 25 ++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'gcc') diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 617a3d8..f55f789 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -5249,7 +5249,11 @@ have support for @option{-pthread}. Specify default compute dimensions for parallel offload regions that do not explicitly specify them. The @var{geom} value is a triple of @samp{:}-separated sizes, in order @var{gang}, @var{worker}, and @var{vector}. -A size can be omitted, to use a target-specific default value. +If a size is to be deferred until execution @samp{-} can be used; +alternatively a size can be omitted to use a target-specific default value. +When deferring to runtime, the environment variable @env{GOMP_OPENACC_DIM} +can be set. It has the same format as the option value, except that +@samp{-} is not permitted. @opindex fopenmp @cindex OpenMP parallel diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc index de9b063..536bfb7 100644 --- a/gcc/omp-offload.cc +++ b/gcc/omp-offload.cc @@ -875,8 +875,9 @@ oacc_get_min_dim (int dim) } /* Parse the default dimension parameter. This is a set of - :-separated optional compute dimensions. Each specified dimension - is a positive integer. When device type support is added, it is + :-separated optional compute dimensions. Each dimension is either + a positive integer, or '-' for a dynamic value computed at + runtime. When device type support is added, it is planned to be a comma separated list of such compute dimensions, with all but the first prefixed by the colon-terminated device type. */ @@ -911,14 +912,20 @@ oacc_parse_default_dims (const char *dims) if (*pos != ':') { - long val; - const char *eptr; + long val = 0; - errno = 0; - val = strtol (pos, CONST_CAST (char **, &eptr), 10); - if (errno || val <= 0 || (int) val != val) - goto malformed; - pos = eptr; + if (*pos == '-') + pos++; + else + { + const char *eptr; + + errno = 0; + val = strtol (pos, CONST_CAST (char **, &eptr), 10); + if (errno || val <= 0 || (int) val != val) + goto malformed; + pos = eptr; + } oacc_default_dims[ix] = (int) val; } } -- cgit v1.1