alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
concepts.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
14#include "alpaka/tag.hpp"
15
16#include <concepts>
17
18namespace alpaka
19{
20 namespace concepts
21 {
22 /** @brief Concept to check if the given type has a `get()` function.
23 */
24 template<typename T>
25 concept HasGet = requires(T t) { t.get(); };
26
27 /** @brief Concept to check if the given type has a static `dim()` function
28 */
29 template<typename T>
30 concept HasStaticDim = requires(T t) { T::dim(); };
31
32 /** @brief Concept to check if the given type is of the given dimensionality
33 *
34 * @details
35 * The checked type must also fulfill HasStaticDim.
36 *
37 * @tparam T The type to check
38 * @tparam T_dim The dimension the checked type should have
39 */
40 template<typename T, unsigned int T_dim>
41 concept Dim = (T::dim() == T_dim);
42
43 /** @brief Concept to check if the given type is a GPU DeviceKind
44 */
45 template<typename T>
46 concept GpuType
49
50 /** @brief Concept to check if the given type is a pointer, using std::is_pointer
51 */
52 template<typename T>
53 concept Pointer = std::is_pointer_v<T>;
54
55 /** @brief Concept to check that a device specification with an API and device kind can be extracted. */
56 template<typename T>
57 concept DeviceSpec = requires(T t) {
58 { internal::getApi(t) } -> alpaka::concepts::Api;
59 { internal::getDeviceKind(t) } -> alpaka::concepts::DeviceKind;
60 };
61 } // namespace concepts
62
63 namespace internal
64 {
65 template<alpaka::concepts::Api T_Api>
66 struct GetApi::Op<T_Api>
67 {
68 inline constexpr auto operator()(auto&& api) const
69 {
70 return api;
71 }
72 };
73 } // namespace internal
74} // namespace alpaka
Concept to check for APIs.
Definition api.hpp:42
Concept to check if something is a device kind.
Definition tag.hpp:147
Concept to check that a device specification with an API and device kind can be extracted.
Definition concepts.hpp:57
Concept to check if the given type is of the given dimensionality.
Definition concepts.hpp:41
Concept to check if the given type is a GPU DeviceKind.
Definition concepts.hpp:47
Concept to check if the given type has a get() function.
Definition concepts.hpp:25
Concept to check if the given type has a static dim() function.
Definition concepts.hpp:30
Concept to check if the given type is a pointer, using std::is_pointer.
Definition concepts.hpp:53
constexpr auto intelGpu
Definition tag.hpp:210
constexpr auto amdGpu
Definition tag.hpp:190
constexpr auto nvidiaGpu
Definition tag.hpp:200
main alpaka namespace.
Definition alpaka.hpp:76