File indexing completed on 2024-04-06 12:15:45
0001 #ifndef HeterogeneousCore_CUDACore_src_cachingAllocatorCommon
0002 #define HeterogeneousCore_CUDACore_src_cachingAllocatorCommon
0003
0004 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0005 #include "HeterogeneousCore/CUDAUtilities/interface/deviceCount.h"
0006
0007 #include <algorithm>
0008 #include <limits>
0009
0010 namespace cms::cuda::allocator {
0011
0012 constexpr unsigned int binGrowth = 2;
0013
0014 constexpr unsigned int minBin = 8;
0015
0016 constexpr unsigned int maxBin = 30;
0017
0018 constexpr size_t maxCachedBytes = 0;
0019
0020 constexpr double maxCachedFraction = 0.8;
0021 constexpr bool debug = false;
0022
0023 inline size_t minCachedBytes() {
0024 size_t ret = std::numeric_limits<size_t>::max();
0025 int currentDevice;
0026 cudaCheck(cudaGetDevice(¤tDevice));
0027 const int numberOfDevices = deviceCount();
0028 for (int i = 0; i < numberOfDevices; ++i) {
0029 size_t freeMemory, totalMemory;
0030 cudaCheck(cudaSetDevice(i));
0031 cudaCheck(cudaMemGetInfo(&freeMemory, &totalMemory));
0032 ret = std::min(ret, static_cast<size_t>(maxCachedFraction * freeMemory));
0033 }
0034 cudaCheck(cudaSetDevice(currentDevice));
0035 if (maxCachedBytes > 0) {
0036 ret = std::min(ret, maxCachedBytes);
0037 }
0038 return ret;
0039 }
0040 }
0041
0042 #endif