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]>
 
class  IndependentGroupElementsAlong
 
class  IndependentGroupsAlong
 
class  UniformElementsAlong
 
class  UniformElementsND
 
class  UniformGroupElementsAlong
 
class  UniformGroupsAlong
 
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 (AllocatorConfig const &config, bool debug)
 
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 ( AllocatorConfig const &  config,
bool  debug 
)

Definition at line 21 of file getDeviceCachingAllocator.h.

References DDDCmsTrackerContruction::construct(), debug, cms::alpakatools::devices(), and mps_fire::i.

21  {
22  using Allocator = CachingAllocator<TDev, TQueue>;
23  auto const& devices = cms::alpakatools::devices<alpaka::Platform<TDev>>();
24  ssize_t const size = devices.size();
25 
26  // allocate the storage for the objects
27  auto ptr = std::allocator<Allocator>().allocate(size);
28 
29  // construct the objects in the storage
30  ptrdiff_t index = 0;
31  try {
32  for (; index < size; ++index) {
33 #if __cplusplus >= 202002L
34  std::construct_at(
35 #else
36  std::allocator<Allocator>().construct(
37 #endif
38  ptr + index,
39  devices[index],
40  config,
41  true, // reuseSameQueueAllocations
42  debug);
43  }
44  } catch (...) {
45  --index;
46  // destroy any object that had been succesfully constructed
47  while (index >= 0) {
48  std::destroy_at(ptr + index);
49  --index;
50  }
51  // deallocate the storage
52  std::allocator<Allocator>().deallocate(ptr, size);
53  // rethrow the exception
54  throw;
55  }
56 
57  // use a custom deleter to destroy all objects and deallocate the memory
58  auto deleter = [size](Allocator* allocators) {
59  for (size_t i = size; i > 0; --i) {
60  std::destroy_at(allocators + i - 1);
61  }
62  std::allocator<Allocator>().deallocate(allocators, size);
63  };
64 
65  return std::unique_ptr<Allocator[], decltype(deleter)>(ptr, deleter);
66  }
size
Write out results.
Definition: config.py:1
#define debug
Definition: HDRShower.cc:19
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 >= (1ul << 40) and value % (1ul << 40) == 0) {
45  return std::to_string(value >> 40) + " TiB";
46  } else if (value >= (1ul << 30) and value % (1ul << 30) == 0) {
47  return std::to_string(value >> 30) + " GiB";
48  } else if (value >= (1ul << 20) and value % (1ul << 20) == 0) {
49  return std::to_string(value >> 20) + " MiB";
50  } else if (value >= (1ul << 10) and value % (1ul << 10) == 0) {
51  return std::to_string(value >> 10) + " KiB";
52  } else {
53  return std::to_string(value) + " B";
54  }
55  }
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