public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Add 'default' to -foffload=; document that flag [PR67300]
@ 2021-06-17 12:08 Tobias Burnus
  2021-06-17 12:27 ` Jakub Jelinek
  0 siblings, 1 reply; 19+ messages in thread
From: Tobias Burnus @ 2021-06-17 12:08 UTC (permalink / raw)
  To: Thomas Schwinge, Richard Biener, Jakub Jelinek, Sandra Loosemore,
	gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1998 bytes --]

Hi all, this patch does two things:

(A) Documentation for -fopenmp

This finally adds documentation - which was lacking a long time but
is increasingly demanded. Often used options:
  -foffload='-lm' and '-lgfortran'
  -foffload=(nvptx-none=)-latomic
  -foffload=(amdgcn-amdhsa=)-march=gfx906

  * * *

(B) -foffload=default

Came up for the testsuite as libatomic is sometimes needed for nvptx
and unsupported (not build) for GCN.
When GCC is configured to support more than one offload target:
* -foffload=-latomic →  fails to build on GCN
* -foffload=nvptx-none=-latomic →  disables all but nvptx

However, it might be also useful in the real world.

  * * *

Loosely tested without offloading support and with only one offload target.
As the following works, I assume the patch is fine – but I would not mind
if someone else would test it, who built GCC with multiple offload targets.

For testing, I want to note that
   gcc -v 2>&1|grep OFFLOAD_TARGET
shows the configured targets (and OFFLOAD_TARGET_DEFAULT=1 when
configured with --enable-offload-defaulted).

As soon as -foffload=... has been specified, the output is changed to
only include the specified devices.

  * * *

Thoughts? Comments? Suggestions? Test results? OK?

  * * *

Crossref:

* Configure option --enable-offload-defaulted,
   see https://gcc.gnu.org/install/configure.html
* PR about documenting -foffload: https://gcc.gnu.org/PR67300
* Current documentation in the wiki: https://gcc.gnu.org/wiki/Offloading
   (First line: 'compilation options' link)
* Email thread about -foffload=default, -foffload=nvptx-none=-latomic
   disabling other hosts and (next in thread) automatically linking
   -latomic.
   https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570627.html

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

[-- Attachment #2: offload.diff --]
[-- Type: text/x-patch, Size: 8394 bytes --]

Add 'default' to -foffload=; document that flag [PR67300]

It is long overdue to add documentation for -foffload; while in the past
the need for the user to know the flag was limited, it is now needed
rather often by users.

Additionally, as soon as only some devices need specific flags such
as -latomic, all non-specified offload targets get disabled, unless
explicitly specified. To make that easier, the new flag -foffload=default
has been added. That issue came up at
https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570627.html

	PR other/67300

gcc/ChangeLog:

	* doc/invoke.texi (-foffload=): Finally add documentation for it.
	* gcc.c (handle_foffload_option): Support -foffload=default.

libgomp/ChangeLog:

	* testsuite/libgomp.c-c++-common/reduction-16.c: Use -foffload=default.
	* testsuite/libgomp.c-c++-common/reduction-5.c: Likewise.
	* testsuite/libgomp.c-c++-common/reduction-6.c: Likewise.
	* testsuite/libgomp.c/target-44.c: Likewise.

 gcc/doc/invoke.texi                                | 40 +++++++++++++++++++++-
 gcc/gcc.c                                          |  7 ++++
 .../testsuite/libgomp.c-c++-common/reduction-16.c  |  6 +++-
 .../testsuite/libgomp.c-c++-common/reduction-5.c   |  7 +++-
 .../testsuite/libgomp.c-c++-common/reduction-6.c   |  7 +++-
 libgomp/testsuite/libgomp.c/target-44.c            |  6 +++-
 6 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fe812cbd512..ab2ac0e6b3b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -203,7 +203,7 @@ in the following sections.
 -fno-asm  -fno-builtin  -fno-builtin-@var{function}  -fgimple@gol
 -fhosted  -ffreestanding @gol
 -fopenacc  -fopenacc-dim=@var{geom} @gol
--fopenmp  -fopenmp-simd @gol
+-fopenmp  -fopenmp-simd -foffload=@var{arg} @gol
 -fms-extensions  -fplan9-extensions  -fsso-struct=@var{endianness} @gol
 -fallow-single-precision  -fcond-mismatch  -flax-vector-conversions @gol
 -fsigned-bitfields  -fsigned-char @gol
@@ -2639,6 +2639,44 @@ Enable handling of OpenMP's SIMD directives with @code{#pragma omp}
 in C/C++ and @code{!$omp} in Fortran. Other OpenMP directives
 are ignored.
 
+@item -foffload=@var{offload-target-triplet}
+@itemx -foffload=@var{offload-target-triplet}=@var{flags}
+@itemx -foffload=@var{flags}
+@opindex foffload
+@cindex Offloading
+@cindex OpenACC
+@cindex OpenMP
+Specifies for which offload/non-host/accelerator devices code should
+be generated when using OpenACC (@option{-fopenacc}) -- or OpenMP
+(@option{-fopenmp}) with target regions.  It additionally permits to
+pass arguments to the offload-target compiler.  Note that code compiled
+for one or more offload-target devices can still be executable when some
+or all offload device are unavailable at runtime, in line with and as
+specified by the OpenACC and OpenMP specifications.
+
+The option @option{-foffload} can be specified multiple times and is
+accumulative, except that @code{-foffload=disable} disables the code
+generation for all offload-target devices that were enabled before that
+option.  By default, code for all supported offload devices is generated;
+however, as soon as any @option{-foffload} with a target triplet has
+been specified, code is only generated for those target triplets
+that appeared in an @option{-foffload} option - that is independent of
+whether only the triplet or triplet plus flags have been used.  By
+specifying @code{-foffload=default} in addition, the code generation
+for all supported devices is enabled.  Note that GCC can be configured
+such that non-installed offload compilers are ignored; in that case,
+using @code{-foffload=default} enforces the compilation with all
+configured devices, which makes the installation of all offload
+compilers mandatory.
+
+The flags specified with @option{-foffload=}@var{flags} are passed to
+the all enabled offloading compilers; whereas using
+@option{-foffload=}@var{offload-target-triplet}=@var{flags}, the flags
+are only passed to the specified compiler.  Typical applications is to
+pass target-specific flags to the offloading compiler or to link
+libraries required for the offloaded code such as @code{-lm},
+@code{-latomic}, or @code{-lgfortran}.
+
 @item -fgnu-tm
 @opindex fgnu-tm
 When the option @option{-fgnu-tm} is specified, the compiler
diff --git a/gcc/gcc.c b/gcc/gcc.c
index af286400a4a..73385b56a89 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4015,6 +4015,13 @@ handle_foffload_option (const char *arg)
 	  break;
 	}
 
+      if (strcmp (target, "default") == 0)
+	{
+	  free (offload_targets);
+	  offload_targets = xstrdup (OFFLOAD_TARGETS);
+	  break;
+	}
+
       /* Check that GCC is configured to support the offload target.  */
       c = OFFLOAD_TARGETS;
       while (c)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c b/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
index 0eea73b144b..669f5d5b1af 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
@@ -1,5 +1,9 @@
 /* { dg-do run } */
-/* { dg-additional-options "-foffload=nvptx-none=-latomic" { target offload_target_nvptx } } */
+/* { dg-additional-options "-foffload=default -foffload=nvptx-none=-latomic" { target offload_target_nvptx } } */
+/* nvptx often needs -latomic (like for this testcase), which is not linked
+   automatically.  However, when the compiler supports the code generation for
+   multiple offload targets including nvptx, the -foffload=default is needed as
+   otherwise the code generation for all other no-host devices is disabled. */
 
 #include <stdlib.h>
 
diff --git a/libgomp/testsuite/libgomp.c-c++-common/reduction-5.c b/libgomp/testsuite/libgomp.c-c++-common/reduction-5.c
index 31fa2670312..95fc1b79eed 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/reduction-5.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/reduction-5.c
@@ -1,4 +1,9 @@
-/* { dg-additional-options "-foffload=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
+/* { dg-additional-options "-foffload=default -foffload=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
+/* nvptx often needs -latomic (like for this testcase), which is not linked
+   automatically.  However, when the compiler supports the code generation for
+   multiple offload targets including nvptx, the -foffload=default is needed as
+   otherwise the code generation for all other no-host devices is disabled. */
+
 /* C / C++'s logical AND and OR operators take any scalar argument
    which compares (un)equal to 0 - the result 1 or 0 and of type int.
 
diff --git a/libgomp/testsuite/libgomp.c-c++-common/reduction-6.c b/libgomp/testsuite/libgomp.c-c++-common/reduction-6.c
index 727e11e4edf..ba2c9bdc2a8 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/reduction-6.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/reduction-6.c
@@ -1,4 +1,9 @@
-/* { dg-additional-options "-foffload=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
+/* { dg-additional-options "-foffload=default -foffload=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
+/* nvptx often needs -latomic (like for this testcase), which is not linked
+   automatically.  However, when the compiler supports the code generation for
+   multiple offload targets including nvptx, the -foffload=default is needed as
+   otherwise the code generation for all other no-host devices is disabled. */
+
 /* C / C++'s logical AND and OR operators take any scalar argument
    which compares (un)equal to 0 - the result 1 or 0 and of type int.
 
diff --git a/libgomp/testsuite/libgomp.c/target-44.c b/libgomp/testsuite/libgomp.c/target-44.c
index b95e807a114..9659fe3ee46 100644
--- a/libgomp/testsuite/libgomp.c/target-44.c
+++ b/libgomp/testsuite/libgomp.c/target-44.c
@@ -1,4 +1,8 @@
-/* { dg-additional-options "-foffload=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
+/* { dg-additional-options "-foffload=default -foffload=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
+/* nvptx often needs -latomic (like for this testcase), which is not linked
+   automatically.  However, when the compiler supports the code generation for
+   multiple offload targets including nvptx, the -foffload=default is needed as
+   otherwise the code generation for all other no-host devices is disabled. */
 
 #include <stdlib.h>
 

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2021-06-30 20:12 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 12:08 [Patch] Add 'default' to -foffload=; document that flag [PR67300] Tobias Burnus
2021-06-17 12:27 ` Jakub Jelinek
2021-06-17 16:03   ` Tobias Burnus
2021-06-17 17:41     ` Sandra Loosemore
2021-06-17 17:50       ` Jakub Jelinek
2021-06-17 19:28         ` Tobias Burnus
2021-06-17 19:40           ` Jakub Jelinek
2021-06-17 21:57             ` Sandra Loosemore
2021-06-17 23:05               ` Tobias Burnus
2021-06-18 22:47                 ` Sandra Loosemore
2021-06-28 11:28                   ` Tobias Burnus
2021-06-28 15:51                     ` Tobias Burnus
2021-06-28 22:34                       ` Sandra Loosemore
2021-06-29 11:58                       ` Jakub Jelinek
2021-06-29 13:47                         ` Tobias Burnus
2021-06-29 13:51                           ` Jakub Jelinek
2021-06-29 20:47                           ` Rainer Orth
2021-06-29 21:02                             ` Christophe Lyon
2021-06-30 20:12                             ` Rainer Orth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).