Commit 91c9a1bf authored by Louis Feng's avatar Louis Feng

Merge branch 'master' into louisfeng/NGMX-296-conv_bias

parents 9c395596 3da0e440
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
namespace ngraph namespace ngraph
{ {
#ifdef NO_GLOBAL_TYPE_ALIASES
/// \brief A set of axes. /// \brief A set of axes.
class AxisSet : public std::set<size_t> class AxisSet : public std::set<size_t>
{ {
...@@ -54,8 +53,4 @@ namespace ngraph ...@@ -54,8 +53,4 @@ namespace ngraph
return *this; return *this;
} }
}; };
#else
// Deprecated definition
using AxisSet = std::set<size_t>;
#endif
} }
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
namespace ngraph namespace ngraph
{ {
#ifdef NO_GLOBAL_TYPE_ALIASES
/// \brief A vector of axes. /// \brief A vector of axes.
class AxisVector : public std::vector<size_t> class AxisVector : public std::vector<size_t>
{ {
...@@ -64,8 +63,4 @@ namespace ngraph ...@@ -64,8 +63,4 @@ namespace ngraph
return *this; return *this;
} }
}; };
#else
// Deprecated definition
using AxisVector = std::vector<size_t>;
#endif
} }
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
namespace ngraph namespace ngraph
{ {
#ifdef NO_GLOBAL_TYPE_ALIASES
/// \brief Coordinates for a tensor element /// \brief Coordinates for a tensor element
class Coordinate : public std::vector<size_t> class Coordinate : public std::vector<size_t>
{ {
...@@ -73,10 +72,6 @@ namespace ngraph ...@@ -73,10 +72,6 @@ namespace ngraph
return *this; return *this;
} }
}; };
#else
// Deprecated definition
using Coordinate = std::vector<size_t>;
#endif
// Removes some values from a vector of axis values // Removes some values from a vector of axis values
template <typename AXIS_VALUES> template <typename AXIS_VALUES>
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
namespace ngraph namespace ngraph
{ {
#ifdef NO_GLOBAL_TYPE_ALIASES
/// \brief A difference (signed) of tensor element coordinates. /// \brief A difference (signed) of tensor element coordinates.
class CoordinateDiff : public std::vector<std::ptrdiff_t> class CoordinateDiff : public std::vector<std::ptrdiff_t>
{ {
...@@ -64,8 +63,4 @@ namespace ngraph ...@@ -64,8 +63,4 @@ namespace ngraph
return *this; return *this;
} }
}; };
#else
// Deprecated definition
using CoordinateDiff = std::vector<std::ptrdiff_t>;
#endif
} }
...@@ -23,8 +23,6 @@ namespace ngraph ...@@ -23,8 +23,6 @@ namespace ngraph
{ {
class Node; class Node;
#ifdef NO_GLOBAL_TYPE_ALIASES
/// \brief Zero or more nodes. /// \brief Zero or more nodes.
class NodeVector : public std::vector<std::shared_ptr<Node>> class NodeVector : public std::vector<std::shared_ptr<Node>>
{ {
...@@ -46,10 +44,4 @@ namespace ngraph ...@@ -46,10 +44,4 @@ namespace ngraph
NodeVector() {} NodeVector() {}
}; };
#else
// Deprecated definitions
using NodeVector = std::vector<std::shared_ptr<Node>>;
using Nodes = NodeVector;
#endif
} }
...@@ -24,8 +24,6 @@ namespace ngraph ...@@ -24,8 +24,6 @@ namespace ngraph
{ {
class Parameter; class Parameter;
#ifdef NO_GLOBAL_TYPE_ALIASES
/// \brief Zero or more nodes. /// \brief Zero or more nodes.
class ParameterVector : public std::vector<std::shared_ptr<op::Parameter>> class ParameterVector : public std::vector<std::shared_ptr<op::Parameter>>
{ {
...@@ -47,11 +45,5 @@ namespace ngraph ...@@ -47,11 +45,5 @@ namespace ngraph
ParameterVector() {} ParameterVector() {}
}; };
#else
// Deprecated definitions
using ParameterVector = std::vector<std::shared_ptr<op::Parameter>>;
using Parameters = ParameterVector;
#endif
} }
} }
...@@ -256,6 +256,10 @@ runtime::cpu::CPU_ExternalFunction::CPU_ExternalFunction( ...@@ -256,6 +256,10 @@ runtime::cpu::CPU_ExternalFunction::CPU_ExternalFunction(
{ {
} }
runtime::cpu::CPU_ExternalFunction::~CPU_ExternalFunction()
{
}
void runtime::cpu::CPU_ExternalFunction::compile() void runtime::cpu::CPU_ExternalFunction::compile()
{ {
if (m_is_compiled) if (m_is_compiled)
...@@ -263,14 +267,16 @@ void runtime::cpu::CPU_ExternalFunction::compile() ...@@ -263,14 +267,16 @@ void runtime::cpu::CPU_ExternalFunction::compile()
return; return;
} }
m_mkldnn_emitter.reset(new MKLDNNEmitter(shared_from_this())); string function_name = m_function->get_name();
m_mkldnn_emitter.reset(new MKLDNNEmitter());
ngraph::pass::Manager pass_manager; ngraph::pass::Manager pass_manager;
pass_manager.register_pass<ngraph::pass::CoreFusion>(); pass_manager.register_pass<ngraph::pass::CoreFusion>();
pass_manager.register_pass<runtime::cpu::pass::CPUFusion>(); pass_manager.register_pass<runtime::cpu::pass::CPUFusion>();
pass_manager.register_pass<runtime::cpu::pass::CPUAssignment>(shared_from_this()); pass_manager.register_pass<runtime::cpu::pass::CPUAssignment>(this);
pass_manager.register_pass<runtime::cpu::pass::CPULayout>(shared_from_this()); pass_manager.register_pass<runtime::cpu::pass::CPULayout>(this);
pass_manager.register_pass<ngraph::pass::Liveness>(); pass_manager.register_pass<ngraph::pass::Liveness>();
pass_manager.register_pass<ngraph::pass::MemoryLayout>(s_memory_pool_alignment); pass_manager.register_pass<ngraph::pass::MemoryLayout>(s_memory_pool_alignment);
......
...@@ -75,6 +75,7 @@ namespace ngraph ...@@ -75,6 +75,7 @@ namespace ngraph
public: public:
CPU_ExternalFunction(const std::shared_ptr<ngraph::Function>& function, CPU_ExternalFunction(const std::shared_ptr<ngraph::Function>& function,
bool release_function = true); bool release_function = true);
~CPU_ExternalFunction();
std::shared_ptr<ngraph::runtime::CallFrame> make_call_frame(); std::shared_ptr<ngraph::runtime::CallFrame> make_call_frame();
const LayoutDescriptorPtrs& get_parameter_layout_descriptors(); const LayoutDescriptorPtrs& get_parameter_layout_descriptors();
......
...@@ -30,7 +30,8 @@ std::shared_ptr<ngraph::runtime::Backend> runtime::cpu::CPU_Manager::allocate_ba ...@@ -30,7 +30,8 @@ std::shared_ptr<ngraph::runtime::Backend> runtime::cpu::CPU_Manager::allocate_ba
std::shared_ptr<ngraph::runtime::ExternalFunction> std::shared_ptr<ngraph::runtime::ExternalFunction>
runtime::cpu::CPU_Manager::compile(const std::shared_ptr<ngraph::Function>& fun) runtime::cpu::CPU_Manager::compile(const std::shared_ptr<ngraph::Function>& fun)
{ {
return std::make_shared<CPU_ExternalFunction>(fun); auto rc = std::make_shared<CPU_ExternalFunction>(fun);
return rc;
} }
ngraph::runtime::Manager::Factory runtime::cpu::CPU_Manager::factory = ngraph::runtime::Manager::Factory runtime::cpu::CPU_Manager::factory =
......
...@@ -27,18 +27,18 @@ using namespace ngraph::runtime::cpu; ...@@ -27,18 +27,18 @@ using namespace ngraph::runtime::cpu;
const std::vector<mkldnn::primitive*>& MKLDNNEmitter::get_mkldnn_primitives() const const std::vector<mkldnn::primitive*>& MKLDNNEmitter::get_mkldnn_primitives() const
{ {
return mkldnn_primitives; return m_mkldnn_primitives;
} }
size_t MKLDNNEmitter::insert_primitive(mkldnn::primitive* primitive) size_t MKLDNNEmitter::insert_primitive(mkldnn::primitive* primitive)
{ {
mkldnn_primitives.emplace_back(primitive); m_mkldnn_primitives.emplace_back(primitive);
return (mkldnn_primitives.size() - 1); return (m_mkldnn_primitives.size() - 1);
} }
const std::vector<size_t>& MKLDNNEmitter::get_primitive_deps(size_t index) const const std::vector<size_t>& MKLDNNEmitter::get_primitive_deps(size_t index) const
{ {
return primitive_deps.at(index); return m_primitive_deps.at(index);
} }
mkldnn::memory::desc MKLDNNEmitter::build_memory_descriptor(const TensorViewWrapper& tvw, mkldnn::memory::desc MKLDNNEmitter::build_memory_descriptor(const TensorViewWrapper& tvw,
...@@ -98,11 +98,11 @@ size_t MKLDNNEmitter::build_convolution_forward(const mkldnn::memory::desc& inpu ...@@ -98,11 +98,11 @@ size_t MKLDNNEmitter::build_convolution_forward(const mkldnn::memory::desc& inpu
mkldnn::memory::dims(padding_above.begin(), padding_above.end()), mkldnn::memory::dims(padding_above.begin(), padding_above.end()),
mkldnn::padding_kind::zero}, mkldnn::padding_kind::zero},
mkldnn_utils::global_cpu_engine}, mkldnn_utils::global_cpu_engine},
*mkldnn_primitives[input_data_index], *m_mkldnn_primitives[input_data_index],
*mkldnn_primitives[weights_index], *m_mkldnn_primitives[weights_index],
*mkldnn_primitives[result_index])); *m_mkldnn_primitives[result_index]));
primitive_deps[conv_index] = {input_data_index, weights_index, result_index}; m_primitive_deps[conv_index] = {input_data_index, weights_index, result_index};
return conv_index; return conv_index;
} }
...@@ -262,16 +262,16 @@ size_t MKLDNNEmitter::build_elementwise_add( ...@@ -262,16 +262,16 @@ size_t MKLDNNEmitter::build_elementwise_add(
size_t input1_data_index = build_memory_primitive(input1_data_desc); size_t input1_data_index = build_memory_primitive(input1_data_desc);
size_t result_index = build_memory_primitive(result_desc); size_t result_index = build_memory_primitive(result_desc);
inputs_primitive.push_back(*mkldnn_primitives[input0_data_index]); inputs_primitive.push_back(*m_mkldnn_primitives[input0_data_index]);
inputs_primitive.push_back(*mkldnn_primitives[input1_data_index]); inputs_primitive.push_back(*m_mkldnn_primitives[input1_data_index]);
// elementwise sum primtive descriptor // elementwise sum primtive descriptor
mkldnn::sum::primitive_desc sum_pd = mkldnn::sum::primitive_desc sum_pd =
mkldnn::sum::primitive_desc(result_desc, scale_vector, inputs_pd); mkldnn::sum::primitive_desc(result_desc, scale_vector, inputs_pd);
// sum primitive // sum primitive
size_t add_index = insert_primitive( size_t add_index = insert_primitive(
new mkldnn::sum(sum_pd, inputs_primitive, *mkldnn_primitives[result_index])); new mkldnn::sum(sum_pd, inputs_primitive, *m_mkldnn_primitives[result_index]));
primitive_deps[add_index] = {input0_data_index, input1_data_index, result_index}; m_primitive_deps[add_index] = {input0_data_index, input1_data_index, result_index};
return add_index; return add_index;
} }
...@@ -37,11 +37,7 @@ namespace ngraph ...@@ -37,11 +37,7 @@ namespace ngraph
class MKLDNNEmitter class MKLDNNEmitter
{ {
public: public:
MKLDNNEmitter(std::shared_ptr<CPU_ExternalFunction> ef) MKLDNNEmitter() {}
: external_function(ef)
{
}
const std::vector<mkldnn::primitive*>& get_mkldnn_primitives() const; const std::vector<mkldnn::primitive*>& get_mkldnn_primitives() const;
size_t insert_primitive(mkldnn::primitive* primitive); size_t insert_primitive(mkldnn::primitive* primitive);
...@@ -103,10 +99,9 @@ namespace ngraph ...@@ -103,10 +99,9 @@ namespace ngraph
const std::vector<mkldnn::memory::primitive_desc>& input_pd); const std::vector<mkldnn::memory::primitive_desc>& input_pd);
private: private:
std::shared_ptr<CPU_ExternalFunction> external_function; std::vector<mkldnn::primitive*> m_mkldnn_primitives;
std::vector<mkldnn::primitive*> mkldnn_primitives; std::vector<mkldnn::stream> m_mkldnn_streams;
std::vector<mkldnn::stream> mkldnn_streams; std::unordered_map<size_t, std::vector<size_t>> m_primitive_deps;
std::unordered_map<size_t, std::vector<size_t>> primitive_deps;
}; };
} }
} }
......
...@@ -256,7 +256,7 @@ bool runtime::cpu::pass::CPUAssignment::run_on_call_graph( ...@@ -256,7 +256,7 @@ bool runtime::cpu::pass::CPUAssignment::run_on_call_graph(
auto handler = s_dispatcher.find(TI(n)); auto handler = s_dispatcher.find(TI(n));
if (handler != s_dispatcher.end()) if (handler != s_dispatcher.end())
{ {
handler->second(m_external_function.get(), node.get()); handler->second(m_external_function, node.get());
} }
} }
......
...@@ -39,7 +39,7 @@ namespace ngraph ...@@ -39,7 +39,7 @@ namespace ngraph
class CPUAssignment : public ngraph::pass::CallGraphPass class CPUAssignment : public ngraph::pass::CallGraphPass
{ {
public: public:
CPUAssignment(std::shared_ptr<CPU_ExternalFunction> external_function) CPUAssignment(CPU_ExternalFunction* external_function)
: m_external_function(external_function) : m_external_function(external_function)
{ {
} }
...@@ -56,7 +56,7 @@ namespace ngraph ...@@ -56,7 +56,7 @@ namespace ngraph
} }
private: private:
std::shared_ptr<CPU_ExternalFunction> m_external_function; CPU_ExternalFunction* m_external_function;
}; };
} }
} }
......
...@@ -719,11 +719,11 @@ bool runtime::cpu::pass::CPULayout::run_on_call_graph(const std::list<std::share ...@@ -719,11 +719,11 @@ bool runtime::cpu::pass::CPULayout::run_on_call_graph(const std::list<std::share
auto handler = s_dispatcher.find(TI(n)); auto handler = s_dispatcher.find(TI(n));
if (handler != s_dispatcher.end()) if (handler != s_dispatcher.end())
{ {
handler->second(m_external_function.get(), node); handler->second(m_external_function, node);
} }
else else
{ {
set_default_layouts(m_external_function.get(), node); set_default_layouts(m_external_function, node);
} }
} }
......
...@@ -39,7 +39,7 @@ namespace ngraph ...@@ -39,7 +39,7 @@ namespace ngraph
class CPULayout : public ngraph::pass::CallGraphPass class CPULayout : public ngraph::pass::CallGraphPass
{ {
public: public:
CPULayout(std::shared_ptr<CPU_ExternalFunction> external_function) CPULayout(CPU_ExternalFunction* external_function)
: m_external_function(external_function) : m_external_function(external_function)
{ {
} }
...@@ -52,7 +52,7 @@ namespace ngraph ...@@ -52,7 +52,7 @@ namespace ngraph
std::shared_ptr<ngraph::Node> node); std::shared_ptr<ngraph::Node> node);
private: private:
std::shared_ptr<CPU_ExternalFunction> m_external_function; CPU_ExternalFunction* m_external_function;
static std::shared_ptr<Node> insert_input_conversions( static std::shared_ptr<Node> insert_input_conversions(
CPU_ExternalFunction* external_function, CPU_ExternalFunction* external_function,
std::shared_ptr<Node>& node, std::shared_ptr<Node>& node,
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
namespace ngraph namespace ngraph
{ {
#ifdef NO_GLOBAL_TYPE_ALIASES
/// \brief Shape for a tensor. /// \brief Shape for a tensor.
class Shape : public std::vector<size_t> class Shape : public std::vector<size_t>
{ {
...@@ -68,10 +67,6 @@ namespace ngraph ...@@ -68,10 +67,6 @@ namespace ngraph
return *this; return *this;
} }
}; };
#else
// Deprecated definition
using Shape = std::vector<size_t>;
#endif
/// Number of elements in spanned by a shape /// Number of elements in spanned by a shape
size_t shape_size(const Shape& shape); size_t shape_size(const Shape& shape);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
namespace ngraph namespace ngraph
{ {
#ifdef NO_GLOBAL_TYPE_ALIASES
/// \brief Strides for a tensor. /// \brief Strides for a tensor.
class Strides : public std::vector<size_t> class Strides : public std::vector<size_t>
{ {
...@@ -63,8 +62,4 @@ namespace ngraph ...@@ -63,8 +62,4 @@ namespace ngraph
return *this; return *this;
} }
}; };
#else
// Deprecated definition
using Strides = std::vector<size_t>;
#endif
} }
...@@ -43,6 +43,29 @@ static const vector<element::Type> s_known_element_types = {element::from<float> ...@@ -43,6 +43,29 @@ static const vector<element::Type> s_known_element_types = {element::from<float>
element::from<uint32_t>(), element::from<uint32_t>(),
element::from<uint64_t>()}; element::from<uint64_t>()};
TEST(${BACKEND_NAME}, component_cleanup)
{
shared_ptr<runtime::Backend> backend;
shared_ptr<runtime::ExternalFunction> external;
shared_ptr<runtime::CallFrame> cf;
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(A + B, op::ParameterVector{A, B});
auto manager = runtime::Manager::get("${BACKEND_NAME}");
external = manager->compile(f);
backend = manager->allocate_backend();
cf = backend->make_call_frame(external);
}
EXPECT_EQ(cf.use_count(), 1);
cf = nullptr;
EXPECT_EQ(backend.use_count(), 1);
backend = nullptr;
EXPECT_EQ(external.use_count(), 1);
}
TEST(${BACKEND_NAME}, aliased_output) TEST(${BACKEND_NAME}, aliased_output)
{ {
Shape shape{2, 2}; Shape shape{2, 2};
...@@ -138,7 +161,7 @@ TEST(${BACKEND_NAME}, abc) ...@@ -138,7 +161,7 @@ TEST(${BACKEND_NAME}, abc)
auto f = make_shared<Function>((A + B) * C, op::ParameterVector{A, B, C}); auto f = make_shared<Function>((A + B) * C, op::ParameterVector{A, B, C});
auto manager = runtime::Manager::get("${BACKEND_NAME}"); auto manager = runtime::Manager::get("${BACKEND_NAME}");
auto external = manager->compile(f); shared_ptr<runtime::ExternalFunction> external = manager->compile(f);
auto backend = manager->allocate_backend(); auto backend = manager->allocate_backend();
auto cf = backend->make_call_frame(external); auto cf = backend->make_call_frame(external);
......
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