Hi,

On Fri, Jul 30, 2021 at 9:50 AM Tobias Burnus <tob...@codesourcery.com>
wrote:

> this patch breaks offloading. The reason is that most code
> in env.c is enclosed in:
>

Indeed, normally I test that configuration but my setup currently has a few
problems.

Although the env vars aren't parsed for those targets it seems to be
appropriate to still provide the complete implementation.  There are other
functions which print something this is likely bogus as well and/or the
output isn't seen.

How about this change?  Compiles for me for NVPTX.  It doesn't change
anything but the location of the function definition in the file and
includes for LIBGOMP_OFFLOADED_ONLY some headers which aren't included in
this file before (but are present).

diff --git a/libgomp/env.c b/libgomp/env.c
index 5220877d533..e7ef294139d 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -30,15 +30,16 @@
 #include "libgomp.h"
 #include "gomp-constants.h"
 #include <limits.h>
+#include <stdio.h>
+#include "thread-stacksize.h"
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h> /* For PRIu64.  */
+#endif
 #ifndef LIBGOMP_OFFLOADED_ONLY
 #include "libgomp_f.h"
 #include "oacc-int.h"
 #include <ctype.h>
 #include <stdlib.h>
-#include <stdio.h>
-#ifdef HAVE_INTTYPES_H
-# include <inttypes.h> /* For PRIu64.  */
-#endif
 #ifdef STRING_WITH_STRINGS
 # include <string.h>
 # include <strings.h>
@@ -52,7 +53,6 @@
 # endif
 #endif
 #include <errno.h>
-#include "thread-stacksize.h"

 #ifndef HAVE_STRTOULL
 # define strtoull(ptr, eptr, base) strtoul (ptr, eptr, base)
@@ -97,11 +97,178 @@ char *goacc_device_type;
 int goacc_device_num;
 int goacc_default_dims[GOMP_DIM_MAX];

-#ifndef LIBGOMP_OFFLOADED_ONLY
-
 static int wait_policy;
 static unsigned long stacksize = GOMP_DEFAULT_STACKSIZE;

