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#if BOOST_COMP_GNUC
44# pragma GCC diagnostic push
45# pragma GCC diagnostic ignored \
46 "-Wcast-align" // "cast from 'unsigned char*' to 'unsigned int*' increases required alignment of target type"
47#endif
48 template<typename T, std::size_t TDataAlignBytes, std::size_t TuniqueId>
49 struct DeclareSharedVar<T, TuniqueId, BlockSharedMemStMemberMasterSync<TDataAlignBytes>>
50 {
52 BlockSharedMemStMemberMasterSync<TDataAlignBytes> const& blockSharedMemSt) -> T&
53 {
54 auto* data = blockSharedMemSt.template getVarPtr<T>(TuniqueId);
55
56 if(!data)
57 {
58 // Assure that all threads have executed the return of the last allocBlockSharedArr function (if
59 // there was one before).
60 blockSharedMemSt.m_syncFn();
61 if(blockSharedMemSt.m_isMasterThreadFn())
62 {
63 blockSharedMemSt.template alloc<T>(TuniqueId);
64 }
65
66 blockSharedMemSt.m_syncFn();
67 // lookup for the data chunk allocated by the master thread
68 data = blockSharedMemSt.template getLatestVarPtr<T>();
69 }
70 ALPAKA_ASSERT(data != nullptr);
71 return *data;
72 }
73 };
74#if BOOST_COMP_GNUC
75# pragma GCC diagnostic pop
76#endif
77 template<std::size_t TDataAlignBytes>
79 {
81 {
82 // shared memory block data will be reused
83 }
84 };
85 } // namespace trait
86} // 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