alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
memFence.hpp
Go to the documentation of this file.
1/* Copyright 2025 Mehmet Yusufoglu, René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
12#include "alpaka/onAcc/Acc.hpp"
15#include "alpaka/tag.hpp"
16
17#include <atomic>
18#include <type_traits>
19
20namespace alpaka::onAcc::internalCompute
21{
22 namespace detail
23 {
24 // suppress warning: `warning: 'atomic_thread_fence' is not supported with '-fsanitize=thread' [-Wtsan]`
25#if defined(__GNUC__) && !defined(__clang__)
26# pragma GCC diagnostic push
27# pragma GCC diagnostic ignored "-Wtsan"
28#endif
29
30 constexpr void hostMemoryFenceImpl(auto const&, auto const scope, concepts::MemoryOrder auto const order)
31 {
32 using ScopeT = std::remove_cvref_t<decltype(scope)>;
33
34 // Block scope requires no fence since threads within a block are simulated/single-threaded
35 if constexpr(!std::same_as<ScopeT, scope::Block>)
36 {
37 std::atomic_thread_fence(MemOrderHost::get(order));
38 }
39 }
40#if defined(__GNUC__) && !defined(__clang__)
41# pragma GCC diagnostic pop
42#endif
43 } // namespace detail
44
45 // Host API: dispatch to executor-specific implementation
46 template<typename T_Scope, concepts::MemoryOrder T_Order>
47 struct MemoryFence::Op<api::Host, T_Scope, T_Order>
48 {
49 void operator()(onAcc::concepts::Acc<api::Host> auto const& acc, T_Scope const scope, T_Order const order)
50 const
51 {
52 detail::hostMemoryFenceImpl(acc[object::exec], scope, order);
53 }
54 };
55} // namespace alpaka::onAcc::internalCompute
constexpr Api api
Definition tag.hpp:24
auto scope(concepts::Level auto logLvl, std::source_location const &location=std::source_location::current())
Log the entry and exit of a scope.
Definition logger.hpp:24