Re: [PATCH] Fortran: fix passing of zero-sized array arguments to procedures [PR86277]
Hi Steve, On 6/13/23 19:45, Steve Kargl via Gcc-patches wrote: On Mon, Jun 12, 2023 at 11:12:45PM +0200, Harald Anlauf via Fortran wrote: Dear all, the attached - actually rather small - patch is the result of a rather intensive session with Mikael in an attempt to fix the situation that we did not create proper temporaries when passing zero-sized array arguments to procedures. When the dummy argument was declared as OPTIONAL, in many cases it was mis-detected as non-present. This also depended on the type of argument, and was different for different intrinsic types, notably character, and derived types, and should explain the rather large ratio of the size of the provided testcases to the actual fix... (What the patch does not address: we still generate too much code for unneeded temporaries, often two temporaries instead of just one. I'll open a separate PR to track this.) Regtested on x86_64-pc-linux-gnu. OK for mainline? If this survives long enough on 14-trunk, would this be eligible for a backport to 13-branch in time for 13.2? OK to commit. I've reviewed the bugzilla exchange between Mikael and you, and agree with committing this and opening a new PR to track the unneeded temporaries issue. this is tracked here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110241 Thanks for the review! Harald
Re: Fortran 2008 DATA statement restrictions
Hi, Thanks Harald. I see there are bugs open, but actually not that many, compared to other areas of the compiler :) I think the code I sent was not really covered in the testsuite, so I have committed it (after testing on x86_64-linux). https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a54c71ccc24874ce79019b51150b3a00b7c785cd Best, FX
Re: [PATCH] Fortran: fix passing of zero-sized array arguments to procedures [PR86277]
On Mon, Jun 12, 2023 at 11:12:45PM +0200, Harald Anlauf via Fortran wrote: > Dear all, > > the attached - actually rather small - patch is the result of a > rather intensive session with Mikael in an attempt to fix the > situation that we did not create proper temporaries when passing > zero-sized array arguments to procedures. When the dummy argument > was declared as OPTIONAL, in many cases it was mis-detected as > non-present. This also depended on the type of argument, and > was different for different intrinsic types, notably character, > and derived types, and should explain the rather large ratio of > the size of the provided testcases to the actual fix... > > (What the patch does not address: we still generate too much code > for unneeded temporaries, often two temporaries instead of just > one. I'll open a separate PR to track this.) > > Regtested on x86_64-pc-linux-gnu. OK for mainline? > > If this survives long enough on 14-trunk, would this be eligible > for a backport to 13-branch in time for 13.2? > OK to commit. I've reviewed the bugzilla exchange between Mikael and you, and agree with committing this and opening a new PR to track the unneeded temporaries issue. -- Steve
Re: [ping] driver: Forward '-lgfortran', '-lm' to offloading compilation
On Tue, 13 Jun 2023, Thomas Schwinge wrote: > Hi! > > On 2023-06-05T14:25:18+0200, I wrote: > > OK to push the attached > > "driver: Forward '-lgfortran', '-lm' to offloading compilation"? > > (We didn't have a PR open for that, or did we?) > > Ping. OK. -- Joseph S. Myers jos...@codesourcery.com
Re: [ping] Add 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90'
On 13.06.23 12:42, Thomas Schwinge wrote: On 2023-06-05T14:18:48+0200, I wrote: OK to push the attached "Add 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90'"? Subject: [PATCH] Add 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90' gcc/testsuite/ * gfortran.fortran-torture/execute/math.f90: Enhance for optional OpenACC, OpenMP 'target' usage. I think it is more readable with a linebreak here and with "OpenACC 'serial' and OpenMP ..." instead of "OpenACC, OpenMP". What I would like to see a hint somewhere in the commit log that the libgomp files include the gfortran.fortran-torture file. I don't care whether you add the hint before the changelog items as free text – or in the bullet above (e.g. "as it is included in libgomp/testsuite") – or after "New." in the following bullet list. libgomp/ * testsuite/libgomp.fortran/fortran-torture_execute_math.f90: New. * testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90: Likewise. --- .../gfortran.fortran-torture/execute/math.f90 | 23 +-- .../fortran-torture_execute_math.f90 | 4 .../fortran-torture_execute_math.f90 | 5 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 index 17cc78f7a10..e71f669304f 100644 --- a/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 +++ b/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 @@ -1,9 +1,14 @@ ! Program to test mathematical intrinsics + +! See also 'libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90'; thus the '!$omp' directives. +! See also 'libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90'; thus the '!$acc' directives. Likewise here: it is not completely obvious that this file is 'include'd by the other testcases. Maybe add a line "! This file is also included in:" and remove the "See also" or some creative variant of it. Minor remark: The OpenMP part is OK, but strict reading of the spec requires an "omp declare target' if a subroutine is in a different compilation unit. And according the glossary, that's the case here. In practice, it also works without as it is in the same translation unit. (compilation unit = for C/C++: translation unit, for Fortran: subprogram). I think the HPE/Cray compiler will complain, but maybe only when used with modules and not with subroutine subprograms. (As many compilers write a .mod file for modules, a late change of attributes can be more problematic.) Otherwise LGTM. Tobias PS: I assume that you have check it with both with an in-build-tree and an in-install-tree testsuite run. + subroutine dotest (n, val4, val8, known) implicit none real(kind=4) val4, known real(kind=8) val8 integer n + !$acc routine seq if (abs (val4 - known) .gt. 0.001) STOP 1 if (abs (real (val8, kind=4) - known) .gt. 0.001) STOP 2 @@ -14,17 +19,20 @@ subroutine dotestc (n, val4, val8, known) complex(kind=4) val4, known complex(kind=8) val8 integer n + !$acc routine seq + if (abs (val4 - known) .gt. 0.001) STOP 3 if (abs (cmplx (val8, kind=4) - known) .gt. 0.001) STOP 4 end subroutine -program testmath +subroutine testmath implicit none real(kind=4) r, two4, half4 real(kind=8) q, two8, half8 complex(kind=4) cr complex(kind=8) cq external dotest, dotestc + !$acc routine seq two4 = 2.0 two8 = 2.0_8 @@ -96,5 +104,16 @@ program testmath cq = log ((-1.0_8, -1.0_8)) call dotestc (21, cr, cq, (0.3466, -2.3562)) -end program +end subroutine +program main + implicit none + external testmath + + !$acc serial + !$omp target + call testmath + !$acc end serial + !$omp end target + +end program diff --git a/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 new file mode 100644 index 000..3348a0bb3ad --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 @@ -0,0 +1,4 @@ +! { dg-do run } +! { dg-additional-options -foffload-options=-lm } + +include '../../../gcc/testsuite/gfortran.fortran-torture/execute/math.f90' diff --git a/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 new file mode 100644 index 000..1b2ac440762 --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 @@ -0,0 +1,5 @@ +! { dg-do run } +!TODO { dg-prune-output {using 'vector_length \(32\)', ignoring 1} } +! { dg-additional-options -foffload-options=-lm } +
[ping] driver: Forward '-lgfortran', '-lm' to offloading compilation
Hi! On 2023-06-05T14:25:18+0200, I wrote: > OK to push the attached > "driver: Forward '-lgfortran', '-lm' to offloading compilation"? > (We didn't have a PR open for that, or did we?) Ping. Grüße Thomas - 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 >From 5d3cb866cad3bbcf47c5e66825e5710e86cc017e Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Mon, 5 Jun 2023 11:26:37 +0200 Subject: [PATCH] driver: Forward '-lgfortran', '-lm' to offloading compilation ..., so that users don't manually need to specify '-foffload-options=-lgfortran', '-foffload-options=-lm' in addition to '-lgfortran', '-lm' (specified manually, or implicitly by the driver). gcc/ * gcc.cc (driver_handle_option): Forward host '-lgfortran', '-lm' to offloading compilation. * config/gcn/mkoffload.cc (main): Adjust. * config/nvptx/mkoffload.cc (main): Likewise. * doc/invoke.texi (foffload-options): Update example. libgomp/ * testsuite/libgomp.fortran/fortran.exp (lang_link_flags): Don't set. * testsuite/libgomp.oacc-fortran/fortran.exp (lang_link_flags): Likewise. * testsuite/libgomp.c/simd-math-1.c: Remove '-foffload-options=-lm'. * testsuite/libgomp.fortran/fortran-torture_execute_math.f90: Likewise. * testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90: Likewise. --- gcc/config/gcn/mkoffload.cc | 12 gcc/config/nvptx/mkoffload.cc | 12 gcc/doc/invoke.texi | 5 +- gcc/gcc.cc| 56 +++ libgomp/testsuite/libgomp.c/simd-math-1.c | 1 - .../fortran-torture_execute_math.f90 | 1 - libgomp/testsuite/libgomp.fortran/fortran.exp | 2 - .../fortran-torture_execute_math.f90 | 1 - .../libgomp.oacc-fortran/fortran.exp | 2 - 9 files changed, 82 insertions(+), 10 deletions(-) diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 988c12318fd..8b608bf024e 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -946,6 +946,18 @@ main (int argc, char **argv) else if (startswith (argv[i], STR)) gcn_stack_size = atoi (argv[i] + strlen (STR)); #undef STR + /* Translate host into offloading libraries. */ + else if (strcmp (argv[i], "-l_GCC_gfortran") == 0 + || strcmp (argv[i], "-l_GCC_m") == 0) + { + /* Elide '_GCC_'. */ + size_t i_dst = strlen ("-l"); + size_t i_src = strlen ("-l_GCC_"); + char c; + do + c = argv[i][i_dst++] = argv[i][i_src++]; + while (c != '\0'); + } } if (!(fopenacc ^ fopenmp)) diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc index 6cdea45cffe..aaea9fb320d 100644 --- a/gcc/config/nvptx/mkoffload.cc +++ b/gcc/config/nvptx/mkoffload.cc @@ -649,6 +649,18 @@ main (int argc, char **argv) else if (strcmp (argv[i], "-dumpbase") == 0 && i + 1 < argc) dumppfx = argv[++i]; + /* Translate host into offloading libraries. */ + else if (strcmp (argv[i], "-l_GCC_gfortran") == 0 + || strcmp (argv[i], "-l_GCC_m") == 0) + { + /* Elide '_GCC_'. */ + size_t i_dst = strlen ("-l"); + size_t i_src = strlen ("-l_GCC_"); + char c; + do + c = argv[i][i_dst++] = argv[i][i_src++]; + while (c != '\0'); + } } if (!(fopenacc ^ fopenmp)) fatal_error (input_location, "either %<-fopenacc%> or %<-fopenmp%> " diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d2d639c92d4..7b3a2a74459 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2716,9 +2716,8 @@ the @option{-foffload-options=@var{target-list}=@var{options}} form. The Typical command lines are @smallexample --foffload-options=-lgfortran -foffload-options=-lm --foffload-options="-lgfortran -lm" -foffload-options=nvptx-none=-latomic --foffload-options=amdgcn-amdhsa=-march=gfx906 -foffload-options=-lm +-foffload-options='-fno-math-errno -ffinite-math-only' -foffload-options=nvptx-none=-latomic +-foffload-options=amdgcn-amdhsa=-march=gfx906 -foffload-options=-O3 @end smallexample @opindex fopenacc diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 2ccca00d603..15995206856 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -47,6 +47,9 @@ compilation is specified by a string called a "spec". */ #include "opts-jobserver.h" #include "common/common-target.h" +#ifndef MATH_LIBRARY +#define MATH_LIBRARY "m" +#endif /* Manage the manipulation of env vars. @@ -4117,6 +4120,48 @@ next_item: } } +/* Forward certain options to offloading compilation. */ + +static void +forward_offload_option (size_t opt_index, const char *arg, bool validated) +{ + switch (opt_index) +{ +case OPT_l: + /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the + host's 'MATH_LIBRARY', for
[ping] Add 'libgomp.{, oacc-}fortran/fortran-torture_execute_math.f90'
Hi! On 2023-06-05T14:18:48+0200, I wrote: > OK to push the attached > "Add 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90'"? Ping. Grüße Thomas - 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 >From 0d5095d8cd2d68113890a39a7fdb649198e576c1 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Fri, 2 Jun 2023 23:11:00 +0200 Subject: [PATCH] Add 'libgomp.{,oacc-}fortran/fortran-torture_execute_math.f90' gcc/testsuite/ * gfortran.fortran-torture/execute/math.f90: Enhance for optional OpenACC, OpenMP 'target' usage. libgomp/ * testsuite/libgomp.fortran/fortran-torture_execute_math.f90: New. * testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90: Likewise. --- .../gfortran.fortran-torture/execute/math.f90 | 23 +-- .../fortran-torture_execute_math.f90 | 4 .../fortran-torture_execute_math.f90 | 5 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 index 17cc78f7a10..e71f669304f 100644 --- a/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 +++ b/gcc/testsuite/gfortran.fortran-torture/execute/math.f90 @@ -1,9 +1,14 @@ ! Program to test mathematical intrinsics + +! See also 'libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90'; thus the '!$omp' directives. +! See also 'libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90'; thus the '!$acc' directives. + subroutine dotest (n, val4, val8, known) implicit none real(kind=4) val4, known real(kind=8) val8 integer n + !$acc routine seq if (abs (val4 - known) .gt. 0.001) STOP 1 if (abs (real (val8, kind=4) - known) .gt. 0.001) STOP 2 @@ -14,17 +19,20 @@ subroutine dotestc (n, val4, val8, known) complex(kind=4) val4, known complex(kind=8) val8 integer n + !$acc routine seq + if (abs (val4 - known) .gt. 0.001) STOP 3 if (abs (cmplx (val8, kind=4) - known) .gt. 0.001) STOP 4 end subroutine -program testmath +subroutine testmath implicit none real(kind=4) r, two4, half4 real(kind=8) q, two8, half8 complex(kind=4) cr complex(kind=8) cq external dotest, dotestc + !$acc routine seq two4 = 2.0 two8 = 2.0_8 @@ -96,5 +104,16 @@ program testmath cq = log ((-1.0_8, -1.0_8)) call dotestc (21, cr, cq, (0.3466, -2.3562)) -end program +end subroutine +program main + implicit none + external testmath + + !$acc serial + !$omp target + call testmath + !$acc end serial + !$omp end target + +end program diff --git a/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 new file mode 100644 index 000..3348a0bb3ad --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/fortran-torture_execute_math.f90 @@ -0,0 +1,4 @@ +! { dg-do run } +! { dg-additional-options -foffload-options=-lm } + +include '../../../gcc/testsuite/gfortran.fortran-torture/execute/math.f90' diff --git a/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 new file mode 100644 index 000..1b2ac440762 --- /dev/null +++ b/libgomp/testsuite/libgomp.oacc-fortran/fortran-torture_execute_math.f90 @@ -0,0 +1,5 @@ +! { dg-do run } +!TODO { dg-prune-output {using 'vector_length \(32\)', ignoring 1} } +! { dg-additional-options -foffload-options=-lm } + +include '../../../gcc/testsuite/gfortran.fortran-torture/execute/math.f90' -- 2.34.1