15 #include <type_traits>
22 template<std::
size_t TMinDataAlignBytes = core::vectorization::defaultAlignment>
34 static constexpr std::uint32_t metaDataSize =
sizeof(MetaData);
40 , m_capacity(static_cast<std::uint32_t>(capacity))
51 void alloc(std::uint32_t
id)
const
54 m_allocdBytes = varChunkEnd<MetaData>(m_allocdBytes);
56 auto* meta = getLatestVarPtr<MetaData>();
59 m_allocdBytes = varChunkEnd<T>(m_allocdBytes);
64 meta->offset = m_allocdBytes;
68 # pragma GCC diagnostic push
69 # pragma GCC diagnostic ignored \
82 std::uint32_t off = 0;
85 while(off < m_allocdBytes)
88 std::uint32_t
const alignedMetaDataOffset
89 = varChunkEnd<MetaData>(off) -
static_cast<std::uint32_t
>(
sizeof(MetaData));
91 (alignedMetaDataOffset +
static_cast<std::uint32_t
>(
sizeof(MetaData))) <= m_allocdBytes);
92 auto* metaDataPtr =
reinterpret_cast<MetaData*
>(m_mem + alignedMetaDataOffset);
93 off = metaDataPtr->offset;
95 if(metaDataPtr->id ==
id)
96 return reinterpret_cast<T*
>(&m_mem[off -
sizeof(T)]);
107 return reinterpret_cast<T*
>(&m_mem[m_allocdBytes -
sizeof(T)]);
112 # pragma GCC diagnostic pop
125 auto varChunkEnd(std::uint32_t byteOffset)
const -> std::uint32_t
127 auto const ptr =
reinterpret_cast<std::size_t
>(m_mem + byteOffset);
128 constexpr
size_t align =
std::max(TMinDataAlignBytes,
alignof(T));
129 std::size_t
const newPtrAdress = ((ptr + align - 1u) / align) * align +
sizeof(T);
130 return static_cast<uint32_t
>(newPtrAdress -
reinterpret_cast<std::size_t
>(m_mem));
135 mutable std::uint32_t m_allocdBytes = 0u;
140 std::uint8_t*
const m_mem;
142 const std::uint32_t m_capacity;
#define ALPAKA_ASSERT_ACC(...)
ALPAKA_ASSERT_ACC is an assert-like macro.
Implementation of static block shared memory provider.
void alloc(std::uint32_t id) const
auto getVarPtr(std::uint32_t id) const -> T *
Give the pointer to an exiting variable.
BlockSharedMemStMemberImpl(std::uint8_t *mem, std::size_t capacity)
auto getLatestVarPtr() const -> T *
Get last allocated variable.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...