alpaka
Abstraction Library for Parallel Kernel Acceleration
BlockSharedMemStMember.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Jeffrey Kelling, Rene Widera, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
9 #include "alpaka/core/Assert.hpp"
11 
12 #include <algorithm>
13 #include <cstdint>
14 #include <type_traits>
15 
16 namespace alpaka
17 {
18  //! Static block shared memory provider using a pointer to
19  //! externally allocated fixed-size memory, likely provided by
20  //! BlockSharedMemDynMember.
21  //! \warning This class is not thread safe!
22  template<std::size_t TDataAlignBytes = core::vectorization::defaultAlignment>
24  : public detail::BlockSharedMemStMemberImpl<TDataAlignBytes>
25  , public interface::Implements<ConceptBlockSharedSt, BlockSharedMemStMember<TDataAlignBytes>>
26  {
27  public:
29  };
30 
31  namespace trait
32  {
33  template<typename T, std::size_t TDataAlignBytes, std::size_t TuniqueId>
34  struct DeclareSharedVar<T, TuniqueId, BlockSharedMemStMember<TDataAlignBytes>>
35  {
36  static auto declareVar(BlockSharedMemStMember<TDataAlignBytes> const& smem) -> T&
37  {
38  auto* data = smem.template getVarPtr<T>(TuniqueId);
39 
40  if(!data)
41  {
42  smem.template alloc<T>(TuniqueId);
43  data = smem.template getLatestVarPtr<T>();
44  }
45  ALPAKA_ASSERT(data != nullptr);
46  return *data;
47  }
48  };
49 
50  template<std::size_t TDataAlignBytes>
51  struct FreeSharedVars<BlockSharedMemStMember<TDataAlignBytes>>
52  {
54  {
55  // shared memory block data will be reused
56  }
57  };
58  } // namespace trait
59 } // namespace alpaka
#define ALPAKA_ASSERT(...)
The assert can be explicit disabled by defining NDEBUG.
Definition: Assert.hpp:13
Static block shared memory provider using a pointer to externally allocated fixed-size memory,...
Implementation of static block shared memory provider.
The alpaka accelerator library.
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition: Interface.hpp:15
static auto declareVar(BlockSharedMemStMember< TDataAlignBytes > const &smem) -> T &
The block shared static memory variable allocation operation trait.
Definition: Traits.hpp:23
static auto freeVars(BlockSharedMemStMember< TDataAlignBytes > const &) -> void
The block shared static memory free operation trait.
Definition: Traits.hpp:26