From patchwork Tue Feb 8 12:57:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 50914 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6030F385842B for ; Tue, 8 Feb 2022 12:58:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6030F385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644325106; bh=/AQGhU9XqvDxX+1+6uvXB92Clqx+62Z8oiyS8eT85jA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Sx0w7TfWI5X1+XW0sxqf+aiHLpsOCLsPVwmZRMP0MA9X6ulEdQsSNrhI+F5gmtZMP 8zh5iE7bXSz50BWzLi7CkW0sINFcJmUfQHHrKuK+grXwrBvJioLdkUIagRqcgm2s6C 8YOHcqx4jeHkU4xot8pM5M9INy5qY97tOQ+DKArU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E130C3858D1E for ; Tue, 8 Feb 2022 12:57:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E130C3858D1E Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 989BD1F383 for ; Tue, 8 Feb 2022 12:57:54 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 835C313C79 for ; Tue, 8 Feb 2022 12:57:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id pjbSHtJoAmJ/UAAAMHmgww (envelope-from ) for ; Tue, 08 Feb 2022 12:57:54 +0000 Date: Tue, 8 Feb 2022 13:57:53 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed][nvptx] Choose -mptx default based on -misa Message-ID: <20220208125751.GA7486@delia.home> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Tom de Vries via Gcc-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, While testing with driver version 390.147 I ran into the problem that it doesn't support ptx isa version 6.3 (the new default), only 6.1. Furthermore, using the -mptx option is a bit user-unfriendly. Say we want to compile for sm_80. We can use -misa=sm_80 to specify that, but then run into errors because the default ptx version is 6.3, which doesn't support sm_80 yet. Address both these issues by: - picking a default -mptx based on the active -misa, and - ensuring that the default -mptx is at least 6.0 (instead of 6.3). Also add an error in case of incompatible options like "-misa=sm_80 -mptx=6.3": ... cc1: error: PTX version (-mptx) needs to be at least 7.0 to support \ selected -misa (sm_80) ... Tested on x86_64-linux with nvptx accelerator. Committed to trunk. Thanks, - Tom [nvptx] Choose -mptx default based on -misa gcc/ChangeLog: 2022-02-08 Tom de Vries PR target/104283 * config/nvptx/nvptx-opts.h (enum ptx_version): Add PTX_VERSION_3_0 and PTX_VERSION_4_2. * config/nvptx/nvptx.cc (first_ptx_version_supporting_sm) (default_ptx_version_option, ptx_version_to_string) (sm_version_to_string, handle_ptx_version_option): New function. (nvptx_option_override): Call handle_ptx_version_option. (nvptx_file_start): Use ptx_version_to_string and sm_version_to_string. * config/nvptx/nvptx.md (define_insn "nvptx_shuffle") (define_insn "nvptx_vote_ballot"): Use TARGET_PTX_6_0. * config/nvptx/nvptx.opt (mptx): Remove 'Init'. --- gcc/config/nvptx/nvptx-opts.h | 2 + gcc/config/nvptx/nvptx.cc | 133 +++++++++++++++++++++++++++++++++++++----- gcc/config/nvptx/nvptx.md | 4 +- gcc/config/nvptx/nvptx.opt | 2 +- 4 files changed, 122 insertions(+), 19 deletions(-) diff --git a/gcc/config/nvptx/nvptx-opts.h b/gcc/config/nvptx/nvptx-opts.h index c754a5193ce..cc488b23720 100644 --- a/gcc/config/nvptx/nvptx-opts.h +++ b/gcc/config/nvptx/nvptx-opts.h @@ -31,7 +31,9 @@ enum ptx_isa enum ptx_version { + PTX_VERSION_3_0, PTX_VERSION_3_1, + PTX_VERSION_4_2, PTX_VERSION_6_0, PTX_VERSION_6_3, PTX_VERSION_7_0 diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc index 006fac8c839..1b0227a2c31 100644 --- a/gcc/config/nvptx/nvptx.cc +++ b/gcc/config/nvptx/nvptx.cc @@ -205,6 +205,109 @@ diagnose_openacc_conflict (bool optval, const char *optname) error ("option %s is not supported together with %<-fopenacc%>", optname); } +static enum ptx_version +first_ptx_version_supporting_sm (enum ptx_isa sm) +{ + switch (sm) + { + case PTX_ISA_SM30: + return PTX_VERSION_3_0; + case PTX_ISA_SM35: + return PTX_VERSION_3_1; + case PTX_ISA_SM53: + return PTX_VERSION_4_2; + case PTX_ISA_SM75: + return PTX_VERSION_6_3; + case PTX_ISA_SM80: + return PTX_VERSION_7_0; + default: + gcc_unreachable (); + } +} + +static enum ptx_version +default_ptx_version_option (void) +{ + enum ptx_version first + = first_ptx_version_supporting_sm ((enum ptx_isa) ptx_isa_option); + + /* Pick a version that supports the sm. */ + enum ptx_version res = first; + + /* Pick at least 3.1. This has been the smallest version historically. */ + res = MAX (res, PTX_VERSION_3_1); + + /* Pick at least 6.0, to enable using bar.warp.sync to have a way to force + warp convergence. */ + res = MAX (res, PTX_VERSION_6_0); + + /* Verify that we pick a version that supports the sm. */ + gcc_assert (first <= res); + return res; +} + +static const char * +ptx_version_to_string (enum ptx_version v) +{ + switch (v) + { + case PTX_VERSION_3_0: + return "3.0"; + case PTX_VERSION_3_1: + return "3.1"; + case PTX_VERSION_4_2: + return "4.2"; + case PTX_VERSION_6_0: + return "6.0"; + case PTX_VERSION_6_3: + return "6.3"; + case PTX_VERSION_7_0: + return "7.0"; + default: + gcc_unreachable (); + } +} + +static const char * +sm_version_to_string (enum ptx_isa sm) +{ + switch (sm) + { + case PTX_ISA_SM30: + return "30"; + case PTX_ISA_SM35: + return "35"; + case PTX_ISA_SM53: + return "53"; + case PTX_ISA_SM70: + return "70"; + case PTX_ISA_SM75: + return "75"; + case PTX_ISA_SM80: + return "80"; + default: + gcc_unreachable (); + } +} + +static void +handle_ptx_version_option (void) +{ + if (!OPTION_SET_P (ptx_version_option)) + { + ptx_version_option = default_ptx_version_option (); + return; + } + + enum ptx_version first + = first_ptx_version_supporting_sm ((enum ptx_isa) ptx_isa_option); + + if (ptx_version_option < first) + error ("PTX version (-mptx) needs to be at least %s to support selected" + " -misa (sm_%s)", ptx_version_to_string (first), + sm_version_to_string ((enum ptx_isa)ptx_isa_option)); +} + /* Implement TARGET_OPTION_OVERRIDE. */ static void @@ -212,6 +315,8 @@ nvptx_option_override (void) { init_machine_status = nvptx_init_machine_status; + handle_ptx_version_option (); + /* Set toplevel_reorder, unless explicitly disabled. We need reordering so that we emit necessary assembler decls of undeclared variables. */ @@ -5430,23 +5535,19 @@ static void nvptx_file_start (void) { fputs ("// BEGIN PREAMBLE\n", asm_out_file); - if (TARGET_PTX_7_0) - fputs ("\t.version\t7.0\n", asm_out_file); - else if (TARGET_PTX_6_3) - fputs ("\t.version\t6.3\n", asm_out_file); - else - fputs ("\t.version\t3.1\n", asm_out_file); - if (TARGET_SM80) - fputs ("\t.target\tsm_80\n", asm_out_file); - else if (TARGET_SM75) - fputs ("\t.target\tsm_75\n", asm_out_file); - else if (TARGET_SM53) - fputs ("\t.target\tsm_53\n", asm_out_file); - else if (TARGET_SM35) - fputs ("\t.target\tsm_35\n", asm_out_file); - else - fputs ("\t.target\tsm_30\n", asm_out_file); + + fputs ("\t.version\t", asm_out_file); + fputs (ptx_version_to_string ((enum ptx_version)ptx_version_option), + asm_out_file); + fputs ("\n", asm_out_file); + + fputs ("\t.target\tsm_", asm_out_file); + fputs (sm_version_to_string ((enum ptx_isa)ptx_isa_option), + asm_out_file); + fputs ("\n", asm_out_file); + fprintf (asm_out_file, "\t.address_size %d\n", GET_MODE_BITSIZE (Pmode)); + fputs ("// END PREAMBLE\n", asm_out_file); } diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index d64dbfd8b33..7463603a0b0 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -1603,7 +1603,7 @@ (define_insn "nvptx_shuffle" UNSPEC_SHUFFLE))] "" { - if (TARGET_PTX_6_3) + if (TARGET_PTX_6_0) return "%.\\tshfl.sync%S3.b32\\t%0, %1, %2, 31, 0xffffffff;"; else return "%.\\tshfl%S3.b32\\t%0, %1, %2, 31;"; @@ -1615,7 +1615,7 @@ (define_insn "nvptx_vote_ballot" UNSPEC_VOTE_BALLOT))] "" { - if (TARGET_PTX_6_3) + if (TARGET_PTX_6_0) return "%.\\tvote.sync.ballot.b32\\t%0, %1, 0xffffffff;"; else return "%.\\tvote.ballot.b32\\t%0, %1;"; diff --git a/gcc/config/nvptx/nvptx.opt b/gcc/config/nvptx/nvptx.opt index 6e12b1f7296..e3f65b2d0b1 100644 --- a/gcc/config/nvptx/nvptx.opt +++ b/gcc/config/nvptx/nvptx.opt @@ -89,5 +89,5 @@ EnumValue Enum(ptx_version) String(7.0) Value(PTX_VERSION_7_0) mptx= -Target RejectNegative ToLower Joined Enum(ptx_version) Var(ptx_version_option) Init(PTX_VERSION_6_3) +Target RejectNegative ToLower Joined Enum(ptx_version) Var(ptx_version_option) Specify the version of the ptx version to use.