https://gcc.gnu.org/g:e25ce4d65f69cefd36f625ebabf13c0b41638954
commit e25ce4d65f69cefd36f625ebabf13c0b41638954 Author: Nathan Sidwell <nat...@acm.org> Date: Mon Apr 14 16:38:55 2025 +0000 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 <tdevr...@suse.de> Co-Authored-By: Thomas Schwinge <tho...@codesourcery.com> Co-Authored-By: Julian Brown <jul...@codesourcery.com> Diff: --- gcc/doc/invoke.texi | 6 +++++- gcc/omp-offload.cc | 25 ++++++++++++++-------- .../loop-default-compile.c | 13 +++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 617a3d8ae182..f55f7896d20a 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 de9b06314a9e..536bfb7889ce 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; } } diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/loop-default-compile.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/loop-default-compile.c new file mode 100644 index 000000000000..6c479e4eb258 --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/loop-default-compile.c @@ -0,0 +1,13 @@ +/* { dg-additional-options "-fopenacc-dim=16:16" } */ +/* This code uses nvptx inline assembly guarded with acc_on_device, which is + not optimized away at -O0, and then confuses the target assembler. + { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ +/* { dg-set-target-env-var "GOMP_OPENACC_DIM" "8:8" } */ + +#include "loop-default.h" + +int main () +{ + /* Environment should be ignored. */ + return test_1 (16, 16, 32); +}