#ifndef DEPTHGUIDE_MEMORY_POOL_IMPL_H #define DEPTHGUIDE_MEMORY_POOL_IMPL_H #include "core/memory_pool.h" #include #include #include #include #include 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>; malloc_pool_type malloc_pool; using reuse_pool_type = std::multimap; 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