alpaka
Abstraction Library for Parallel Kernel Acceleration
MemFenceCpuSerial.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Jan Stephan, Andrea Bocci
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
9 
10 #include <atomic>
11 
12 namespace alpaka
13 {
14  //! The serial CPU memory fence.
15  class MemFenceCpuSerial : public interface::Implements<ConceptMemFence, MemFenceCpuSerial>
16  {
17  };
18 
19  namespace trait
20  {
21  template<>
22  struct MemFence<MemFenceCpuSerial, memory_scope::Block>
23  {
24  static auto mem_fence(MemFenceCpuSerial const&, memory_scope::Block const&)
25  {
26  /* Nothing to be done on the block level for the serial case. */
27  }
28  };
29 
30  template<>
31  struct MemFence<MemFenceCpuSerial, memory_scope::Grid>
32  {
33  static auto mem_fence(MemFenceCpuSerial const&, memory_scope::Grid const&)
34  {
35  /* Nothing to be done on the grid level for the serial case. */
36  }
37  };
38 
39  template<typename TMemScope>
40  struct MemFence<MemFenceCpuSerial, TMemScope>
41  {
42  static auto mem_fence(MemFenceCpuSerial const&, TMemScope const&)
43  {
44  /* Enable device fences because we may want to synchronize with other (serial) kernels. */
45  std::atomic_thread_fence(std::memory_order_acq_rel);
46  }
47  };
48  } // namespace trait
49 } // namespace alpaka
The serial CPU memory fence.
The alpaka accelerator library.
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition: Interface.hpp:15
Memory fences are observed by all threads in the same block.
Definition: Traits.hpp:20
Memory fences are observed by all threads in the same grid.
Definition: Traits.hpp:25
static auto mem_fence(MemFenceCpuSerial const &, TMemScope const &)
static auto mem_fence(MemFenceCpuSerial const &, memory_scope::Block const &)
static auto mem_fence(MemFenceCpuSerial const &, memory_scope::Grid const &)
The mem_fence trait.
Definition: Traits.hpp:39