CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
allocate_device.cc
Go to the documentation of this file.
1 #include <limits>
2 
7 
9 
10 namespace {
11  const size_t maxAllocationSize =
13 }
14 
15 namespace cms::cuda {
16  void *allocate_device(int dev, size_t nbytes, cudaStream_t stream) {
17  void *ptr = nullptr;
18  if constexpr (allocator::useCaching) {
19  if (UNLIKELY(nbytes > maxAllocationSize)) {
20  throw std::runtime_error("Tried to allocate " + std::to_string(nbytes) +
21  " bytes, but the allocator maximum is " + std::to_string(maxAllocationSize));
22  }
23  cudaCheck(allocator::getCachingDeviceAllocator().DeviceAllocate(dev, &ptr, nbytes, stream));
24  } else {
25  ScopedSetDevice setDeviceForThisScope(dev);
26  cudaCheck(cudaMalloc(&ptr, nbytes));
27  }
28  return ptr;
29  }
30 
31  void free_device(int device, void *ptr) {
32  if constexpr (allocator::useCaching) {
33  cudaCheck(allocator::getCachingDeviceAllocator().DeviceFree(device, ptr));
34  } else {
35  ScopedSetDevice setDeviceForThisScope(device);
36  cudaCheck(cudaFree(ptr));
37  }
38  }
39 
40 } // 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 unsigned int IntPow(unsigned int base, unsigned int exp)
void free_device(int device, void *ptr)
void * allocate_device(int dev, size_t nbytes, cudaStream_t stream)
constexpr bool useCaching
notcub::CachingDeviceAllocator & getCachingDeviceAllocator()
#define UNLIKELY(x)
Definition: Likely.h:21
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
constexpr unsigned int binGrowth