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