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)
 
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, and cms::alpakatools::config::minBin.

22  {
23  using Allocator = CachingAllocator<TDev, TQueue>;
24  auto const& devices = cms::alpakatools::devices<alpaka::Platform<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:22
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 41 of file CachingAllocator.h.

References SiStripPI::max, and to_string().

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

41  {
43  return "unlimited";
44  } else if (value >= (1 << 30) and value % (1 << 30) == 0) {
45  return std::to_string(value >> 30) + " GB";
46  } else if (value >= (1 << 20) and value % (1 << 20) == 0) {
47  return std::to_string(value >> 20) + " MB";
48  } else if (value >= (1 << 10) and value % (1 << 10) == 0) {
49  return std::to_string(value >> 10) + " kB";
50  } else {
51  return std::to_string(value) + " B";
52  }
53  }
static std::string to_string(const XMLCh *ch)
Definition: value.py:1

◆ power()

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