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 <sycl/memory_enums.hpp> // for getStdMemoryOrder, memory_order
12 
13 #ifdef __SYCL_DEVICE_ONLY__
14 #include <sycl/detail/spirv.hpp>
15 #else
16 #include <atomic> // for atomic_thread_fence
17 #endif
18 
19 namespace sycl {
20 inline namespace _V1 {
21 
22 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 } // namespace _V1
35 } // namespace sycl
std::memory_order getStdMemoryOrder(__spv::MemorySemanticsMask::Flag)
Definition: atomic.hpp:82
void atomic_fence(memory_order order, memory_scope scope)
Definition: access.hpp:18
__SYCL_CONVERGENT__ __DPCPP_SYCL_EXTERNAL void __spirv_MemoryBarrier(__spv::Scope Memory, uint32_t Semantics) noexcept
Definition: spirv_ops.cpp:36