CMS 3D CMS Logo

Classes | Functions
cms::alpakatools::detail Namespace Reference

Classes

struct  buffer_type
 
struct  buffer_type< TDev, T[]>
 
struct  buffer_type< TDev, T[N]>
 
struct  view_type
 
struct  view_type< TDev, T[]>
 
struct  view_type< TDev, T[N]>
 

Functions

template<typename TDev , typename TQueue , typename = std::enable_if_t<alpaka::isDevice<TDev> and alpaka::isQueue<TQueue>>>
auto allocate_device_allocators ()
 
std::string as_bytes (size_t value)
 
template<typename TPlatform , typename = std::enable_if_t<alpaka::isPlatform<TPlatform>>>
std::vector< alpaka::Dev< TPlatform > > enumerate_devices ()
 
alpaka::DevCpu enumerate_host ()
 
constexpr unsigned int power (unsigned int base, unsigned int exponent)
 

Function Documentation

◆ allocate_device_allocators()

template<typename TDev , typename TQueue , typename = std::enable_if_t<alpaka::isDevice<TDev> and alpaka::isQueue<TQueue>>>
auto cms::alpakatools::detail::allocate_device_allocators ( )

Definition at line 22 of file getDeviceCachingAllocator.h.

References cms::alpakatools::config::binGrowth, DDDCmsTrackerContruction::construct(), cms::alpakatools::devices(), mps_fire::i, cms::alpakatools::config::maxBin, cms::alpakatools::config::maxCachedBytes, cms::alpakatools::config::maxCachedFraction, cms::alpakatools::config::minBin, and findQualityFiles::size.

22  {
23  using Allocator = CachingAllocator<TDev, TQueue>;
24  auto const& devices = cms::alpakatools::devices<alpaka::Pltf<TDev>>();
25  ssize_t const size = devices.size();
26 
27  // allocate the storage for the objects
28  auto ptr = std::allocator<Allocator>().allocate(size);
29 
30  // construct the objects in the storage
31  ptrdiff_t index = 0;
32  try {
33  for (; index < size; ++index) {
34 #if __cplusplus >= 202002L
35  std::construct_at(
36 #else
37  std::allocator<Allocator>().construct(
38 #endif
39  ptr + index,
40  devices[index],
46  true, // reuseSameQueueAllocations
47  false); // debug
48  }
49  } catch (...) {
50  --index;
51  // destroy any object that had been succesfully constructed
52  while (index >= 0) {
53  std::destroy_at(ptr + index);
54  --index;
55  }
56  // deallocate the storage
57  std::allocator<Allocator>().deallocate(ptr, size);
58  // rethrow the exception
59  throw;
60  }
61 
62  // use a custom deleter to destroy all objects and deallocate the memory
63  auto deleter = [size](Allocator* ptr) {
64  for (size_t i = size; i > 0; --i) {
65  std::destroy_at(ptr + i - 1);
66  }
67  std::allocator<Allocator>().deallocate(ptr, size);
68  };
69 
70  return std::unique_ptr<Allocator[], decltype(deleter)>(ptr, deleter);
71  }
size
Write out results.
constexpr unsigned int minBin
constexpr unsigned int maxBin
constexpr double maxCachedFraction
constexpr size_t maxCachedBytes
constexpr unsigned int binGrowth
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:35
std::unique_ptr< GeometricDet > construct(DDCompactView const &cpv, std::vector< int > const &detidShifts)

◆ as_bytes()

std::string cms::alpakatools::detail::as_bytes ( size_t  value)
inline

Definition at line 40 of file CachingAllocator.h.

References SiStripPI::max, and cond::impl::to_string().

Referenced by cms::alpakatools::CachingAllocator< TDev, TQueue >::CachingAllocator().

40  {
42  return "unlimited";
43  } else if (value >= (1 << 30) and value % (1 << 30) == 0) {
44  return std::to_string(value >> 30) + " GB";
45  } else if (value >= (1 << 20) and value % (1 << 20) == 0) {
46  return std::to_string(value >> 20) + " MB";
47  } else if (value >= (1 << 10) and value % (1 << 10) == 0) {
48  return std::to_string(value >> 10) + " kB";
49  } else {
50  return std::to_string(value) + " B";
51  }
52  }
std::string to_string(const V &value)
Definition: OMSAccess.h:77
Definition: value.py:1

◆ enumerate_devices()

template<typename TPlatform , typename = std::enable_if_t<alpaka::isPlatform<TPlatform>>>
std::vector<alpaka::Dev<TPlatform> > cms::alpakatools::detail::enumerate_devices ( )
inline

Definition at line 16 of file devices.h.

References cms::cuda::assert(), cms::alpakatools::devices(), mps_fire::i, and dqmiodumpmetadata::n.

16  {
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  }
assert(be >=bs)
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:35

◆ enumerate_host()

alpaka::DevCpu cms::alpakatools::detail::enumerate_host ( )
inline

Definition at line 10 of file host.h.

References cms::cuda::assert(), and cms::alpakatools::host().

Referenced by cms::alpakatools::host().

10  {
11  using Platform = alpaka::PltfCpu;
12  using Host = alpaka::DevCpu;
13 
14  assert(alpaka::getDevCount<Platform>() == 1);
15  Host host = alpaka::getDevByIdx<Platform>(0);
16  assert(alpaka::getNativeHandle(host) == 0);
17 
18  return host;
19  }
assert(be >=bs)
alpaka::DevCpu const & host()
Definition: host.h:24

◆ power()

constexpr unsigned int cms::alpakatools::detail::power ( unsigned int  base,
unsigned int  exponent 
)
inline