Skip to content

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Dec 6, 2024

Summary:
Adds support for scoped fences now that the NVPTX backend doesn't break
on them.

@llvmbot llvmbot added the libc label Dec 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 6, 2024

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

Changes

Summary:
Adds support for scoped fences now that the NVPTX backend doesn't break
on them.


Full diff: https://github.com/llvm/llvm-project/pull/119018.diff

1 Files Affected:

  • (modified) libc/src/__support/CPP/atomic.h (+7-6)
diff --git a/libc/src/__support/CPP/atomic.h b/libc/src/__support/CPP/atomic.h
index c67e4e9b6f1cbc..b4b86fd511e248 100644
--- a/libc/src/__support/CPP/atomic.h
+++ b/libc/src/__support/CPP/atomic.h
@@ -214,13 +214,14 @@ template <typename T> struct Atomic {
 };
 
 // Issue a thread fence with the given memory ordering.
-LIBC_INLINE void atomic_thread_fence([[maybe_unused]] MemoryOrder mem_ord) {
-// The NVPTX backend currently does not support atomic thread fences so we use a
-// full system fence instead.
-#ifdef LIBC_TARGET_ARCH_IS_NVPTX
-  __nvvm_membar_sys();
+LIBC_INLINE void atomic_thread_fence(
+    MemoryOrder mem_ord,
+    [[maybe_unused]] MemoryScope mem_scope = MemoryScope::DEVICE) {
+#if __has_builtin(__scoped_atomic_thread_fence)
+  return __scoped_atomic_thread_fence(static_cast<int>(mem_ord),
+                                      static_cast<int>(mem_scope));
 #else
-  __atomic_thread_fence(static_cast<int>(mem_ord));
+  return __atomic_thread_fence(static_cast<int>(mem_ord));
 #endif
 }
 

Summary:
Adds support for scoped fences now that the NVPTX backend doesn't break
on them.
@jhuber6 jhuber6 merged commit 7ff8929 into llvm:main Dec 6, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants