Unverified Commit 62342c4e authored by Jai Menon's avatar Jai Menon Committed by GitHub

CPU: Restore use of the single-specification helper macro EMITTER_DECL (#495)

in emitter function definitions
parent 7cf242d3
...@@ -97,21 +97,15 @@ void runtime::cpu::CPU_Emitter::EmitMKLDNNPreamble(codegen::CodeWriter& writer) ...@@ -97,21 +97,15 @@ void runtime::cpu::CPU_Emitter::EmitMKLDNNPreamble(codegen::CodeWriter& writer)
writer << "using namespace mkldnn;\n\n"; writer << "using namespace mkldnn;\n\n";
} }
void runtime::cpu::CPU_Emitter::EmitNop(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitNop)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
} }
void runtime::cpu::CPU_Emitter::EmitAdd(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitAdd)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
// TODO: Audit all uses of Add and fix this to use // TODO: Audit all uses of Add and fix this to use
// the right alignment instead of Eigen::Unaligned // the right alignment instead of Eigen::Unaligned
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << "Eigen::Map<Eigen::Array<" << out[0].get_element_type().c_type_string() << ", " writer << "Eigen::Map<Eigen::Array<" << out[0].get_element_type().c_type_string() << ", "
...@@ -137,10 +131,7 @@ void runtime::cpu::CPU_Emitter::EmitAdd(codegen::CodeWriter& writer, ...@@ -137,10 +131,7 @@ void runtime::cpu::CPU_Emitter::EmitAdd(codegen::CodeWriter& writer,
//a) emitting customized code for initializing output/bias //a) emitting customized code for initializing output/bias
//b) emitting two cblas calls (one for gemm on W and x and the second for gemm on Bias and E^T + the result of the first gemm) //b) emitting two cblas calls (one for gemm on W and x and the second for gemm on Bias and E^T + the result of the first gemm)
//@jbobba suggests b) is more efficient but we should benchmark both //@jbobba suggests b) is more efficient but we should benchmark both
void runtime::cpu::CPU_Emitter::EmitMatmulBias(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitMatmulBias)
const ngraph::Node* node,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
const ngraph::op::MatmulBias* cg = static_cast<const ngraph::op::MatmulBias*>(node); const ngraph::op::MatmulBias* cg = static_cast<const ngraph::op::MatmulBias*>(node);
...@@ -189,12 +180,9 @@ void runtime::cpu::CPU_Emitter::EmitMatmulBias(codegen::CodeWriter& writer, ...@@ -189,12 +180,9 @@ void runtime::cpu::CPU_Emitter::EmitMatmulBias(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitDot)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
const ngraph::op::Dot* dot = static_cast<const ngraph::op::Dot*>(n); const ngraph::op::Dot* dot = static_cast<const ngraph::op::Dot*>(node);
const Shape& arg0_shape = args[0].get_shape(); const Shape& arg0_shape = args[0].get_shape();
const Shape& arg1_shape = args[1].get_shape(); const Shape& arg1_shape = args[1].get_shape();
...@@ -203,7 +191,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer, ...@@ -203,7 +191,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer,
auto& first = (arg0_shape.empty() ? args[0] : args[1]); auto& first = (arg0_shape.empty() ? args[0] : args[1]);
auto& second = (arg0_shape.empty() ? args[1] : args[0]); auto& second = (arg0_shape.empty() ? args[1] : args[0]);
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0]) << "\n = "; writer << emit_vector(out[0]) << "\n = ";
writer << first.get_name() << "[0]\n * " << emit_vector(second) << ";\n"; writer << first.get_name() << "[0]\n * " << emit_vector(second) << ";\n";
...@@ -213,7 +201,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer, ...@@ -213,7 +201,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer,
else if ((arg0_shape.size() == 1) && (arg1_shape.size() == 1) && else if ((arg0_shape.size() == 1) && (arg1_shape.size() == 1) &&
dot->get_reduction_axes_count() == 1) dot->get_reduction_axes_count() == 1)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0]) << " << \n" writer << emit_vector(out[0]) << " << \n"
<< " " << emit_vector(args[0]) << ".dot(" << emit_vector(args[1]) << ");\n"; << " " << emit_vector(args[0]) << ".dot(" << emit_vector(args[1]) << ");\n";
...@@ -223,7 +211,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer, ...@@ -223,7 +211,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer,
else if ((arg0_shape.size() == 2) && (arg1_shape.size() == 1) && else if ((arg0_shape.size() == 2) && (arg1_shape.size() == 1) &&
dot->get_reduction_axes_count() == 1) dot->get_reduction_axes_count() == 1)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0]) << " = \n" writer << emit_vector(out[0]) << " = \n"
<< " " << emit_matrix(args[0]) << " * " << emit_vector(args[1]) << ";\n"; << " " << emit_matrix(args[0]) << " * " << emit_vector(args[1]) << ";\n";
...@@ -237,7 +225,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer, ...@@ -237,7 +225,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer,
// clang-format off // clang-format off
if (args[0].get_element_type() == element::f32) if (args[0].get_element_type() == element::f32)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << "cblas::cblas_sgemm(" writer << "cblas::cblas_sgemm("
<< "cblas::Layout::RowMajor, " << "cblas::Layout::RowMajor, "
...@@ -252,7 +240,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer, ...@@ -252,7 +240,7 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer,
// clang-format on // clang-format on
else else
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_matrix(out[0]) << " = \n" writer << emit_matrix(out[0]) << " = \n"
<< " " << emit_matrix(args[0]) << " * " << emit_matrix(args[1]) << ";\n"; << " " << emit_matrix(args[0]) << " * " << emit_matrix(args[1]) << ";\n";
...@@ -272,12 +260,9 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer, ...@@ -272,12 +260,9 @@ void runtime::cpu::CPU_Emitter::EmitDot(codegen::CodeWriter& writer,
} }
} }
void runtime::cpu::CPU_Emitter::EmitMultiply(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitMultiply)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -295,15 +280,11 @@ void runtime::cpu::CPU_Emitter::EmitMultiply(codegen::CodeWriter& writer, ...@@ -295,15 +280,11 @@ void runtime::cpu::CPU_Emitter::EmitMultiply(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitGetOutputElement( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitGetOutputElement)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto get_tuple_element = static_cast<const op::GetOutputElement*>(n); auto get_tuple_element = static_cast<const op::GetOutputElement*>(node);
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << "memcpy(" << out[0].get_name() << ", " << args[get_tuple_element->get_n()].get_name() writer << "memcpy(" << out[0].get_name() << ", " << args[get_tuple_element->get_n()].get_name()
<< ", " << out[0].get_size() * out[0].get_element_type().size() << ");\n"; << ", " << out[0].get_size() * out[0].get_element_type().size() << ");\n";
...@@ -311,12 +292,9 @@ void runtime::cpu::CPU_Emitter::EmitGetOutputElement( ...@@ -311,12 +292,9 @@ void runtime::cpu::CPU_Emitter::EmitGetOutputElement(
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitTuple(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitTuple)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
for (size_t i = 0; i < args.size(); ++i) for (size_t i = 0; i < args.size(); ++i)
{ {
...@@ -327,12 +305,9 @@ void runtime::cpu::CPU_Emitter::EmitTuple(codegen::CodeWriter& writer, ...@@ -327,12 +305,9 @@ void runtime::cpu::CPU_Emitter::EmitTuple(codegen::CodeWriter& writer,
writer += "}\n"; writer += "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitAbs(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitAbs)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n"; writer << emit_array1d(out[0]) << " =\n";
...@@ -348,17 +323,14 @@ void runtime::cpu::CPU_Emitter::EmitAbs(codegen::CodeWriter& writer, ...@@ -348,17 +323,14 @@ void runtime::cpu::CPU_Emitter::EmitAbs(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitConcat(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitConcat)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto result_shape = out[0].get_shape(); auto result_shape = out[0].get_shape();
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
if (result_shape.size() == 1) if (result_shape.size() == 1)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0], "out_vector") << ";\n"; writer << emit_vector(out[0], "out_vector") << ";\n";
...@@ -374,9 +346,9 @@ void runtime::cpu::CPU_Emitter::EmitConcat(codegen::CodeWriter& writer, ...@@ -374,9 +346,9 @@ void runtime::cpu::CPU_Emitter::EmitConcat(codegen::CodeWriter& writer,
} }
else if (result_shape.size() == 2) else if (result_shape.size() == 2)
{ {
auto axis = (dynamic_cast<const op::Concat*>(n))->get_concatenation_axis(); auto axis = (dynamic_cast<const op::Concat*>(node))->get_concatenation_axis();
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_matrix(out[0], "out_matrix") << ";\n"; writer << emit_matrix(out[0], "out_matrix") << ";\n";
...@@ -439,7 +411,7 @@ void runtime::cpu::CPU_Emitter::EmitConcat(codegen::CodeWriter& writer, ...@@ -439,7 +411,7 @@ void runtime::cpu::CPU_Emitter::EmitConcat(codegen::CodeWriter& writer,
} }
} }
#else #else
auto axis = (dynamic_cast<const op::Concat*>(n))->get_concatenation_axis(); auto axis = (dynamic_cast<const op::Concat*>(node))->get_concatenation_axis();
std::vector<std::string> arg_names; std::vector<std::string> arg_names;
std::vector<Shape> arg_shapes; std::vector<Shape> arg_shapes;
...@@ -460,14 +432,11 @@ void runtime::cpu::CPU_Emitter::EmitConcat(codegen::CodeWriter& writer, ...@@ -460,14 +432,11 @@ void runtime::cpu::CPU_Emitter::EmitConcat(codegen::CodeWriter& writer,
#endif #endif
} }
void runtime::cpu::CPU_Emitter::EmitDivide(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitDivide)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
if (n->get_element_type().is_real() == false) if (node->get_element_type().is_real() == false)
{ {
// Check for divide by zero for integer types only // Check for divide by zero for integer types only
size_t element_count = args[1].get_size(); size_t element_count = args[1].get_size();
...@@ -493,12 +462,9 @@ void runtime::cpu::CPU_Emitter::EmitDivide(codegen::CodeWriter& writer, ...@@ -493,12 +462,9 @@ void runtime::cpu::CPU_Emitter::EmitDivide(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitEqual(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitEqual)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -516,12 +482,9 @@ void runtime::cpu::CPU_Emitter::EmitEqual(codegen::CodeWriter& writer, ...@@ -516,12 +482,9 @@ void runtime::cpu::CPU_Emitter::EmitEqual(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitGreater(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitGreater)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << " xxx\n"; writer << "{ // " << node->get_name() << " xxx\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -539,12 +502,9 @@ void runtime::cpu::CPU_Emitter::EmitGreater(codegen::CodeWriter& writer, ...@@ -539,12 +502,9 @@ void runtime::cpu::CPU_Emitter::EmitGreater(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitGreaterEq(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitGreaterEq)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -562,12 +522,9 @@ void runtime::cpu::CPU_Emitter::EmitGreaterEq(codegen::CodeWriter& writer, ...@@ -562,12 +522,9 @@ void runtime::cpu::CPU_Emitter::EmitGreaterEq(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitLess(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitLess)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -585,12 +542,9 @@ void runtime::cpu::CPU_Emitter::EmitLess(codegen::CodeWriter& writer, ...@@ -585,12 +542,9 @@ void runtime::cpu::CPU_Emitter::EmitLess(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitLessEq(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitLessEq)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -608,12 +562,9 @@ void runtime::cpu::CPU_Emitter::EmitLessEq(codegen::CodeWriter& writer, ...@@ -608,12 +562,9 @@ void runtime::cpu::CPU_Emitter::EmitLessEq(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitLog(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitLog)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -629,12 +580,9 @@ void runtime::cpu::CPU_Emitter::EmitLog(codegen::CodeWriter& writer, ...@@ -629,12 +580,9 @@ void runtime::cpu::CPU_Emitter::EmitLog(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitMaximum(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitMaximum)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -653,12 +601,9 @@ void runtime::cpu::CPU_Emitter::EmitMaximum(codegen::CodeWriter& writer, ...@@ -653,12 +601,9 @@ void runtime::cpu::CPU_Emitter::EmitMaximum(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitMinimum(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitMinimum)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -677,12 +622,9 @@ void runtime::cpu::CPU_Emitter::EmitMinimum(codegen::CodeWriter& writer, ...@@ -677,12 +622,9 @@ void runtime::cpu::CPU_Emitter::EmitMinimum(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitNegative(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitNegative)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -698,12 +640,9 @@ void runtime::cpu::CPU_Emitter::EmitNegative(codegen::CodeWriter& writer, ...@@ -698,12 +640,9 @@ void runtime::cpu::CPU_Emitter::EmitNegative(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitNotEqual(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitNotEqual)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -721,12 +660,9 @@ void runtime::cpu::CPU_Emitter::EmitNotEqual(codegen::CodeWriter& writer, ...@@ -721,12 +660,9 @@ void runtime::cpu::CPU_Emitter::EmitNotEqual(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitSelect(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSelect)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -745,12 +681,9 @@ void runtime::cpu::CPU_Emitter::EmitSelect(codegen::CodeWriter& writer, ...@@ -745,12 +681,9 @@ void runtime::cpu::CPU_Emitter::EmitSelect(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitSubtract(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSubtract)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -768,14 +701,11 @@ void runtime::cpu::CPU_Emitter::EmitSubtract(codegen::CodeWriter& writer, ...@@ -768,14 +701,11 @@ void runtime::cpu::CPU_Emitter::EmitSubtract(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitBroadcast)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto broadcast = static_cast<const op::Broadcast*>(n); auto broadcast = static_cast<const op::Broadcast*>(node);
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
auto arg_shape = args[0].get_shape(); auto arg_shape = args[0].get_shape();
...@@ -783,7 +713,7 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer, ...@@ -783,7 +713,7 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer,
if (broadcast->get_broadcast_axes().empty()) if (broadcast->get_broadcast_axes().empty())
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", " writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", "
<< out[0].get_size() * out[0].get_element_type().size() << ");\n"; << out[0].get_size() * out[0].get_element_type().size() << ");\n";
...@@ -792,7 +722,7 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer, ...@@ -792,7 +722,7 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer,
} }
else if (arg_shape.size() == 0) else if (arg_shape.size() == 0)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
<< " " << emit_array1d(args[0]) << "(0, 0);\n"; << " " << emit_array1d(args[0]) << "(0, 0);\n";
...@@ -803,7 +733,7 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer, ...@@ -803,7 +733,7 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer,
{ {
if (broadcast->get_broadcast_axes() == AxisSet{1}) if (broadcast->get_broadcast_axes() == AxisSet{1})
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_matrix(out[0]) << ".colwise() =\n" writer << emit_matrix(out[0]) << ".colwise() =\n"
<< " " << emit_vector(args[0]) << ";\n"; << " " << emit_vector(args[0]) << ";\n";
...@@ -812,7 +742,7 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer, ...@@ -812,7 +742,7 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer,
} }
else if (broadcast->get_broadcast_axes() == AxisSet{0}) else if (broadcast->get_broadcast_axes() == AxisSet{0})
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << "Eigen::Map<Eigen::Matrix<" << out[0].get_element_type().c_type_string() writer << "Eigen::Map<Eigen::Matrix<" << out[0].get_element_type().c_type_string()
...@@ -856,14 +786,11 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer, ...@@ -856,14 +786,11 @@ void runtime::cpu::CPU_Emitter::EmitBroadcast(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitConvert(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitConvert)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto& result_element_type = out[0].get_element_type(); auto& result_element_type = out[0].get_element_type();
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -881,20 +808,14 @@ void runtime::cpu::CPU_Emitter::EmitConvert(codegen::CodeWriter& writer, ...@@ -881,20 +808,14 @@ void runtime::cpu::CPU_Emitter::EmitConvert(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitConstant(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitConstant)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
} }
void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitReshape)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto reshape = static_cast<const op::Reshape*>(n); auto reshape = static_cast<const op::Reshape*>(node);
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
auto arg_shape = args[0].get_shape(); auto arg_shape = args[0].get_shape();
...@@ -917,7 +838,7 @@ void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer, ...@@ -917,7 +838,7 @@ void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer,
// we can just copy. // we can just copy.
if (same_layout || result_shape_product < 2) if (same_layout || result_shape_product < 2)
{ {
writer << "{ // " << n->get_name() << " 1\n"; writer << "{ // " << node->get_name() << " 1\n";
writer.indent++; writer.indent++;
writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", " writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", "
<< out[0].get_size() * out[0].get_element_type().size() << ");\n"; << out[0].get_size() * out[0].get_element_type().size() << ");\n";
...@@ -931,7 +852,7 @@ void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer, ...@@ -931,7 +852,7 @@ void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer,
// clang-format off // clang-format off
if (result_element_type == ngraph::element::f32) if (result_element_type == ngraph::element::f32)
{ {
writer << "{ // " << n->get_name() << " 2\n"; writer << "{ // " << node->get_name() << " 2\n";
writer.indent++; writer.indent++;
writer << "mkl::MKL_Somatcopy('R', 'T', " << to_string(arg_shape[0]) << ",\n" << writer << "mkl::MKL_Somatcopy('R', 'T', " << to_string(arg_shape[0]) << ",\n" <<
" " << to_string(arg_shape[1]) << ", 1.0f,\n" << " " << to_string(arg_shape[1]) << ", 1.0f,\n" <<
...@@ -945,7 +866,7 @@ void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer, ...@@ -945,7 +866,7 @@ void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer,
// clang-format on // clang-format on
else else
{ {
writer << "{ // " << n->get_name() << " 3\n"; writer << "{ // " << node->get_name() << " 3\n";
writer.indent++; writer.indent++;
writer << emit_matrix(out[0]) << " =\n" writer << emit_matrix(out[0]) << " =\n"
<< " " << emit_matrix(args[0]) << ".transpose();\n"; << " " << emit_matrix(args[0]) << ".transpose();\n";
...@@ -976,13 +897,9 @@ void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer, ...@@ -976,13 +897,9 @@ void runtime::cpu::CPU_Emitter::EmitReshape(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitFunctionCall( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitFunctionCall)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto function_call = static_cast<const op::FunctionCall*>(n); auto function_call = static_cast<const op::FunctionCall*>(node);
shared_ptr<Function> function = function_call->get_functions()[0]; shared_ptr<Function> function = function_call->get_functions()[0];
writer << "{ // Call " << function->get_name() << "\n"; writer << "{ // Call " << function->get_name() << "\n";
...@@ -1026,12 +943,9 @@ void runtime::cpu::CPU_Emitter::EmitFunctionCall( ...@@ -1026,12 +943,9 @@ void runtime::cpu::CPU_Emitter::EmitFunctionCall(
// the compiled version of these ops is intended to have semantics identical // the compiled version of these ops is intended to have semantics identical
// to what's seen there (for now atleast) // to what's seen there (for now atleast)
void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitReduce)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto reduce = static_cast<const op::Reduce*>(n); auto reduce = static_cast<const op::Reduce*>(node);
auto reduction_function = reduce->get_functions()[0]; auto reduction_function = reduce->get_functions()[0];
auto reductee_shape = args[0].get_shape(); auto reductee_shape = args[0].get_shape();
...@@ -1044,7 +958,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1044,7 +958,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
// Trivial case: no reduction axes (this includes the scalar-reductee case). // Trivial case: no reduction axes (this includes the scalar-reductee case).
if (reduction_axes.empty()) if (reduction_axes.empty())
{ {
writer << "{ // " << n->get_name() << " 1\n"; writer << "{ // " << node->get_name() << " 1\n";
writer.indent++; writer.indent++;
writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", " writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", "
<< out[0].get_size() * out[0].get_element_type().size() << ");\n"; << out[0].get_size() * out[0].get_element_type().size() << ");\n";
...@@ -1081,7 +995,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1081,7 +995,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
{ {
if (reductee_shape.at(0) == 0 || (reductee_shape.size() == 2 && reductee_shape.at(1) == 0)) if (reductee_shape.at(0) == 0 || (reductee_shape.size() == 2 && reductee_shape.at(1) == 0))
{ {
writer << "{ // " << n->get_name() << " 2\n"; writer << "{ // " << node->get_name() << " 2\n";
writer.indent++; writer.indent++;
writer << "memcpy(" << out[0].get_name() << ", " << args[1].get_name() << ", " writer << "memcpy(" << out[0].get_name() << ", " << args[1].get_name() << ", "
<< out[0].get_size() * out[0].get_element_type().size() << ");\n"; << out[0].get_size() * out[0].get_element_type().size() << ");\n";
...@@ -1090,7 +1004,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1090,7 +1004,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
} }
else else
{ {
writer << "{ // " << n->get_name() << " 3\n"; writer << "{ // " << node->get_name() << " 3\n";
writer.indent++; writer.indent++;
string type = f_result_element_type.c_type_string(); string type = f_result_element_type.c_type_string();
writer << "auto f = [&](" << type << " x, " << type << " y) -> " << type << "\n{"; writer << "auto f = [&](" << type << " x, " << type << " y) -> " << type << "\n{";
...@@ -1113,7 +1027,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1113,7 +1027,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
{ {
if (reductee_shape.at(1) == 0) if (reductee_shape.at(1) == 0)
{ {
writer << "{ // " << n->get_name() << " 4\n"; writer << "{ // " << node->get_name() << " 4\n";
writer.indent++; writer.indent++;
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
<< " " << emit_array1d(args[1]) << "(0, 0);\n"; << " " << emit_array1d(args[1]) << "(0, 0);\n";
...@@ -1126,7 +1040,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1126,7 +1040,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
// dynamic_pointer_cast<CallFrame>(external->make_call_frame()); // dynamic_pointer_cast<CallFrame>(external->make_call_frame());
// ef->get_callees().emplace_back(cf); // ef->get_callees().emplace_back(cf);
writer << "{ // " << n->get_name() << " 5\n"; writer << "{ // " << node->get_name() << " 5\n";
writer.indent++; writer.indent++;
string type = f_result_element_type.c_type_string(); string type = f_result_element_type.c_type_string();
writer << "auto f = [&](" << type << " x, " << type << " y) -> " << type << "\n{"; writer << "auto f = [&](" << type << " x, " << type << " y) -> " << type << "\n{";
...@@ -1149,7 +1063,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1149,7 +1063,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
{ {
if (reductee_shape.at(0) == 0) if (reductee_shape.at(0) == 0)
{ {
writer << "{ // " << n->get_name() << " 6\n"; writer << "{ // " << node->get_name() << " 6\n";
writer.indent++; writer.indent++;
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
<< " " << emit_array1d(args[1]) << "(0, 0);\n"; << " " << emit_array1d(args[1]) << "(0, 0);\n";
...@@ -1158,7 +1072,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1158,7 +1072,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
} }
else else
{ {
writer << "{ // " << n->get_name() << " 7\n"; writer << "{ // " << node->get_name() << " 7\n";
writer.indent++; writer.indent++;
string type = f_result_element_type.c_type_string(); string type = f_result_element_type.c_type_string();
writer << "auto f = [&](" << type << " x, " << type << " y) -> " << type << "\n{"; writer << "auto f = [&](" << type << " x, " << type << " y) -> " << type << "\n{";
...@@ -1179,7 +1093,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1179,7 +1093,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
} }
else else
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
string type = f_result_element_type.c_type_string(); string type = f_result_element_type.c_type_string();
...@@ -1206,7 +1120,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1206,7 +1120,7 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
#else #else
writer << "{ // " << n->get_name() << " 1\n"; writer << "{ // " << node->get_name() << " 1\n";
writer.indent++; writer.indent++;
string type = f_result_element_type.c_type_string(); string type = f_result_element_type.c_type_string();
...@@ -1236,12 +1150,9 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer, ...@@ -1236,12 +1150,9 @@ void runtime::cpu::CPU_Emitter::EmitReduce(codegen::CodeWriter& writer,
#endif #endif
} }
void runtime::cpu::CPU_Emitter::EmitSign(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSign)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1258,14 +1169,11 @@ void runtime::cpu::CPU_Emitter::EmitSign(codegen::CodeWriter& writer, ...@@ -1258,14 +1169,11 @@ void runtime::cpu::CPU_Emitter::EmitSign(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSlice)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
const op::Slice* slice = static_cast<const op::Slice*>(n); const op::Slice* slice = static_cast<const op::Slice*>(node);
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
size_t arg_rank = args[0].get_shape().size(); size_t arg_rank = args[0].get_shape().size();
...@@ -1286,7 +1194,7 @@ void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer, ...@@ -1286,7 +1194,7 @@ void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer,
// Scalar slice is necessarily just a copy. // Scalar slice is necessarily just a copy.
if (!strided && arg_rank == 0) if (!strided && arg_rank == 0)
{ {
writer << "{ // " << n->get_name() << " 1\n"; writer << "{ // " << node->get_name() << " 1\n";
writer.indent++; writer.indent++;
writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", " writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", "
<< out[0].get_size() * out[0].get_element_type().size() << ");\n"; << out[0].get_size() * out[0].get_element_type().size() << ");\n";
...@@ -1295,7 +1203,7 @@ void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer, ...@@ -1295,7 +1203,7 @@ void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer,
} }
else if (!strided && arg_rank == 1) else if (!strided && arg_rank == 1)
{ {
writer << "{ // " << n->get_name() << " 2\n"; writer << "{ // " << node->get_name() << " 2\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0]) << " =\n" writer << emit_vector(out[0]) << " =\n"
<< " " << emit_vector(args[0]) << ".segment(\n" << " " << emit_vector(args[0]) << ".segment(\n"
...@@ -1306,7 +1214,7 @@ void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer, ...@@ -1306,7 +1214,7 @@ void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer,
} }
else if (!strided && arg_rank == 2) else if (!strided && arg_rank == 2)
{ {
writer << "{ // " << n->get_name() << " 3\n"; writer << "{ // " << node->get_name() << " 3\n";
writer.indent++; writer.indent++;
writer << emit_matrix(out[0]) << " = \n" writer << emit_matrix(out[0]) << " = \n"
<< " " << emit_matrix(args[0]) << ".block(" << to_string(lower_bounds[0]) << " " << emit_matrix(args[0]) << ".block(" << to_string(lower_bounds[0])
...@@ -1342,13 +1250,10 @@ void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer, ...@@ -1342,13 +1250,10 @@ void runtime::cpu::CPU_Emitter::EmitSlice(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSum)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
const op::Sum* sum = static_cast<const op::Sum*>(n); const op::Sum* sum = static_cast<const op::Sum*>(node);
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
const Shape& arg_shape = args[0].get_shape(); const Shape& arg_shape = args[0].get_shape();
...@@ -1358,7 +1263,7 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer, ...@@ -1358,7 +1263,7 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer,
// Trivial case: no reduction axes. // Trivial case: no reduction axes.
if (reduction_axes.size() == 0) if (reduction_axes.size() == 0)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", " writer << "memcpy(" << out[0].get_name() << ", " << args[0].get_name() << ", "
<< out[0].get_size() * out[0].get_element_type().size() << ");\n"; << out[0].get_size() * out[0].get_element_type().size() << ");\n";
...@@ -1369,7 +1274,7 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer, ...@@ -1369,7 +1274,7 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer,
else if ((arg_rank == 1 && reduction_axes == AxisSet{0}) || else if ((arg_rank == 1 && reduction_axes == AxisSet{0}) ||
(arg_rank == 2 && reduction_axes == AxisSet{0, 1})) (arg_rank == 2 && reduction_axes == AxisSet{0, 1}))
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
<< " " << emit_array1d(args[0]) << ".sum();\n"; << " " << emit_array1d(args[0]) << ".sum();\n";
...@@ -1378,7 +1283,7 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer, ...@@ -1378,7 +1283,7 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer,
} }
else if (arg_rank == 2 && reduction_axes == AxisSet{1}) else if (arg_rank == 2 && reduction_axes == AxisSet{1})
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0]) << " =\n" writer << emit_vector(out[0]) << " =\n"
<< " " << emit_matrix(args[0]) << ".rowwise().sum();\n"; << " " << emit_matrix(args[0]) << ".rowwise().sum();\n";
...@@ -1387,7 +1292,7 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer, ...@@ -1387,7 +1292,7 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer,
} }
else if (arg_rank == 2 && reduction_axes == AxisSet{0}) else if (arg_rank == 2 && reduction_axes == AxisSet{0})
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0]) << " =\n" writer << emit_vector(out[0]) << " =\n"
<< " " << emit_matrix(args[0]) << ".colwise().sum();\n"; << " " << emit_matrix(args[0]) << ".colwise().sum();\n";
...@@ -1415,12 +1320,9 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer, ...@@ -1415,12 +1320,9 @@ void runtime::cpu::CPU_Emitter::EmitSum(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitExp(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitExp)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1436,12 +1338,9 @@ void runtime::cpu::CPU_Emitter::EmitExp(codegen::CodeWriter& writer, ...@@ -1436,12 +1338,9 @@ void runtime::cpu::CPU_Emitter::EmitExp(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitSin(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSin)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1457,12 +1356,9 @@ void runtime::cpu::CPU_Emitter::EmitSin(codegen::CodeWriter& writer, ...@@ -1457,12 +1356,9 @@ void runtime::cpu::CPU_Emitter::EmitSin(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitSinh(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSinh)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1478,12 +1374,9 @@ void runtime::cpu::CPU_Emitter::EmitSinh(codegen::CodeWriter& writer, ...@@ -1478,12 +1374,9 @@ void runtime::cpu::CPU_Emitter::EmitSinh(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitCos(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitCos)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1499,12 +1392,9 @@ void runtime::cpu::CPU_Emitter::EmitCos(codegen::CodeWriter& writer, ...@@ -1499,12 +1392,9 @@ void runtime::cpu::CPU_Emitter::EmitCos(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitCosh(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitCosh)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1520,12 +1410,9 @@ void runtime::cpu::CPU_Emitter::EmitCosh(codegen::CodeWriter& writer, ...@@ -1520,12 +1410,9 @@ void runtime::cpu::CPU_Emitter::EmitCosh(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitTan(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitTan)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1541,16 +1428,13 @@ void runtime::cpu::CPU_Emitter::EmitTan(codegen::CodeWriter& writer, ...@@ -1541,16 +1428,13 @@ void runtime::cpu::CPU_Emitter::EmitTan(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitTanh(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitTanh)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
// Eigen's generic_fast_tanh_float<float> is currently miscompiled by Clang/LLVM // Eigen's generic_fast_tanh_float<float> is currently miscompiled by Clang/LLVM
// so we fall-back to tanh // so we fall-back to tanh
// TODO: Implement our own internal fast/approximate tanh if this actually gets used // TODO: Implement our own internal fast/approximate tanh if this actually gets used
// by models // by models
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 0 #if PREFER_EIGEN == 0
writer << "#pragma omp parallel for\n"; writer << "#pragma omp parallel for\n";
...@@ -1563,12 +1447,9 @@ void runtime::cpu::CPU_Emitter::EmitTanh(codegen::CodeWriter& writer, ...@@ -1563,12 +1447,9 @@ void runtime::cpu::CPU_Emitter::EmitTanh(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitAsin(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitAsin)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1584,12 +1465,9 @@ void runtime::cpu::CPU_Emitter::EmitAsin(codegen::CodeWriter& writer, ...@@ -1584,12 +1465,9 @@ void runtime::cpu::CPU_Emitter::EmitAsin(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitAcos(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitAcos)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1605,12 +1483,9 @@ void runtime::cpu::CPU_Emitter::EmitAcos(codegen::CodeWriter& writer, ...@@ -1605,12 +1483,9 @@ void runtime::cpu::CPU_Emitter::EmitAcos(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitAtan(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitAtan)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " =\n" writer << emit_array1d(out[0]) << " =\n"
...@@ -1626,12 +1501,9 @@ void runtime::cpu::CPU_Emitter::EmitAtan(codegen::CodeWriter& writer, ...@@ -1626,12 +1501,9 @@ void runtime::cpu::CPU_Emitter::EmitAtan(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitPower(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitPower)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
writer << emit_array1d(out[0]) << " = \n"; writer << emit_array1d(out[0]) << " = \n";
...@@ -1651,14 +1523,10 @@ void runtime::cpu::CPU_Emitter::EmitPower(codegen::CodeWriter& writer, ...@@ -1651,14 +1523,10 @@ void runtime::cpu::CPU_Emitter::EmitPower(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitReplaceSlice( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitReplaceSlice)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto replace_slice = static_cast<const op::Slice*>(n); auto replace_slice = static_cast<const op::Slice*>(node);
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
#if PREFER_EIGEN == 1 #if PREFER_EIGEN == 1
size_t arg0_rank = args[0].get_shape().size(); size_t arg0_rank = args[0].get_shape().size();
...@@ -1679,7 +1547,7 @@ void runtime::cpu::CPU_Emitter::EmitReplaceSlice( ...@@ -1679,7 +1547,7 @@ void runtime::cpu::CPU_Emitter::EmitReplaceSlice(
// Scalar slice is necessarily just a copy. // Scalar slice is necessarily just a copy.
if (!strided && arg0_rank == 0) if (!strided && arg0_rank == 0)
{ {
writer << "{ // " << n->get_name() << " 1\n"; writer << "{ // " << node->get_name() << " 1\n";
writer.indent++; writer.indent++;
writer << "memcpy(" << out[0].get_name() << ", " << args[1].get_name() << ", " writer << "memcpy(" << out[0].get_name() << ", " << args[1].get_name() << ", "
<< out[0].get_size() * out[0].get_element_type().size() << ");\n"; << out[0].get_size() * out[0].get_element_type().size() << ");\n";
...@@ -1688,7 +1556,7 @@ void runtime::cpu::CPU_Emitter::EmitReplaceSlice( ...@@ -1688,7 +1556,7 @@ void runtime::cpu::CPU_Emitter::EmitReplaceSlice(
} }
else if (!strided && arg0_rank == 1) else if (!strided && arg0_rank == 1)
{ {
writer << "{ // " << n->get_name() << " 2\n"; writer << "{ // " << node->get_name() << " 2\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0]) << " =\n" writer << emit_vector(out[0]) << " =\n"
<< " " << emit_vector(args[0]) << ";\n" << " " << emit_vector(args[0]) << ";\n"
...@@ -1701,7 +1569,7 @@ void runtime::cpu::CPU_Emitter::EmitReplaceSlice( ...@@ -1701,7 +1569,7 @@ void runtime::cpu::CPU_Emitter::EmitReplaceSlice(
} }
else if (!strided && arg0_rank == 2) else if (!strided && arg0_rank == 2)
{ {
writer << "{ // " << n->get_name() << " 3\n"; writer << "{ // " << node->get_name() << " 3\n";
writer.indent++; writer.indent++;
writer << emit_matrix(out[0]) << " =\n" writer << emit_matrix(out[0]) << " =\n"
<< " " << emit_matrix(args[0]) << ";\n" << " " << emit_matrix(args[0]) << ";\n"
...@@ -1743,12 +1611,9 @@ void runtime::cpu::CPU_Emitter::EmitReplaceSlice( ...@@ -1743,12 +1611,9 @@ void runtime::cpu::CPU_Emitter::EmitReplaceSlice(
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitOneHot(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitOneHot)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto oh = static_cast<const op::OneHot*>(n); auto oh = static_cast<const op::OneHot*>(node);
auto arg_rank = args[0].get_shape().size(); auto arg_rank = args[0].get_shape().size();
...@@ -1756,7 +1621,7 @@ void runtime::cpu::CPU_Emitter::EmitOneHot(codegen::CodeWriter& writer, ...@@ -1756,7 +1621,7 @@ void runtime::cpu::CPU_Emitter::EmitOneHot(codegen::CodeWriter& writer,
if (arg_rank == 0) if (arg_rank == 0)
{ {
writer << "{ // " << n->get_name() << " 1\n"; writer << "{ // " << node->get_name() << " 1\n";
writer.indent++; writer.indent++;
writer << emit_vector(out[0], "out_vector") << ";\n"; writer << emit_vector(out[0], "out_vector") << ";\n";
...@@ -1787,7 +1652,7 @@ void runtime::cpu::CPU_Emitter::EmitOneHot(codegen::CodeWriter& writer, ...@@ -1787,7 +1652,7 @@ void runtime::cpu::CPU_Emitter::EmitOneHot(codegen::CodeWriter& writer,
} }
else if (arg_rank == 1) else if (arg_rank == 1)
{ {
writer << "{ // " << n->get_name() << " 1\n"; writer << "{ // " << node->get_name() << " 1\n";
writer.indent++; writer.indent++;
writer << emit_vector(args[0], "arg_vector") << ";\n"; writer << emit_vector(args[0], "arg_vector") << ";\n";
...@@ -1838,12 +1703,9 @@ void runtime::cpu::CPU_Emitter::EmitOneHot(codegen::CodeWriter& writer, ...@@ -1838,12 +1703,9 @@ void runtime::cpu::CPU_Emitter::EmitOneHot(codegen::CodeWriter& writer,
} }
} }
void runtime::cpu::CPU_Emitter::EmitCeiling(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitCeiling)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
size_t element_count = out[0].get_size(); size_t element_count = out[0].get_size();
#if PREFER_EIGEN == 0 #if PREFER_EIGEN == 0
...@@ -1857,12 +1719,9 @@ void runtime::cpu::CPU_Emitter::EmitCeiling(codegen::CodeWriter& writer, ...@@ -1857,12 +1719,9 @@ void runtime::cpu::CPU_Emitter::EmitCeiling(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitFloor(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitFloor)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
size_t element_count = out[0].get_size(); size_t element_count = out[0].get_size();
#if PREFER_EIGEN == 0 #if PREFER_EIGEN == 0
...@@ -1876,12 +1735,9 @@ void runtime::cpu::CPU_Emitter::EmitFloor(codegen::CodeWriter& writer, ...@@ -1876,12 +1735,9 @@ void runtime::cpu::CPU_Emitter::EmitFloor(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitSqrt(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSqrt)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
size_t element_count = out[0].get_size(); size_t element_count = out[0].get_size();
#if PREFER_EIGEN == 0 #if PREFER_EIGEN == 0
...@@ -1895,12 +1751,9 @@ void runtime::cpu::CPU_Emitter::EmitSqrt(codegen::CodeWriter& writer, ...@@ -1895,12 +1751,9 @@ void runtime::cpu::CPU_Emitter::EmitSqrt(codegen::CodeWriter& writer,
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitConvolution(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitConvolution)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto convolution = static_cast<const op::Convolution*>(n); auto convolution = static_cast<const op::Convolution*>(node);
auto arg0_shape = args[0].get_shape(); auto arg0_shape = args[0].get_shape();
auto arg1_shape = args[1].get_shape(); auto arg1_shape = args[1].get_shape();
...@@ -2025,13 +1878,9 @@ void runtime::cpu::CPU_Emitter::EmitConvolution(codegen::CodeWriter& writer, ...@@ -2025,13 +1878,9 @@ void runtime::cpu::CPU_Emitter::EmitConvolution(codegen::CodeWriter& writer,
} }
} }
void runtime::cpu::CPU_Emitter::EmitConvolutionBackpropFilters( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitConvolutionBackpropFilters)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto convolution = static_cast<const op::ConvolutionBackpropFilters*>(n); auto convolution = static_cast<const op::ConvolutionBackpropFilters*>(node);
auto arg0_shape = args[0].get_shape(); auto arg0_shape = args[0].get_shape();
auto arg1_shape = args[1].get_shape(); auto arg1_shape = args[1].get_shape();
...@@ -2136,13 +1985,9 @@ void runtime::cpu::CPU_Emitter::EmitConvolutionBackpropFilters( ...@@ -2136,13 +1985,9 @@ void runtime::cpu::CPU_Emitter::EmitConvolutionBackpropFilters(
} }
} }
void runtime::cpu::CPU_Emitter::EmitConvolutionBackpropData( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitConvolutionBackpropData)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto convolution = static_cast<const op::ConvolutionBackpropData*>(n); auto convolution = static_cast<const op::ConvolutionBackpropData*>(node);
auto arg0_shape = args[0].get_shape(); auto arg0_shape = args[0].get_shape();
auto arg1_shape = args[1].get_shape(); auto arg1_shape = args[1].get_shape();
...@@ -2246,22 +2091,16 @@ void runtime::cpu::CPU_Emitter::EmitConvolutionBackpropData( ...@@ -2246,22 +2091,16 @@ void runtime::cpu::CPU_Emitter::EmitConvolutionBackpropData(
} }
} }
void runtime::cpu::CPU_Emitter::EmitNot(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitNot)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
writer << "kernel::logical_not(" << args[0].get_name() << ",\n" writer << "kernel::logical_not(" << args[0].get_name() << ",\n"
<< " " << out[0].get_name() << ",\n" << " " << out[0].get_name() << ",\n"
<< " " << out[0].get_size() << ");\n"; << " " << out[0].get_size() << ");\n";
} }
void runtime::cpu::CPU_Emitter::EmitMaxPool(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitMaxPool)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto max_pool = static_cast<const op::MaxPool*>(n); auto max_pool = static_cast<const op::MaxPool*>(node);
auto arg_shape = args[0].get_shape(); auto arg_shape = args[0].get_shape();
auto arg_rank = arg_shape.size(); auto arg_rank = arg_shape.size();
...@@ -2318,12 +2157,9 @@ void runtime::cpu::CPU_Emitter::EmitMaxPool(codegen::CodeWriter& writer, ...@@ -2318,12 +2157,9 @@ void runtime::cpu::CPU_Emitter::EmitMaxPool(codegen::CodeWriter& writer,
} }
} }
void runtime::cpu::CPU_Emitter::EmitReverse(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitReverse)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto reverse = static_cast<const op::Reverse*>(n); auto reverse = static_cast<const op::Reverse*>(node);
auto arg_shape = args[0].get_shape(); auto arg_shape = args[0].get_shape();
auto result_shape = out[0].get_shape(); auto result_shape = out[0].get_shape();
...@@ -2335,20 +2171,16 @@ void runtime::cpu::CPU_Emitter::EmitReverse(codegen::CodeWriter& writer, ...@@ -2335,20 +2171,16 @@ void runtime::cpu::CPU_Emitter::EmitReverse(codegen::CodeWriter& writer,
writer << " {" << join(reverse->get_reversed_axes()) << "});\n"; writer << " {" << join(reverse->get_reversed_axes()) << "});\n";
} }
void runtime::cpu::CPU_Emitter::EmitReduceWindow( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitReduceWindow)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto reduce_window = static_cast<const op::ReduceWindow*>(n); auto reduce_window = static_cast<const op::ReduceWindow*>(node);
auto arg_reductee_shape = args[0].get_shape(); auto arg_reductee_shape = args[0].get_shape();
auto result_shape = out[0].get_shape(); auto result_shape = out[0].get_shape();
auto reduction_function = reduce_window->get_functions()[0]; auto reduction_function = reduce_window->get_functions()[0];
auto& f_result_element_type = out[0].get_element_type(); auto& f_result_element_type = out[0].get_element_type();
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
string type = f_result_element_type.c_type_string(); string type = f_result_element_type.c_type_string();
...@@ -2377,13 +2209,9 @@ void runtime::cpu::CPU_Emitter::EmitReduceWindow( ...@@ -2377,13 +2209,9 @@ void runtime::cpu::CPU_Emitter::EmitReduceWindow(
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitSelectAndScatter( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitSelectAndScatter)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto select_and_scatter = static_cast<const op::SelectAndScatter*>(n); auto select_and_scatter = static_cast<const op::SelectAndScatter*>(node);
auto selection_function = select_and_scatter->get_functions()[0]; auto selection_function = select_and_scatter->get_functions()[0];
auto scatter_function = select_and_scatter->get_functions()[1]; auto scatter_function = select_and_scatter->get_functions()[1];
...@@ -2391,10 +2219,10 @@ void runtime::cpu::CPU_Emitter::EmitSelectAndScatter( ...@@ -2391,10 +2219,10 @@ void runtime::cpu::CPU_Emitter::EmitSelectAndScatter(
auto arg1_shape = args[1].get_shape(); auto arg1_shape = args[1].get_shape();
auto result_shape = out[0].get_shape(); auto result_shape = out[0].get_shape();
writer << "{ // " << n->get_name() << "\n"; writer << "{ // " << node->get_name() << "\n";
writer.indent++; writer.indent++;
string type = n->get_output_element_type(0).c_type_string(); string type = node->get_output_element_type(0).c_type_string();
writer << "auto f_select = [&](" << type << " x, " << type << " y) -> char\n{"; writer << "auto f_select = [&](" << type << " x, " << type << " y) -> char\n{";
writer.indent++; writer.indent++;
...@@ -2436,12 +2264,9 @@ void runtime::cpu::CPU_Emitter::EmitSelectAndScatter( ...@@ -2436,12 +2264,9 @@ void runtime::cpu::CPU_Emitter::EmitSelectAndScatter(
writer << "}\n"; writer << "}\n";
} }
void runtime::cpu::CPU_Emitter::EmitAvgPool(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitAvgPool)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto avg_pool = static_cast<const op::AvgPool*>(n); auto avg_pool = static_cast<const op::AvgPool*>(node);
auto arg_shape = args[0].get_shape(); auto arg_shape = args[0].get_shape();
auto arg_rank = arg_shape.size(); auto arg_rank = arg_shape.size();
...@@ -2501,12 +2326,9 @@ void runtime::cpu::CPU_Emitter::EmitAvgPool(codegen::CodeWriter& writer, ...@@ -2501,12 +2326,9 @@ void runtime::cpu::CPU_Emitter::EmitAvgPool(codegen::CodeWriter& writer,
} }
} }
void runtime::cpu::CPU_Emitter::EmitPad(codegen::CodeWriter& writer, void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitPad)
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto pad = static_cast<const op::Pad*>(n); auto pad = static_cast<const op::Pad*>(node);
auto arg0_shape = args[0].get_shape(); auto arg0_shape = args[0].get_shape();
auto result_shape = out[0].get_shape(); auto result_shape = out[0].get_shape();
...@@ -2521,13 +2343,9 @@ void runtime::cpu::CPU_Emitter::EmitPad(codegen::CodeWriter& writer, ...@@ -2521,13 +2343,9 @@ void runtime::cpu::CPU_Emitter::EmitPad(codegen::CodeWriter& writer,
writer << " {" << join(pad->get_padding_interior()) << "});\n"; writer << " {" << join(pad->get_padding_interior()) << "});\n";
} }
void runtime::cpu::CPU_Emitter::EmitAvgPoolBackprop( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitAvgPoolBackprop)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto apb = static_cast<const op::AvgPoolBackprop*>(n); auto apb = static_cast<const op::AvgPoolBackprop*>(node);
auto delta_shape = args[0].get_shape(); auto delta_shape = args[0].get_shape();
auto delta_rank = delta_shape.size(); auto delta_rank = delta_shape.size();
...@@ -2586,13 +2404,9 @@ void runtime::cpu::CPU_Emitter::EmitAvgPoolBackprop( ...@@ -2586,13 +2404,9 @@ void runtime::cpu::CPU_Emitter::EmitAvgPoolBackprop(
} }
} }
void runtime::cpu::CPU_Emitter::EmitMaxPoolBackprop( void runtime::cpu::CPU_Emitter::EMITTER_DECL(EmitMaxPoolBackprop)
codegen::CodeWriter& writer,
const ngraph::Node* n,
const vector<runtime::cpu::TensorViewWrapper>& args,
const vector<runtime::cpu::TensorViewWrapper>& out)
{ {
auto mpb = static_cast<const op::MaxPoolBackprop*>(n); auto mpb = static_cast<const op::MaxPoolBackprop*>(node);
auto delta_shape = args[1].get_shape(); auto delta_shape = args[1].get_shape();
auto out_shape = out[0].get_shape(); auto out_shape = out[0].get_shape();
......
...@@ -25,8 +25,9 @@ ...@@ -25,8 +25,9 @@
#include "ngraph/runtime/cpu/cpu_tensor_view_wrapper.hpp" #include "ngraph/runtime/cpu/cpu_tensor_view_wrapper.hpp"
#define EMITTER_DECL(E) \ #define EMITTER_DECL(E) \
E(codegen::CodeWriter& writer, \ E(ngraph::runtime::cpu::CPU_ExternalFunction* external_function, \
const ngraph::Node* n, \ codegen::CodeWriter& writer, \
const ngraph::Node* node, \
const std::vector<ngraph::runtime::cpu::TensorViewWrapper>& args, \ const std::vector<ngraph::runtime::cpu::TensorViewWrapper>& args, \
const std::vector<ngraph::runtime::cpu::TensorViewWrapper>& out) const std::vector<ngraph::runtime::cpu::TensorViewWrapper>& out)
......
...@@ -677,7 +677,7 @@ using namespace ngraph::runtime; ...@@ -677,7 +677,7 @@ using namespace ngraph::runtime;
} }
if (func_name.empty()) if (func_name.empty())
{ {
handler->second(writer, node.get(), in, out); handler->second(this, writer, node.get(), in, out);
} }
else else
{ {
...@@ -952,7 +952,7 @@ string runtime::cpu::CPU_ExternalFunction::emit_op_as_function(const Node& node, ...@@ -952,7 +952,7 @@ string runtime::cpu::CPU_ExternalFunction::emit_op_as_function(const Node& node,
writer << "\n)\n"; writer << "\n)\n";
writer << "{\n"; writer << "{\n";
writer.indent++; writer.indent++;
handler->second(writer, &node, in, out); handler->second(this, writer, &node, in, out);
writer.indent--; writer.indent--;
writer << "}\n"; writer << "}\n";
......
...@@ -43,7 +43,8 @@ namespace ngraph ...@@ -43,7 +43,8 @@ namespace ngraph
class CPU_Emitter; class CPU_Emitter;
class CPU_CallFrame; class CPU_CallFrame;
using OpFunction = std::function<void(codegen::CodeWriter&, using OpFunction = std::function<void(CPU_ExternalFunction* external_function,
codegen::CodeWriter&,
const ngraph::Node*, const ngraph::Node*,
const std::vector<TensorViewWrapper>& inputs, const std::vector<TensorViewWrapper>& inputs,
const std::vector<TensorViewWrapper>& outputs)>; const std::vector<TensorViewWrapper>& outputs)>;
......
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