From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 6D289385800E; Wed, 14 Sep 2022 10:09:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D289385800E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663150161; bh=GtiHgzjBKdDvUJayl2V73gG3KgQQtmSm9avwOmPIJtE=; h=From:To:Subject:Date:From; b=PhluSy8i0rXActEbQcCt2mcgWUXa0fNQG1PsdFCzVnYQeh9DsLWpMFAh4rLCTF8B4 wEwv/nWKh0a33fXfKXDVlREUtJD3jXcF4fAAbBYcFOOoyzxzEm3bVgP7yrKjOyIjQG FYOKg1pWMfE3tnKOSgJ9ukanN0mO+R/N2hKwKlIM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10987] [nvptx] Add uniform_warp_check insn X-Act-Checkin: gcc X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 50d326b90572d3e25a468f38603a6a971ecda938 X-Git-Newrev: 3875b025a97ae667523bebf9f4cf157a8f5854ce Message-Id: <20220914100921.6D289385800E@sourceware.org> Date: Wed, 14 Sep 2022 10:09:21 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3875b025a97ae667523bebf9f4cf157a8f5854ce commit r10-10987-g3875b025a97ae667523bebf9f4cf157a8f5854ce Author: Tom de Vries Date: Fri Jan 28 10:28:59 2022 +0100 [nvptx] Add uniform_warp_check insn 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. gcc/ChangeLog: 2022-01-31 Tom de Vries * config/nvptx/nvptx.c (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. (cherry picked from commit f32f74c2e8cef5fe37af6d4e8d7e8f6b4c8ae9a8) Diff: --- gcc/config/nvptx/nvptx.c | 22 ++++++++++++++++++---- gcc/config/nvptx/nvptx.md | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index eec07fc3d13..0b67d544e48 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -4425,15 +4425,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 b2350ab0d2d..34062027312 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -56,6 +56,7 @@ UNSPECV_XCHG UNSPECV_BARSYNC UNSPECV_WARPSYNC + UNSPECV_UNIFORM_WARP_CHECK UNSPECV_MEMBAR UNSPECV_MEMBAR_CTA UNSPECV_DIM_POS @@ -1483,6 +1484,23 @@ "\\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))]