Re: [PATCH 0/5] openmp: Handle pinned and unified shared memory.

2022-04-13 Thread Andrew Stubbs
This patch adjusts the testcases, previously proposed, to allow for 
testing on machines with varying page sizes and default amounts of 
lockable memory.  There turns out to be more variation than I had thought.


This should go on mainline at the same time as the previous patches in 
this thread.


I'll commit it to OG11 shortly.

Andrewlibgomp: autodetect page sizes in pinned memory tests

There's not one number that works everywhere.
This also fixes the failure mode on non-Linux hosts.

libgomp/ChangeLog:

* testsuite/libgomp.c/alloc-pinned-1.c: Autodetect page size.
* testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-3.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-4.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-6.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-7.c: Clean up.

diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c 
b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
index 0a6360cda29..79792b16d83 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
@@ -4,13 +4,23 @@
 
 /* Test that pinned memory works.  */
 
+#include 
+#include 
+
 #ifdef __linux__
 #include 
 #include 
-#include 
-#include 
 
 #include 
+#include 
+
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+#define CHECK_SIZE(SIZE) { \
+  struct rlimit limit; \
+  if (getrlimit (RLIMIT_MEMLOCK, &limit) \
+  || limit.rlim_cur <= SIZE) \
+fprintf (stderr, "unsufficient lockable memory; please increase 
ulimit\n"); \
+  }
 
 int
 get_pinned_mem ()
@@ -34,6 +44,9 @@ get_pinned_mem ()
   abort ();
 }
 #else
