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