alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
OmpStaticShared.hpp
Go to the documentation of this file.
1/* Copyright 2024 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
8
9#if ALPAKA_OMP
10
11namespace alpaka::onAcc
12{
13 namespace cpu
14 {
15 template<std::size_t TDataAlignBytes>
16 struct OmpStaticShared : private detail::SharedStorage<TDataAlignBytes>
17 {
18 template<typename T, size_t T_unique>
19 T& allocVar()
20 {
21 using Base = detail::SharedStorage<TDataAlignBytes>;
22
23 auto* data = Base::template getVarPtr<T>(T_unique);
24
25 if(!data)
26 {
27 // Assure that all threads have executed the return of the last allocBlockSharedArr function (if
28 // there was one before).
29# pragma omp barrier
30# pragma omp single nowait
31 {
32 Base::template alloc<T>(T_unique);
33 }
34
35# pragma omp barrier
36 // lookup for the data chunk allocated by the master thread
37 data = Base::template getLatestVarPtr<T>();
38 }
39 ALPAKA_ASSERT(data != nullptr);
40 return *data;
41 }
42
43 template<typename T, size_t T_unique>
44 T* allocDynamic(uint32_t numBytes)
45 {
46 using Base = detail::SharedStorage<TDataAlignBytes>;
47
48 auto* data = Base::template getVarPtr<T>(T_unique);
49
50 if(!data)
51 {
52 // Assure that all threads have executed the return of the last allocBlockSharedArr function (if
53 // there was one before).
54# pragma omp barrier
55# pragma omp single nowait
56 {
57 Base::template allocDynamic<T>(T_unique, numBytes);
58 }
59
60# pragma omp barrier
61 // lookup for the data chunk allocated by the master thread
62 data = Base::template getLatestVarPtr<T>();
63 }
64 ALPAKA_ASSERT(data != nullptr);
65 return data;
66 }
67
68 void reset()
69 {
70 }
71 };
72 } // namespace cpu
73} // namespace alpaka::onAcc
74
75#endif
#define ALPAKA_ASSERT(...)
The assert can be explicit disabled by defining NDEBUG.
Definition Assert.hpp:14
functionality which is usable on the accelerator compute device from within a kernel.
Definition executor.hpp:38
decltype(auto) data(auto &&any)
pointer to data of an object