/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
HeterogeneousCore/CUDAUtilities/src/StreamCache.cc
44 строки
2 KB
Andrea Bocci
Rename GPU check macros to uppercase
24 июл 2026, 18:36
Не верифицирован
24 июл 2026, 18:36
4ca8016
Код
Авторство
О чём код?
#include "FWCore/Utilities/interface/thread_safety_macros.h" #include "HeterogeneousCore/CUDAUtilities/interface/StreamCache.h" #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h" #include "HeterogeneousCore/CUDAUtilities/interface/currentDevice.h" #include "HeterogeneousCore/CUDAUtilities/interface/deviceCount.h" #include "HeterogeneousCore/CUDAUtilities/interface/ScopedSetDevice.h" namespace cms::cuda { void StreamCache::Deleter::operator()(cudaStream_t stream) const { if (device_ != -1) { ScopedSetDevice deviceGuard{device_}; CUDA_CHECK(cudaStreamDestroy(stream)); } } // StreamCache should be constructed by the first call to // getStreamCache() only if we have CUDA devices present StreamCache::StreamCache() : cache_(deviceCount()) {} SharedStreamPtr StreamCache::get() { const auto dev = currentDevice(); return cache_[dev].makeOrGet([dev]() { cudaStream_t stream; CUDA_CHECK(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking)); return std::unique_ptr<BareStream, Deleter>(stream, Deleter{dev}); }); } void StreamCache::clear() { // Reset the contents of the caches, but leave an // edm::ReusableObjectHolder alive for each device. This is needed // mostly for the unit tests, where the function-static // StreamCache lives through multiple tests (and go through // multiple shutdowns of the framework). cache_.clear(); cache_.resize(deviceCount()); } StreamCache& getStreamCache() { // the public interface is thread safe CMS_THREAD_SAFE static StreamCache cache; return cache; } } // namespace cms::cuda