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, Tim Hanel
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
8#include "alpaka/concepts.hpp"
10#include "alpaka/tag.hpp"
11#include "alpaka/trait.hpp"
12#include "alpaka/unused.hpp"
13
14namespace alpaka
15{
16 /** Get the executor associated with an object
17 *
18 * @param any object carrying an executor, e.g. an accelerator or backend dictionary
19 * @return executor tag
20 *
21 * @{
22 */
23 inline constexpr decltype(auto) getExecutor(auto&& any)
24 {
26 }
27
28 inline constexpr decltype(auto) getExecutor(alpaka::concepts::HasGet auto&& any)
29 {
30 return alpaka::internal::getExecutor(*any.get());
31 }
32
33 /** @} */
34
35 /** Get the API an object depends on
36 *
37 * @param any can be a platform, device, queue, view
38 * @return API tag
39 *
40 * @{
41 */
42 inline constexpr decltype(auto) getApi(auto&& any)
43 {
45 }
46
47 inline constexpr decltype(auto) getApi(alpaka::concepts::HasGet auto&& any)
48 {
49 return alpaka::internal::getApi(*any.get());
50 }
51
52 namespace concepts
53 {
54 /** Concept to check if the given type implements the `getExecutor(T x)` function returning an
55 * alpaka::concepts::Executor
56 */
57 template<typename T_Any>
58 concept HasExecutor = requires(T_Any&& any) {
60 };
61 /** Concept to check if the given type implements the `getApi(T x)` function returning an alpaka::concepts::Api
62 */
63 template<typename T_Any>
64 concept HasApi = requires(T_Any&& any) {
65 { getApi(any) } -> alpaka::concepts::Api;
66 };
67 } // namespace concepts
68
69 /** @} */
70
71 /** Get the device type of an object
72 *
73 * @param any can be a platform, device, queue, view
74 * @return type from alpaka::deviceKind
75 *
76 * @{
77 */
78 inline constexpr decltype(auto) getDeviceKind(auto&& any)
79 {
81 }
82
83 inline constexpr decltype(auto) getDeviceKind(alpaka::concepts::HasGet auto&& any)
84 {
85 return alpaka::internal::getDeviceKind(*any.get());
86 }
87
88 /** @} */
89
90
91 /** Get the number of elements to compute per thread.
92 *
93 * This function considers the SIMD width for the corresponding data type and the potential for instruction
94 * parallelism.
95 *
96 * @tparam T_Type The data type used to determine the SIMD width.
97 * @return The minimum number of elements a thread should compute to achieve optimal utilization.
98 */
99 template<typename T_Type>
100 constexpr uint32_t getNumElemPerThread(auto&& any)
101 {
103 }
104
105 /** get SIMD with in bytes for the
106 *
107 * @tparam T_Type data type
108 * @return number of elements that can be processed in parallel in a vector register
109 */
110 template<typename T_Type>
111 constexpr uint32_t getArchSimdWidth(auto&& any)
112 {
114 }
115
116 /** get the number of instruction can be issued in parallel */
117 constexpr uint32_t getNumPipelines(auto&& any)
118 {
120 }
121
122 /** Get the value type alignment of an object
123 *
124 * @param any type derive the alignment from
125 * @return alignment in bytes, if not defined the alignment of the value_type will be returned
126 */
127 constexpr auto getAlignment(auto&& any)
128 {
130 }
131
132} // namespace alpaka
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:154
#define ALPAKA_FORWARD(instance)
Perfectly forward an instance as argument.
Definition common.hpp:148
Concept to check for APIs.
Definition api.hpp:42
Concept to check for an executor.
Definition trait.hpp:133
Concept to check if the given type implements the getApi(T x) function returning an alpaka::concepts:...
Definition interface.hpp:64
Concept to check if the given type implements the getExecutor(T x) function returning an alpaka::conc...
Definition interface.hpp:58
Concept to check if the given type has a get() function.
Definition concepts.hpp:26
constexpr auto getExecutor(T_Any &&any) -> decltype(GetExecutor::Op< ALPAKA_TYPEOF(any)>{}(any))
Definition interface.hpp:86
constexpr auto getDeviceKind(auto &&any) -> decltype(GetDeviceType::Op< ALPAKA_TYPEOF(any)>{}(any))
constexpr auto getAlignment(auto &&any)
constexpr auto getApi(auto &&any) -> decltype(GetApi::Op< ALPAKA_TYPEOF(any)>{}(any))
Definition interface.hpp:62
main alpaka namespace.
Definition alpaka.hpp:76
consteval uint32_t getNumPipelines(concepts::Api auto const api, alpaka::concepts::DeviceKind auto const deviceType)
Get the number of instructions that can be issued in parallel.
Definition trait.hpp:161
constexpr decltype(auto) getExecutor(auto &&any)
Get the executor associated with an object.
Definition interface.hpp:23
consteval uint32_t getNumElemPerThread(concepts::Api auto const api, alpaka::concepts::DeviceKind auto const deviceType)
Get the number of elements to compute per thread.
Definition trait.hpp:177
constexpr auto getAlignment(auto &&any)
Get the value type alignment of an object.
consteval uint32_t getArchSimdWidth(concepts::Api auto const api, alpaka::concepts::DeviceKind auto const deviceType)
Get the SIMD width in bytes for an API and device kind combination.
Definition trait.hpp:152
constexpr decltype(auto) getDeviceKind(auto &&any)
Get the device type of an object.
Definition interface.hpp:78
constexpr decltype(auto) getApi(auto &&any)
Get the API an object depends on.
Definition interface.hpp:42