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 
10 
11 namespace cms::alpakatools {
12 
13  namespace detail {
14 
15  template <typename TPlatform, typename = std::enable_if_t<alpaka::isPlatform<TPlatform>>>
16  inline std::vector<alpaka::Dev<TPlatform>> enumerate_devices() {
17  using Platform = TPlatform;
18  using Device = alpaka::Dev<Platform>;
19 
20  std::vector<Device> devices;
21  uint32_t n = alpaka::getDevCount<Platform>();
22  devices.reserve(n);
23  for (uint32_t i = 0; i < n; ++i) {
24  devices.push_back(alpaka::getDevByIdx<Platform>(i));
25  assert(alpaka::getNativeHandle(devices.back()) == static_cast<int>(i));
26  }
27 
28  return devices;
29  }
30 
31  } // namespace detail
32 
33  // return the alpaka accelerator devices for the given platform
34  template <typename TPlatform, typename = std::enable_if_t<alpaka::isPlatform<TPlatform>>>
35  inline std::vector<alpaka::Dev<TPlatform>> const& devices() {
36  static const auto devices = detail::enumerate_devices<TPlatform>();
37  return devices;
38  }
39 
40 } // namespace cms::alpakatools
41 
42 #endif // HeterogeneousCore_AlpakaInterface_interface_devices_h
assert(be >=bs)
std::vector< alpaka::Dev< TPlatform > > enumerate_devices()
Definition: devices.h:16
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:35