Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:45

0001 #ifndef HeterogeneousCore_CUDACore_src_getCachingHostAllocator
0002 #define HeterogeneousCore_CUDACore_src_getCachingHostAllocator
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0006 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0007 #include "HeterogeneousCore/CUDAUtilities/interface/cachingAllocators.h"
0008 
0009 #include "CachingDeviceAllocator.h"
0010 #include "CachingHostAllocator.h"
0011 #include "cachingAllocatorCommon.h"
0012 
0013 #include <iomanip>
0014 
0015 namespace cms::cuda::allocator {
0016   inline notcub::CachingHostAllocator& getCachingHostAllocator() {
0017     LogDebug("CachingHostAllocator").log([](auto& log) {
0018       log << "cub::CachingHostAllocator settings\n"
0019           << "  bin growth " << binGrowth << "\n"
0020           << "  min bin    " << minBin << "\n"
0021           << "  max bin    " << maxBin << "\n"
0022           << "  resulting bins:\n";
0023       for (auto bin = minBin; bin <= maxBin; ++bin) {
0024         auto binSize = notcub::CachingDeviceAllocator::IntPow(binGrowth, bin);
0025         if (binSize >= (1 << 30) and binSize % (1 << 30) == 0) {
0026           log << "    " << std::setw(8) << (binSize >> 30) << " GB\n";
0027         } else if (binSize >= (1 << 20) and binSize % (1 << 20) == 0) {
0028           log << "    " << std::setw(8) << (binSize >> 20) << " MB\n";
0029         } else if (binSize >= (1 << 10) and binSize % (1 << 10) == 0) {
0030           log << "    " << std::setw(8) << (binSize >> 10) << " kB\n";
0031         } else {
0032           log << "    " << std::setw(9) << binSize << " B\n";
0033         }
0034       }
0035       log << "  maximum amount of cached memory: " << (minCachedBytes() >> 20) << " MB\n";
0036     });
0037 
0038     // the public interface is thread safe
0039     CMS_THREAD_SAFE static notcub::CachingHostAllocator allocator{binGrowth,
0040                                                                   minBin,
0041                                                                   maxBin,
0042                                                                   minCachedBytes(),
0043                                                                   false,  // do not skip cleanup
0044                                                                   debug};
0045     return allocator;
0046   }
0047 }  // namespace cms::cuda::allocator
0048 
0049 #endif