alpaka
Abstraction Library for Parallel Kernel Acceleration
Traits.hpp
Go to the documentation of this file.
1 /* Copyright 2024 Benjamin Worpitz, Bernhard Manfred Gruber, Jan Stephan, Andrea Bocci
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/core/Common.hpp"
9 
10 #include <algorithm>
11 #include <cctype>
12 #include <cstddef>
13 #include <string>
14 #include <vector>
15 
16 namespace alpaka
17 {
18  //! The device traits.
19  namespace trait
20  {
21  //! The device type trait.
22  template<typename T, typename TSfinae = void>
23  struct DevType;
24 
25  //! The device get trait.
26  template<typename T, typename TSfinae = void>
27  struct GetDev;
28 
29  //! The device name get trait.
30  template<typename TDev, typename TSfinae = void>
31  struct GetName;
32 
33  //! The device memory size get trait.
34  template<typename TDev, typename TSfinae = void>
35  struct GetMemBytes;
36 
37  //! The device free memory size get trait.
38  template<typename T, typename TSfinae = void>
40 
41  //! The device warp size get trait.
42  template<typename T, typename TSfinae = void>
43  struct GetWarpSizes;
44 
45  //! The device preferred warp size get trait.
46  template<typename T, typename TSfinae = void>
48 
49  //! The device reset trait.
50  template<typename T, typename TSfinae = void>
51  struct Reset;
52  } // namespace trait
53 
54  //! The device type trait alias template to remove the ::type.
55  template<typename T>
56  using Dev = typename trait::DevType<T>::type;
57 
58  struct ConceptGetDev;
59 
60  struct ConceptDev;
61 
62  //! True if TDev is a device, i.e. if it implements the ConceptDev concept.
63  template<typename TDev>
65 
66  //! \return The device this object is bound to.
67  template<typename T>
68  ALPAKA_FN_HOST auto getDev(T const& t)
69  {
72  }
73 
74  namespace detail
75  {
76  inline auto trim(std::string s) -> std::string
77  {
78  auto const pred = [](char c) { return !std::isspace(c); };
79  s.erase(std::find_if(rbegin(s), rend(s), pred).base(), end(s));
80  s.erase(begin(s), std::find_if(begin(s), end(s), pred));
81  return s;
82  }
83  } // namespace detail
84 
85  //! \return The device name with leading/trailing space characters trimmed off.
86  template<typename TDev>
87  ALPAKA_FN_HOST auto getName(TDev const& dev) -> std::string
88  {
90  }
91 
92  //! \return The memory on the device in Bytes. Returns 0 if querying memory
93  //! is not supported.
94  template<typename TDev>
95  ALPAKA_FN_HOST auto getMemBytes(TDev const& dev) -> std::size_t
96  {
98  }
99 
100  //! \return The free memory on the device in Bytes.
101  //
102  //! \note Do not use this query if getMemBytes returned 0.
103  template<typename TDev>
104  ALPAKA_FN_HOST auto getFreeMemBytes(TDev const& dev) -> std::size_t
105  {
107  }
108 
109  //! \return The supported warp sizes on the device in number of threads.
110  template<typename TDev>
111  ALPAKA_FN_HOST auto getWarpSizes(TDev const& dev) -> std::vector<std::size_t>
112  {
114  }
115 
116  //! \return The preferred warp size on the device in number of threads.
117  template<typename TDev>
118  ALPAKA_FN_HOST constexpr auto getPreferredWarpSize(TDev const& dev) -> std::size_t
119  {
121  }
122 
123  //! Resets the device.
124  //! What this method does is dependent on the accelerator.
125  template<typename TDev>
126  ALPAKA_FN_HOST auto reset(TDev const& dev) -> void
127  {
129  }
130 
131  namespace trait
132  {
133  //! Get device type
134  template<typename TDev>
135  struct DevType<TDev, std::enable_if_t<interface::ImplementsInterface<ConceptDev, TDev>::value>>
136  {
138  };
139  } // namespace trait
140 } // namespace alpaka
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
auto trim(std::string s) -> std::string
Definition: Traits.hpp:76
typename detail::ImplementationBaseType< TInterface, TDerived >::type ImplementationBase
Returns the type that implements the given interface in the inheritance hierarchy.
Definition: Interface.hpp:66
ALPAKA_FN_HOST auto end(TView &view) -> Iterator< TView >
Definition: Iterator.hpp:139
ALPAKA_FN_HOST auto begin(TView &view) -> Iterator< TView >
Definition: Iterator.hpp:133
The alpaka accelerator library.
ALPAKA_FN_HOST auto getName(TDev const &dev) -> std::string
Definition: Traits.hpp:87
typename trait::DevType< T >::type Dev
The device type trait alias template to remove the ::type.
Definition: Traits.hpp:56
ALPAKA_FN_HOST auto getWarpSizes(TDev const &dev) -> std::vector< std::size_t >
Definition: Traits.hpp:111
ALPAKA_FN_HOST auto reset(TDev const &dev) -> void
Resets the device. What this method does is dependent on the accelerator.
Definition: Traits.hpp:126
ALPAKA_FN_HOST auto getFreeMemBytes(TDev const &dev) -> std::size_t
Definition: Traits.hpp:104
ALPAKA_FN_HOST auto getMemBytes(TDev const &dev) -> std::size_t
Definition: Traits.hpp:95
constexpr ALPAKA_FN_HOST auto getPreferredWarpSize(TDev const &dev) -> std::size_t
Definition: Traits.hpp:118
ALPAKA_FN_HOST auto getDev(T const &t)
Definition: Traits.hpp:68
constexpr bool isDevice
True if TDev is a device, i.e. if it implements the ConceptDev concept.
Definition: Traits.hpp:64
Checks whether the interface is implemented by the given class.
Definition: Interface.hpp:21
The device type trait.
Definition: Traits.hpp:23
The device get trait.
Definition: Traits.hpp:27
The device free memory size get trait.
Definition: Traits.hpp:39
The device memory size get trait.
Definition: Traits.hpp:35
The device name get trait.
Definition: Traits.hpp:31
The device preferred warp size get trait.
Definition: Traits.hpp:47
The device warp size get trait.
Definition: Traits.hpp:43
The device reset trait.
Definition: Traits.hpp:51