[committed, amdgcn] Wait for exit value to write before exiting.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[committed, amdgcn] Wait for exit value to write before exiting.

Andrew Stubbs
This patch fixes a bug in which GCN5 devices often fail to return an
exit value because it's not yet been written to memory when the program
exits. The fix is simply to wait for it properly. GCN3 devices did not
demonstrate the problem, but it was technically wrong there also. The
bug was introduced when we stopped waiting for all writes to complete.

I've also taken the opportunity to adjust gcn-run such that a similar
issue can't go unnoticed for so long, in future.

Andrew Stubbs
Mentor Graphics / CodeSourcery

GCN: Wait for exit value to write before exiting.

2019-05-24  Andrew Stubbs  <[hidden email]>

        gcc/
        * config/gcn/gcn-run.c (main): Set a non-zero return value if the
        kernel does not exit cleanly.
        * config/gcn/gcn.md (gcn_return): Insert s_waitcnt before s_dcache_wb.

diff --git a/gcc/config/gcn/gcn-run.c b/gcc/config/gcn/gcn-run.c
index 84718f42846..21852d78bc5 100644
--- a/gcc/config/gcn/gcn-run.c
+++ b/gcc/config/gcn/gcn-run.c
@@ -853,7 +853,10 @@ main (int argc, char *argv[])
 
   unsigned int upper = (return_value & ~0xffff) >> 16;
   if (upper == 0xcafe)
-    printf ("Kernel exit value was never set\n");
+    {
+      printf ("Kernel exit value was never set\n");
+      return_value = 0xff;
+    }
   else if (upper == 0xffff)
     ; /* Set by exit.  */
   else if (upper == 0)
diff --git a/gcc/config/gcn/gcn.md b/gcc/config/gcn/gcn.md
index 2b805a73c56..1f06d0bd5cc 100644
--- a/gcc/config/gcn/gcn.md
+++ b/gcc/config/gcn/gcn.md
@@ -784,10 +784,10 @@
     if (cfun && cfun->machine && cfun->machine->normal_function)
       return "s_setpc_b64\ts[18:19]";
     else
-      return "s_dcache_wb\;s_endpgm";
+      return "s_waitcnt\tlgkmcnt(0)\;s_dcache_wb\;s_endpgm";
   }
   [(set_attr "type" "sop1")
-   (set_attr "length" "8")])
+   (set_attr "length" "12")])
 
 (define_expand "call"
   [(parallel [(call (match_operand 0 "")
Reply | Threaded
Open this post in threaded view
|

Re: [committed, amdgcn] Wait for exit value to write before exiting.

Andrew Stubbs-4
On 24/05/2019 16:31, Andrew Stubbs wrote:
> This patch fixes a bug in which GCN5 devices often fail to return an
> exit value because it's not yet been written to memory when the program
> exits. The fix is simply to wait for it properly. GCN3 devices did not
> demonstrate the problem, but it was technically wrong there also. The
> bug was introduced when we stopped waiting for all writes to complete.
>
> I've also taken the opportunity to adjust gcn-run such that a similar
> issue can't go unnoticed for so long, in future.

Now backported to gcc-9-branch.

Andrew