alpaka
Abstraction Library for Parallel Kernel Acceleration
BlockSharedMemStGenericSycl.hpp
Go to the documentation of this file.
1 /* Copyright 2023 Jan Stephan, Andrea Bocci
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
9 
10 #include <cstddef>
11 #include <cstdint>
12 
13 #ifdef ALPAKA_ACC_SYCL_ENABLED
14 
15 # include <sycl/sycl.hpp>
16 
17 namespace alpaka
18 {
19  //! The generic SYCL shared memory allocator.
20  class BlockSharedMemStGenericSycl
22  , public interface::Implements<ConceptBlockSharedSt, BlockSharedMemStGenericSycl>
23  {
24  public:
25  BlockSharedMemStGenericSycl(sycl::local_accessor<std::byte> accessor)
26  : BlockSharedMemStMemberImpl(
27  reinterpret_cast<std::uint8_t*>(accessor.get_multi_ptr<sycl::access::decorated::no>().get()),
28  accessor.size())
29  , m_accessor{accessor}
30  {
31  }
32 
33  private:
34  sycl::local_accessor<std::byte> m_accessor;
35  };
36 } // namespace alpaka
37 
38 namespace alpaka::trait
39 {
40  template<typename T, std::size_t TUniqueId>
41  struct DeclareSharedVar<T, TUniqueId, BlockSharedMemStGenericSycl>
42  {
43  static auto declareVar(BlockSharedMemStGenericSycl const& smem) -> T&
44  {
45  auto* data = smem.template getVarPtr<T>(TUniqueId);
46 
47  if(!data)
48  {
49  smem.template alloc<T>(TUniqueId);
50  data = smem.template getLatestVarPtr<T>();
51  }
52  ALPAKA_ASSERT(data != nullptr);
53  return *data;
54  }
55  };
56 
57  template<>
58  struct FreeSharedVars<BlockSharedMemStGenericSycl>
59  {
60  static auto freeVars(BlockSharedMemStGenericSycl const&) -> void
61  {
62  // shared memory block data will be reused
63  }
64  };
65 } // namespace alpaka::trait
66 
67 #endif
#define ALPAKA_ASSERT(...)
The assert can be explicit disabled by defining NDEBUG.
Definition: Assert.hpp:13
Implementation of static block shared memory provider.
The accelerator traits.
The alpaka accelerator library.