alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
BlockSharedMemStMemberMasterSync.hpp
Go to the documentation of this file.
1/* Copyright 2022 Benjamin Worpitz, Erik Zenker, Matthias Werner, René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
12
13#include <functional>
14#include <memory>
15#include <utility>
16#include <vector>
17
18namespace alpaka
19{
20 template<std::size_t TDataAlignBytes = core::vectorization::defaultAlignment>
22 : public detail::BlockSharedMemStMemberImpl<TDataAlignBytes>
23 , public interface::Implements<ConceptBlockSharedSt, BlockSharedMemStMemberMasterSync<TDataAlignBytes>>
24 {
25 public:
27 uint8_t* mem,
28 std::size_t capacity,
29 std::function<void()> fnSync,
30 std::function<bool()> fnIsMasterThread)
31 : detail::BlockSharedMemStMemberImpl<TDataAlignBytes>(mem, capacity)
32 , m_syncFn(std::move(fnSync))
33 , m_isMasterThreadFn(std::move(fnIsMasterThread))
34 {
35 }
36
37 std::function<void()> m_syncFn;
38 std::function<bool()> m_isMasterThreadFn;
39 };
40
41 namespace trait
42 {
43 template<typename T, std::size_t TDataAlignBytes, std::size_t TuniqueId>
44 struct DeclareSharedVar<T, TuniqueId, BlockSharedMemStMemberMasterSync<TDataAlignBytes>>
45 {
47 BlockSharedMemStMemberMasterSync<TDataAlignBytes> const& blockSharedMemSt) -> T&
48 {
49 auto* data = blockSharedMemSt.template getVarPtr<T>(TuniqueId);
50
51 if(!data)
52 {
53 // Assure that all threads have executed the return of the last allocBlockSharedArr function (if
54 // there was one before).
55 blockSharedMemSt.m_syncFn();
56 if(blockSharedMemSt.m_isMasterThreadFn())
57 {
58 blockSharedMemSt.template alloc<T>(TuniqueId);
59 }
60
61 blockSharedMemSt.m_syncFn();
62 // lookup for the data chunk allocated by the master thread
63 data = blockSharedMemSt.template getLatestVarPtr<T>();
64 }
65 ALPAKA_ASSERT(data != nullptr);
66 return *data;
67 }
68 };
69
70 template<std::size_t TDataAlignBytes>
72 {
74 {
75 // shared memory block data will be reused
76 }
77 };
78 } // namespace trait
79} // namespace alpaka
#define ALPAKA_ASSERT(...)
The assert can be explicit disabled by defining NDEBUG.
Definition Assert.hpp:13
BlockSharedMemStMemberMasterSync(uint8_t *mem, std::size_t capacity, std::function< void()> fnSync, std::function< bool()> fnIsMasterThread)
Implementation of static block shared memory provider.
BlockSharedMemStMemberImpl(std::uint8_t *mem, std::size_t capacity)
#define ALPAKA_FN_HOST
Definition Common.hpp:40
The alpaka accelerator library.
STL namespace.
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition Interface.hpp:15
static ALPAKA_FN_HOST auto declareVar(BlockSharedMemStMemberMasterSync< TDataAlignBytes > const &blockSharedMemSt) -> T &
The block shared static memory variable allocation operation trait.
Definition Traits.hpp:23
static ALPAKA_FN_HOST auto freeVars(BlockSharedMemStMemberMasterSync< TDataAlignBytes > const &) -> void
The block shared static memory free operation trait.
Definition Traits.hpp:26