+#define PAGE_SIZE 1 /* unknown */
+#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n");
+
 int
 get_pinned_mem ()
 {
@@ -43,12 +56,13 @@ get_pinned_mem ()
 
 #include 
 
-/* Allocate more than a page each time, but stay within the ulimit.  */
-#define SIZE 10*1024
-
 int
 main ()
 {
+  /* Allocate at least a page each time, but stay within the ulimit.  */
+  const int SIZE = PAGE_SIZE;
+  CHECK_SIZE (SIZE*3);
+
   const omp_alloctrait_t traits[] = {
   { omp_atk_pinned, 1 }
   };
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c 
b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
index 8fdb4ff5cfd..228c656b715 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
@@ -4,13 +4,23 @@
 
 /* Test that pinned memory works (pool_size code path).  */
 
+#include 
+#include 
+
 #ifdef __linux__
 #include 
 #include 
-#include 
-#include 
 
 #include 
+#include 
+
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+#define CHECK_SIZE(SIZE) { \
+  struct rlimit limit; \
+  if (getrlimit (RLIMIT_MEMLOCK, &limit) \
+  || limit.rlim_cur <= SIZE) \
+fprintf (stderr, "unsufficient lockable memory; please increase 
ulimit\n"); \
+  }
 
 int
 get_pinned_mem ()
@@ -34,6 +44,9 @@ get_pinned_mem ()
   abort ();
 }
 #else
+#define PAGE_SIZE 1 /* unknown */
+#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n");
+
 int
 get_pinned_mem ()
 {
@@ -43,12 +56,13 @@ get_pinned_mem ()
 
 #include 
 
-/* Allocate more than a page each time, but stay within the ulimit.  */
-#define SIZE 10*1024
-
 int
 main ()
 {
+  /* Allocate at least a page each time, but stay within the ulimit.  */
+  const int SIZE = PAGE_SIZE;
+  CHECK_SIZE (SIZE*3);
+
   const omp_alloctrait_t traits[] = {
   { omp_atk_pinned, 1 },
   { omp_atk_pool_size, SIZE*8 }
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-3.c 
b/libgomp/testsuite/libgomp.c/alloc-pinned-3.c
index 943dfea5c9b..90539ffe3e0 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-3.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-3.c
@@ -2,15 +2,18 @@
 
 /* Test that pinned memory fails correctly.  */
 
+#include 
+#include 
+
 #ifdef __linux__
 #include 
 #include 
-#include 
-#include 
 
 #include 
 #include 
 
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+
 int
 get_pinned_mem ()
 {
@@ -45,6 +48,8 @@ set_pin_limit (int size)
 }
 #else
 int
+#define PAGE_SIZE 1*1024 /* unknown */
+
 get_pinned_mem ()
 {
   return 0;
@@ -58,12 +63,12 @@ set_pin_limit ()
 
 #include 
 
-/* This should be large enough to cover multiple pages.  */
-#define SIZE 1*1024
-
 int
 main ()
 {
+  /* This needs to be large enough to cover multiple pages.  */
+  const int SIZE = PAGE_SIZE*4;
+
   /* Pinned memory, no fallback.  */
   const omp_alloctrait_t traits1[] = {
   { omp_atk_pinned, 1 },
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-4.c 
b/libgomp/testsuite/libgomp.c/alloc-pinned-4.c
index d9cb8dfe1fd..534e49eefc4 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-4.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-4.c
@@ -2,15 +2,18 @@
 
 /* Test that pinned memory fails correctly, pool_size code path.  */
 
+#include 
+#include 
+
 #ifdef __linux__
 #include 
 #include 
-#include 
-#include 
 
 #include 
 #include 
 
+#define PAGE_SIZE

Re: [PATCH] fortran: use fpu-glibc on powerpc*-unknown-freebsd

2022-04-13 Thread Piotr Kubaj via Fortran
On 22-03-20 16:30:08, FX wrote:
> Hi,
> 
> (Please send all Fortran (front-end and libgfortran) patches in CC to the 
> Fortran list.)
> 
> Please hold from pushing the patch as is, I have some questions:
> 
> - If FreeBSD has feenableexcept() and related functions, it should already 
> use the fpu-glibc code, because of this:
> 
> if test "x${have_feenableexcept}" = "xyes"; then
>   fpu_host='fpu-glibc'
>   ieee_support='yes'
> fi
> 
> So before the patch, what was configure.host returning, and what is the value 
> of have_feenableexcept?
> 
> - Why restrict the patch to powerpc*? Don’t other FreeBSD targets have that 
> function?
> - How does the patch affect the results of “make check-gfortran”?
> 
> 
> Thanks,
> FX

Hello,

the problem is that configure checks for feenableexcept() in libm:
AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes 
AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])

FreeBSD doesn't have this function in libm, it's implemented in 
/usr/include/fenv.h.


signature.asc
Description: PGP signature


[Patch] OpenMP/Fortran: Fix EXIT in loop diagnostic [PR105242]

2022-04-13 Thread Tobias Burnus

Trivial fix – after finding the issue. The LOOP directive and
several LOOP/DO/SIMD combined directives were missing in the
check. As the PR shows, this leads to an ICE on invalid code.

OK?

Tobias
-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
OpenMP/Fortran: Fix EXIT in loop diagnostic [PR105242]

gcc/fortran/ChangeLog:

	PR fortran/105242
	* match.cc (match_exit_cycle): Handle missing OMP LOOP, DO and SIMD
	directives in the EXIT/CYCLE diagnostic.

gcc/testsuite/ChangeLog:

	PR fortran/105242
	* gfortran.dg/gomp/loop-exit.f90: New test.

 gcc/fortran/match.cc | 166 ---
 gcc/testsuite/gfortran.dg/gomp/loop-exit.f90 | 674 +++
 2 files changed, 769 insertions(+), 71 deletions(-)

diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc
index 715a74eba51..205811bb969 100644
--- a/gcc/fortran/match.cc
+++ b/gcc/fortran/match.cc
@@ -2857,83 +2857,107 @@ match_exit_cycle (gfc_statement st, gfc_exec_op op)
 
   for (o = p, cnt = 0; o->state == COMP_DO && o->previous != NULL; cnt++)
 o = o->previous;
+
+  int count = 1;
   if (cnt > 0
   && o != NULL
-  && o->state == COMP_OMP_STRUCTURED_BLOCK
-  && (o->head->op == EXEC_OACC_LOOP
-	  || o->head->op == EXEC_OACC_KERNELS_LOOP
-	  || o->head->op == EXEC_OACC_PARALLEL_LOOP
-	  || o->head->op == EXEC_OACC_SERIAL_LOOP))
-{
-  int collapse = 1;
-  gcc_assert (o->head->next != NULL
-		  && (o->head->next->op == EXEC_DO
-		  || o->head->next->op == EXEC_DO_WHILE)
-		  && o->previous != NULL
-		  && o->previous->tail->op == o->head->op);
-  if (o->previous->tail->ext.omp_clauses != NULL)
-	{
-	  /* Both collapsed and tiled loops are lowered the same way, but are not
-	 compatible.  In gfc_trans_omp_do, the tile is prioritized.  */
-	  if (o->previous->tail->ext.omp_clauses->tile_list)
-	{
-	  collapse = 0;
-	  gfc_expr_list *el = o->previous->tail->ext.omp_clauses->tile_list;
-	  for ( ; el; el = el->next)
-		++collapse;
-	}
-	  else if (o->previous->tail->ext.omp_clauses->collapse > 1)
-	collapse = o->previous->tail->ext.omp_clauses->collapse;
-	}
-  if (st == ST_EXIT && cnt <= collapse)
-	{
-	  gfc_error ("EXIT statement at %C terminating !$ACC LOOP loop");
-	  return MATCH_ERROR;
-	}
-  if (st == ST_CYCLE && cnt < collapse)
-	{
-	  gfc_error (o->previous->tail->ext.omp_clauses->tile_list
-		 ? G_("CYCLE statement at %C to non-innermost tiled"
-			  " !$ACC LOOP loop")
-		 : G_("CYCLE statement at %C to non-innermost collapsed"
-			  " !$ACC LOOP loop"));
-	  return MATCH_ERROR;
-	}
-}
-  if (cnt > 0
-  && o != NULL
-  && (o->state == COMP_OMP_STRUCTURED_BLOCK)
-  && (o->head->op == EXEC_OMP_DO
-	  || o->head->op == EXEC_OMP_PARALLEL_DO
-	  || o->head->op == EXEC_OMP_SIMD
-	  || o->head->op == EXEC_OMP_DO_SIMD
-	  || o->head->op == EXEC_OMP_PARALLEL_DO_SIMD))
-{
-  int count = 1;
-  gcc_assert (o->head->next != NULL
+  && o->state == COMP_OMP_STRUCTURED_BLOCK)
+switch (o->head->op)
+  {
+  case EXEC_OACC_LOOP:
+  case EXEC_OACC_KERNELS_LOOP:
+  case EXEC_OACC_PARALLEL_LOOP:
+  case EXEC_OACC_SERIAL_LOOP:
+	gcc_assert (o->head->next != NULL
+		&& (o->head->next->op == EXEC_DO
+			|| o->head->next->op == EXEC_DO_WHILE)
+		&& o->previous != NULL
+		&& o->previous->tail->op == o->head->op);
+	if (o->previous->tail->ext.omp_clauses != NULL)
+	  {
+	/* Both collapsed and tiled loops are lowered the same way, but are
+	   not compatible.  In gfc_trans_omp_do, the tile is prioritized. */
+	if (o->previous->tail->ext.omp_clauses->tile_list)
+	  {
+		count = 0;
+		gfc_expr_list *el
+		  = o->previous->tail->ext.omp_clauses->tile_list;
+		for ( ; el; el = el->next)
+		  ++count;
+	  }
+	else if (o->previous->tail->ext.omp_clauses->collapse > 1)
+	  count = o->previous->tail->ext.omp_clauses->collapse;
+	  }
+	if (st == ST_EXIT && cnt <= count)
+	  {
+	gfc_error ("EXIT statement at %C terminating !$ACC LOOP loop");
+	return MATCH_ERROR;
+	  }
+	if (st == ST_CYCLE && cnt < count)
+	  {
+	gfc_error (o->previous->tail->ext.omp_clauses->tile_list
+		   ? G_("CYCLE statement at %C to non-innermost tiled "
+			"!$ACC LOOP loop")
+		   : G_("CYCLE statement at %C to non-innermost collapsed "
+			"!$ACC LOOP loop"));
+	return MATCH_ERROR;
+	  }
+	break;
+  case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
+  case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
+  case EXEC_OMP_TARGET_SIMD:
+  case EXEC_OMP_TASKLOOP_SIMD:
+  case EXEC_OMP_PARALLEL_MASTER_TASKLOOP_SIMD:
+  case EXEC_OMP_MASTER_TASKLOOP_SIMD:
+  case EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD:
+  case EXEC_OMP_MASKED_TASKLOOP_SIMD:
+ 

Re: [PATCH] fortran: use fpu-glibc on powerpc*-unknown-freebsd

2022-04-13 Thread FX via Fortran
Hi,

> the problem is that configure checks for feenableexcept() in libm:
> AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes 
> AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
> 
> FreeBSD doesn't have this function in libm, it's implemented in 
> /usr/include/fenv.h.

I see. Then we probably can use AC_CHECK_FUNCS, or design a specific check, so 
that it gives the right value on both glibc and FreeBSD targets.

Could you test something on your end?

FX

Re: [Patch] OpenMP/Fortran: Fix EXIT in loop diagnostic [PR105242]

2022-04-13 Thread Jakub Jelinek via Fortran
On Wed, Apr 13, 2022 at 05:16:48PM +0200, Tobias Burnus wrote:
> Trivial fix – after finding the issue. The LOOP directive and
> several LOOP/DO/SIMD combined directives were missing in the
> check. As the PR shows, this leads to an ICE on invalid code.
> 
> OK?
> 
> Tobias
> -
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
> München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
> Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
> München, HRB 106955

> OpenMP/Fortran: Fix EXIT in loop diagnostic [PR105242]
> 
> gcc/fortran/ChangeLog:
> 
>   PR fortran/105242
>   * match.cc (match_exit_cycle): Handle missing OMP LOOP, DO and SIMD
>   directives in the EXIT/CYCLE diagnostic.
> 
> gcc/testsuite/ChangeLog:
> 
>   PR fortran/105242
>   * gfortran.dg/gomp/loop-exit.f90: New test.

Ok, thanks.

Jakub



Re: [PATCH] fortran: use fpu-glibc on powerpc*-unknown-freebsd

2022-04-13 Thread Piotr Kubaj via Fortran
Hello,

can you check the following patch?

On 22-04-13 17:27:11, FX wrote:
> Hi,
> 
> > the problem is that configure checks for feenableexcept() in libm:
> > AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes 
> > AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
> > 
> > FreeBSD doesn't have this function in libm, it's implemented in 
> > /usr/include/fenv.h.
> 
> I see. Then we probably can use AC_CHECK_FUNCS, or design a specific check, 
> so that it gives the right value on both glibc and FreeBSD targets.
> 
> Could you test something on your end?
> 
> FX

-- 
From d5e255f09b4cfd2cb3688d0e2d5feba85d1f5dc8 Mon Sep 17 00:00:00 2001
From: Piotr Kubaj 
Date: Thu, 14 Apr 2022 02:35:26 +0200
Subject: [PATCH] powerpc: properly detect feenableexcept on FreeBSD

FreeBSD doesn't have feenableexcept in libm, but in fenv.h.

Signed-off-by: Piotr Kubaj 
---
 libgfortran/configure| 48 +++-
 libgfortran/configure.ac | 18 ++-
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/libgfortran/configure b/libgfortran/configure
index ae64dca3114..2f1011d7fdc 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -27338,8 +27338,52 @@ fi
 
 
 
+case x$target in
+  xpowerpc*-freebsd*)
+# Check for the existence of  functions.
+for ac_header in fenv.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "fenv.h" "ac_cv_header_fenv_h" "$ac_includes_default"
+if test "x$ac_cv_header_fenv_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_FENV_H 1
+_ACEOF
+ ac_has_fenv_h=yes
+else
+  ac_has_fenv_h=no
+fi
+
+done
+
+if test x"$ac_has_fenv_h" = x"yes"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for feenableexcept in " >&5
+$as_echo_n "checking for feenableexcept in ... " >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include 
+int
+main ()
+{
+int except, ret;
+  ret = feenableexcept(except);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  have_feenableexcept=yes
+$as_echo "#define HAVE_FEENABLEEXCEPT 1" >>confdefs.h
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_feenableexcept" >&5
+$as_echo "$have_feenableexcept" >&6; }
+fi
+;;
+  *)
 # Check for GNU libc feenableexcept
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for feenableexcept in -lm" >&5
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for feenableexcept in -lm" >&5
 $as_echo_n "checking for feenableexcept in -lm... " >&6; }
 if ${ac_cv_lib_m_feenableexcept+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -27384,6 +27428,8 @@ $as_echo "#define HAVE_FEENABLEEXCEPT 1" >>confdefs.h
 
 fi
 
+;;
+esac
 
 # At least for glibc, clock_gettime is in librt.  But don't
 # pull that in if it still doesn't give us the function we want.  This
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 97cc490cb5e..7c285aaf79c 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -602,8 +602,24 @@ fi
 # Check whether we have a __float128 type, depends on enable_libquadmath_support
 LIBGFOR_CHECK_FLOAT128
 
+case x$target in
+  xpowerpc*-freebsd*)
+# Check for the existence of  functions.
+AC_CHECK_HEADERS(fenv.h, ac_has_fenv_h=yes, ac_has_fenv_h=no)
+if test x"$ac_has_fenv_h" = x"yes"; then
+  AC_MSG_CHECKING([for feenableexcept in ])
+  AC_TRY_COMPILE([#include ],
+ [int except, ret;
+  ret = feenableexcept(except);
+ ],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[fenv.h includes feenableexcept])])
+  AC_MSG_RESULT($have_feenableexcept)
+fi
+;;
+  *)
 # Check for GNU libc feenableexcept
-AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
+AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
+;;
+esac
 
 # At least for glibc, clock_gettime is in librt.  But don't
 # pull that in if it still doesn't give us the function we want.  This
-- 
2.35.1



signature.asc
Description: PGP signature