alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
interface.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
6
7#include "alpaka/CVec.hpp"
8#include "alpaka/UniqueId.hpp"
9#include "alpaka/Vec.hpp"
11#include "alpaka/onAcc/tag.hpp"
12#include "alpaka/tag.hpp"
13
14namespace alpaka::onAcc
15{
16 namespace internalCompute
17 {
18 struct Sync
19 {
20 template<typename T_Acc, alpaka::concepts::Layer T_Scope>
21 struct Op
22 {
23 constexpr auto operator()(T_Acc const& acc, T_Scope const scope) const;
24 };
25 };
26
27 constexpr void sync(auto const& acc, alpaka::concepts::Layer auto const scope)
28 {
29 Sync::Op<ALPAKA_TYPEOF(acc), ALPAKA_TYPEOF(scope)>{}(acc, scope);
30 }
31
32 struct SharedMemory
33 {
34 template<typename T, size_t T_uniqueId, typename T_Acc>
35 struct Static
36 {
37 constexpr decltype(auto) operator()(auto const& acc) const
38 {
39 return acc[layer::shared].template allocVar<T, T_uniqueId>();
40 }
41 };
42
43 template<typename T, typename T_Acc>
44 struct Dynamic
45 {
46 constexpr auto operator()(auto const& acc) const -> T*
47 {
48 static_assert(
49 T_Acc::hasKey(object::dynSharedMemBytes),
50 "Dynamic shared memory not configured. Add member 'dynSharedMemBytes' to the kernel or "
51 "specialize 'onHost::trait:BlockDynSharedMemBytes'!");
52 uint32_t numBytes = acc[object::dynSharedMemBytes];
53 return acc[layer::dynShared].template allocDynamic<T, uniqueId()>(numBytes);
54 }
55 };
56 };
57
58 template<typename T, size_t T_uniqueId>
59 constexpr decltype(auto) declareSharedVar(auto const& acc)
60 {
61 return SharedMemory::Static<T, T_uniqueId, std::decay_t<decltype(acc)>>{}(acc);
62 }
63
64 template<typename T>
65 constexpr auto declareDynamicSharedMem(auto const& acc) -> T*
66 {
67 return SharedMemory::Dynamic<T, std::decay_t<decltype(acc)>>{}(acc);
68 }
69
70 struct Atomic
71 {
72 /** Implements a atomic operation */
73 template<typename TOp, typename TAtomicImpl, typename T, typename T_Scope, typename TSfinae = void>
74 struct Op;
75 };
76
77 /** Get the index of an object within a layer in the selected units*/
78 struct GetIdxWithin
79 {
80 template<typename T_Acc, typename T_Origin, typename T_Unit>
81 struct Op
82 {
83 constexpr alpaka::concepts::Vector auto operator()(T_Acc const& acc, T_Origin origin, T_Unit unit)
84 const;
85 };
86 };
87
88 /** Get the number of elments in a layer in the selected units*/
89 struct GetExtentsOf
90 {
91 template<typename T_Acc, typename T_Origin, typename T_Unit>
92 struct Op
93 {
94 constexpr alpaka::concepts::Vector auto operator()(T_Acc const& acc, T_Origin origin, T_Unit unit)
95 const;
96 };
97 };
98
99 struct MemoryFence
100 {
101 // Backend specializations provide the definition.
102 template<typename T_Acc, typename T_MemoryOrder, typename T_Scope>
103 struct Op
104 {
105 constexpr void operator()(T_Acc const& acc, T_MemoryOrder const order, T_Scope const scope) const;
106 };
107 };
108 } // namespace internalCompute
109} // namespace alpaka::onAcc
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:153
functionality which is usable on the accelerator compute device from within a kernel.
Definition executor.hpp:38
auto scope(concepts::Level auto logLvl, std::source_location const &location=std::source_location::current())
Log the entry and exit of a scope.
Definition logger.hpp:24