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;
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
Likely.h
cms::cuda
Definition: Product.h:14
allocate_host.h
cms::cuda::allocator::useCaching
constexpr bool useCaching
Definition: getCachingDeviceAllocator.h:14
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
cms::cuda::allocate_host
void * allocate_host(size_t nbytes, cudaStream_t stream)
Definition: allocate_host.cc:15
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
notcub::CachingDeviceAllocator::IntPow
static unsigned int IntPow(unsigned int base, unsigned int exp)
Definition: CachingDeviceAllocator.h:211
getCachingHostAllocator.h
cms::cuda::allocator::maxBin
constexpr unsigned int maxBin
Definition: getCachingDeviceAllocator.h:20
cudaCheck.h
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:62
cms::cuda::allocator::getCachingHostAllocator
notcub::CachingHostAllocator & getCachingHostAllocator()
Definition: getCachingHostAllocator.h:14
cms::cuda::allocator::binGrowth
constexpr unsigned int binGrowth
Definition: getCachingDeviceAllocator.h:16
cms::cuda::free_host
void free_host(void *ptr)
Definition: allocate_host.cc:29