Commit ab7341d7 authored by Mahbub Zaman's avatar Mahbub Zaman Committed by Sang Ik Lee

Adds basic support for provenance (#2591)

* Adds basic support for provenance

* undoing accidental white space change.

* Fixes style errors

* Cometic changes.

* Addresses review comments. 1.Makes reference constant and 2.changes remove function type to void.
parent 90ec2510
......@@ -165,6 +165,7 @@ void ngraph::replace_node(std::shared_ptr<Node> target, std::shared_ptr<Node> re
input->replace_output(replacement->get_outputs().at(i));
}
}
replacement->merge_provenance_tags_from(target);
}
// Check if all paths from X to a result go through Y
......
......@@ -158,6 +158,29 @@ void Node::set_placement_index(size_t placement)
m_placement_index = placement;
}
const std::unordered_set<std::string>& Node::get_provenance_tags() const
{
return m_provenance_tags;
}
void Node::add_provenance_tag(const std::string& tag)
{
m_provenance_tags.insert(tag);
}
void Node::remove_provenance_tag(const std::string& tag)
{
m_provenance_tags.erase(tag);
}
void Node::merge_provenance_tags_from(const std::shared_ptr<const Node>& source)
{
for (auto& tag : source->get_provenance_tags())
{
add_provenance_tag(tag);
}
}
std::shared_ptr<Node> Node::get_argument(size_t index) const
{
for (auto& i : get_inputs())
......
......@@ -245,6 +245,13 @@ namespace ngraph
/// Set device placement
void set_placement_index(size_t placement);
const std::unordered_set<std::string>& get_provenance_tags() const;
void add_provenance_tag(const std::string& tag);
void remove_provenance_tag(const std::string& tag);
// to be used when nodes are replaced
void merge_provenance_tags_from(const std::shared_ptr<const Node>& source);
/// Get input descriptor that is connected to src
descriptor::Input* get_input_from(const std::shared_ptr<Node>& src);
......@@ -268,6 +275,7 @@ namespace ngraph
std::string m_friendly_name;
const std::string m_unique_name;
static std::atomic<size_t> m_next_instance_id;
std::unordered_set<std::string> m_provenance_tags;
std::deque<descriptor::Input> m_inputs;
std::deque<descriptor::Output> m_outputs;
std::unordered_map<Node*, autodiff::Adjoints> m_adjoint_map;
......
......@@ -19,8 +19,10 @@
#include <string>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ngraph/graph_util.hpp"
#include "ngraph/ngraph.hpp"
using namespace std;
......@@ -41,3 +43,35 @@ TEST(op, is_parameter)
ASSERT_NE(nullptr, t0);
EXPECT_FALSE(t0->is_parameter());
}
TEST(op, provenance_tag)
{
auto node = make_shared<op::Parameter>(element::f32, Shape{1});
auto tag1 = "parameter node";
auto tag2 = "f32 node";
node->add_provenance_tag(tag1);
node->add_provenance_tag(tag2);
node->remove_provenance_tag(tag1);
auto tags = node->get_provenance_tags();
ASSERT_TRUE(tags.find(tag1) == tags.end());
ASSERT_TRUE(tags.find(tag2) != tags.end());
}
// TODO: Need to mock Node, Op etc to be able to unit test functions like replace_node().
// Mocking them directly isn't possible because google test requires methods to be
// non-virtual. For non-virtual methods we will need to templatize these classes and call using
// different template argument between testing and production.
/*
TEST(op, provenance_replace_node)
{
class MockOp: public op::Op
{
MOCK_CONST_METHOD1(copy_with_new_args, std::shared_ptr<Node>(const NodeVector& new_args));
MOCK_CONST_METHOD1(get_users, NodeVector (bool check_is_used)); // This can't be mocked as it's non-virtual
};
::testing::NiceMock<MockOp> mock_op;
}
*/
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