DPC++ Runtime
Runtime libraries for oneAPI DPC++
atomic_fence.hpp
Go to the documentation of this file.
1 //==--------- atomic_fence.hpp - SYCL 2020 atomic_fence --------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <CL/__spirv/spirv_ops.hpp>
12 #include <sycl/detail/spirv.hpp>
13 #include <sycl/memory_enums.hpp>
14 
15 #ifndef __SYCL_DEVICE_ONLY__
16 #include <atomic>
17 #endif
18 
19 namespace sycl {
21 
22 static inline void atomic_fence(memory_order order, memory_scope scope) {
23 #ifdef __SYCL_DEVICE_ONLY__
24  auto SPIRVOrder = detail::spirv::getMemorySemanticsMask(order);
25  auto SPIRVScope = detail::spirv::getScope(scope);
26  __spirv_MemoryBarrier(SPIRVScope, static_cast<uint32_t>(SPIRVOrder));
27 #else
28  (void)scope;
29  auto StdOrder = detail::getStdMemoryOrder(order);
30  atomic_thread_fence(StdOrder);
31 #endif
32 }
33 
34 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
35 } // namespace sycl
#define __SYCL_INLINE_VER_NAMESPACE(X)
static std::memory_order getStdMemoryOrder(__spv::MemorySemanticsMask::Flag)
Definition: atomic.hpp:84
static void atomic_fence(memory_order order, memory_scope scope)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
__SYCL_CONVERGENT__ SYCL_EXTERNAL void __spirv_MemoryBarrier(__spv::Scope Memory, uint32_t Semantics) noexcept
Definition: spirv_ops.cpp:36