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 22 of file getDeviceCachingAllocator.h.

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

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],
41  config,
42  true, // reuseSameQueueAllocations
43  debug);
44  }
45  } catch (...) {
46  --index;
47  // destroy any object that had been succesfully constructed
48  while (index >= 0) {
49  std::destroy_at(ptr + index);
50  --index;
51  }
52  // deallocate the storage
53  std::allocator<Allocator>().deallocate(ptr, size);
54  // rethrow the exception
55  throw;
56  }
57 
58  // use a custom deleter to destroy all objects and deallocate the memory
59  auto deleter = [size](Allocator* allocators) {
60  for (size_t i = size; i > 0; --i) {
61  std::destroy_at(allocators + i - 1);
62  }
63  std::allocator<Allocator>().deallocate(allocators, size);
64  };
65 
66  return std::unique_ptr<Allocator[], decltype(deleter)>(ptr, deleter);
67  }
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