+
+void
+omp_display_env (int verbose)
+{
+  int i;
+
+  fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr);
+
+  fputs ("  _OPENMP = '201511'\n", stderr);
+  fprintf (stderr, "  OMP_DYNAMIC = '%s'\n",
+   gomp_global_icv.dyn_var ? "TRUE" : "FALSE");
+  fprintf (stderr, "  OMP_NESTED = '%s'\n",
+   gomp_global_icv.max_active_levels_var > 1 ? "TRUE" : "FALSE");
+
+  fprintf (stderr, "  OMP_NUM_THREADS = '%lu",
gomp_global_icv.nthreads_var);
+  for (i = 1; i < gomp_nthreads_var_list_len; i++)
+    fprintf (stderr, ",%lu", gomp_nthreads_var_list[i]);
+  fputs ("'\n", stderr);
+
+  fprintf (stderr, "  OMP_SCHEDULE = '");
+  if ((gomp_global_icv.run_sched_var & GFS_MONOTONIC))
+    {
+      if (gomp_global_icv.run_sched_var != (GFS_MONOTONIC | GFS_STATIC))
+ fputs ("MONOTONIC:", stderr);
+    }
+  else if (gomp_global_icv.run_sched_var == GFS_STATIC)
+    fputs ("NONMONOTONIC:", stderr);
+  switch (gomp_global_icv.run_sched_var & ~GFS_MONOTONIC)
+    {
+    case GFS_RUNTIME:
+      fputs ("RUNTIME", stderr);
+      if (gomp_global_icv.run_sched_chunk_size != 1)
+ fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
+      break;
+    case GFS_STATIC:
+      fputs ("STATIC", stderr);
+      if (gomp_global_icv.run_sched_chunk_size != 0)
+ fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
+      break;
+    case GFS_DYNAMIC:
+      fputs ("DYNAMIC", stderr);
+      if (gomp_global_icv.run_sched_chunk_size != 1)
+ fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
+      break;
+    case GFS_GUIDED:
+      fputs ("GUIDED", stderr);
+      if (gomp_global_icv.run_sched_chunk_size != 1)
+ fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
+      break;
+    case GFS_AUTO:
+      fputs ("AUTO", stderr);
+      break;
+    }
+  fputs ("'\n", stderr);
+
+  fputs ("  OMP_PROC_BIND = '", stderr);
+  switch (gomp_global_icv.bind_var)
+    {
+    case omp_proc_bind_false:
+      fputs ("FALSE", stderr);
+      break;
+    case omp_proc_bind_true:
+      fputs ("TRUE", stderr);
+      break;
+    case omp_proc_bind_master:
+      fputs ("MASTER", stderr);
+      break;
+    case omp_proc_bind_close:
+      fputs ("CLOSE", stderr);
+      break;
+    case omp_proc_bind_spread:
+      fputs ("SPREAD", stderr);
+      break;
+    }
+  for (i = 1; i < gomp_bind_var_list_len; i++)
+    switch (gomp_bind_var_list[i])
+      {
+      case omp_proc_bind_master:
+ fputs (",MASTER", stderr);
+ break;
+      case omp_proc_bind_close:
+ fputs (",CLOSE", stderr);
+ break;
+      case omp_proc_bind_spread:
+ fputs (",SPREAD", stderr);
+ break;
+      }
+  fputs ("'\n", stderr);
+  fputs ("  OMP_PLACES = '", stderr);
+  for (i = 0; i < gomp_places_list_len; i++)
+    {
+      fputs ("{", stderr);
+      gomp_affinity_print_place (gomp_places_list[i]);
+      fputs (i + 1 == gomp_places_list_len ? "}" : "},", stderr);
+    }
+  fputs ("'\n", stderr);
+
+  fprintf (stderr, "  OMP_STACKSIZE = '%lu'\n", stacksize);
+
+  /* GOMP's default value is actually neither active nor passive.  */
+  fprintf (stderr, "  OMP_WAIT_POLICY = '%s'\n",
+   wait_policy > 0 ? "ACTIVE" : "PASSIVE");
+  fprintf (stderr, "  OMP_THREAD_LIMIT = '%u'\n",
+   gomp_global_icv.thread_limit_var);
+  fprintf (stderr, "  OMP_MAX_ACTIVE_LEVELS = '%u'\n",
+   gomp_global_icv.max_active_levels_var);
+
+  fprintf (stderr, "  OMP_CANCELLATION = '%s'\n",
+   gomp_cancel_var ? "TRUE" : "FALSE");
+  fprintf (stderr, "  OMP_DEFAULT_DEVICE = '%d'\n",
+   gomp_global_icv.default_device_var);
+  fprintf (stderr, "  OMP_MAX_TASK_PRIORITY = '%d'\n",
+   gomp_max_task_priority_var);
+  fprintf (stderr, "  OMP_DISPLAY_AFFINITY = '%s'\n",
+   gomp_display_affinity_var ? "TRUE" : "FALSE");
+  fprintf (stderr, "  OMP_AFFINITY_FORMAT = '%s'\n",
+   gomp_affinity_format_var);
+  fprintf (stderr, "  OMP_ALLOCATOR = '");
+  switch (gomp_def_allocator)
+    {
+#define C(v) case v: fputs (#v, stderr); break;
+    C (omp_default_mem_alloc)
+    C (omp_large_cap_mem_alloc)
+    C (omp_const_mem_alloc)
+    C (omp_high_bw_mem_alloc)
+    C (omp_low_lat_mem_alloc)
+    C (omp_cgroup_mem_alloc)
+    C (omp_pteam_mem_alloc)
+    C (omp_thread_mem_alloc)
+#undef C
+    default: break;
+    }
+  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);
+      fprintf (stderr, "  GOMP_STACKSIZE = '%lu'\n", stacksize);
+#ifdef HAVE_INTTYPES_H
+      fprintf (stderr, "  GOMP_SPINCOUNT = '%"PRIu64"'\n",
+       (uint64_t) gomp_spin_count_var);
+#else
+      fprintf (stderr, "  GOMP_SPINCOUNT = '%lu'\n",
+       (unsigned long) gomp_spin_count_var);
+#endif
+    }
+
+  fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr);
+}
+ialias (omp_display_env)
+
+
+#ifndef LIBGOMP_OFFLOADED_ONLY
+
 /* Parse the OMP_SCHEDULE environment variable.  */

 static void
@@ -1213,171 +1380,6 @@ parse_gomp_openacc_dim (void)
     }
 }

