alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
trait.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/utility.hpp"
9
10#include <concepts>
11#include <cstdint>
12#include <limits>
13
14namespace alpaka
15{
16 /** This type is used in cases where a template type parameter is not required and can optionally be passed to a
17 * trait or concept.
18 */
20 {
21 };
22
23 constexpr uint32_t notRequiredDim = std::numeric_limits<uint32_t>::max();
24 constexpr uint32_t notRequiredWidth = notRequiredDim;
25
26 namespace trait
27 {
28 template<typename T>
29 struct GetDim
30 {
31 static constexpr uint32_t value = T::dim();
32 };
33
34 template<std::integral T>
35 struct GetDim<T>
36 {
37 static constexpr uint32_t value = 1u;
38 };
39
40 template<typename T>
41 constexpr uint32_t getDim_v = GetDim<T>::value;
42
43 template<typename T>
45 {
46 using type = typename T::value_type;
47 };
48
49 template<typename T>
50 requires(std::is_fundamental_v<T>)
52 {
53 using type = T;
54 };
55
56 // resolve handles
57 template<typename T>
58 requires requires() { typename T::element_type; }
59 struct GetValueType<T>
60 {
62 };
63
64 template<typename T>
66
67 /** Check if a type used as kernel argument is trivially copyable
68 *
69 * @attention In case this trait is specialized for a user type, the user should be sure that the result of
70 * calling the copy constructor is equivalent to using memcpy to duplicate the object. An existing destructor
71 * must be free of side effects.
72 *
73 * It is implementation defined whether the closure type of a lambda is trivially copyable.
74 * Therefore, the default implementation is true for trivially copyable or empty (stateless) types.
75 *
76 * @tparam T type to check
77 */
78 template<typename T, typename = void>
80 : std::bool_constant<std::is_empty_v<T> || std::is_trivially_copyable_v<T>>
81 {
82 };
83
84 /** Check if the kernel type is trivially copyable
85 *
86 * @attention In case this trait is specialized for a user type, the user should be sure that the result of
87 * calling the copy constructor is equivalent to using memcpy to duplicate the object. An existing destructor
88 * must be free of side effects.
89 *
90 * The default implementation is true for trivially copyable types (or for extended lambda expressions for
91 * CUDA).
92 *
93 * @tparam T type to check
94 * @{
95 */
96 template<typename T, typename = void>
99 : std::bool_constant<
100 std::is_trivially_copyable_v<T> || __nv_is_extended_device_lambda_closure_type(T)
101 || __nv_is_extended_host_device_lambda_closure_type(T)>
102#else
103 : std::is_trivially_copyable<T>
104#endif
105 {
106 };
107 } // namespace trait
108
109 template<typename T>
111
112 template<typename T>
114
115 template<typename T>
116 [[nodiscard]] consteval uint32_t getDim([[maybe_unused]] T const& any)
117 {
118 return trait::getDim_v<T>;
119 }
120
121 template<typename T_From, typename T_To>
123
124 template<typename T_From, typename T_To>
126
127 namespace concepts
128 {
129 /** @brief Concept to check for a kernel function object
130 *
131 * @details
132 * The kernel function object must be trivially copyable.
133 */
134 template<typename T>
136
137 /** @brief Concept to check for a kernel argument object
138 *
139 * @details
140 * A kernel call requires that its arguments are trivially copyable, which this concept requires.
141 */
142 template<typename T>
144 } // namespace concepts
145} // namespace alpaka
Concept to check for a kernel argument object.
Definition trait.hpp:143
Concept to check for a kernel function object.
Definition trait.hpp:135
Concept to check if a type can be lossless converted to another type.
#define ALPAKA_LANG_CUDA
Definition config.hpp:258
#define ALPAKA_COMP_NVCC
Definition config.hpp:164
typename GetValueType< T >::type GetValueType_t
Definition trait.hpp:65
constexpr uint32_t getDim_v
Definition trait.hpp:41
main alpaka namespace.
Definition alpaka.hpp:76
constexpr uint32_t notRequiredDim
Definition trait.hpp:23
constexpr bool isLosslesslyConvertible_v
Definition trait.hpp:122
constexpr uint32_t notRequiredWidth
Definition trait.hpp:24
consteval uint32_t getDim(T const &any)
Definition trait.hpp:116
constexpr bool isKernelTriviallyCopyable_v
Definition trait.hpp:113
constexpr bool isConvertible_v
Definition trait.hpp:125
constexpr bool isKernelArgumentTriviallyCopyable_v
Definition trait.hpp:110
This type is used in cases where a template type parameter is not required and can optionally be pass...
Definition trait.hpp:20
static constexpr uint32_t value
Definition trait.hpp:37
static constexpr uint32_t value
Definition trait.hpp:31
typename T::value_type type
Definition trait.hpp:46
Check if a type used as kernel argument is trivially copyable.
Definition trait.hpp:81
Check if the kernel type is trivially copyable.
Definition trait.hpp:105