[gcc/devel/omp/gcc-16] Default compute dimensions (compile time)

Sandra Loosemore via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:dcd8a542c270f1bc0fe9593403e98204c63ce826

commit dcd8a542c270f1bc0fe9593403e98204c63ce826
Author: Nathan Sidwell <[email protected]>
Date:   Sun Apr 5 21:28:12 2026 +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  <[email protected]>
    Co-Authored-By: Thomas Schwinge  <[email protected]>
    Co-Authored-By: Julian Brown  <[email protected]>

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 2fe30324693c..799bdac1f12f 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -5552,7 +5552,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
 @opindex fno-openmp
diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc
index e66f4b072f86..64b3401dd500 100644
--- a/gcc/omp-offload.cc
+++ b/gcc/omp-offload.cc
@@ -876,8 +876,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.  */
@@ -912,14 +913,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);
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.