From patchwork Mon Sep 12 12:02:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1845260wrt; Mon, 12 Sep 2022 05:03:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR5DUim0QYZrQTIUb01U/i1shsqiiYqpo0Y5WS0zJFgZe3hCAm3XVwuwao32PHL1PKp8uTIy X-Received: by 2002:a17:906:7956:b0:77c:e80c:de53 with SMTP id l22-20020a170906795600b0077ce80cde53mr4088340ejo.115.1662984181509; Mon, 12 Sep 2022 05:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662984181; cv=none; d=google.com; s=arc-20160816; b=oTp5nlJEPH12bd8czVTkywY4JxFhrk1hHq13eovxsimcOPpgfX6os597l6cvc9jwKb rhSyH1cIu/dmviIi2zKGFVfIYeIogKc63HexufAFhpMhjmVE9xFW1rJLVV+jrRhErn5+ 6tkez/WdVN4EMLjZJ7QodPE9lzdTBVhZTpv7h0TcwVqggqNsByme3Q1qvzsBq2fwz75c tTLUAtsV5mhGl+DdySR72C1j3mkMjACMDmvMM/Cni1FSQrJbGqpFyFkaQV4/FtZlqkWF l6IEctko8Y/1rBfdE+G63Q+Utjzd7LkfKyg48yHwzBLka0FEfUC88OMyZ6f1EzjnmzVl kmcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=4Gb51FsLUmWQDIOOjnAowy6W9caSVE3lp79cKjY5qPw=; b=TaYKRWtmexh0aBLcCraHUlluLhO27z9Vf5c55zdUrp+CFt4mlZUUUvhp6CDgThoUzv JcczCpM30QUtA/ER34jWeCJSmbvhPP6b+VNGMw2fkfE4x6UZFT2CI3b8UFG//RVZ1ME6 ira5wfLC2wwu78i+5K2riJKmFv7VZOd8l6IyTQnvAVtm1Pi117suX711r7+IzKFROeMo BkXdy3kuxNJ1Wj+NPaKiBwHxaeig+BhOrJRdeT5tFCMR9aNtpVMrf927mEAC4VVzonCn jwv4XyLsmh1rpFhu6hYg3sAtaD+Y5gDuS38zGG3NCJyTH2ENcmBFVmOL9fnHouTO/TtM JRpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id oz9-20020a1709077d8900b007308fcad6d2si5986913ejc.358.2022.09.12.05.03.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 05:03:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18E28385114D for ; Mon, 12 Sep 2022 12:02:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 31A2E38515FA for ; Mon, 12 Sep 2022 12:02:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 31A2E38515FA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,310,1654588800"; d="diff'?scan'208,217";a="82914298" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 12 Sep 2022 04:02:23 -0800 IronPort-SDR: Uj5UntMkgEtPkljITF9yMUiaC86gRszzY1NMKd3wVNhZHLAxzoVPTJp57/nEm4oFV03yKIgxey qWf23Qt3U+KW6S6uB8mRYaKQy16q1IsxBCYw/DwpD/47g9gstajeKSe2f6W6F8LycDeBDX/Mb4 FpicVmnQwSdNlr11aLUIcDT0LGwGzteT7UIwe0092B8Gznyhzb4rxZCbo7020aAPYXzRsgMcwN FyivgLgaJRP1efEywURhZDZQZOBa5wTFWD0YNhhRdEhQaSGwBXvA/ljVMnyrqTEVDX3K1QYAfM NUk= Message-ID: Date: Mon, 12 Sep 2022 14:02:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [Patch] nvptx/mkoffload.cc: Warn instead of error when reverse offload is not possible (was: Re: [Patch][2/3][v2] nvptx: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup) Content-Language: en-US To: Jakub Jelinek References: <40563a1c-49ef-a185-3c01-9f717cd48fc5@codesourcery.com> <8301889b-64f9-8c60-15ca-2fa1fc495791@codesourcery.com> From: Tobias Burnus In-Reply-To: X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: , Cc: gcc-patches Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743765300920230781?= X-GMAIL-MSGID: =?utf-8?q?1743765300920230781?= On 09.09.22 17:36, Jakub Jelinek wrote: Wonder if we instead shouldn't arrange for silent request for no PTX offloading (or one with warning?) if sm_30 and reverse offload is needed. Error might be too harsh, the program can still offload to GCN or host just fine... Attached patch now implements the warning. I think silently failing is not the proper solution. It is too confusing and without telling the user, they may not notice this issue. I also changed the "progname" variable; it seems as if the only user is the diagnostic machinery and it seems to make sense to have: nvptx mkoffload: warning: 'omp requires reverse_offload' requires at least 'sm_35' for '-misa=' - disabling offload-code generation for this device type instead of guessing whether "mkoffload" is for the host, gcn or nvptx. I know that the common way is to use the binary name ("lto1") or ... but I still think this prefix – which is the tool_name. Makes sense. (BTW: gcc/config/i386/intelmic-mkoffload.cc uses "mkoffload-intelmic".) I also changed "-misa=" in the diagnostic to "-march=" as Tom changed the default from "-misa=" (now an alias) to "-march=" in GCC 12 (+plus added -march-map= in addition). I also added a testcase for this – and updated the testsuite for the dg-warning. OK for mainline? Tobias PS: As no code for nvptx is generated, there is no "device present bit not used" warning with GOMP_DEBUG, but as there is a compile-time warning, I guess that's fine. ----------------- 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 nvptx/mkoffload.cc: Warn instead of error when reverse offload is not possible Reverse offload requests at least -misa=sm_35; with this patch, a warning instead of an error is shown, still permitting reverse offload for all other configured device types. This is achieved by not calling GOMP_offload_register_ver (and stopping generating pointless 'static const char' variables, once known.) The tool_name as progname changes adds "nvptx " and "gcn " to the "mkoffload: warning/error:" diagnostic. gcc/ChangeLog: * config/nvptx/mkoffload.cc (process): Replace a fatal_error by a warning + not enabling offloading if -misa=sm_30 prevents reverse offload. (main): Use tool_name as progname for diagnostic. * config/gcn/mkoffload.cc (main): Likewise. libgomp/ChangeLog: * libgomp.texi (Offload-Target Specifics: nvptx): Document that reverse offload requires >= -march=sm_35. * testsuite/libgomp.c-c++-common/requires-4.c: Build for nvptx with -misa=sm_35. * testsuite/libgomp.c-c++-common/requires-5.c: Likewise. * testsuite/libgomp.c-c++-common/requires-6.c: Likewise. * testsuite/libgomp.c-c++-common/reverse-offload-1.c: Likewise. * testsuite/libgomp.fortran/reverse-offload-1.f90: Likewise. * testsuite/libgomp.c/reverse-offload-sm30.c: New test. gcc/config/gcn/mkoffload.cc | 2 +- gcc/config/nvptx/mkoffload.cc | 17 +++++++++++++---- libgomp/libgomp.texi | 3 +++ libgomp/testsuite/libgomp.c-c++-common/requires-4.c | 1 + libgomp/testsuite/libgomp.c-c++-common/requires-5.c | 1 + libgomp/testsuite/libgomp.c-c++-common/requires-6.c | 2 ++ .../testsuite/libgomp.c-c++-common/reverse-offload-1.c | 1 + libgomp/testsuite/libgomp.c/reverse-offload-sm30.c | 15 +++++++++++++++ libgomp/testsuite/libgomp.fortran/reverse-offload-1.f90 | 1 + 9 files changed, 38 insertions(+), 5 deletions(-) diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 24d327355e3..64037806acf 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -805,7 +805,7 @@ main (int argc, char **argv) FILE *cfile = stdout; const char *outname = 0; - progname = "mkoffload"; + progname = tool_name; diagnostic_initialize (global_dc, 0); obstack_init (&files_to_cleanup); diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc index 834b2059aac..5f3e07ad066 100644 --- a/gcc/config/nvptx/mkoffload.cc +++ b/gcc/config/nvptx/mkoffload.cc @@ -324,9 +324,18 @@ process (FILE *in, FILE *out, uint32_t omp_requires) { if (sm_ver && sm_ver[0] == '3' && sm_ver[1] == '0' && sm_ver[2] == '\n') - fatal_error (input_location, - "% requires at least " - "% for %<-misa=%>"); + { + warning_at (input_location, 0, + "% requires at " + "least % for %<-march=%> - disabling " + "offload-code generation for this device type"); + /* As now an empty file is compiled and there is no call to + GOMP_offload_register_ver, this device type is effectively + disabled. */ + fflush (out); + ftruncate (fileno (out), 0); + return; + } sm_ver2 = sm_ver; version2 = version; } @@ -526,7 +535,7 @@ main (int argc, char **argv) FILE *out = stdout; const char *outname = 0; - progname = "mkoffload"; + progname = tool_name; diagnostic_initialize (global_dc, 0); if (atexit (mkoffload_cleanup) != 0) diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi index 4eaad4348bb..1f402d6df79 100644 --- a/libgomp/libgomp.texi +++ b/libgomp/libgomp.texi @@ -4386,6 +4386,9 @@ The implementation remark: @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported using the C library @code{printf} functions and the Fortran @code{print}/@code{write} statements. +@item Compilation OpenMP code that contains @code{requires reverse_offload} + requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30} + is not supported. @end itemize diff --git a/libgomp/testsuite/libgomp.c-c++-common/requires-4.c b/libgomp/testsuite/libgomp.c-c++-common/requires-4.c index 6ed5a5f647a..5883eff0d93 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/requires-4.c +++ b/libgomp/testsuite/libgomp.c-c++-common/requires-4.c @@ -1,4 +1,5 @@ /* { dg-additional-options "-flto" } */ +/* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */ /* { dg-additional-sources requires-4-aux.c } */ /* Check no diagnostic by device-compiler's or host compiler's lto1. diff --git a/libgomp/testsuite/libgomp.c-c++-common/requires-5.c b/libgomp/testsuite/libgomp.c-c++-common/requires-5.c index 7fe0c735d27..d43d78db6fa 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/requires-5.c +++ b/libgomp/testsuite/libgomp.c-c++-common/requires-5.c @@ -1,3 +1,4 @@ +/* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */ /* { dg-additional-sources requires-5-aux.c } */ /* Depending on offload device capabilities, it may print something like the diff --git a/libgomp/testsuite/libgomp.c-c++-common/requires-6.c b/libgomp/testsuite/libgomp.c-c++-common/requires-6.c index b00c7459bbc..a25b4d2dedd 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/requires-6.c +++ b/libgomp/testsuite/libgomp.c-c++-common/requires-6.c @@ -1,3 +1,5 @@ +/* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */ + #pragma omp requires unified_shared_memory, unified_address, reverse_offload /* The requires line is not active as there is none of: diff --git a/libgomp/testsuite/libgomp.c-c++-common/reverse-offload-1.c b/libgomp/testsuite/libgomp.c-c++-common/reverse-offload-1.c index 976e129f560..52d828caf1c 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/reverse-offload-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/reverse-offload-1.c @@ -1,4 +1,5 @@ /* { dg-do run } */ +/* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */ /* { dg-additional-sources reverse-offload-1-aux.c } */ /* Check that reverse offload works in particular: diff --git a/libgomp/testsuite/libgomp.c/reverse-offload-sm30.c b/libgomp/testsuite/libgomp.c/reverse-offload-sm30.c new file mode 100644 index 00000000000..14aed0132b7 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/reverse-offload-sm30.c @@ -0,0 +1,15 @@ +/* { dg-do link { target { offload_target_nvptx } } } */ +/* { dg-additional-options "-foffload-options=nvptx-none=-march=sm_30 -foffload=-mptx=_" } */ + +#pragma omp requires reverse_offload + +int +main () +{ + #pragma omp target + { + } + return 0; +} + +/* { dg-warning "'omp requires reverse_offload' requires at least 'sm_35' for '-march=' - disabling offload-code generation for this device type" "" { target *-*-* } 0 } */ diff --git a/libgomp/testsuite/libgomp.fortran/reverse-offload-1.f90 b/libgomp/testsuite/libgomp.fortran/reverse-offload-1.f90 index 7cfb8b6552e..de68011f8f7 100644 --- a/libgomp/testsuite/libgomp.fortran/reverse-offload-1.f90 +++ b/libgomp/testsuite/libgomp.fortran/reverse-offload-1.f90 @@ -1,4 +1,5 @@ ! { dg-do run } +! { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } ! { dg-additional-sources reverse-offload-1-aux.f90 } ! Check that reverse offload works in particular: