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
2
* SPDX-License-Identifier: MPL-2.0
3
*/
4
5
#pragma once
6
7
#include "
alpaka/core/Interface.hpp
"
8
#include "
alpaka/mem/fence/Traits.hpp
"
9
10
#ifdef ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED
11
12
# if _OPENMP < 200203
13
# error If ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
14
# endif
15
16
namespace
alpaka
17
{
18
//! The CPU OpenMP 2.0 block memory fence.
19
class
MemFenceOmp2Threads
:
public
interface::Implements
<ConceptMemFence, MemFenceOmp2Threads>
20
{
21
};
22
23
namespace
trait
24
{
25
template
<
typename
TMemScope>
26
struct
MemFence<
MemFenceOmp2Threads
, TMemScope>
27
{
28
static
auto
mem_fence
(
MemFenceOmp2Threads
const
&, TMemScope
const
&)
29
{
30
/*
31
* Intuitively, this pragma creates a fence on the block level.
32
*
33
* Creating a block fence is enough for the whole device because the blocks are executed serially. By
34
* definition of fences, preceding blocks don't have a guarantee to see the results of this block's
35
* STORE operations (only that they will be ordered correctly); the following blocks see the results
36
* once they start. Consider the following code:
37
*
38
* int x = 1;
39
* int y = 2;
40
*
41
* void foo()
42
* {
43
* x = 10;
44
* alpaka::mem_fence(acc, memory_scope::device);
45
* y = 20;
46
* }
47
*
48
* void bar()
49
* {
50
* auto b = y;
51
* alpaka::mem_fence(acc, memory_scope::device);
52
* auto a = x;
53
* }
54
*
55
* The following are all valid outcomes:
56
* a == 1 && b == 2
57
* a == 10 && b == 2
58
* a == 10 && b == 20
59
*/
60
# pragma omp flush
61
# ifdef _MSC_VER
62
;
// MSVC needs an empty statement here or it diagnoses a syntax error
63
# endif
64
}
65
};
66
}
// namespace trait
67
}
// namespace alpaka
68
#endif
Interface.hpp
alpaka::MemFenceOmp2Threads
The CPU OpenMP 2.0 block memory fence.
Definition
MemFenceOmp2Threads.hpp:20
Traits.hpp
alpaka
The alpaka accelerator library.
Definition
AccCpuOmp2Blocks.hpp:49
alpaka::mem_fence
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto mem_fence(TMemFence const &fence, TMemScope const &scope) -> void
Issues memory fence instructions.
Definition
Traits.hpp:61
alpaka::interface::Implements
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition
Interface.hpp:15
include
alpaka
mem
fence
MemFenceOmp2Threads.hpp
Generated on Tue Feb 4 2025 09:02:23 for alpaka by
1.9.8