| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #ifndef DEPTHGUIDE_MEMORY_POOL_IMPL_H
- #define DEPTHGUIDE_MEMORY_POOL_IMPL_H
- #include "core/memory_pool.h"
- #include <boost/asio/io_context.hpp>
- #include <list>
- #include <map>
- #include <mutex>
- #include <thread>
- struct memory_pool::impl {
- // reuse_length * reuse_threshold >= request_length
- static constexpr auto reuse_threshold = 0.5;
- enum memory_layout : uint8_t {
- MEM_LINEAR, MEM_PITCH
- };
- struct mem_info_type {
- void *ptr;
- memory_location loc;
- memory_layout lay;
- // for MEM_LINEAR and MEM_PITCH
- size_t count;
- cudaEvent_t event = nullptr;
- };
- using malloc_pool_type = std::map<void *, mem_info_type, std::greater<>>;
- malloc_pool_type malloc_pool;
- using reuse_pool_type = std::multimap<size_t, mem_info_type>;
- reuse_pool_type reuse_host_pool;
- reuse_pool_type reuse_cuda_pool;
- std::mutex mu;
- void reg_allocate(mem_info_type mem_info);
- void *try_reuse_host(size_t count);
- void *try_reuse_cuda(size_t count);
- void *direct_allocate_host(size_t count);
- void *direct_allocate_cuda(size_t count);
- void *allocate_host(size_t count);
- void *allocate_cuda(size_t count);
- void *allocate(size_t count, memory_location mem_loc);
- void *allocate_pitch(size_t width, size_t rows, memory_location mem_loc, size_t *pitch);
- cudaEvent_t get_event(void *ptr);
- static void system_deallocate(mem_info_type mem_info);
- void deallocate(void *ptr);
- void purge();
- };
- #endif //DEPTHGUIDE_MEMORY_POOL_IMPL_H
|