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

Remove internal functions (#3079)

parent 52c0827d
...@@ -385,7 +385,6 @@ set (SRC ...@@ -385,7 +385,6 @@ set (SRC
pass/liveness.hpp pass/liveness.hpp
pass/manager.cpp pass/manager.cpp
pass/manager.hpp pass/manager.hpp
pass/manager_state.cpp
pass/manager_state.hpp pass/manager_state.hpp
pass/memory_layout.cpp pass/memory_layout.cpp
pass/memory_layout.hpp pass/memory_layout.hpp
......
...@@ -108,33 +108,6 @@ void ngraph::traverse_nodes(const NodeVector& subgraph_results, ...@@ -108,33 +108,6 @@ void ngraph::traverse_nodes(const NodeVector& subgraph_results,
} }
} }
void ngraph::traverse_functions(std::shared_ptr<ngraph::Function> p,
std::function<void(shared_ptr<Function>)> f)
{
std::unordered_set<shared_ptr<Function>> instances_seen;
deque<shared_ptr<Function>> stack;
stack.push_front(p);
while (stack.size() > 0)
{
shared_ptr<Function> func = stack.front();
if (instances_seen.find(func) == instances_seen.end())
{
instances_seen.insert(func);
f(func);
}
stack.pop_front();
for (shared_ptr<Node> op : func->get_ops())
{
for (shared_ptr<Function> fp : op->get_functions())
{
stack.push_front(fp);
}
}
}
}
NodeVector ngraph::find_common_args(std::shared_ptr<Node> target, std::shared_ptr<Node> replacement) NodeVector ngraph::find_common_args(std::shared_ptr<Node> target, std::shared_ptr<Node> replacement)
{ {
std::unordered_set<std::shared_ptr<Node>> target_args; std::unordered_set<std::shared_ptr<Node>> target_args;
......
...@@ -70,8 +70,12 @@ namespace ngraph ...@@ -70,8 +70,12 @@ namespace ngraph
bool include_control_deps, bool include_control_deps,
const NodeVector& subgraph_params = {}); const NodeVector& subgraph_params = {});
void traverse_functions(std::shared_ptr<Function> p, inline void traverse_functions(std::shared_ptr<Function> p,
std::function<void(std::shared_ptr<Function>)> f); std::function<void(std::shared_ptr<Function>)> f)
NGRAPH_DEPRECATED("Replace with f(p)")
{
f(p);
};
void replace_node(std::shared_ptr<Node> target, std::shared_ptr<Node> replacement); void replace_node(std::shared_ptr<Node> target, std::shared_ptr<Node> replacement);
......
...@@ -339,11 +339,6 @@ void Node::add_control_dependency(std::shared_ptr<Node> node) ...@@ -339,11 +339,6 @@ void Node::add_control_dependency(std::shared_ptr<Node> node)
m_control_dependencies.insert(node); m_control_dependencies.insert(node);
} }
std::vector<std::shared_ptr<Function>> Node::get_functions() const
{
return std::vector<std::shared_ptr<Function>>{};
}
namespace ngraph namespace ngraph
{ {
ostream& operator<<(ostream& out, const Node& node) ostream& operator<<(ostream& out, const Node& node)
......
...@@ -323,8 +323,6 @@ namespace ngraph ...@@ -323,8 +323,6 @@ namespace ngraph
// Will be replaced with an OutputVector version // Will be replaced with an OutputVector version
virtual std::shared_ptr<Node> copy_with_new_args(const NodeVector& new_args) const = 0; virtual std::shared_ptr<Node> copy_with_new_args(const NodeVector& new_args) const = 0;
virtual std::vector<std::shared_ptr<Function>> get_functions() const;
/// True if this and node have one output with same element type and shape /// True if this and node have one output with same element type and shape
bool has_same_type(std::shared_ptr<const Node> node) const; bool has_same_type(std::shared_ptr<const Node> node) const;
......
...@@ -61,27 +61,9 @@ void pass::Manager::run_passes(shared_ptr<Function> func, bool transitive) ...@@ -61,27 +61,9 @@ void pass::Manager::run_passes(shared_ptr<Function> func, bool transitive)
{ {
bool profile_enabled = getenv("NGRAPH_PROFILE_PASS_ENABLE") != nullptr; bool profile_enabled = getenv("NGRAPH_PROFILE_PASS_ENABLE") != nullptr;
vector<std::pair<shared_ptr<Function>, bool>> fs; get_state().set_function(func);
if (transitive) vector<std::pair<shared_ptr<Function>, bool>> fs{std::make_pair(func, func->is_dynamic())};
{ vector<shared_ptr<Function>> f_array{func};
// find all functions
traverse_functions(func, [&](shared_ptr<Function> f) {
fs.push_back(std::make_pair(f, f->is_dynamic()));
});
}
else
{
fs = {std::make_pair(func, func->is_dynamic())};
}
set<shared_ptr<Function>> tfs;
std::vector<shared_ptr<Function>> f_array;
for (auto f_pair : fs)
{
shared_ptr<Function> f = f_pair.first;
tfs.insert(f);
f_array.push_back(f);
}
get_state().set_functions(tfs);
size_t index = 0; size_t index = 0;
stopwatch pass_timer; stopwatch pass_timer;
......
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include <iostream>
#include <memory>
#include "ngraph/function.hpp"
#include "ngraph/log.hpp"
#include "ngraph/node.hpp"
#include "ngraph/pass/manager_state.hpp"
using namespace std;
using namespace ngraph;
const vector<shared_ptr<Function>>& pass::ManagerState::get_functions()
{
return m_function_list;
}
...@@ -41,15 +41,6 @@ namespace ngraph ...@@ -41,15 +41,6 @@ namespace ngraph
class ngraph::pass::ManagerState class ngraph::pass::ManagerState
{ {
public: public:
const std::vector<std::shared_ptr<Function>>& get_functions();
template <typename T>
void set_functions(const T& collection)
{
m_function_list.clear();
m_function_list.insert(m_function_list.begin(), collection.begin(), collection.end());
}
void set_visualize_tree_ops_map(const visualize_tree_ops_map_t& ops_map) void set_visualize_tree_ops_map(const visualize_tree_ops_map_t& ops_map)
{ {
m_visualize_tree_ops_map = ops_map; m_visualize_tree_ops_map = ops_map;
...@@ -60,7 +51,15 @@ public: ...@@ -60,7 +51,15 @@ public:
return m_visualize_tree_ops_map; return m_visualize_tree_ops_map;
} }
void set_function(const std::shared_ptr<Function> function) { m_function = function; }
std::shared_ptr<Function> get_function() const { return m_function; }
std::vector<std::shared_ptr<Function>> get_functions() const
NGRAPH_DEPRECATED("Use get_function()")
{
return {m_function};
}
private: private:
std::vector<std::shared_ptr<Function>> m_function_list;
visualize_tree_ops_map_t m_visualize_tree_ops_map; visualize_tree_ops_map_t m_visualize_tree_ops_map;
std::shared_ptr<Function> m_function;
}; };
...@@ -184,11 +184,7 @@ void runtime::gpu::GPUCompiledFunction::compile() ...@@ -184,11 +184,7 @@ void runtime::gpu::GPUCompiledFunction::compile()
string dump_filename = file_util::path_join(get_output_dir(), m_function_name + "_ops.txt"); string dump_filename = file_util::path_join(get_output_dir(), m_function_name + "_ops.txt");
pass_manager.register_pass<ngraph::pass::DumpSorted>(dump_filename); pass_manager.register_pass<ngraph::pass::DumpSorted>(dump_filename);
pass_manager.run_passes(m_function); pass_manager.run_passes(m_function);
m_function_ordered_ops.emplace(m_function, m_function->get_ordered_ops());
for (shared_ptr<Function> current_function : pass_manager.get_state().get_functions())
{
m_function_ordered_ops.emplace(current_function, current_function->get_ordered_ops());
}
add_passes(pass_manager); add_passes(pass_manager);
emit(); emit();
......
...@@ -340,33 +340,24 @@ static void serialize_to_cpio(ostream& out, shared_ptr<ngraph::Function> func, s ...@@ -340,33 +340,24 @@ static void serialize_to_cpio(ostream& out, shared_ptr<ngraph::Function> func, s
cpio::Writer writer(out); cpio::Writer writer(out);
writer.write(func->get_name(), j.c_str(), static_cast<uint32_t>(j.size())); writer.write(func->get_name(), j.c_str(), static_cast<uint32_t>(j.size()));
traverse_functions(func, [&](shared_ptr<ngraph::Function> f) { traverse_nodes(const_cast<Function*>(func.get()),
traverse_nodes(const_cast<Function*>(f.get()), [&](shared_ptr<Node> node) {
[&](shared_ptr<Node> node) { if (auto c = dynamic_pointer_cast<op::Constant>(node))
if (auto c = dynamic_pointer_cast<op::Constant>(node)) {
{ uint32_t size =
uint32_t size = static_cast<uint32_t>(shape_size(c->get_output_shape(0)) *
static_cast<uint32_t>(shape_size(c->get_output_shape(0)) * c->get_output_element_type(0).size());
c->get_output_element_type(0).size()); writer.write(c->get_name(), c->get_data_ptr(), size);
writer.write(c->get_name(), c->get_data_ptr(), size); }
} },
}, true);
true);
});
} }
#endif #endif
static string serialize(shared_ptr<ngraph::Function> func, size_t indent, bool binary_constant_data) static string serialize(shared_ptr<ngraph::Function> func, size_t indent, bool binary_constant_data)
{ {
json j; json j;
vector<json> functions; j.push_back(write(*func, binary_constant_data));
traverse_functions(func, [&](shared_ptr<ngraph::Function> f) {
functions.push_back(write(*f, binary_constant_data));
});
for (auto it = functions.rbegin(); it != functions.rend(); it++)
{
j.push_back(*it);
}
string rc; string rc;
if (indent == 0) if (indent == 0)
......
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