Commit ab34197e authored by pruthvi's avatar pruthvi

- add virtual destructor method to CPU allocator

- fix clang errors
parent 65eb0f09
...@@ -148,13 +148,13 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context() ...@@ -148,13 +148,13 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context()
ngraph::runtime::cpu::CPUAllocator* allocator = nullptr; ngraph::runtime::cpu::CPUAllocator* allocator = nullptr;
if (m_framework_allocator && m_framework_deallocator) if (m_framework_allocator && m_framework_deallocator)
{ {
auto fw_allocator = new ngraph::runtime::FrameworkAllocator( auto fw_allocator =
m_framework_allocator, m_framework_deallocator, alignment); new ngraph::runtime::FrameworkAllocator(m_framework_allocator, m_framework_deallocator);
allocator = new ngraph::runtime::cpu::CPUAllocator(fw_allocator, alignment); allocator = new ngraph::runtime::cpu::CPUAllocator(fw_allocator, alignment);
} }
else else
{ {
auto sys_allocator = new ngraph::runtime::SystemAllocator(alignment); auto sys_allocator = new ngraph::runtime::SystemAllocator();
allocator = new ngraph::runtime::cpu::CPUAllocator(sys_allocator, alignment); allocator = new ngraph::runtime::cpu::CPUAllocator(sys_allocator, alignment);
} }
......
...@@ -31,7 +31,7 @@ ngraph::runtime::cpu::CPUAllocator::~CPUAllocator() ...@@ -31,7 +31,7 @@ ngraph::runtime::cpu::CPUAllocator::~CPUAllocator()
void* ngraph::runtime::cpu::CPUAllocator::malloc(size_t size) void* ngraph::runtime::cpu::CPUAllocator::malloc(size_t size)
{ {
m_allocator->cpu_malloc(nullptr, size, m_alignment); return m_allocator->cpu_malloc(nullptr, size, m_alignment);
} }
void ngraph::runtime::cpu::CPUAllocator::free(void* ptr) void ngraph::runtime::cpu::CPUAllocator::free(void* ptr)
...@@ -39,16 +39,21 @@ void ngraph::runtime::cpu::CPUAllocator::free(void* ptr) ...@@ -39,16 +39,21 @@ void ngraph::runtime::cpu::CPUAllocator::free(void* ptr)
m_allocator->cpu_free(nullptr, ptr); m_allocator->cpu_free(nullptr, ptr);
} }
ngraph::runtime::SystemAllocator::SystemAllocator(size_t alignment) ngraph::runtime::SystemAllocator::SystemAllocator()
: m_alignment(alignment)
{ {
} }
ngraph::runtime::FrameworkAllocator::FrameworkAllocator(AllocateFunc allocator, ngraph::runtime::SystemAllocator::~SystemAllocator()
DestroyFunc deallocator, {
size_t alignment) }
ngraph::runtime::FrameworkAllocator::~FrameworkAllocator()
{
}
ngraph::runtime::FrameworkAllocator::FrameworkAllocator(AllocateFunc& allocator,
DestroyFunc& deallocator)
: m_allocator(allocator) : m_allocator(allocator)
, m_deallocator(deallocator) , m_deallocator(deallocator)
, m_alignment(alignment)
{ {
} }
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "ngraph/runtime/aligned_buffer.hpp" #include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
using namespace ngraph;
using AllocateFunc = void* (*)(void*, size_t, size_t); using AllocateFunc = void* (*)(void*, size_t, size_t);
using DestroyFunc = void (*)(void*, void*); using DestroyFunc = void (*)(void*, void*);
...@@ -75,6 +74,7 @@ private: ...@@ -75,6 +74,7 @@ private:
class ngraph::runtime::Allocator class ngraph::runtime::Allocator
{ {
public: public:
virtual ~Allocator() = default;
virtual void* cpu_malloc(void*, size_t size, size_t alignment) = 0; virtual void* cpu_malloc(void*, size_t size, size_t alignment) = 0;
virtual void cpu_free(void* ptr, void*) = 0; virtual void cpu_free(void* ptr, void*) = 0;
}; };
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
class ngraph::runtime::SystemAllocator : public ngraph::runtime::Allocator class ngraph::runtime::SystemAllocator : public ngraph::runtime::Allocator
{ {
public: public:
SystemAllocator(size_t alignment); SystemAllocator();
~SystemAllocator(); ~SystemAllocator();
void* cpu_malloc(void*, size_t size, size_t alignment) override void* cpu_malloc(void*, size_t size, size_t alignment) override
...@@ -107,9 +107,6 @@ public: ...@@ -107,9 +107,6 @@ public:
free(ptr); free(ptr);
} }
} }
private:
size_t m_alignment;
}; };
// FrameworkAllocator overides and implements "cpu_malloc" & "cpu_free" of Alloctaor interface class, // FrameworkAllocator overides and implements "cpu_malloc" & "cpu_free" of Alloctaor interface class,
...@@ -117,7 +114,7 @@ private: ...@@ -117,7 +114,7 @@ private:
class ngraph::runtime::FrameworkAllocator : public ngraph::runtime::Allocator class ngraph::runtime::FrameworkAllocator : public ngraph::runtime::Allocator
{ {
public: public:
FrameworkAllocator(AllocateFunc allocator, DestroyFunc deallocator, size_t alignment); FrameworkAllocator(AllocateFunc& allocator, DestroyFunc& deallocator);
~FrameworkAllocator(); ~FrameworkAllocator();
void* cpu_malloc(void*, size_t size, size_t alignment) override void* cpu_malloc(void*, size_t size, size_t alignment) override
...@@ -144,5 +141,4 @@ public: ...@@ -144,5 +141,4 @@ public:
private: private:
AllocateFunc m_allocator; AllocateFunc m_allocator;
DestroyFunc m_deallocator; DestroyFunc m_deallocator;
size_t m_alignment;
}; };
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