CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
allocate_host.cc
Go to the documentation of this file.
1 #include <limits>
2 
6 
8 
9 namespace {
10  const size_t maxAllocationSize =
12 }
13 
14 namespace cms::cuda {
15  void *allocate_host(size_t nbytes, cudaStream_t stream) {
16  void *ptr = nullptr;
17  if constexpr (allocator::useCaching) {
18  if (UNLIKELY(nbytes > maxAllocationSize)) {
19  throw std::runtime_error("Tried to allocate " + std::to_string(nbytes) +
20  " bytes, but the allocator maximum is " + std::to_string(maxAllocationSize));
21  }
22  cudaCheck(allocator::getCachingHostAllocator().HostAllocate(&ptr, nbytes, stream));
23  } else {
24  cudaCheck(cudaMallocHost(&ptr, nbytes));
25  }
26  return ptr;
27  }
28 
29  void free_host(void *ptr) {
30  if constexpr (allocator::useCaching) {
32  } else {
33  cudaCheck(cudaFreeHost(ptr));
34  }
35  }
36 
37 } // namespace cms::cuda
constexpr unsigned int maxBin
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
void free_host(void *ptr)
static unsigned int IntPow(unsigned int base, unsigned int exp)
notcub::CachingHostAllocator & getCachingHostAllocator()
constexpr bool useCaching
void * allocate_host(size_t nbytes, cudaStream_t stream)
#define UNLIKELY(x)
Definition: Likely.h:21
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
constexpr unsigned int binGrowth