Commit 0b68da17 authored by pruthvi's avatar pruthvi

- made changes to the backend/call_frame API to accept allocator instance…

- made changes to the backend/call_frame API to accept allocator instance instead of individual framework allocator instance
parent 3beb5fe3
......@@ -32,7 +32,7 @@ runtime::AlignedBuffer::AlignedBuffer()
runtime::AlignedBuffer::AlignedBuffer(size_t byte_size,
size_t alignment,
ngraph::runtime::Allocator* allocator)
std::shared_ptr<ngraph::runtime::Allocator> allocator)
{
m_allocator = allocator;
m_byte_size = byte_size;
......@@ -42,7 +42,7 @@ runtime::AlignedBuffer::AlignedBuffer(size_t byte_size,
if (m_allocator)
{
m_allocated_buffer =
static_cast<char*>(allocator->Malloc(nullptr, allocation_size, alignment));
static_cast<char*>(m_allocator->Malloc(nullptr, allocation_size, alignment));
}
else
{
......
......@@ -17,6 +17,7 @@
#pragma once
#include <cstddef>
#include <memory>
namespace ngraph
{
......@@ -35,7 +36,7 @@ class ngraph::runtime::AlignedBuffer
public:
AlignedBuffer(size_t byte_size,
size_t alignment,
ngraph::runtime::Allocator* allocator = nullptr);
std::shared_ptr<ngraph::runtime::Allocator> allocator = nullptr);
AlignedBuffer();
~AlignedBuffer();
......@@ -47,8 +48,8 @@ private:
AlignedBuffer(AlignedBuffer&&) = delete;
AlignedBuffer& operator=(const AlignedBuffer&) = delete;
std::shared_ptr<ngraph::runtime::Allocator> m_allocator;
char* m_allocated_buffer;
char* m_aligned_buffer;
ngraph::runtime::Allocator* m_allocator;
size_t m_byte_size;
};
......@@ -42,8 +42,6 @@ vector<string> runtime::Backend::get_registered_devices()
std::shared_ptr<runtime::Executable>
runtime::Backend::compile(std::shared_ptr<Function> func,
ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator,
bool enable_performance_data)
{
return compile(func, enable_performance_data);
......
......@@ -96,8 +96,6 @@ public:
/// \returns compiled function or nullptr on failure
virtual std::shared_ptr<Executable> compile(std::shared_ptr<Function> func,
ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator = nullptr,
DestroyFunc memory_deallocator = nullptr,
bool enable_performance_data = false);
/// \brief Test if a backend is capable of supporting an op
......
......@@ -61,10 +61,9 @@ runtime::cpu::CPU_Backend::~CPU_Backend()
shared_ptr<runtime::cpu::CPU_CallFrame> runtime::cpu::CPU_Backend::make_call_frame(
const shared_ptr<runtime::cpu::CPU_ExternalFunction>& external_function,
ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator)
std::shared_ptr<ngraph::runtime::Allocator> allocator)
{
return external_function->make_call_frame(pass_config, memory_allocator, memory_deallocator);
return external_function->make_call_frame(pass_config, allocator);
}
shared_ptr<runtime::Tensor>
......@@ -94,14 +93,12 @@ shared_ptr<runtime::Executable>
runtime::cpu::CPU_Backend::compile(shared_ptr<Function> func, bool performance_counters_enabled)
{
ngraph::pass::PassConfig pass_config;
return compile(func, pass_config, nullptr, nullptr, performance_counters_enabled);
return compile(func, pass_config, performance_counters_enabled);
}
shared_ptr<runtime::Executable>
runtime::cpu::CPU_Backend::compile(shared_ptr<Function> func,
ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator,
bool performance_counters_enabled)
{
shared_ptr<runtime::Executable> rc;
......@@ -113,7 +110,7 @@ shared_ptr<runtime::Executable>
else
{
rc = make_shared<CPU_Executable>(
func, pass_config, memory_allocator, memory_deallocator, performance_counters_enabled);
func, pass_config, m_allocator, performance_counters_enabled);
m_exec_map.insert({func, rc});
}
return rc;
......@@ -121,8 +118,7 @@ shared_ptr<runtime::Executable>
runtime::cpu::CPU_Executable::CPU_Executable(shared_ptr<Function> func,
ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator,
std::shared_ptr<ngraph::runtime::Allocator> allocator,
bool performance_counters_enabled)
{
FunctionInstance& instance = m_function_instance;
......@@ -130,8 +126,7 @@ runtime::cpu::CPU_Executable::CPU_Executable(shared_ptr<Function> func,
{
instance.m_external_function = make_shared<CPU_ExternalFunction>(func);
instance.m_external_function->m_emit_timing = performance_counters_enabled;
auto cf = instance.m_external_function->make_call_frame(
pass_config, memory_allocator, memory_deallocator);
auto cf = instance.m_external_function->make_call_frame(pass_config, allocator);
instance.m_call_frame = dynamic_pointer_cast<CPU_CallFrame>(cf);
}
set_parameters_and_results(*func);
......
......@@ -42,8 +42,7 @@ namespace ngraph
std::shared_ptr<CPU_CallFrame>
make_call_frame(const std::shared_ptr<CPU_ExternalFunction>& external_function,
ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator);
std::shared_ptr<ngraph::runtime::Allocator> allocator);
std::shared_ptr<ngraph::runtime::Tensor>
create_tensor(const ngraph::element::Type& element_type,
......@@ -61,8 +60,6 @@ namespace ngraph
std::shared_ptr<ngraph::runtime::Executable>
compile(std::shared_ptr<Function> func,
ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator = nullptr,
DestroyFunc memory_deallocator = nullptr,
bool enable_performance_counters = false) override;
void remove_compiled_function(std::shared_ptr<Executable> exec) override;
......@@ -85,8 +82,7 @@ namespace ngraph
public:
CPU_Executable(std::shared_ptr<Function> func,
ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator,
std::shared_ptr<ngraph::runtime::Allocator> allocator,
bool performance_counters_enabled);
bool call(const std::vector<std::shared_ptr<runtime::Tensor>>& outputs,
const std::vector<std::shared_ptr<runtime::Tensor>>& inputs) override;
......
......@@ -33,16 +33,13 @@ runtime::cpu::CPU_CallFrame::CPU_CallFrame(std::shared_ptr<CPU_ExternalFunction>
InitContextFuncCG compiled_init_ctx_func,
DestroyContextFuncCG compiled_destroy_ctx_func,
EntryPoint compiled_function,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator)
std::shared_ptr<ngraph::runtime::Allocator> allocator)
: m_external_function(external_function)
, m_memory_allocator(memory_allocator)
, m_memory_deallocator(memory_deallocator)
, m_compiled_init_ctx_func(compiled_init_ctx_func)
, m_compiled_destroy_ctx_func(compiled_destroy_ctx_func)
, m_compiled_function(compiled_function)
{
setup_runtime_context();
setup_runtime_context(allocator);
if (!m_external_function->is_direct_execution())
{
// Invoke codegen runtime context initialization function.
......@@ -128,7 +125,8 @@ void runtime::cpu::CPU_CallFrame::propagate_layouts(
}
}
void runtime::cpu::CPU_CallFrame::setup_runtime_context()
void runtime::cpu::CPU_CallFrame::setup_runtime_context(
std::shared_ptr<ngraph::runtime::Allocator> allocator)
{
ctx = new CPURuntimeContext;
ctx->pc = 0;
......@@ -143,9 +141,6 @@ 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(m_memory_allocator, m_memory_deallocator);
for (auto buffer_size : m_external_function->get_memory_buffer_sizes())
{
auto buffer = new AlignedBuffer(buffer_size, alignment, allocator);
......
......@@ -59,9 +59,7 @@ namespace ngraph
InitContextFuncCG compiled_init_ctx_func,
DestroyContextFuncCG compiled_destroy_ctx_func,
EntryPoint compiled_function,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator);
std::shared_ptr<ngraph::runtime::Allocator> allocator);
~CPU_CallFrame();
/// \brief Invoke the function with values matching the signature of the function.
......@@ -73,7 +71,7 @@ namespace ngraph
void propagate_layouts(const std::vector<std::shared_ptr<runtime::Tensor>>& tvs,
const LayoutDescriptorPtrs& layouts) const;
void setup_runtime_context();
void setup_runtime_context(std::shared_ptr<ngraph::runtime::Allocator> allocator);
void setup_cg_runtime_context();
void cleanup_runtime_context();
......@@ -89,10 +87,6 @@ namespace ngraph
CPURuntimeContext* ctx = nullptr;
// memeber function pointers to hold the framework allocators
AllocateFunc m_memory_allocator;
DestroyFunc m_memory_deallocator;
/* Codegen specific */
/// Function that initializes the context used in codegen mode.
......
......@@ -1712,10 +1712,8 @@ void*& runtime::cpu::CPU_ExternalFunction::get_tensor_data(const std::string& na
}
}
shared_ptr<ngraph::runtime::cpu::CPU_CallFrame>
runtime::cpu::CPU_ExternalFunction::make_call_frame(ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator)
shared_ptr<ngraph::runtime::cpu::CPU_CallFrame> runtime::cpu::CPU_ExternalFunction::make_call_frame(
ngraph::pass::PassConfig& pass_config, std::shared_ptr<ngraph::runtime::Allocator> allocator)
{
#if defined(NGRAPH_DEX_ONLY)
if (pass_config.get_compilation_mode() == ngraph::pass::CompilationMode::CODEGEN)
......@@ -1744,8 +1742,7 @@ shared_ptr<ngraph::runtime::cpu::CPU_CallFrame>
m_compiled_init_ctx_func,
m_compiled_destroy_ctx_func,
m_compiled_function,
memory_allocator,
memory_deallocator);
allocator);
}
const runtime::cpu::LayoutDescriptorPtrs&
......
......@@ -102,9 +102,7 @@ namespace ngraph
~CPU_ExternalFunction();
std::shared_ptr<ngraph::runtime::cpu::CPU_CallFrame>
make_call_frame(ngraph::pass::PassConfig& pass_config,
AllocateFunc memory_allocator,
DestroyFunc memory_deallocator);
std::shared_ptr<ngraph::runtime::Allocator> allocator);
const LayoutDescriptorPtrs& get_parameter_layout_descriptors();
const LayoutDescriptorPtrs& get_result_layout_descriptors();
const std::vector<size_t>& get_memory_buffer_sizes() const
......
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