CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cachingAllocatorCommon.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_CUDACore_src_cachingAllocatorCommon
2 #define HeterogeneousCore_CUDACore_src_cachingAllocatorCommon
3 
6 
7 #include <algorithm>
8 #include <limits>
9 
10 namespace cms::cuda::allocator {
11  // Growth factor (bin_growth in cub::CachingDeviceAllocator
12  constexpr unsigned int binGrowth = 2;
13  // Smallest bin, corresponds to binGrowth^minBin bytes (min_bin in cub::CacingDeviceAllocator
14  constexpr unsigned int minBin = 8;
15  // Largest bin, corresponds to binGrowth^maxBin bytes (max_bin in cub::CachingDeviceAllocator). Note that unlike in cub, allocations larger than binGrowth^maxBin are set to fail.
16  constexpr unsigned int maxBin = 30;
17  // Total storage for the allocator. 0 means no limit.
18  constexpr size_t maxCachedBytes = 0;
19  // Fraction of total device memory taken for the allocator. In case there are multiple devices with different amounts of memory, the smallest of them is taken. If maxCachedBytes is non-zero, the smallest of them is taken.
20  constexpr double maxCachedFraction = 0.8;
21  constexpr bool debug = false;
22 
23  inline size_t minCachedBytes() {
25  int currentDevice;
26  cudaCheck(cudaGetDevice(&currentDevice));
27  const int numberOfDevices = deviceCount();
28  for (int i = 0; i < numberOfDevices; ++i) {
29  size_t freeMemory, totalMemory;
30  cudaCheck(cudaSetDevice(i));
31  cudaCheck(cudaMemGetInfo(&freeMemory, &totalMemory));
32  ret = std::min(ret, static_cast<size_t>(maxCachedFraction * freeMemory));
33  }
34  cudaCheck(cudaSetDevice(currentDevice));
35  if (maxCachedBytes > 0) {
36  ret = std::min(ret, maxCachedBytes);
37  }
38  return ret;
39  }
40 } // namespace cms::cuda::allocator
41 
42 #endif
int deviceCount()
Definition: deviceCount.h:10
tuple ret
prodAgent to be discontinued
constexpr unsigned int maxBin
constexpr size_t maxCachedBytes
T min(T a, T b)
Definition: MathUtil.h:58
int numberOfDevices()
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
constexpr unsigned int binGrowth
int currentDevice()
Definition: currentDevice.h:10
constexpr unsigned int minBin
constexpr double maxCachedFraction