From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id CDFC1385BF80 for ; Tue, 1 Feb 2022 18:31:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CDFC1385BF80 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-out1.suse.de (Postfix) with ESMTPS id 0F8D921126 for ; Tue, 1 Feb 2022 18:31:29 +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 EFB1113B54 for ; Tue, 1 Feb 2022 18:31:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4C1EOYB8+WG3CQAAMHmgww (envelope-from ) for ; Tue, 01 Feb 2022 18:31:28 +0000 Date: Tue, 1 Feb 2022 19:31:27 +0100 From: Tom de Vries To: gcc-patches@gcc.gnu.org Subject: [committed][nvptx] Add uniform_warp_check insn Message-ID: <20220201183125.GA4286@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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-List-Received-Date: Tue, 01 Feb 2022 18:31:31 -0000 Hi, On a GT 1030, with driver version 470.94 and -mptx=3.1 I run into: ... FAIL: libgomp.oacc-c/../libgomp.oacc-c-c++-common/parallel-dims.c \ -DACC_DEVICE_TYPE_nvidia=1 -DACC_MEM_SHARED=0 -foffload=nvptx-none \ -O2 execution test ... which minimizes to the same test-case as listed in commit "[nvptx] Update default ptx isa to 6.3". The problem is again that the first diverging branch is not handled as such in SASS, which causes problems with a subsequent shfl insn, but given that we have -mptx=3.1 we can't use the bar.warp.sync insn. Given that the default is now -mptx=6.3, and consequently -mptx=3.1 is of a lesser importance, implement the next best thing: abort when detecting non-convergence using this insn: ... { .reg.b32 act; vote.ballot.b32 act,1; .reg.pred uni; setp.eq.b32 uni,act,0xffffffff; @ !uni trap; @ !uni exit; } ... Interestingly, the effect of this is that rather than aborting, the test-case now passes. Tested on x86_64 with nvptx accelerator. Committed to trunk. Thanks, - Tom [nvptx] Add uniform_warp_check insn gcc/ChangeLog: 2022-01-31 Tom de Vries * config/nvptx/nvptx.cc (nvptx_single): Use nvptx_uniform_warp_check. * config/nvptx/nvptx.md (define_c_enum "unspecv"): Add UNSPECV_UNIFORM_WARP_CHECK. (define_insn "nvptx_uniform_warp_check"): New define_insn. --- gcc/config/nvptx/nvptx.cc | 22 ++++++++++++++++++---- gcc/config/nvptx/nvptx.md | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc index 1b91990ca1f..b3bb97c3c14 100644 --- a/gcc/config/nvptx/nvptx.cc +++ b/gcc/config/nvptx/nvptx.cc @@ -4631,15 +4631,29 @@ nvptx_single (unsigned mask, basic_block from, basic_block to) if (tail_branch) { label_insn = emit_label_before (label, before); - if (TARGET_PTX_6_0 && mode == GOMP_DIM_VECTOR) - warp_sync = emit_insn_after (gen_nvptx_warpsync (), label_insn); + if (mode == GOMP_DIM_VECTOR) + { + if (TARGET_PTX_6_0) + warp_sync = emit_insn_after (gen_nvptx_warpsync (), + label_insn); + else + warp_sync = emit_insn_after (gen_nvptx_uniform_warp_check (), + label_insn); + } before = label_insn; } else { label_insn = emit_label_after (label, tail); - if (TARGET_PTX_6_0 && mode == GOMP_DIM_VECTOR) - warp_sync = emit_insn_after (gen_nvptx_warpsync (), label_insn); + if (mode == GOMP_DIM_VECTOR) + { + if (TARGET_PTX_6_0) + warp_sync = emit_insn_after (gen_nvptx_warpsync (), + label_insn); + else + warp_sync = emit_insn_after (gen_nvptx_uniform_warp_check (), + label_insn); + } if ((mode == GOMP_DIM_VECTOR || mode == GOMP_DIM_WORKER) && CALL_P (tail) && find_reg_note (tail, REG_NORETURN, NULL)) emit_insn_after (gen_exit (), label_insn); diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index b4c7cd6e56d..92768dd9e95 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -57,6 +57,7 @@ (define_c_enum "unspecv" [ UNSPECV_XCHG UNSPECV_BARSYNC UNSPECV_WARPSYNC + UNSPECV_UNIFORM_WARP_CHECK UNSPECV_MEMBAR UNSPECV_MEMBAR_CTA UNSPECV_MEMBAR_GL @@ -1985,6 +1986,23 @@ (define_insn "nvptx_warpsync" "\\tbar.warp.sync\\t0xffffffff;" [(set_attr "predicable" "false")]) +(define_insn "nvptx_uniform_warp_check" + [(unspec_volatile [(const_int 0)] UNSPECV_UNIFORM_WARP_CHECK)] + "" + { + output_asm_insn ("{", NULL); + output_asm_insn ("\\t" ".reg.b32" "\\t" "act;", NULL); + output_asm_insn ("\\t" "vote.ballot.b32" "\\t" "act,1;", NULL); + output_asm_insn ("\\t" ".reg.pred" "\\t" "uni;", NULL); + output_asm_insn ("\\t" "setp.eq.b32" "\\t" "uni,act,0xffffffff;", + NULL); + output_asm_insn ("@ !uni\\t" "trap;", NULL); + output_asm_insn ("@ !uni\\t" "exit;", NULL); + output_asm_insn ("}", NULL); + return ""; + } + [(set_attr "predicable" "false")]) + (define_expand "memory_barrier" [(set (match_dup 0) (unspec_volatile:BLK [(match_dup 0)] UNSPECV_MEMBAR))]