Commit c571b7a7 authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

rename and document the node name methods (#2490)

* rename and document the node name methods

* address more references to renamed methods

* fix compile error

* fix build error
parent b277627a
...@@ -42,7 +42,7 @@ void regclass_pyngraph_Function(py::module m) ...@@ -42,7 +42,7 @@ void regclass_pyngraph_Function(py::module m)
function.def("get_result", &ngraph::Function::get_result); function.def("get_result", &ngraph::Function::get_result);
function.def("get_unique_name", &ngraph::Function::get_name); function.def("get_unique_name", &ngraph::Function::get_name);
function.def("get_name", &ngraph::Function::get_friendly_name); function.def("get_name", &ngraph::Function::get_friendly_name);
function.def("set_name", &ngraph::Function::set_name); function.def("set_friendly_name", &ngraph::Function::set_friendly_name);
function.def("__repr__", [](const ngraph::Function& self) { function.def("__repr__", [](const ngraph::Function& self) {
std::string class_name = py::cast(self).get_type().attr("__name__").cast<std::string>(); std::string class_name = py::cast(self).get_type().attr("__name__").cast<std::string>();
std::string shape = std::string shape =
......
...@@ -70,6 +70,6 @@ void regclass_pyngraph_Node(py::module m) ...@@ -70,6 +70,6 @@ void regclass_pyngraph_Node(py::module m)
node.def("get_argument", &ngraph::Node::get_argument); node.def("get_argument", &ngraph::Node::get_argument);
node.def("get_unique_name", &ngraph::Node::get_name); node.def("get_unique_name", &ngraph::Node::get_name);
node.def_property("name", &ngraph::Node::get_friendly_name, &ngraph::Node::set_name); node.def_property("name", &ngraph::Node::get_friendly_name, &ngraph::Node::set_friendly_name);
node.def_property_readonly("shape", &ngraph::Node::get_shape); node.def_property_readonly("shape", &ngraph::Node::get_shape);
} }
...@@ -64,7 +64,7 @@ namespace ngraph ...@@ -64,7 +64,7 @@ namespace ngraph
graph.get_ng_outputs(), graph.get_ng_parameters(), graph.get_name()); graph.get_ng_outputs(), graph.get_ng_parameters(), graph.get_name());
for (std::size_t i{0}; i < function->get_output_size(); ++i) for (std::size_t i{0}; i < function->get_output_size(); ++i)
{ {
function->get_output_op(i)->set_name(graph.get_outputs().at(i).get_name()); function->get_output_op(i)->set_friendly_name(graph.get_outputs().at(i).get_name());
} }
return function; return function;
} }
......
...@@ -118,7 +118,7 @@ const std::string& Function::get_name() const ...@@ -118,7 +118,7 @@ const std::string& Function::get_name() const
return m_unique_name; return m_unique_name;
} }
void Function::set_name(const string& name) void Function::set_friendly_name(const string& name)
{ {
if (m_name.empty()) if (m_name.empty())
{ {
......
...@@ -71,9 +71,21 @@ namespace ngraph ...@@ -71,9 +71,21 @@ namespace ngraph
/// Check that there is a single result and return it. /// Check that there is a single result and return it.
std::shared_ptr<Node> get_result() const; std::shared_ptr<Node> get_result() const;
const std::string& get_friendly_name() const; /// \brief Get the unique name of the function.
/// \returns A const reference to the function's unique name.
const std::string& get_name() const; const std::string& get_name() const;
void set_name(const std::string& name);
/// \brief Sets a friendly name for a function. This does not overwrite the unique name
/// of the function and is retrieved via get_friendly_name(). Used mainly for debugging.
/// The friendly name may be set exactly once.
/// \param name is the friendly name to set
void set_friendly_name(const std::string& name);
/// \brief Gets the friendly name for a function. If no friendly name has been set via
/// set_friendly_name then the function's unique name is returned.
/// \returns A const reference to the function's friendly name.
const std::string& get_friendly_name() const;
std::list<std::shared_ptr<Node>> get_ops(bool include_control_deps = true) const; std::list<std::shared_ptr<Node>> get_ops(bool include_control_deps = true) const;
std::list<std::shared_ptr<Node>> get_ordered_ops(bool include_control_deps = true) const; std::list<std::shared_ptr<Node>> get_ordered_ops(bool include_control_deps = true) const;
friend std::ostream& operator<<(std::ostream&, const Function&); friend std::ostream& operator<<(std::ostream&, const Function&);
......
...@@ -114,13 +114,18 @@ bool Node::is_constant() const ...@@ -114,13 +114,18 @@ bool Node::is_constant() const
return false; return false;
} }
const std::string& Node::description() const
{
return m_node_type;
}
const std::string& Node::get_friendly_name() const const std::string& Node::get_friendly_name() const
{ {
if (m_name.empty()) if (m_friendly_name.empty())
{ {
return m_unique_name; return m_unique_name;
} }
return m_name; return m_friendly_name;
} }
const std::string& Node::get_name() const const std::string& Node::get_name() const
...@@ -128,11 +133,11 @@ const std::string& Node::get_name() const ...@@ -128,11 +133,11 @@ const std::string& Node::get_name() const
return m_unique_name; return m_unique_name;
} }
void Node::set_name(const string& name) void Node::set_friendly_name(const string& name)
{ {
if (m_name.empty()) if (m_friendly_name.empty())
{ {
m_name = name; m_friendly_name = name;
} }
else else
{ {
......
...@@ -108,11 +108,26 @@ namespace ngraph ...@@ -108,11 +108,26 @@ namespace ngraph
// Called after transition // Called after transition
void delayed_validate_and_infer_types(); void delayed_validate_and_infer_types();
/// The class name, must not contain spaces /// \brief Get the string name for the type of the node, such as `Add` or `Multiply`.
std::string description() const { return m_node_type; } /// The class name, must not contain spaces as it is used for codegen.
const std::string& get_friendly_name() const; /// \returns A const reference to the node's type name
const std::string& description() const;
/// \brief Get the unique name of the node.
/// \returns A const reference to the node's unique name.
const std::string& get_name() const; const std::string& get_name() const;
void set_name(const std::string& name);
/// \brief Sets a friendly name for a node. This does not overwrite the unique name
/// of the node and is retrieved via get_friendly_name(). Used mainly for debugging.
/// The friendly name may be set exactly once.
/// \param name is the friendly name to set
void set_friendly_name(const std::string& name);
/// \brief Gets the friendly name for a node. If no friendly name has been set via
/// set_friendly_name then the node's unique name is returned.
/// \returns A const reference to the node's friendly name.
const std::string& get_friendly_name() const;
/// Return true if this has the same implementing class as node. This /// Return true if this has the same implementing class as node. This
/// will be used by the pattern matcher when comparing a pattern /// will be used by the pattern matcher when comparing a pattern
/// graph against the graph. /// graph against the graph.
...@@ -247,9 +262,9 @@ namespace ngraph ...@@ -247,9 +262,9 @@ namespace ngraph
std::set<std::shared_ptr<Node>> m_control_dependencies; std::set<std::shared_ptr<Node>> m_control_dependencies;
void set_output_size(size_t n); void set_output_size(size_t n);
std::string m_node_type; const std::string m_node_type;
size_t m_instance_id; size_t m_instance_id;
std::string m_name; std::string m_friendly_name;
const std::string m_unique_name; const std::string m_unique_name;
static std::atomic<size_t> m_next_instance_id; static std::atomic<size_t> m_next_instance_id;
std::deque<descriptor::Input> m_inputs; std::deque<descriptor::Input> m_inputs;
......
...@@ -1193,13 +1193,8 @@ static shared_ptr<ngraph::Function> ...@@ -1193,13 +1193,8 @@ static shared_ptr<ngraph::Function>
node->add_control_dependency(node_map.at(name)); node->add_control_dependency(node_map.at(name));
} }
node->set_name(node_name); node->set_friendly_name(node_name);
node_map[node_name] = node; node_map[node_name] = node;
// Typically, it could be unsafe to change the name of a node since it may break nameing
// uniqueness. However, it could sometimes be helpful to use the original name from
// the serialization for debugging.
// node->set_name(node_name);
} }
catch (...) catch (...)
{ {
......
...@@ -115,7 +115,7 @@ NGRAPH_TEST(${BACKEND_NAME}, node_name) ...@@ -115,7 +115,7 @@ NGRAPH_TEST(${BACKEND_NAME}, node_name)
auto A = make_shared<op::Parameter>(element::f32, shape); auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape); auto B = make_shared<op::Parameter>(element::f32, shape);
auto C = A + B; auto C = A + B;
C->set_name("a node name"); C->set_friendly_name("a node name");
auto f = make_shared<Function>(C, ParameterVector{A, B}); auto f = make_shared<Function>(C, ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}"); auto backend = runtime::Backend::create("${BACKEND_NAME}");
......
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