Commit dc45b5ac authored by Fenglei's avatar Fenglei Committed by Robert Kimball

reset workspace manager after use (#1574)

* reset workspace manager after use

* use unique_ptr for pass memory manager
parent 5d8687d0
......@@ -27,7 +27,7 @@ constexpr const uint32_t initial_buffer_size = 10 * 1024 * 1024;
runtime::gpu::GPUMemoryManager::GPUMemoryManager(GPUPrimitiveEmitter* emitter)
: m_buffer_offset(0)
, m_buffered_mem(initial_buffer_size)
, m_workspace_manager(runtime::gpu::GPUMemoryManager::alignment)
, m_workspace_manager(new pass::MemoryManager(runtime::gpu::GPUMemoryManager::alignment))
, m_argspace_mem(1, {nullptr, 0})
, m_workspace_mem(1, {nullptr, 0})
, m_primitive_emitter(emitter)
......@@ -62,7 +62,7 @@ runtime::gpu::GPUMemoryManager::~GPUMemoryManager()
void runtime::gpu::GPUMemoryManager::allocate()
{
if (m_workspace_manager.get_node_list().size() != 1)
if (m_workspace_manager->get_node_list().size() != 1)
{
throw std::runtime_error(
"Attempt to allocate memory while reservations are inprogress. Ensure all "
......@@ -83,12 +83,14 @@ void runtime::gpu::GPUMemoryManager::allocate()
m_buffer_offset = 0;
}
auto workspace_size = m_workspace_manager.max_allocated();
auto workspace_size = m_workspace_manager->max_allocated();
if (workspace_size)
{
m_workspace_mem.back().ptr = runtime::gpu::create_gpu_buffer(workspace_size);
m_workspace_mem.back().size = workspace_size;
m_workspace_mem.push_back({nullptr, 0});
m_workspace_manager.reset(
new pass::MemoryManager(runtime::gpu::GPUMemoryManager::alignment));
}
}
......@@ -142,7 +144,7 @@ size_t runtime::gpu::GPUAllocator::reserve_argspace(const void* data, size_t siz
size_t runtime::gpu::GPUAllocator::reserve_workspace(size_t size, bool zero_initialize)
{
size_t offset = m_manager->m_workspace_manager.allocate(size);
size_t offset = m_manager->m_workspace_manager->allocate(size);
m_active.push(offset);
auto local = std::prev(m_manager->m_workspace_mem.end());
// return a lambda that will yield the gpu memory address. this
......@@ -168,7 +170,7 @@ void runtime::gpu::GPUAllocator::close()
{
while (!m_active.empty())
{
m_manager->m_workspace_manager.free(m_active.top());
m_manager->m_workspace_manager->free(m_active.top());
m_active.pop();
}
}
......
......@@ -73,7 +73,7 @@ namespace ngraph
size_t m_buffer_offset;
std::vector<uint8_t> m_buffered_mem;
ngraph::pass::MemoryManager m_workspace_manager;
std::unique_ptr<ngraph::pass::MemoryManager> m_workspace_manager;
static constexpr const uint16_t alignment = 8;
struct allocation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment