From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id E63A8393BC0D for ; Thu, 17 Jun 2021 12:08:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E63A8393BC0D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: Utv7oEum/NhKg+UFX9kmR+nwlL4SjDD/wr1Yo/OS/1AxoY+9lh82VQM+Mgx0xU/c1yFKZ9XVMR r8xsgxcAVMcaxFuHh+1/Qoan1yo/VdO2XC3pDSkBqc4XMeci6wI/o9xw5dlv10FDYGFewBKW7M f34zWpYIzPx+QOj+o1RopDuNIqLRI2BxQQbtb4tATm1gcv1vy9+Y1wFzNbc98gm2+7F015GVZc JbdZ2FPwa6FSf+LFI7kpjBEMoFrp9U+zHwhb4/TVDMt6HZTd7u8tEJMm6EqCuWkQAqxY+Yed3O m7U= X-IronPort-AV: E=Sophos;i="5.83,280,1616486400"; d="diff'?scan'208";a="62512935" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 17 Jun 2021 04:08:16 -0800 IronPort-SDR: yNifTii2nUHtSn4H2x0T5sLR5RBRwhJMJC13tG9pWrkZk5FZtilvvXbFhjFGubrXPALiU4oShi aiFObNul7H242NCcIQV6+cXqaMC+QBPi6nWUPCXY4kreZefk5dHBMcYm0eVyxjoDY4bDssxcnT MZusXDclqm74YluWjzbHzH418SVO7MpbwXk0mS7qPOJhsb2C3mt2P6B5ezEDMpKrSRT7o7TqdC i3QmhAa0HeT8Wguv+tOhY9Lg41qxkndr1finXX2c3RFXMNlNJ+ETMYuPh4xOV0wmvWnVx8B4jB DFc= To: Thomas Schwinge , Richard Biener , Jakub Jelinek , Sandra Loosemore , gcc-patches From: Tobias Burnus Subject: [Patch] Add 'default' to -foffload=; document that flag [PR67300] Message-ID: <1587c151-b99f-2f44-3044-7b01c296b9ad@codesourcery.com> Date: Thu, 17 Jun 2021 14:08:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------12C17E9C558C5755296E18D3" Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2021 12:08:40 -0000 --------------12C17E9C558C5755296E18D3 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable 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=3D'-lm' and '-lgfortran' -foffload=3D(nvptx-none=3D)-latomic -foffload=3D(amdgcn-amdhsa=3D)-march=3Dgfx906 * * * (B) -foffload=3Ddefault 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=3D-latomic =E2=86=92 fails to build on GCN * -foffload=3Dnvptx-none=3D-latomic =E2=86=92 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 =E2=80=93 but I would no= t 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=3D1 when configured with --enable-offload-defaulted). As soon as -foffload=3D... 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=3Ddefault, -foffload=3Dnvptx-none=3D-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=C3=BCnchen R= egistergericht M=C3=BCnchen HRB 106955, Gesch=C3=A4ftsf=C3=BChrer: Thomas H= eurung, Frank Th=C3=BCrauf --------------12C17E9C558C5755296E18D3 Content-Type: text/x-patch; charset="UTF-8"; name="offload.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="offload.diff" 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 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 --------------12C17E9C558C5755296E18D3--