CMS 3D CMS Logo

devices.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaInterface_interface_devices_h
2 #define HeterogeneousCore_AlpakaInterface_interface_devices_h
3 
4 #include <cassert>
5 #include <vector>
6 
7 #include <alpaka/alpaka.hpp>
8 
11 
12 namespace cms::alpakatools {
13 
14  namespace detail {
15 
16  template <typename TPlatform, typename = std::enable_if_t<is_platform_v<TPlatform>>>
17  inline std::vector<alpaka::Dev<TPlatform>> enumerate_devices() {
18  using Platform = TPlatform;
19  using Device = alpaka::Dev<Platform>;
20 
21  std::vector<Device> devices;
22  uint32_t n = alpaka::getDevCount<Platform>();
23  devices.reserve(n);
24  for (uint32_t i = 0; i < n; ++i) {
25  devices.push_back(alpaka::getDevByIdx<Platform>(i));
26  assert(alpaka::getNativeHandle(devices.back()) == static_cast<int>(i));
27  }
28 
29  return devices;
30  }
31 
32  } // namespace detail
33 
34  // return the alpaka accelerator devices for the given platform
35  template <typename TPlatform, typename = std::enable_if_t<is_platform_v<TPlatform>>>
36  inline std::vector<alpaka::Dev<TPlatform>> const& devices() {
37  static const auto devices = detail::enumerate_devices<TPlatform>();
38  return devices;
39  }
40 
41 } // namespace cms::alpakatools
42 
43 #endif // HeterogeneousCore_AlpakaInterface_interface_devices_h
assert(be >=bs)
std::vector< alpaka::Dev< TPlatform > > enumerate_devices()
Definition: devices.h:17
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:36