13#include <unordered_map>
19struct AllocationInfo {
25 AllocationInfo(
void* p =
nullptr,
size_t s = 0,
const std::string& t =
"")
46struct MemoryPoolConfig {
55 size_t input_size = 0,
56 float multiplier = 3.0f,
87 MemoryPool(
const MemoryPool&) =
delete;
88 MemoryPool& operator=(
const MemoryPool&) =
delete;
103 const std::string& tag =
"",
bool persistent =
false);
106 void free(
void* ptr, fz::stream_t stream);
171 if (!mem_pool_)
return current_allocated_bytes_;
177 if (!mem_pool_)
return current_allocated_bytes_;
184 void printStats()
const;
198 int getDeviceId()
const {
return config_.
device_id; }
221 std::shared_ptr<const void> alive_ = std::make_shared<const char>(
'\0');
224 fz::mempool_t mem_pool_;
226 std::unordered_map<void*, AllocationInfo> allocations_;
227 std::unordered_map<void*, AllocationInfo> persistent_allocations_;
230 std::vector<PersistentAllocInfo> persistent_allocs_;
231 size_t persistent_device_bytes_ = 0;
232 size_t persistent_pinned_bytes_ = 0;
234 size_t total_allocations_;
238 size_t current_allocated_bytes_;
241 bool overflow_warned_;
244 void initializeMemPool();
void synchronize(fz::stream_t stream)
size_t getPersistentPinnedBytes() const
Definition mempool.h:167
void freePersistentPinned(void *ptr)
bool isFallbackMode() const
Definition mempool.h:196
std::weak_ptr< const void > lifetimeToken() const
Definition mempool.h:217
fz::mempool_t getMemPool() const
Definition mempool.h:193
size_t getPeakUsage() const
Definition mempool.h:176
void * allocatePersistentPinned(size_t bytes, const std::string &tag="")
void free(void *ptr, fz::stream_t stream)
void reset(fz::stream_t stream)
size_t getCurrentUsage() const
Definition mempool.h:170
void * allocate(size_t size, fz::stream_t stream, const std::string &tag="", bool persistent=false)
size_t getAllocationCount() const
Definition mempool.h:182
void setReleaseThreshold(size_t bytes)
void * allocatePersistentDevice(size_t bytes, const std::string &tag="")
size_t getPersistentDeviceBytes() const
Definition mempool.h:164
size_t getConfiguredSize() const
Definition mempool.h:190
void freePersistentDevice(void *ptr)
size_t getPoolUsedMemCurrent(mempool_t pool)
Definition types.h:89
size_t getPoolUsedMemHigh(mempool_t pool)
Definition types.h:97
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:49
bool enable_reuse
Enable opportunistic buffer reuse.
Definition mempool.h:50
size_t getPoolSize() const
Definition mempool.h:67
size_t input_data_size
Input byte count used to size the pool.
Definition mempool.h:47
float pool_size_multiplier
Pool capacity = input_data_size × multiplier.
Definition mempool.h:48
bool force_fallback
Skip pool creation and use cudaMalloc; for vGPU or testing.
Definition mempool.h:52
bool is_pinned
true = cudaMallocHost; false = cudaMalloc
Definition mempool.h:42
Backend-neutral GPU type aliases.