CMS 3D CMS Logo

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;
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) {
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
static std::string to_string(const XMLCh *ch)
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