public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-10] [libgomp, nvptx] Add __sync_compare_and_swap_16
@ 2020-09-14  7:13 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2020-09-14  7:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:fafbe5379f9bbd80d9957df84aae2d54915ce69e

commit fafbe5379f9bbd80d9957df84aae2d54915ce69e
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Sep 14 09:13:27 2020 +0200

    [libgomp, nvptx] Add __sync_compare_and_swap_16
    
    As reported here
    ( https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553070.html  ),
    when running test-case libgomp.c-c++-common/reduction-16.c for powerpc host
    with nvptx accelerator, we run into:
    ...
    unresolved symbol __sync_val_compare_and_swap_16
    ...
    
    I can reproduce the problem on x86_64 with a trigger patch that:
    - initializes ix86_isa_flags2 to TARGET_ISA2_CX16
    - enables define_expand "atomic_load<mode>" in gcc/config/i386/sync.md
      for TImode
    
    The problem is that omp-expand.c generates atomic builtin calls based on
    checks whether those are supported on the host, which forces the target to
    support these, even though those checks fail for the accelerator target.
    
    Fix this by:
    - adding a __sync_val_compare_and_swap_16 in libgomp for nvptx,
      which falls back onto libatomic's __atomic_compare_and_swap_16
    - adding -foffload=-latomic in the test-case
    
    Tested libgomp on x86_64-linux with nvptx accelerator.
    
    Tested libgomp with trigger patch on x86_64-linux with nvptx accelerator.
    
    libgomp/ChangeLog:
    
            * config/nvptx/atomic.c: New file.  Add
            __sync_val_compare_and_swap_16.
            * testsuite/libgomp.c-c++-common/reduction-16.c: Add -latomic for
            target offload_target_nvptx.
    
    (cherry picked from commit 4ac7b66958016225724084078e6e7937e23ffcd3)

Diff:
---
 libgomp/ChangeLog.omp                                 | 10 ++++++++++
 libgomp/config/nvptx/atomic.c                         | 18 ++++++++++++++++++
 libgomp/testsuite/libgomp.c-c++-common/reduction-16.c |  1 +
 3 files changed, 29 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index cd700bcefcd..6b7c71c58be 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,13 @@
+2020-09-14  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline
+	2020-09-14  Tom de Vries  <tdevries@suse.de>
+
+	* config/nvptx/atomic.c: New file.  Add
+	__sync_val_compare_and_swap_16.
+	* testsuite/libgomp.c-c++-common/reduction-16.c: Add -latomic for
+	target offload_target_nvptx.
+
 2020-08-21  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline
diff --git a/libgomp/config/nvptx/atomic.c b/libgomp/config/nvptx/atomic.c
new file mode 100644
index 00000000000..2e13b09b497
--- /dev/null
+++ b/libgomp/config/nvptx/atomic.c
@@ -0,0 +1,18 @@
+#include "libgomp.h"
+
+#include "../../atomic.c"
+
+/* Implement __sync_val_compare_and_swap_16, to support offloading from hosts
+   that support this builtin.  Fallback on libatomic.  This can be removed
+   once omp-expand starts using __atomic_compare_exchange_n instead.  */
+
+unsigned __int128
+__sync_val_compare_and_swap_16 (volatile void *vptr, unsigned __int128 oldval,
+				unsigned __int128 newval)
+{
+  volatile __int128 *ptr = vptr;
+  __int128 expected = oldval;
+  __atomic_compare_exchange_n (ptr, &expected, newval, false,
+			       MEMMODEL_SEQ_CST, MEMMODEL_SEQ_CST);
+  return expected;
+}
diff --git a/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c b/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
index d0e82b04790..e60fe3664ed 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
@@ -1,4 +1,5 @@
 /* { dg-do run } */
+/* { dg-additional-options "-foffload=-latomic" { target offload_target_nvptx } } */
 
 #include <stdlib.h>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-14  7:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14  7:13 [gcc/devel/omp/gcc-10] [libgomp, nvptx] Add __sync_compare_and_swap_16 Tobias Burnus

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