Commit 2a3ebb35 authored by pruthvi's avatar pruthvi

- fix compilation error

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