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<cms::alpakatools::is_device_v<TDev> and cms::alpakatools::is_queue_v<TQueue>>>
auto allocate_device_allocators ()
 
std::string as_bytes (size_t value)
 
template<typename TPlatform , typename = std::enable_if_t<is_platform_v<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<cms::alpakatools::is_device_v<TDev> and cms::alpakatools::is_queue_v<TQueue>>>
auto cms::alpakatools::detail::allocate_device_allocators ( )

Definition at line 20 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.

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

◆ enumerate_devices()

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

Definition at line 17 of file devices.h.

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

17  {
18  using Platform = TPlatform;
19  using Device = alpaka::Dev<Platform>;
20 
21  std::vector<Device> devices;
22  uint32_t n = alpaka::getDevCount<Platform>();
23  devices.reserve(n);
24  for (uint32_t i = 0; i < n; ++i) {
25  devices.push_back(alpaka::getDevByIdx<Platform>(i));
26  assert(alpaka::getNativeHandle(devices.back()) == static_cast<int>(i));
27  }
28 
29  return devices;
30  }
assert(be >=bs)
std::vector< alpaka::Dev< TPlatform > > const & devices()
Definition: devices.h:36

◆ 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