alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
MemFenceOmp2Order.hpp
Go to the documentation of this file.
1/* Copyright 2025 Tapish Narwal
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
8#include "alpaka/core/PP.hpp"
11
12#include <atomic>
13#include <concepts>
14
15#if defined(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED) || defined(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED)
16
17# if ALPAKA_OMP < ALPAKA_VERSION_NUMBER(2002, 03, 0)
18# ifdef(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED)
19# error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
20# endif
21# ifdef(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED)
22# error If ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
23# endif
24# endif
25
26namespace alpaka::detail
27{
28
29 template<MemoryOrder TMemOrder>
30 inline auto flushOmp(TMemOrder)
31 {
32 if constexpr(std::same_as<TMemOrder, mem_order::SeqCst>)
33 {
34 // sequenital consistency in openMP is only enforced in implicit flush.
35 // We use std atomics since our openMP is limited to CPU backends
36 std::atomic_thread_fence(std::memory_order::seq_cst);
37 }
38 else if constexpr(std::same_as<TMemOrder, mem_order::AcqRel>)
39 {
40 // Flush orderings were introduced in OpenMP 5.0
41# if ALPAKA_OMP >= ALPAKA_VERSION_NUMBER(2018, 11, 0)
42# pragma omp flush acq_rel
43# else
44# pragma omp flush
45# endif
46 }
47 else if constexpr(std::same_as<TMemOrder, mem_order::Release>)
48 {
49 // Flush orderings were introduced in OpenMP 5.0
50# if ALPAKA_OMP >= ALPAKA_VERSION_NUMBER(2018, 11, 0)
51# pragma omp flush release
52# else
53# pragma omp flush
54# endif
55 }
56 else if constexpr(std::same_as<TMemOrder, mem_order::Acquire>)
57 {
58 // Flush orderings were introduced in OpenMP 5.0
59# if ALPAKA_OMP >= ALPAKA_VERSION_NUMBER(2018, 11, 0)
60# pragma omp flush acquire
61# else
62# pragma omp flush
63# endif
64 }
65 else if constexpr(std::same_as<TMemOrder, mem_order::Relaxed>)
66 {
67 // Relaxed memory barrier is a no op
68 }
69 else
70 {
72 }
73 }
74} // namespace alpaka::detail
75
76#endif
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
auto flushOmp(TMemOrder)