alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
MemFenceOmp2Threads.hpp
Go to the documentation of this file.
1/* Copyright 2022 Jan Stephan, Bernhard Manfred Gruber, Tapish Narwal
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
10
11#ifdef ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED
12
13# if _OPENMP < 200203
14# error If ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
15# endif
16
17namespace alpaka
18{
19 //! The CPU OpenMP 2.0 block memory fence.
20 class MemFenceOmp2Threads : public interface::Implements<ConceptMemFence, MemFenceOmp2Threads>
21 {
22 };
23
24 namespace trait
25 {
26 template<>
27 struct MemFenceDefaultOrder<MemFenceOmp2Threads>
28 {
29 using type = mem_order::AcqRel;
30 static constexpr auto value = mem_order::acq_rel;
31 };
32
33 template<MemoryOrder TMemOrder, MemoryScope TMemScope>
34 struct MemFence<MemFenceOmp2Threads, TMemOrder, TMemScope>
35 {
36 static auto mem_fence(MemFenceOmp2Threads const&, TMemOrder order, TMemScope const&)
37 {
38 /*
39 * Intuitively, this pragma creates a fence on the block level.
40 *
41 * Creating a block fence is enough for the whole device because the blocks are executed serially. By
42 * definition of fences, preceding blocks don't have a guarantee to see the results of this block's
43 * STORE operations (only that they will be ordered correctly); the following blocks see the results
44 * once they start. Consider the following code:
45 *
46 * int x = 1;
47 * int y = 2;
48 *
49 * void foo()
50 * {
51 * x = 10;
52 * alpaka::mem_fence(acc, memory_scope::device);
53 * y = 20;
54 * }
55 *
56 * void bar()
57 * {
58 * auto b = y;
59 * alpaka::mem_fence(acc, memory_scope::device);
60 * auto a = x;
61 * }
62 *
63 * The following are all valid outcomes:
64 * a == 1 && b == 2
65 * a == 10 && b == 2
66 * a == 10 && b == 20
67 */
69# ifdef _MSC_VER
70 ; // MSVC needs an empty statement here or it diagnoses a syntax error
71# endif
72 }
73 };
74 } // namespace trait
75} // namespace alpaka
76#endif
The CPU OpenMP 2.0 block memory fence.
auto flushOmp(TMemOrder)
static constexpr AcqRel acq_rel
The alpaka accelerator library.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto mem_fence(TMemFence const &fence, TMemOrder order, TMemScope const &scope) -> void
Issues memory fence instructions.
Definition Traits.hpp:80
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition Interface.hpp:15