public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas@codesourcery.com>
To: Tom de Vries <tdevries@suse.de>
Cc: <gcc-patches@gcc.gnu.org>
Subject: Re: [committed][nvptx] Add uniform_warp_check insn
Date: Wed, 14 Sep 2022 11:41:30 +0200	[thread overview]
Message-ID: <87fsgumgxh.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <20220201183125.GA4286@delia.home>

[-- Attachment #1: Type: text/plain, Size: 5946 bytes --]

Hi Tom!

On 2022-02-01T19:31:27+0100, Tom de Vries via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 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
> ...

This relates to PR99932 "OpenACC/nvptx offloading execution regressions
starting with CUDA 11.2-era Nvidia Driver 460.27.04".  You've fixed that
for GCC 12+, but testing nvptx offloading for GCC 11, GCC 10 branches on
a system with current Nvidia Driver, we're still running into the several
FAILs and annoying 'WARNING: program timed out' reported in PR99932.

GCC 11, GCC 10 only build '.version 3.1' target libraries, and with
"[nvptx] Add bar.warp.sync" in place (which this patch here thus only
textually depends on), we've got good test results again.

OK to push to GCC 11, GCC 10 branches the attached
"[nvptx] Add uniform_warp_check insn"?


Grüße
 Thomas


> 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  <tdevries@suse.de>
>
>       * 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))]


-----------------
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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-nvptx-Add-uniform_warp_check-insn.patch --]
[-- Type: text/x-diff, Size: 4293 bytes --]

From 8128d1ef7f7c1d6a65122845f7ba8ce87e867851 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Fri, 28 Jan 2022 10:28:59 +0100
Subject: [PATCH] [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  <tdevries@suse.de>

	* 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)
---
 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 6782f13f787..6618b6fdc39 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))]
-- 
2.35.1


  reply	other threads:[~2022-09-14  9:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01 18:31 Tom de Vries
2022-09-14  9:41 ` Thomas Schwinge [this message]
2022-09-14  9:56   ` Tom de Vries
2022-12-15 18:27 ` nvptx: Make 'nvptx_uniform_warp_check' fit for non-full-warp execution (was: [committed][nvptx] Add uniform_warp_check insn) Thomas Schwinge
2023-01-11 11:37   ` [PING] " Thomas Schwinge
2023-01-20 20:23   ` [og12] nvptx: Make 'nvptx_uniform_warp_check' fit for non-full-warp execution Thomas Schwinge
2024-06-04 19:53   ` nvptx: Make 'nvptx_uniform_warp_check' fit for non-full-warp execution, via 'vote.all.pred' (was: nvptx: Make 'nvptx_uniform_warp_check' fit for non-full-warp execution (was: [committed][nvptx] Add uniform_warp_check insn)) Thomas Schwinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fsgumgxh.fsf@euler.schwinge.homeip.net \
    --to=thomas@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).