-void
-omp_display_env (int verbose)
-{
-  int i;
-
-  fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr);
-
-  fputs ("  _OPENMP = '201511'\n", stderr);
-  fprintf (stderr, "  OMP_DYNAMIC = '%s'\n",
-   gomp_global_icv.dyn_var ? "TRUE" : "FALSE");
-  fprintf (stderr, "  OMP_NESTED = '%s'\n",
-   gomp_global_icv.max_active_levels_var > 1 ? "TRUE" : "FALSE");
-
-  fprintf (stderr, "  OMP_NUM_THREADS = '%lu",
gomp_global_icv.nthreads_var);
-  for (i = 1; i < gomp_nthreads_var_list_len; i++)
-    fprintf (stderr, ",%lu", gomp_nthreads_var_list[i]);
-  fputs ("'\n", stderr);
-
-  fprintf (stderr, "  OMP_SCHEDULE = '");
-  if ((gomp_global_icv.run_sched_var & GFS_MONOTONIC))
-    {
-      if (gomp_global_icv.run_sched_var != (GFS_MONOTONIC | GFS_STATIC))
- fputs ("MONOTONIC:", stderr);
-    }
-  else if (gomp_global_icv.run_sched_var == GFS_STATIC)
-    fputs ("NONMONOTONIC:", stderr);
-  switch (gomp_global_icv.run_sched_var & ~GFS_MONOTONIC)
-    {
-    case GFS_RUNTIME:
-      fputs ("RUNTIME", stderr);
-      if (gomp_global_icv.run_sched_chunk_size != 1)
- fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
-      break;
-    case GFS_STATIC:
-      fputs ("STATIC", stderr);
-      if (gomp_global_icv.run_sched_chunk_size != 0)
- fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
-      break;
-    case GFS_DYNAMIC:
-      fputs ("DYNAMIC", stderr);
-      if (gomp_global_icv.run_sched_chunk_size != 1)
- fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
-      break;
-    case GFS_GUIDED:
-      fputs ("GUIDED", stderr);
-      if (gomp_global_icv.run_sched_chunk_size != 1)
- fprintf (stderr, ",%d", gomp_global_icv.run_sched_chunk_size);
-      break;
-    case GFS_AUTO:
-      fputs ("AUTO", stderr);
-      break;
-    }
-  fputs ("'\n", stderr);
-
-  fputs ("  OMP_PROC_BIND = '", stderr);
-  switch (gomp_global_icv.bind_var)
-    {
-    case omp_proc_bind_false:
-      fputs ("FALSE", stderr);
-      break;
-    case omp_proc_bind_true:
-      fputs ("TRUE", stderr);
-      break;
-    case omp_proc_bind_master:
-      fputs ("MASTER", stderr);
-      break;
-    case omp_proc_bind_close:
-      fputs ("CLOSE", stderr);
-      break;
-    case omp_proc_bind_spread:
-      fputs ("SPREAD", stderr);
-      break;
-    }
-  for (i = 1; i < gomp_bind_var_list_len; i++)
-    switch (gomp_bind_var_list[i])
-      {
-      case omp_proc_bind_master:
- fputs (",MASTER", stderr);
- break;
-      case omp_proc_bind_close:
- fputs (",CLOSE", stderr);
- break;
-      case omp_proc_bind_spread:
- fputs (",SPREAD", stderr);
- break;
-      }
-  fputs ("'\n", stderr);
-  fputs ("  OMP_PLACES = '", stderr);
-  for (i = 0; i < gomp_places_list_len; i++)
-    {
-      fputs ("{", stderr);
-      gomp_affinity_print_place (gomp_places_list[i]);
-      fputs (i + 1 == gomp_places_list_len ? "}" : "},", stderr);
-    }
-  fputs ("'\n", stderr);
-
-  fprintf (stderr, "  OMP_STACKSIZE = '%lu'\n", stacksize);
-
-  /* GOMP's default value is actually neither active nor passive.  */
-  fprintf (stderr, "  OMP_WAIT_POLICY = '%s'\n",
-   wait_policy > 0 ? "ACTIVE" : "PASSIVE");
-  fprintf (stderr, "  OMP_THREAD_LIMIT = '%u'\n",
-   gomp_global_icv.thread_limit_var);
-  fprintf (stderr, "  OMP_MAX_ACTIVE_LEVELS = '%u'\n",
-   gomp_global_icv.max_active_levels_var);
-
-  fprintf (stderr, "  OMP_CANCELLATION = '%s'\n",
-   gomp_cancel_var ? "TRUE" : "FALSE");
-  fprintf (stderr, "  OMP_DEFAULT_DEVICE = '%d'\n",
-   gomp_global_icv.default_device_var);
-  fprintf (stderr, "  OMP_MAX_TASK_PRIORITY = '%d'\n",
-   gomp_max_task_priority_var);
-  fprintf (stderr, "  OMP_DISPLAY_AFFINITY = '%s'\n",
-   gomp_display_affinity_var ? "TRUE" : "FALSE");
-  fprintf (stderr, "  OMP_AFFINITY_FORMAT = '%s'\n",
-   gomp_affinity_format_var);
-  fprintf (stderr, "  OMP_ALLOCATOR = '");
-  switch (gomp_def_allocator)
-    {
-#define C(v) case v: fputs (#v, stderr); break;
-    C (omp_default_mem_alloc)
-    C (omp_large_cap_mem_alloc)
-    C (omp_const_mem_alloc)
-    C (omp_high_bw_mem_alloc)
-    C (omp_low_lat_mem_alloc)
-    C (omp_cgroup_mem_alloc)
-    C (omp_pteam_mem_alloc)
-    C (omp_thread_mem_alloc)
-#undef C
-    default: break;
-    }
-  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);
-      fprintf (stderr, "  GOMP_STACKSIZE = '%lu'\n", stacksize);
-#ifdef HAVE_INTTYPES_H
-      fprintf (stderr, "  GOMP_SPINCOUNT = '%"PRIu64"'\n",
-       (uint64_t) gomp_spin_count_var);
-#else
-      fprintf (stderr, "  GOMP_SPINCOUNT = '%lu'\n",
-       (unsigned long) gomp_spin_count_var);
-#endif
-    }
-
-  fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr);
-}
-ialias (omp_display_env)
-
 static void
 handle_omp_display_env (void)
 {

Reply via email to