/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
HeterogeneousCore/CUDAUtilities/src/allocate_device.cc
40 строк
1 KB
Andrea Bocci
Rename GPU check macros to uppercase
24 июл 2026, 18:36
Не верифицирован
24 июл 2026, 18:36
4ca8016
Код
Авторство
О чём код?
#include <limits> #include "FWCore/Utilities/interface/Likely.h" #include "HeterogeneousCore/CUDAUtilities/interface/ScopedSetDevice.h" #include "HeterogeneousCore/CUDAUtilities/interface/allocate_device.h" #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h" #include "getCachingDeviceAllocator.h" namespace { const size_t maxAllocationSize = notcub::CachingDeviceAllocator::IntPow(cms::cuda::allocator::binGrowth, cms::cuda::allocator::maxBin); } namespace cms::cuda { void *allocate_device(int dev, size_t nbytes, cudaStream_t stream) { void *ptr = nullptr; if constexpr (allocator::useCaching) { if (UNLIKELY(nbytes > maxAllocationSize)) { throw std::runtime_error("Tried to allocate " + std::to_string(nbytes) + " bytes, but the allocator maximum is " + std::to_string(maxAllocationSize)); } CUDA_CHECK(allocator::getCachingDeviceAllocator().DeviceAllocate(dev, &ptr, nbytes, stream)); } else { ScopedSetDevice setDeviceForThisScope(dev); CUDA_CHECK(cudaMalloc(&ptr, nbytes)); } return ptr; } void free_device(int device, void *ptr) { if constexpr (allocator::useCaching) { CUDA_CHECK(allocator::getCachingDeviceAllocator().DeviceFree(device, ptr)); } else { ScopedSetDevice setDeviceForThisScope(device); CUDA_CHECK(cudaFree(ptr)); } } } // namespace cms::cuda