From b8d0837f4924cb88f991b367d2ffbec85e631b7f Mon Sep 17 00:00:00 2001 From: Vincenzo Innocente Date: Sun, 15 May 2022 15:54:23 +0200 Subject: [PATCH] use same deleter --- .../interface/SimplePoolAllocator.h | 6 +++--- .../CUDAUtilities/interface/cudaMemoryPool.h | 16 ++++------------ .../plugins/CAHitNtupletGeneratorKernels.cc | 3 +-- .../plugins/CAHitNtupletGeneratorKernels.cu | 3 +-- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/HeterogeneousCore/CUDAUtilities/interface/SimplePoolAllocator.h b/HeterogeneousCore/CUDAUtilities/interface/SimplePoolAllocator.h index e3f7dfa49bb8a..c80af3c60be98 100644 --- a/HeterogeneousCore/CUDAUtilities/interface/SimplePoolAllocator.h +++ b/HeterogeneousCore/CUDAUtilities/interface/SimplePoolAllocator.h @@ -126,13 +126,13 @@ template struct SimplePoolAllocatorImpl final : public SimplePoolAllocator { using Traits = T; - SimplePoolAllocatorImpl(int maxSlots) : SimplePoolAllocator(maxSlots) {} + using SimplePoolAllocator::SimplePoolAllocator; ~SimplePoolAllocatorImpl() override { garbageCollect(); - //#ifdef MEMORY_POOL_DEBUG +#ifdef MEMORY_POOL_DEBUG dumpStat(); - //#endif +#endif } Pointer doAlloc(size_t size) override { return Traits::alloc(size); } diff --git a/HeterogeneousCore/CUDAUtilities/interface/cudaMemoryPool.h b/HeterogeneousCore/CUDAUtilities/interface/cudaMemoryPool.h index 9e2d284f2716f..b99d425eca25c 100644 --- a/HeterogeneousCore/CUDAUtilities/interface/cudaMemoryPool.h +++ b/HeterogeneousCore/CUDAUtilities/interface/cudaMemoryPool.h @@ -32,17 +32,9 @@ namespace memoryPool { } struct CudaDeleterBase : public DeleterBase { - CudaDeleterBase(cudaStream_t const &stream, Where where) : DeleterBase(getPool(where)), m_stream(stream) { - // if (stream) return; - // std::cout << "0 stream???" << std::endl; - // throw std::bad_alloc(); - } + CudaDeleterBase(cudaStream_t const &stream, Where where) : DeleterBase(getPool(where)), m_stream(stream) {} - CudaDeleterBase(cudaStream_t const &stream, SimplePoolAllocator *pool) : DeleterBase(pool), m_stream(stream) { - // if (stream) return; - // std::cout << "0 stream???" << std::endl; - // throw std::bad_alloc(); - } + CudaDeleterBase(cudaStream_t const &stream, SimplePoolAllocator *pool) : DeleterBase(pool), m_stream(stream) {} ~CudaDeleterBase() override = default; @@ -57,7 +49,7 @@ namespace memoryPool { }; struct BundleDelete final : public CudaDeleterBase { - using CudaDeleterBase::CudaDeleterBase; + BundleDelete(cudaStream_t const &stream, Where where) : CudaDeleterBase(stream, where) { m_buckets.reserve(8); } ~BundleDelete() override { free(m_stream, std::move(m_buckets), *pool()); } @@ -88,7 +80,7 @@ namespace memoryPool { template Buffer makeBuffer(uint64_t size, cudaStream_t const &stream, Where where) { - return makeBuffer(size, Deleter(std::make_shared(stream, getPool(where)))); + return makeBuffer(size, Deleter(std::make_shared(stream, where))); } } // namespace cuda diff --git a/RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletGeneratorKernels.cc b/RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletGeneratorKernels.cc index f41a716d1a060..d48af27a329be 100644 --- a/RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletGeneratorKernels.cc +++ b/RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletGeneratorKernels.cc @@ -22,8 +22,7 @@ void CAHitNtupletGeneratorKernelsCPU::buildDoublets(HitsOnCPU const &hh, cudaStr #endif // use "nhits" to heuristically dimension the workspace - memoryPool::Deleter deleter = - memoryPool::Deleter(std::make_shared(nullptr, memoryPool::onCPU)); + memoryPool::Deleter const &deleter = device_storage_.deleter(); device_isOuterHitOfCell_ = memoryPool::cuda::makeBuffer(std::max(1U, nhits), deleter); assert(device_isOuterHitOfCell_.get()); diff --git a/RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletGeneratorKernels.cu b/RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletGeneratorKernels.cu index 5866f28f8721b..e29b15fc80e53 100644 --- a/RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletGeneratorKernels.cu +++ b/RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletGeneratorKernels.cu @@ -145,8 +145,7 @@ void CAHitNtupletGeneratorKernelsGPU::buildDoublets(HitsOnCPU const &hh, cudaStr #endif // in principle we can use "nhits" to heuristically dimension the workspace... - memoryPool::Deleter deleter = - memoryPool::Deleter(std::make_shared(stream, memoryPool::onDevice)); + memoryPool::Deleter const &deleter = device_storage_.deleter(); device_isOuterHitOfCell_ = memoryPool::cuda::makeBuffer(std::max(1, nhits), deleter); assert(device_isOuterHitOfCell_.get());