8#include <cuda_runtime.h>
13#include <unordered_map>
25 AllocationInfo(
void* p =
nullptr,
size_t s = 0,
const std::string& t =
"")
37 size_t input_size = 0,
38 float multiplier = 3.0f,
82 void*
allocate(
size_t size, cudaStream_t stream,
83 const std::string& tag =
"",
bool persistent =
false);
86 void free(
void* ptr, cudaStream_t stream);
91 void reset(cudaStream_t stream);
114 cudaMemPoolGetAttribute(mem_pool_, cudaMemPoolAttrUsedMemCurrent, &used);
115 return static_cast<size_t>(used);
121 cudaMemPoolGetAttribute(mem_pool_, cudaMemPoolAttrUsedMemHigh, &high);
122 return static_cast<size_t>(high);
128 void printStats()
const;
139 int getDeviceId()
const {
return config_.
device_id; }
142 MemoryPoolConfig config_;
143 cudaMemPool_t mem_pool_;
145 std::unordered_map<void*, AllocationInfo> allocations_;
146 std::unordered_map<void*, AllocationInfo> graph_allocations_;
148 size_t total_allocations_;
152 size_t current_allocated_bytes_;
155 bool overflow_warned_;
158 void initializeMemPool();
void reset(cudaStream_t stream)
cudaMemPool_t getMemPool() const
Definition mempool.h:137
void free(void *ptr, cudaStream_t stream)
void synchronize(cudaStream_t stream)
size_t getPeakUsage() const
Definition mempool.h:119
size_t getCurrentUsage() const
Definition mempool.h:112
size_t getAllocationCount() const
Definition mempool.h:126
void setReleaseThreshold(size_t bytes)
void * allocate(size_t size, cudaStream_t stream, const std::string &tag="", bool persistent=false)
size_t getConfiguredSize() const
Definition mempool.h:134
Definition fzm_format.h:25
size_t size
Size in bytes.
Definition mempool.h:21
std::string tag
Debug label (e.g. "lorenzo_output").
Definition mempool.h:22
void * ptr
Device pointer.
Definition mempool.h:20
bool in_use
True while allocated.
Definition mempool.h:23
int device_id
CUDA device index.
Definition mempool.h:33
bool enable_reuse
Enable opportunistic buffer reuse.
Definition mempool.h:34
size_t getPoolSize() const
Definition mempool.h:47
size_t input_data_size
Input byte count used to size the pool.
Definition mempool.h:31
float pool_size_multiplier
Pool capacity = input_data_size × multiplier.
Definition mempool.h:32