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
8#include "alpaka/Vec.hpp"
13
14namespace alpaka
15{
16 /** alpaka internal implementations.
17 *
18 * @attention do not use any functions from this namespace in our user applications.
19 * The interface can change at any time without further notice and is for internal use only.
20 */
21 namespace internal
22 {
23 struct GetStaticName
24 {
25 template<typename T_Any>
26 struct Op
27 {
28 auto operator()([[maybe_unused]] T_Any const& any) const
29 {
30 if constexpr(requires { T_Any::getName(); })
31 return T_Any::getName();
32 else
33 return onHost::demangledName(any);
34 }
35 };
36 };
37
38 struct GetName
39 {
40 template<typename T_Any>
41 struct Op
42 {
43 auto operator()(T_Any const& any) const
44 {
45 return any.getName();
46 }
47 };
48 };
49
50 struct GetApi
51 {
52 template<typename T_Any>
53 struct Op
54 {
55 inline constexpr auto operator()(auto&& any) const
56 {
57 return any.getApi();
58 }
59 };
60 };
61
62 inline constexpr auto getApi(auto&& any)
63 {
64 return GetApi::Op<std::decay_t<decltype(any)>>{}(any);
65 }
66
67 template<typename T_Any>
68 inline constexpr auto getApi(onHost::Handle<T_Any>&& anyHandle)
69 {
70 return GetApi::Op<ALPAKA_TYPEOF(*anyHandle.get())>{}(*anyHandle.get());
71 }
72
73 struct GetDeviceType
74 {
75 template<typename T_Any>
76 struct Op
77 {
78 inline constexpr auto operator()(auto&& any) const
79 {
80 return any.getDeviceKind();
81 }
82 };
83 };
84
85 inline constexpr auto getDeviceKind(auto&& any)
86 {
87 return GetDeviceType::Op<std::decay_t<decltype(any)>>{}(any);
88 }
89
90 struct GetAlignment
91 {
92 template<typename T_Any>
93 struct Op
94 {
95 constexpr auto operator()(auto&& any) const requires requires { any.getAlignment(); }
96 {
97 return any.getAlignment();
98 }
99
100 constexpr auto operator()(auto&& any) const
101 {
102 alpaka::unused(any);
103 return Alignment<>{};
104 }
105 };
106 };
107
108 constexpr auto getAlignment(auto&& any)
109 {
110 return GetAlignment::Op<std::decay_t<decltype(any)>>{}(any);
111 }
112
113 /** Load data from a data source as SIMD vector
114 *
115 * A data source is not required to have physical stored data, it can also be a generator, therefore only the
116 * data source knows how load create aSIMD vector.
117 */
118 struct LoadAsSimd
119 {
120 template<typename T_AnyDataSource, alpaka::concepts::Alignment T_Alignment, alpaka::concepts::Vector T_Idx>
121 struct Op
122 {
123 /** Get data as SIMD vector
124 *
125 * @see loadAsSimd for more details.
126 */
127 template<uint32_t T_simdWidth>
128 constexpr auto load(auto&& anyDataSource, T_Alignment dataAlignment, T_Idx const& index) const;
129 };
130 };
131
132 /** Get data as SIMD vector
133 *
134 * Load T_simdWidth contiguous data staring from index. The data is contiguous in the fast moving dimension of
135 * index.
136 *
137 * @tparam T_simdWidth number of elements in the SIMD vector
138 * @param anyDataSource data source to load data from
139 * @param dataAlignment Alignment of the data source resulting SIMD vector. This can be smaller or equal
140 * compared to the data source alignment due to possible offsets applied before.
141 * @param index Offset index relative to the first element of data source.
142 * @return SIMD vector with data loaded from the data source, aligned to dataAlignment
143 */
144 template<uint32_t T_simdWidth>
145 constexpr auto loadAsSimd(auto&& anyDataSource, auto dataAlignment, auto const& index)
146 {
147 return LoadAsSimd::Op<ALPAKA_TYPEOF(anyDataSource), ALPAKA_TYPEOF(dataAlignment), ALPAKA_TYPEOF(index)>{}
148 .template load<T_simdWidth>(ALPAKA_FORWARD(anyDataSource), dataAlignment, index);
149 }
150 } // namespace internal
151} // namespace alpaka
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:153
#define ALPAKA_FORWARD(instance)
Perfectly forward an instance as argument.
Definition common.hpp:147
use source_location to derive the demangled type name based on: https://www.reddit....
constexpr bool any(alpaka::onAcc::concepts::Acc auto const &acc, int32_t predicate)
Evaluates predicate for all active threads of the warp.
Definition warp.hpp:83
std::shared_ptr< T > Handle
Definition Handle.hpp:30
constexpr auto demangledName()
main alpaka namespace.
Definition alpaka.hpp:76