Commit 222e0811 authored by Robert Kimball's avatar Robert Kimball

update CPU backend

parent b7e2fd7f
......@@ -67,44 +67,52 @@ shared_ptr<runtime::Tensor> runtime::cpu::CPU_Backend::create_tensor(
return make_shared<runtime::cpu::CPUTensorView>(element_type, shape, memory_pointer, this);
}
runtime::Handle runtime::cpu::CPU_Backend::compile(shared_ptr<Function> func)
shared_ptr<runtime::Executable>
runtime::cpu::CPU_Backend::compile(shared_ptr<Function> func, bool performance_counters_enabled)
{
FunctionInstance& instance = m_function_map[func];
if (instance.m_external_function == nullptr)
shared_ptr<runtime::Executable> rc;
auto it = m_exec_map.find(func);
if (it != m_exec_map.end())
{
instance.m_external_function = make_shared<CPU_ExternalFunction>(func);
instance.m_external_function->m_emit_timing = instance.m_performance_counters_enabled;
auto cf = instance.m_external_function->make_call_frame();
instance.m_call_frame = dynamic_pointer_cast<CPU_CallFrame>(cf);
rc = it->second;
}
else
{
rc = make_shared<CPU_Executable>(func, performance_counters_enabled);
m_exec_map.insert({func, rc});
}
return func;
return rc;
}
std::shared_ptr<ngraph::runtime::cpu::CPU_CallFrame>
runtime::cpu::CPU_Backend::get_call_frame(std::shared_ptr<Function> func)
runtime::cpu::CPU_Executable::CPU_Executable(shared_ptr<Function> func,
bool performance_counters_enabled)
{
FunctionInstance& instance = m_function_map[func];
FunctionInstance& instance = m_function_instance;
if (instance.m_external_function == nullptr)
{
auto rc = compile(func);
if (!rc)
{
throw ngraph_error("couldn't compile a function");
}
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();
instance.m_call_frame = dynamic_pointer_cast<CPU_CallFrame>(cf);
}
set_parameters_and_results(*func);
}
std::shared_ptr<ngraph::runtime::cpu::CPU_CallFrame> runtime::cpu::CPU_Executable::get_call_frame()
{
FunctionInstance& instance = m_function_instance;
return instance.m_call_frame;
}
bool runtime::cpu::CPU_Backend::call(shared_ptr<Function> func,
const vector<shared_ptr<runtime::Tensor>>& outputs,
const vector<shared_ptr<runtime::Tensor>>& inputs)
bool runtime::cpu::CPU_Executable::call(const vector<shared_ptr<runtime::Tensor>>& outputs,
const vector<shared_ptr<runtime::Tensor>>& inputs)
{
bool rc = true;
FunctionInstance& instance = m_function_map[func];
FunctionInstance& instance = m_function_instance;
if (instance.m_external_function == nullptr)
{
NGRAPH_INFO;
throw runtime_error("compile() must be called before call().");
}
......@@ -113,35 +121,15 @@ bool runtime::cpu::CPU_Backend::call(shared_ptr<Function> func,
return rc;
}
void runtime::cpu::CPU_Backend::remove_compiled_function(shared_ptr<Function> func)
{
m_function_map.erase(func);
}
void runtime::cpu::CPU_Backend::enable_performance_data(shared_ptr<Function> func, bool enable)
{
FunctionInstance& instance = m_function_map[func];
if (instance.m_external_function != nullptr)
{
throw runtime_error("Performance data collection must be enabled prior to compiling.");
}
instance.m_performance_counters_enabled = enable;
}
vector<runtime::PerformanceCounter>
runtime::cpu::CPU_Backend::get_performance_data(shared_ptr<Function> func) const
vector<runtime::PerformanceCounter> runtime::cpu::CPU_Executable::get_performance_data() const
{
vector<runtime::PerformanceCounter> rc;
auto it = m_function_map.find(func);
if (it != m_function_map.end())
const FunctionInstance& instance = m_function_instance;
if (instance.m_external_function != nullptr)
{
const FunctionInstance& instance = it->second;
if (instance.m_external_function != nullptr)
{
rc.insert(rc.end(),
instance.m_external_function->get_perf_counters().begin(),
instance.m_external_function->get_perf_counters().end());
}
rc.insert(rc.end(),
instance.m_external_function->get_perf_counters().begin(),
instance.m_external_function->get_perf_counters().end());
}
return rc;
}
......@@ -150,7 +138,6 @@ bool runtime::cpu::CPU_Backend::is_supported(const Node& op) const
{
return true;
}
bool runtime::cpu::CPU_Backend::is_supported_property(const Property prop) const
{
if (prop == Property::memory_attach)
......
......@@ -45,32 +45,37 @@ namespace ngraph
create_tensor(const ngraph::element::Type& element_type,
const Shape& shape) override;
Handle compile(std::shared_ptr<Function> func) override;
std::shared_ptr<ngraph::runtime::Executable>
compile(std::shared_ptr<Function> func,
bool enable_performance_counters = false) override;
bool call(std::shared_ptr<Function> func,
const std::vector<std::shared_ptr<runtime::Tensor>>& outputs,
const std::vector<std::shared_ptr<runtime::Tensor>>& inputs) override;
bool is_supported(const Node& node) const override;
bool is_supported_property(const Property prop) const override;
private:
std::unordered_map<std::shared_ptr<Function>, std::shared_ptr<Executable>>
m_exec_map;
};
void remove_compiled_function(std::shared_ptr<Function> func) override;
std::shared_ptr<CPU_CallFrame> get_call_frame(std::shared_ptr<Function> func);
class CPU_Executable : public runtime::Executable
{
public:
CPU_Executable(std::shared_ptr<Function> func, 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;
void enable_performance_data(std::shared_ptr<Function> func, bool enable) override;
std::vector<PerformanceCounter>
get_performance_data(std::shared_ptr<Function> func) const override;
std::shared_ptr<CPU_CallFrame> get_call_frame();
bool is_supported(const Node& node) const override;
bool is_supported_property(const Property prop) const override;
std::vector<PerformanceCounter> get_performance_data() const override;
private:
class FunctionInstance
{
public:
std::shared_ptr<CPU_ExternalFunction> m_external_function;
std::shared_ptr<CPU_CallFrame> m_call_frame;
std::shared_ptr<CPU_ExternalFunction> m_external_function = nullptr;
std::shared_ptr<CPU_CallFrame> m_call_frame = nullptr;
bool m_performance_counters_enabled = false;
};
std::map<std::shared_ptr<Function>, FunctionInstance> m_function_map;
} m_function_instance;
};
}
}
......
......@@ -92,6 +92,7 @@ namespace ngraph
friend class CPU_Backend;
friend class CPU_CallFrame;
friend class CPU_Debugger;
friend class CPU_Executable;
public:
enum class CPUTensorRole
......
......@@ -7,6 +7,7 @@ one_hot_vector_1_far_oob
one_hot_vector_1_fp_nonint
backwards_maxpool_n2_c1_hw5_3x3_str2_max_pad1x2_2x3
backwards_batch_norm_training
shape_of_scalar
shape_of_vector
shape_of_matrix
......
......@@ -61,8 +61,8 @@ TEST(debugger, add_breakpoint)
copy_data(a, dataA);
copy_data(b, dataB);
auto cf =
std::dynamic_pointer_cast<ngraph::runtime::cpu::CPU_Backend>(backend)->get_call_frame(f);
shared_ptr<runtime::Executable> handle = backend->compile(f);
auto cf = dynamic_pointer_cast<runtime::cpu::CPU_Executable>(handle)->get_call_frame();
ngraph::runtime::cpu::CPU_Debugger dbg(*cf);
......@@ -97,8 +97,8 @@ TEST(debugger, stepping)
copy_data(a, dataA);
copy_data(b, dataB);
auto cf =
std::dynamic_pointer_cast<ngraph::runtime::cpu::CPU_Backend>(backend)->get_call_frame(f);
shared_ptr<runtime::Executable> handle = backend->compile(f);
auto cf = dynamic_pointer_cast<runtime::cpu::CPU_Executable>(handle)->get_call_frame();
ngraph::runtime::cpu::CPU_Debugger dbg(*cf);
......@@ -134,8 +134,8 @@ TEST(debugger, delete_breakpoint)
copy_data(a, dataA);
copy_data(b, dataB);
auto cf =
std::dynamic_pointer_cast<ngraph::runtime::cpu::CPU_Backend>(backend)->get_call_frame(f);
shared_ptr<runtime::Executable> handle = backend->compile(f);
auto cf = dynamic_pointer_cast<runtime::cpu::CPU_Executable>(handle)->get_call_frame();
ngraph::runtime::cpu::CPU_Debugger dbg(*cf);
......@@ -174,8 +174,8 @@ TEST(debugger, while_stepping)
copy_data(a, dataA);
copy_data(b, dataB);
auto cf =
std::dynamic_pointer_cast<ngraph::runtime::cpu::CPU_Backend>(backend)->get_call_frame(f);
shared_ptr<runtime::Executable> handle = backend->compile(f);
auto cf = dynamic_pointer_cast<runtime::cpu::CPU_Executable>(handle)->get_call_frame();
ngraph::runtime::cpu::CPU_Debugger dbg(*cf);
......@@ -212,8 +212,8 @@ TEST(debugger, resume)
copy_data(a, dataA);
copy_data(b, dataB);
auto cf =
std::dynamic_pointer_cast<ngraph::runtime::cpu::CPU_Backend>(backend)->get_call_frame(f);
shared_ptr<runtime::Executable> handle = backend->compile(f);
auto cf = dynamic_pointer_cast<runtime::cpu::CPU_Executable>(handle)->get_call_frame();
ngraph::runtime::cpu::CPU_Debugger dbg(*cf);
......@@ -248,8 +248,8 @@ TEST(tracer, basic)
copy_data(a, dataA);
copy_data(b, dataB);
auto cf =
std::dynamic_pointer_cast<ngraph::runtime::cpu::CPU_Backend>(backend)->get_call_frame(f);
shared_ptr<runtime::Executable> handle = backend->compile(f);
auto cf = dynamic_pointer_cast<runtime::cpu::CPU_Executable>(handle)->get_call_frame();
ngraph::runtime::cpu::CPU_Debugger dbg(*cf);
......@@ -281,8 +281,8 @@ TEST(tracer, count_tracepoint)
shared_ptr<runtime::Tensor> b = backend->create_tensor(element::i32, shape);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::i32, shape);
auto cf =
std::dynamic_pointer_cast<ngraph::runtime::cpu::CPU_Backend>(backend)->get_call_frame(f);
shared_ptr<runtime::Executable> handle = backend->compile(f);
auto cf = dynamic_pointer_cast<runtime::cpu::CPU_Executable>(handle)->get_call_frame();
ngraph::runtime::cpu::CPU_Debugger dbg(*cf);
......@@ -322,8 +322,8 @@ TEST(tracer, conditional_tracepoint)
shared_ptr<runtime::Tensor> b = backend->create_tensor(element::i32, shape);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::i32, shape);
auto cf =
std::dynamic_pointer_cast<ngraph::runtime::cpu::CPU_Backend>(backend)->get_call_frame(f);
shared_ptr<runtime::Executable> handle = backend->compile(f);
auto cf = dynamic_pointer_cast<runtime::cpu::CPU_Executable>(handle)->get_call_frame();
ngraph::runtime::cpu::CPU_Debugger dbg(*cf);
......
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