Skip to content

Commit

Permalink
use same deleter
Browse files Browse the repository at this point in the history
  • Loading branch information
VinInn committed May 15, 2022
1 parent e2d5802 commit b8d0837
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ template <typename T>
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); }
Expand Down
16 changes: 4 additions & 12 deletions HeterogeneousCore/CUDAUtilities/interface/cudaMemoryPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()); }

Expand Down Expand Up @@ -88,7 +80,7 @@ namespace memoryPool {

template <typename T>
Buffer<T> makeBuffer(uint64_t size, cudaStream_t const &stream, Where where) {
return makeBuffer<T>(size, Deleter(std::make_shared<DeleteOne>(stream, getPool(where))));
return makeBuffer<T>(size, Deleter(std::make_shared<DeleteOne>(stream, where)));
}

} // namespace cuda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<memoryPool::cuda::BundleDelete>(nullptr, memoryPool::onCPU));
memoryPool::Deleter const &deleter = device_storage_.deleter();
device_isOuterHitOfCell_ =
memoryPool::cuda::makeBuffer<GPUCACell::OuterHitOfCellContainer>(std::max(1U, nhits), deleter);
assert(device_isOuterHitOfCell_.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<memoryPool::cuda::BundleDelete>(stream, memoryPool::onDevice));
memoryPool::Deleter const &deleter = device_storage_.deleter();
device_isOuterHitOfCell_ =
memoryPool::cuda::makeBuffer<GPUCACell::OuterHitOfCellContainer>(std::max(1, nhits), deleter);
assert(device_isOuterHitOfCell_.get());
Expand Down

0 comments on commit b8d0837

Please sign in to comment.