Commit e762262e authored by pruthvi's avatar pruthvi

change CPU allocator to accept the framework allocators

parent e8ebfa27
......@@ -22,31 +22,17 @@ namespace ngraph
{
namespace cpu
{
CPUAllocator::CPUAllocator() {}
CPUAllocator::CPUAllocator(runtime::AllocateFunc alloc, runtime::DestroyFunc dealloc)
: m_alloc(alloc)
, m_dealloc(dealloc)
{
}
CPUAllocator::~CPUAllocator() {}
CPUAllocator& GetCPUAllocator()
{
static CPUAllocator cpu_allocator;
static CPUAllocator cpu_allocator(nullptr, nullptr);
return cpu_allocator;
}
}
}
}
/*ngraph::runtime::SystemAllocator::SystemAllocator()
{
}
ngraph::runtime::SystemAllocator::~SystemAllocator()
{
}
ngraph::runtime::FrameworkAllocator::~FrameworkAllocator()
{
}
ngraph::runtime::FrameworkAllocator::FrameworkAllocator(AllocateFunc& allocator,
DestroyFunc& deallocator)
: m_allocator(allocator)
, m_deallocator(deallocator)
{
}*/
......@@ -56,12 +56,20 @@ namespace ngraph
class ngraph::runtime::cpu::CPUAllocator : public ngraph::runtime::Allocator
{
public:
CPUAllocator();
CPUAllocator(runtime::AllocateFunc alloc, runtime::DestroyFunc dealloc);
~CPUAllocator();
void* Malloc(void* handle, size_t size, size_t alignment)
{
void* ptr = malloc(size);
void* ptr;
if (m_alloc)
{
ptr = m_alloc(handle, size, alignment);
}
else
{
ptr = malloc(size);
}
// check for exception
if (size != 0 && !ptr)
{
......@@ -74,7 +82,18 @@ public:
{
if (ptr)
{
free(ptr);
if (m_dealloc)
{
m_dealloc(handle, ptr);
}
else
{
free(ptr);
}
}
}
private:
runtime::AllocateFunc m_alloc;
runtime::DestroyFunc m_dealloc;
};
......@@ -143,7 +143,8 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context()
// Create temporary buffer pools
size_t alignment = runtime::cpu::CPU_ExternalFunction::s_memory_pool_alignment;
ngraph::runtime::Allocator* allocator = new ngraph::runtime::cpu::CPUAllocator();
ngraph::runtime::Allocator* allocator =
new ngraph::runtime::cpu::CPUAllocator(nullptr, nullptr);
/*if (m_framework_allocator && m_framework_deallocator)
{
auto fw_allocator =
......
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