Unverified Commit d0f8dff2 authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

add comments for every emitted function in CPU backend. (#509)

parent 8ad86ab9
...@@ -40,7 +40,7 @@ std::string codegen::CodeWriter::generate_temporary_name(std::string prefix) ...@@ -40,7 +40,7 @@ std::string codegen::CodeWriter::generate_temporary_name(std::string prefix)
{ {
std::stringstream ss; std::stringstream ss;
ss << prefix << "__" << m_temporary_name_count; ss << prefix << m_temporary_name_count;
m_temporary_name_count++; m_temporary_name_count++;
return ss.str(); return ss.str();
......
...@@ -284,13 +284,8 @@ void runtime::cpu::CPU_ExternalFunction::compile() ...@@ -284,13 +284,8 @@ void runtime::cpu::CPU_ExternalFunction::compile()
} }
writer += writer +=
R"(// Generated by the NGraph CPU backend R"(// Generated by the nGraph CPU backend
#include <cmath> #include <cmath>
)";
writer +=
R"(#include <Eigen/Dense>
#include "ngraph/except.hpp" #include "ngraph/except.hpp"
#include "ngraph/runtime/aligned_buffer.hpp" #include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/runtime/cpu/cpu_eigen_utils.hpp" #include "ngraph/runtime/cpu/cpu_eigen_utils.hpp"
...@@ -669,7 +664,8 @@ using namespace ngraph::runtime; ...@@ -669,7 +664,8 @@ using namespace ngraph::runtime;
throw ngraph_error("Unhandled op during code generation : " + node->description()); throw ngraph_error("Unhandled op during code generation : " + node->description());
} }
vector<TensorViewWrapper> in; vector<TensorViewWrapper> in;
vector<string> node_input_names, node_output_names; vector<string> node_input_names;
vector<string> node_output_names;
for (const descriptor::Input& input : node->get_inputs()) for (const descriptor::Input& input : node->get_inputs())
{ {
const descriptor::Output& output = input.get_output(); const descriptor::Output& output = input.get_output();
...@@ -714,19 +710,23 @@ using namespace ngraph::runtime; ...@@ -714,19 +710,23 @@ using namespace ngraph::runtime;
} }
} }
writer << "\n// " << node->get_name() << "(";
vector<string> parameter_nodes = node_input_names;
parameter_nodes.insert(
parameter_nodes.end(), node_output_names.begin(), node_output_names.end());
writer << join(parameter_nodes);
writer << ")\n";
// Emit operation body // Emit operation body
string func_name; string func_name;
auto it = match_functions.find(node.get()); auto it = match_functions.find(node.get());
if (it != match_functions.end()) if (it == match_functions.end())
{
func_name = it->second;
}
if (func_name.empty())
{ {
handler->second(this, writer, node.get(), in, out); handler->second(this, writer, node.get(), in, out);
} }
else else
{ {
func_name = it->second;
vector<string> names; vector<string> names;
for (const TensorViewWrapper& tv : in) for (const TensorViewWrapper& tv : in)
{ {
......
...@@ -30,9 +30,6 @@ string emit_bracketed_string(vector<T> data) ...@@ -30,9 +30,6 @@ string emit_bracketed_string(vector<T> data)
{ {
stringstream ss; stringstream ss;
if (data.size() == 0)
return "";
for (auto s : data) for (auto s : data)
{ {
ss << "[" << s << "]"; ss << "[" << s << "]";
...@@ -75,7 +72,7 @@ vector<string> ...@@ -75,7 +72,7 @@ vector<string>
vector<string> index_vars; vector<string> index_vars;
for (size_t i = 0; i < top.size(); i++) for (size_t i = 0; i < top.size(); i++)
{ {
string index_var = writer.generate_temporary_name("i"); string index_var = writer.generate_temporary_name("_i");
writer << runtime::cpu::kernel::start_index_loop(index_var, new_bottom[i], top[i], i == 0); writer << runtime::cpu::kernel::start_index_loop(index_var, new_bottom[i], top[i], i == 0);
writer.indent++; writer.indent++;
......
...@@ -149,7 +149,7 @@ string ngraph::runtime::cpu::kernel::end_index_loop(const string& index_var) ...@@ -149,7 +149,7 @@ string ngraph::runtime::cpu::kernel::end_index_loop(const string& index_var)
{ {
stringstream ss; stringstream ss;
ss << "} // end for(" << index_var << ")\n"; ss << "}\n";
return ss.str(); return ss.str();
} }
...@@ -209,7 +209,7 @@ void ngraph::runtime::cpu::kernel::emit_pointwise_copy(codegen::CodeWriter& writ ...@@ -209,7 +209,7 @@ void ngraph::runtime::cpu::kernel::emit_pointwise_copy(codegen::CodeWriter& writ
for (size_t i = 0; i < n_axes; i++) for (size_t i = 0; i < n_axes; i++)
{ {
string index_var = writer.generate_temporary_name("i"); string index_var = writer.generate_temporary_name("_j");
writer << start_index_loop(index_var, source_start_corner[i], source_end_corner[i], i == 0); writer << start_index_loop(index_var, source_start_corner[i], source_end_corner[i], i == 0);
writer.indent++; writer.indent++;
......
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