Commit 2a3ebb35 authored by pruthvi's avatar pruthvi

- fix compilation error

parent 594e3f9e
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
using namespace ngraph; using namespace ngraph;
runtime::cpu::CPUAlignedBuffer::CPUAlignedBuffer(size_t byte_size, size_t alignment, ngraph::runtime::cpu::CPUAllocator* cpu_allocator) runtime::cpu::CPUAlignedBuffer::CPUAlignedBuffer(size_t byte_size,
size_t alignment,
ngraph::runtime::cpu::CPUAllocator* cpu_allocator)
{ {
m_byte_size = byte_size; m_byte_size = byte_size;
m_cpu_allocator = cpu_allocator; m_cpu_allocator = cpu_allocator;
......
...@@ -36,7 +36,9 @@ namespace ngraph ...@@ -36,7 +36,9 @@ namespace ngraph
class ngraph::runtime::cpu::CPUAlignedBuffer class ngraph::runtime::cpu::CPUAlignedBuffer
{ {
public: public:
CPUAlignedBuffer(size_t byte_size, size_t alignment, ngraph::runtime::cpu::CPUAllocator* cpu_allocator); CPUAlignedBuffer(size_t byte_size,
size_t alignment,
ngraph::runtime::cpu::CPUAllocator* cpu_allocator);
~CPUAlignedBuffer(); ~CPUAlignedBuffer();
size_t size() const { return m_byte_size; } size_t size() const { return m_byte_size; }
......
...@@ -145,21 +145,19 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context() ...@@ -145,21 +145,19 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context()
// Create temporary buffer pools // Create temporary buffer pools
size_t alignment = runtime::cpu::CPU_ExternalFunction::s_memory_pool_alignment; size_t alignment = runtime::cpu::CPU_ExternalFunction::s_memory_pool_alignment;
// assign the passed memory allocators ngraph::runtime::cpu::CPUAllocator* allocator = nullptr;
/*ngraph::runtime::cpu::CPUAllocator::framework_allocator = m_framework_allocator;
ngraph::runtime::cpu::CPUAllocator::framework_deallocator = m_framework_deallocator;
ngraph::runtime::cpu::CPUAllocator::alignment = alignment;
*/
std::unique_ptr<ngraph::runtime::cpu::CPUAllocator> alloctor = nullptr;
if (m_framework_allocator && m_framework_deallocator) if (m_framework_allocator && m_framework_deallocator)
{ {
alloctor = new ngraph::runtime::cpu::CPUAllocator(ngraph::runtime::FrameworkAllocator(m_framework_allocator, m_framework_deallocator, s_memory_pool_alignment)); auto fw_allocator = new ngraph::runtime::FrameworkAllocator(
m_framework_allocator, m_framework_deallocator, alignment);
allocator = new ngraph::runtime::cpu::CPUAllocator(fw_allocator, alignment);
} }
else else
{ {
allocator = new ngraph::runtime::cpu::CPUAllocator(ngraph::runtime::SystemAllocator(s_memory_pool_alignment)); auto sys_allocator = new ngraph::runtime::SystemAllocator(alignment);
allocator = new ngraph::runtime::cpu::CPUAllocator(sys_allocator, alignment);
} }
for (auto buffer_size : m_external_function->get_memory_buffer_sizes()) for (auto buffer_size : m_external_function->get_memory_buffer_sizes())
{ {
auto buffer = new CPUAlignedBuffer(buffer_size, alignment, allocator); auto buffer = new CPUAlignedBuffer(buffer_size, alignment, allocator);
......
...@@ -14,48 +14,41 @@ ...@@ -14,48 +14,41 @@
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include "ngraph/runtime/cpu/cpu_mkl_allocator.hpp"
#include <string> #include <string>
#include "ngraph/runtime/cpu/cpu_external_function.hpp" #include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/cpu/cpu_mkl_allocator.hpp"
ngraph::runtime::cpu::CPUAllocator::CPUAllocator()
{
}
ngraph::runtime::cpu::CPUAllocator::CPUAllocator(ngraph::runtime::Allocator* allocator) ngraph::runtime::cpu::CPUAllocator::CPUAllocator(ngraph::runtime::Allocator* allocator,
: m_allocator(allocator) size_t alignment)
: m_allocator(allocator)
, m_alignment(alignment)
{ {
} }
ngraph::runtime::cpu::CPUAllocator::~CPUAllocator() 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(size); m_allocator->cpu_malloc(nullptr, size, m_alignment);
} }
void ngraph::runtime::cpu::cpuAllocator::free(void* ptr) void ngraph::runtime::cpu::CPUAllocator::free(void* ptr)
{ {
m_allocator->cpu_free(ptr); m_allocator->cpu_free(nullptr, ptr);
} }
ngraph::runtime::SystemAllocator::SystemAllocator(size_t alignment) ngraph::runtime::SystemAllocator::SystemAllocator(size_t alignment)
: m_alignment(alignment) : m_alignment(alignment)
{ {
} }
ngraph::runtime::FrameworkAllocator::FrameworkAllocator(AllocateFunc allocator, DestroyFunc deallocator, size_t alignment) ngraph::runtime::FrameworkAllocator::FrameworkAllocator(AllocateFunc allocator,
: m_allocator(allocator) DestroyFunc deallocator,
, m_deallocator(deallocator) size_t alignment)
, m_alignment(alignment) : m_allocator(allocator)
, m_deallocator(deallocator)
, m_alignment(alignment)
{ {
} }
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include "ngraph/except.hpp"
#include "ngraph/runtime/aligned_buffer.hpp" #include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
#include "ngraph/except.hpp"
using namespace ngraph; using namespace ngraph;
using AllocateFunc = void* (*)(void*, size_t, size_t); using AllocateFunc = void* (*)(void*, size_t, size_t);
...@@ -51,8 +51,6 @@ namespace ngraph ...@@ -51,8 +51,6 @@ namespace ngraph
namespace cpu namespace cpu
{ {
class CPUAllocator; class CPUAllocator;
void* cpu_malloc(size_t size, size_t alignment, AllocateFunc framework_allocator);
void cpu_free(void* ptr, DestroyFunc framework_deallocator);
} }
} }
} }
...@@ -60,41 +58,35 @@ namespace ngraph ...@@ -60,41 +58,35 @@ namespace ngraph
class ngraph::runtime::cpu::CPUAllocator class ngraph::runtime::cpu::CPUAllocator
{ {
public: public:
CPUAllocator(ngraph::runtime::Allocator* alloctor); CPUAllocator(ngraph::runtime::Allocator* alloctor, size_t alignment);
CPUAllocator();
~CPUAllocator(); ~CPUAllocator();
void* malloc(size_t size); void* malloc(size_t size);
void free(void* ptr); void free(void* ptr);
private: private:
std::unique_ptr<ngraph::runtime::Allocator> m_allocator; std::unique_ptr<ngraph::runtime::Allocator> m_allocator;
size_t m_alignment;
}; };
// Abstarct class for the allocator
// Abstarct class for the allocator class ngraph::runtime::Allocator
class ngraph::runtime::Allocator
{ {
public: public:
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;
}; };
class ngraph::runtime::SystemAllocator : public ngraph::runtime::Allocator
class ngraph::runtime::SystemAllocator : public ngraph::runtime::Allocator
{ {
public:
SystemAllocator(size_t alignment);
~SystemAllocator();
public: void* cpu_malloc(void*, size_t size, size_t alignment) override
SystemAllocator(size_t alignment);
~SystemAllocator();
void* cpu_malloc(void*, size_t size, size_t alignment) override
{ {
void *ptr = malloc(size); void* ptr = malloc(size);
// check for exception // check for exception
if (size != 0 && !ptr) if (size != 0 && !ptr)
{ {
...@@ -102,7 +94,7 @@ class ngraph::runtime::SystemAllocator : public ngraph::runtime::Allocator ...@@ -102,7 +94,7 @@ class ngraph::runtime::SystemAllocator : public ngraph::runtime::Allocator
throw std::bad_alloc(); throw std::bad_alloc();
} }
return ptr; return ptr;
} }
void cpu_free(void* ptr, void*) override void cpu_free(void* ptr, void*) override
{ {
...@@ -112,22 +104,20 @@ class ngraph::runtime::SystemAllocator : public ngraph::runtime::Allocator ...@@ -112,22 +104,20 @@ class ngraph::runtime::SystemAllocator : public ngraph::runtime::Allocator
} }
} }
private: private:
size_t m_alignment; size_t m_alignment;
}; };
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, size_t alignment);
~FrameworkAllocator(); ~FrameworkAllocator();
void* cpu_malloc(void*, size_t size, size_t alignment) override void* cpu_malloc(void*, size_t size, size_t alignment) override
{ {
void *ptr = m_allocator(nullptr, alignment, size); void* ptr = m_allocator(nullptr, alignment, size);
// check for exception // check for exception
if (size != 0 && !ptr) if (size != 0 && !ptr)
{ {
...@@ -135,7 +125,7 @@ class ngraph::runtime::FrameworkAllocator : public ngraph::runtime::Allocator ...@@ -135,7 +125,7 @@ class ngraph::runtime::FrameworkAllocator : public ngraph::runtime::Allocator
throw std::bad_alloc(); throw std::bad_alloc();
} }
return ptr; return ptr;
} }
void cpu_free(void* ptr, void*) override void cpu_free(void* ptr, void*) override
{ {
...@@ -145,9 +135,8 @@ class ngraph::runtime::FrameworkAllocator : public ngraph::runtime::Allocator ...@@ -145,9 +135,8 @@ class ngraph::runtime::FrameworkAllocator : public ngraph::runtime::Allocator
} }
} }
private: private:
AllocateFunc m_allocator; AllocateFunc m_allocator;
DestroyFunc m_deallocator; DestroyFunc m_deallocator;
size_t m_alignment; 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