Commit 3eb0eca0 authored by Robert Kimball's avatar Robert Kimball

wip

parent 3049267e
......@@ -54,49 +54,34 @@ static std::string eigen_matrix_format(const ngraph::Shape& shape, const ngraph:
return ss.str();
}
void Emitter::EmitNop(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitNop(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
}
void Emitter::EmitAdd(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitAdd(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
string type = et.c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << emit_array1d(outputs[0]) << " = \n";
TU.indent++;
TU << "EigenArray1d<" << type << ">(" << inputs[0].get_tensor().get_name() << ", "
<< eigen_vector_format(inputs[0]) << ") +\n";
TU << "EigenArray1d<" << type << ">(" << inputs[1].get_tensor().get_name() << ", "
<< eigen_vector_format(inputs[1]) << ");\n";
TU << emit_array1d(inputs[0]) << " +\n ";
TU << emit_array1d(inputs[1]) << ";\n";
TU.indent -= 2;
TU << "}\n";
}
void Emitter::EmitDot(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitDot(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto& arg_nodes = n->get_arguments();
assert(arg_nodes.size() == 2);
auto arg0_tensor_type =
dynamic_pointer_cast<const TensorViewType>(arg_nodes.at(0)->get_value_type());
auto arg0_tensor_type = dynamic_pointer_cast<const TensorViewType>(arg_nodes.at(0)->get_value_type());
assert(arg0_tensor_type);
auto arg1_tensor_type =
dynamic_pointer_cast<const TensorViewType>(arg_nodes.at(1)->get_value_type());
auto arg1_tensor_type = dynamic_pointer_cast<const TensorViewType>(arg_nodes.at(1)->get_value_type());
assert(arg1_tensor_type);
auto arg0_shape = arg0_tensor_type->get_shape();
......@@ -110,11 +95,7 @@ void Emitter::EmitDot(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenVector<" << arg0_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ")\n = " << first.get_tensor().get_name() << "[0]\n * EigenVector<"
<< arg0_element_type.c_type_string() << ">(" << second.get_tensor().get_name() << ", "
<< eigen_vector_format(second) << ");\n";
TU << "EigenVector<" << arg0_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ")\n = " << first.get_tensor().get_name() << "[0]\n * EigenVector<" << arg0_element_type.c_type_string() << ">(" << second.get_tensor().get_name() << ", " << eigen_vector_format(second) << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -122,15 +103,9 @@ void Emitter::EmitDot(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenVector<" << arg0_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") << \n"
<< " EigenVector<" << arg0_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0])
<< ").dot("
<< "EigenVector<" << arg0_element_type.c_type_string() << ">("
<< inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[1])
<< "));\n";
TU << "EigenVector<" << arg0_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") << \n"
<< " EigenVector<" << arg0_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ").dot("
<< "EigenVector<" << arg0_element_type.c_type_string() << ">(" << inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[1]) << "));\n";
TU.indent--;
TU << "}\n";
}
......@@ -140,14 +115,9 @@ void Emitter::EmitDot(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenVector<" << arg0_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") = \n"
<< " EigenMatrix<" << arg0_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ") * "
<< "EigenVector<" << arg0_element_type.c_type_string() << ">("
<< inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[1]) << ");\n";
TU << "EigenVector<" << arg0_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") = \n"
<< " EigenMatrix<" << arg0_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ") * "
<< "EigenVector<" << arg0_element_type.c_type_string() << ">(" << inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[1]) << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -178,18 +148,9 @@ void Emitter::EmitDot(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenMatrix<" << arg0_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides())
<< ") = \n"
<< " EigenMatrix<" << arg0_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides())
<< ") * "
<< "EigenMatrix<" << arg0_element_type.c_type_string() << ">("
<< inputs[1].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg1_layout->get_shape(), arg1_layout->get_strides())
<< ");\n";
TU << "EigenMatrix<" << arg0_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ") = \n"
<< " EigenMatrix<" << arg0_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ") * "
<< "EigenMatrix<" << arg0_element_type.c_type_string() << ">(" << inputs[1].get_tensor().get_name() << ", " << eigen_matrix_format(arg1_layout->get_shape(), arg1_layout->get_strides()) << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -200,32 +161,21 @@ void Emitter::EmitDot(const ngraph::Node* n,
}
}
void Emitter::EmitMultiply(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitMultiply(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
string type = et.c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << type << ">(" << outputs[0].get_tensor().get_name() << ", "
<< eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << type << ">(" << inputs[0].get_tensor().get_name() << ", "
<< eigen_vector_format(inputs[0]) << ") *\n"
<< " EigenArray1d<" << type << ">(" << inputs[1].get_tensor().get_name() << ", "
<< eigen_vector_format(inputs[1]) << ");\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << " *\n"
<< " " << emit_array1d(inputs[1]) << ";\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitGetTupleElement(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitGetTupleElement(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto get_tuple_element = static_cast<const op::GetTupleElement*>(n);
auto result_tensor_type = dynamic_pointer_cast<const TensorViewType>(n->get_value_type());
......@@ -235,19 +185,12 @@ void Emitter::EmitGetTupleElement(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", "
<< inputs[get_tuple_element->get_n()].get_tensor().get_name() << ", "
<< outputs[0].get_tensor_view_layout()->get_size() *
outputs[0].get_tensor_view_layout()->get_element_type().size()
<< ");\n";
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", " << inputs[get_tuple_element->get_n()].get_tensor().get_name() << ", " << outputs[0].get_tensor_view_layout()->get_size() * outputs[0].get_tensor_view_layout()->get_element_type().size() << ");\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitTuple(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitTuple(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
assert(inputs.size() == outputs.size());
......@@ -256,43 +199,27 @@ void Emitter::EmitTuple(const ngraph::Node* n,
for (size_t i = 0; i < inputs.size(); ++i)
{
auto& et = inputs.at(i).get_tensor_view_layout()->get_element_type();
TU << "// call_frame->get_parameterized_tensor_view<" << et.c_type_string() << ">("
<< outputs.at(i).get_index() << ")->get_vector() =\n"
<< "// call_frame->get_parameterized_tensor_view<" << et.c_type_string() << ">("
<< inputs.at(i).get_index() << ")->get_vector();\n";
TU << "memcpy(" << outputs.at(i).get_tensor().get_name() << ", "
<< inputs.at(i).get_tensor().get_name() << ", "
<< outputs[i].get_tensor_view_layout()->get_size() *
outputs[i].get_tensor_view_layout()->get_element_type().size()
<< ");\n";
TU << "// call_frame->get_parameterized_tensor_view<" << et.c_type_string() << ">(" << outputs.at(i).get_index() << ")->get_vector() =\n"
<< "// call_frame->get_parameterized_tensor_view<" << et.c_type_string() << ">(" << inputs.at(i).get_index() << ")->get_vector();\n";
TU << "memcpy(" << outputs.at(i).get_tensor().get_name() << ", " << inputs.at(i).get_tensor().get_name() << ", " << outputs[i].get_tensor_view_layout()->get_size() * outputs[i].get_tensor_view_layout()->get_element_type().size() << ");\n";
}
TU.indent--;
TU += "}\n";
}
void Emitter::EmitAbs(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitAbs(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n";
TU << "Eigen::abs(EigenArray1d<" << et.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << "));\n";
TU << emit_array1d(outputs[0]) << " =\n";
TU << "Eigen::abs(" << emit_array1d(inputs[0]) << ");\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitConcat(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitConcat(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto result_tensor_type = dynamic_pointer_cast<const TensorViewType>(n->get_value_type());
assert(result_tensor_type);
......@@ -304,18 +231,13 @@ void Emitter::EmitConcat(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenVector<" << result_element_type.c_type_string() << "> out_vector("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ");\n";
TU << "EigenVector<" << result_element_type.c_type_string() << "> out_vector(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ");\n";
size_t concat_pos = 0;
for (size_t i = 0; i < inputs.size(); i++)
{
TU << "out_vector.segment(" << concat_pos << ", "
<< inputs[i].get_tensor_view_layout()->get_shape().at(0) << ") << "
<< "EigenVector<" << result_element_type.c_type_string() << ">("
<< inputs[i].get_tensor().get_name() << ", " << eigen_vector_format(inputs[i])
<< ");\n";
TU << "out_vector.segment(" << concat_pos << ", " << inputs[i].get_tensor_view_layout()->get_shape().at(0) << ") << "
<< "EigenVector<" << result_element_type.c_type_string() << ">(" << inputs[i].get_tensor().get_name() << ", " << eigen_vector_format(inputs[i]) << ");\n";
concat_pos += inputs[i].get_tensor_view_layout()->get_shape().at(0);
}
TU.indent--;
......@@ -328,9 +250,7 @@ void Emitter::EmitConcat(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenMatrix<" << result_element_type.c_type_string() << "> out_matrix("
<< outputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ");\n";
TU << "EigenMatrix<" << result_element_type.c_type_string() << "> out_matrix(" << outputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ");\n";
size_t concat_pos[2]{0, 0};
for (size_t i = 0; i < inputs.size(); i++)
......@@ -338,11 +258,8 @@ void Emitter::EmitConcat(const ngraph::Node* n,
auto arg_layout = inputs[i].get_layout<DenseTensorViewLayout>();
auto& arg_shape = inputs[i].get_tensor_view_layout()->get_shape();
TU << "out_matrix.block(" << concat_pos[0] << ", " << concat_pos[1] << ", "
<< arg_shape.at(0) << ", " << arg_shape.at(1) << ") << "
<< "EigenMatrix<" << result_element_type.c_type_string() << ">("
<< inputs[i].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg_layout->get_shape(), arg_layout->get_strides()) << ");\n";
TU << "out_matrix.block(" << concat_pos[0] << ", " << concat_pos[1] << ", " << arg_shape.at(0) << ", " << arg_shape.at(1) << ") << "
<< "EigenMatrix<" << result_element_type.c_type_string() << ">(" << inputs[i].get_tensor().get_name() << ", " << eigen_matrix_format(arg_layout->get_shape(), arg_layout->get_strides()) << ");\n";
concat_pos[axis] += arg_shape.at(axis);
}
......@@ -352,454 +269,299 @@ void Emitter::EmitConcat(const ngraph::Node* n,
}
}
void Emitter::EmitDivide(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitDivide(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ") /\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << ");\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << " /\n"
<< " " << emit_array1d(inputs[1]) << ";\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitEqual(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitEqual(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ") ==\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << ")).template cast<char>();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " (" << emit_array1d(inputs[0]) << " ==\n"
<< " " << emit_array1d(inputs[1]) << ").template cast<char>();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitGreater(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitGreater(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ") >\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << ")).template cast<char>();\n";
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (" << emit_array1d(inputs[0]) << " >\n"
<< " " << emit_array1d(inputs[1]) << ").template cast<char>();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitGreaterEq(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitGreaterEq(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ") >=\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << ")).template cast<char>();\n";
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (" << emit_array1d(inputs[0]) << " >=\n"
<< " " << emit_array1d(inputs[1]) << ").template cast<char>();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitLess(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitLess(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ") <\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << ")).template cast<char>();\n";
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (" << emit_array1d(inputs[0]) << " <\n"
<< " " << emit_array1d(inputs[1]) << ").template cast<char>();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitLessEq(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitLessEq(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ") <=\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << ")).template cast<char>();\n";
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (" << emit_array1d(inputs[0]) << " <=\n"
<< " " << emit_array1d(inputs[1]) << ").template cast<char>();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitLog(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitLog(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " Eigen::log(EigenArray1d<" << et.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << "));\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " Eigen::log(" << emit_array1d(inputs[0]) << ");\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitMaximum(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitMaximum(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").max(\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << "));\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".max(\n"
<< " " << emit_array1d(inputs[1]) << ");\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitMinimum(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitMinimum(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").min(\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << "));\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".min(\n"
<< " " << emit_array1d(inputs[1]) << ");\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitNegative(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitNegative(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " -EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ");\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " -" << emit_array1d(inputs[0]) << ";\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitNotEqual(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitNotEqual(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ") !=\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << ")).template cast<char>();\n";
TU << "EigenArray1d<" << element::Bool::element_type().c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " (" << emit_array1d(inputs[0]) << " !=\n"
<< " " << emit_array1d(inputs[1]) << ").template cast<char>();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitSelect(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitSelect(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(1)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(1)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << element::Bool::element_type().c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ")\n"
<< " .select(EigenArray1d<" << et.c_type_string() << ">("
<< inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << "),\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[2].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << "));\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " EigenArray1d<" << element::Bool::element_type().c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ")\n"
<< " .select(" << emit_array1d(inputs[1]) << ",\n"
<< " " << emit_array1d(inputs[2]) << ");\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitSubtract(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitSubtract(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ") -\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[1].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[1]) << ");\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << " -\n"
<< " " << emit_array1d(inputs[1]) << ";\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitParameterizedConstantBool(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitParameterizedConstantBool(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Bool>*>(n)
->get_value()
->get_vector();
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Bool>*>(n)->get_value()->get_vector();
string type = element::Bool::element_type().c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
for (size_t i = 0; i < value.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">("
<< (value[i] ? "true" : "false") << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">(" << (value[i] ? "true" : "false") << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitParameterizedConstantFloat32(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitParameterizedConstantFloat32(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Float32>*>(n)
->get_value()
->get_vector();
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Float32>*>(n)->get_value()->get_vector();
string type = element::Float32::element_type().c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
for (size_t i = 0; i < value.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">("
<< value[i] << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">(" << value[i] << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitParameterizedConstantInt8(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitParameterizedConstantInt8(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Int8>*>(n)
->get_value()
->get_vector();
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Int8>*>(n)->get_value()->get_vector();
string type = element::Int8::element_type().c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
for (size_t i = 0; i < value.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">("
<< value[i] << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">(" << value[i] << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitParameterizedConstantInt32(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitParameterizedConstantInt32(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Int32>*>(n)
->get_value()
->get_vector();
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Int32>*>(n)->get_value()->get_vector();
string type = element::Int32::element_type().c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
for (size_t i = 0; i < value.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">("
<< value[i] << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">(" << value[i] << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitParameterizedConstantInt64(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitParameterizedConstantInt64(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Int64>*>(n)
->get_value()
->get_vector();
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::Int64>*>(n)->get_value()->get_vector();
string type = element::Int64::element_type().c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
for (size_t i = 0; i < value.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">("
<< value[i] << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">(" << value[i] << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitParameterizedConstantUInt8(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitParameterizedConstantUInt8(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::UInt8>*>(n)
->get_value()
->get_vector();
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::UInt8>*>(n)->get_value()->get_vector();
string type = element::UInt8::element_type().c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
for (size_t i = 0; i < value.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">("
<< value[i] << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">(" << value[i] << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitParameterizedConstantUInt32(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitParameterizedConstantUInt32(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::UInt32>*>(n)
->get_value()
->get_vector();
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::UInt32>*>(n)->get_value()->get_vector();
string type = element::UInt32::element_type().c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
for (size_t i = 0; i < value.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">("
<< value[i] << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">(" << value[i] << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitParameterizedConstantUInt64(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitParameterizedConstantUInt64(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::UInt64>*>(n)
->get_value()
->get_vector();
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::UInt64>*>(n)->get_value()->get_vector();
string type = element::UInt64::element_type().c_type_string();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
for (size_t i = 0; i < value.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">("
<< value[i] << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << type << ">(" << value[i] << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitBroadcast(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitBroadcast(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto broadcast = static_cast<const op::Broadcast*>(n);
auto arg_tensor_type =
dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type());
auto arg_tensor_type = dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type());
assert(arg_tensor_type);
auto result_tensor_type = dynamic_pointer_cast<const TensorViewType>(n->get_value_type());
......@@ -813,11 +575,7 @@ void Emitter::EmitBroadcast(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", "
<< inputs[0].get_tensor().get_name() << ", "
<< outputs[0].get_tensor_view_layout()->get_size() *
outputs[0].get_tensor_view_layout()->get_element_type().size()
<< ");\n";
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", " << inputs[0].get_tensor().get_name() << ", " << outputs[0].get_tensor_view_layout()->get_size() * outputs[0].get_tensor_view_layout()->get_element_type().size() << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -825,12 +583,8 @@ void Emitter::EmitBroadcast(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenArray1d<" << result_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0])
<< ")(0, 0);\n";
TU << "EigenArray1d<" << result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << result_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ")(0, 0);\n";
TU.indent--;
TU << "}\n";
}
......@@ -842,13 +596,8 @@ void Emitter::EmitBroadcast(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenMatrix<" << result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides())
<< ").colwise() =\n"
<< " EigenVector<" << result_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0])
<< ");\n";
TU << "EigenMatrix<" << result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ").colwise() =\n"
<< " EigenVector<" << result_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -858,13 +607,8 @@ void Emitter::EmitBroadcast(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenMatrix<" << result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides())
<< ").rowwise() =\n"
<< " EigenVector<" << result_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0])
<< ").transpose();\n";
TU << "EigenMatrix<" << result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ").rowwise() =\n"
<< " EigenVector<" << result_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ").transpose();\n";
TU.indent--;
TU << "}\n";
}
......@@ -881,10 +625,7 @@ void Emitter::EmitBroadcast(const ngraph::Node* n,
}
}
void Emitter::EmitConvert(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitConvert(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto arg = n->get_arguments().at(0);
......@@ -900,19 +641,14 @@ void Emitter::EmitConvert(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << arg_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ")\n"
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << "\n"
<< " .template cast<" << result_element_type.c_type_string() << ">();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitConstant(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitConstant(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto c = static_cast<const op::Constant*>(n);
auto c_tensor_type = dynamic_pointer_cast<const TensorViewType>(c->get_value_type());
......@@ -924,17 +660,13 @@ void Emitter::EmitConstant(const ngraph::Node* n,
TU.indent++;
for (size_t i = 0; i < c_value_strings.size(); i++)
{
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<"
<< c_element_type.c_type_string() << ">(" << c_value_strings[i] << ");\n";
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<" << c_element_type.c_type_string() << ">(" << c_value_strings[i] << ");\n";
}
TU.indent--;
TU << "}\n";
}
void Emitter::EmitReshape(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitReshape(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto reshape = static_cast<const op::Reshape*>(n);
......@@ -965,11 +697,7 @@ void Emitter::EmitReshape(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << " 1\n";
TU.indent++;
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", "
<< inputs[0].get_tensor().get_name() << ", "
<< outputs[0].get_tensor_view_layout()->get_size() *
outputs[0].get_tensor_view_layout()->get_element_type().size()
<< ");\n";
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", " << inputs[0].get_tensor().get_name() << ", " << outputs[0].get_tensor_view_layout()->get_size() * outputs[0].get_tensor_view_layout()->get_element_type().size() << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -999,13 +727,8 @@ void Emitter::EmitReshape(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << " 3\n";
TU.indent++;
TU << "EigenMatrix<" << result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ") =\n"
<< " EigenMatrix<" << result_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides())
<< ").transpose();\n";
TU << "EigenMatrix<" << result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ") =\n"
<< " EigenMatrix<" << result_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ").transpose();\n";
TU.indent--;
TU << "}\n";
}
......@@ -1013,15 +736,11 @@ void Emitter::EmitReshape(const ngraph::Node* n,
// Other cases (reordering of axes for tensors with rank>2) are not handled yet.
else
{
throw ngraph_error(
"Axis permutation in reshape is not implemented yet for tensors with rank>2");
throw ngraph_error("Axis permutation in reshape is not implemented yet for tensors with rank>2");
}
}
void Emitter::EmitFunctionCall(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitFunctionCall(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto function_call = static_cast<const op::FunctionCall*>(n);
shared_ptr<Function> function = function_call->get_function();
......@@ -1039,10 +758,7 @@ void Emitter::EmitFunctionCall(const ngraph::Node* n,
// the compiled version of these ops is intended to have semantics identical
// to what's seen there (for now atleast)
void Emitter::EmitReduce(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitReduce(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto reduce = static_cast<const op::Reduce*>(n);
auto reduction_function = reduce->get_reduction_function();
......@@ -1071,11 +787,7 @@ void Emitter::EmitReduce(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << " 1\n";
TU.indent++;
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", "
<< inputs[0].get_tensor().get_name() << ", "
<< outputs[0].get_tensor_view_layout()->get_size() *
outputs[0].get_tensor_view_layout()->get_element_type().size()
<< ");\n";
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", " << inputs[0].get_tensor().get_name() << ", " << outputs[0].get_tensor_view_layout()->get_size() * outputs[0].get_tensor_view_layout()->get_element_type().size() << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -1104,18 +816,13 @@ void Emitter::EmitReduce(const ngraph::Node* n,
// required to appear at least once. If so, this will need to be reworked,
// assuming we actually want to mimic XLA's semantics that closely, which
// we may not.
else if ((reductee_shape.size() == 1 && reduction_axes == AxisSet{0}) ||
(reductee_shape.size() == 2 && reduction_axes == AxisSet{0, 1}))
else if ((reductee_shape.size() == 1 && reduction_axes == AxisSet{0}) || (reductee_shape.size() == 2 && reduction_axes == AxisSet{0, 1}))
{
if (reductee_shape.at(0) == 0 || (reductee_shape.size() == 2 && reductee_shape.at(1) == 0))
{
TU << "{ // " << n->get_name() << " 2\n";
TU.indent++;
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", "
<< inputs[1].get_tensor().get_name() << ", "
<< outputs[0].get_tensor_view_layout()->get_size() *
outputs[0].get_tensor_view_layout()->get_element_type().size()
<< ");\n";
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", " << inputs[1].get_tensor().get_name() << ", " << outputs[0].get_tensor_view_layout()->get_size() * outputs[0].get_tensor_view_layout()->get_element_type().size() << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -1134,12 +841,8 @@ void Emitter::EmitReduce(const ngraph::Node* n,
TU << "return result;\n";
TU.indent--;
TU << "};\n";
TU << "EigenArray1d<" << f_result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenArray1d<" << f_result_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0])
<< ").redux(f);\n";
TU << "EigenArray1d<" << f_result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << f_result_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ").redux(f);\n";
TU.indent--;
TU << "}\n";
}
......@@ -1150,12 +853,8 @@ void Emitter::EmitReduce(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << " 4\n";
TU.indent++;
TU << "EigenArray1d<" << f_result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenArray1d<" << f_result_element_type.c_type_string() << ">("
<< inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[1])
<< ")(0, 0);\n";
TU << "EigenArray1d<" << f_result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << f_result_element_type.c_type_string() << ">(" << inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[1]) << ")(0, 0);\n";
TU.indent--;
TU << "}\n";
}
......@@ -1178,13 +877,8 @@ void Emitter::EmitReduce(const ngraph::Node* n,
TU << "return result;\n";
TU.indent--;
TU << "};\n";
TU << "EigenVector<" << f_result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenMatrix<" << f_result_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides())
<< ").rowwise().redux(f);\n";
TU << "EigenVector<" << f_result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenMatrix<" << f_result_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ").rowwise().redux(f);\n";
TU.indent--;
TU << "}\n";
}
......@@ -1195,12 +889,8 @@ void Emitter::EmitReduce(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << " 6\n";
TU.indent++;
TU << "EigenArray1d<" << f_result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenArray1d<" << f_result_element_type.c_type_string() << ">("
<< inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[1])
<< ")(0, 0);\n";
TU << "EigenArray1d<" << f_result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << f_result_element_type.c_type_string() << ">(" << inputs[1].get_tensor().get_name() << ", " << eigen_vector_format(inputs[1]) << ")(0, 0);\n";
TU.indent--;
TU << "}\n";
}
......@@ -1219,13 +909,8 @@ void Emitter::EmitReduce(const ngraph::Node* n,
TU << "return result;\n";
TU.indent--;
TU << "};\n";
TU << "EigenVector<" << f_result_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenMatrix<" << f_result_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides())
<< ").colwise().redux(f);\n";
TU << "EigenVector<" << f_result_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenMatrix<" << f_result_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ").colwise().redux(f);\n";
TU.indent--;
TU << "}\n";
}
......@@ -1236,29 +921,19 @@ void Emitter::EmitReduce(const ngraph::Node* n,
}
}
void Emitter::EmitSign(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitSign(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").sign();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".sign();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitSlice(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitSlice(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto slice = static_cast<const op::Slice*>(n);
......@@ -1285,11 +960,7 @@ void Emitter::EmitSlice(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << " 1\n";
TU.indent++;
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", "
<< inputs[0].get_tensor().get_name() << ", "
<< outputs[0].get_tensor_view_layout()->get_size() *
outputs[0].get_tensor_view_layout()->get_element_type().size()
<< ");\n";
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", " << inputs[0].get_tensor().get_name() << ", " << outputs[0].get_tensor_view_layout()->get_size() * outputs[0].get_tensor_view_layout()->get_element_type().size() << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -1297,14 +968,9 @@ void Emitter::EmitSlice(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << " 2\n";
TU.indent++;
TU << "EigenVector<" << arg_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenVector<" << arg_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0])
<< ").segment(\n"
<< " " << to_string(lower_bounds[0]) << ", "
<< to_string(upper_bounds[0] - lower_bounds[0]) << ");\n";
TU << "EigenVector<" << arg_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenVector<" << arg_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ").segment(\n"
<< " " << to_string(lower_bounds[0]) << ", " << to_string(upper_bounds[0] - lower_bounds[0]) << ");\n";
TU.indent--;
TU << "}\n";
}
......@@ -1315,14 +981,8 @@ void Emitter::EmitSlice(const ngraph::Node* n,
TU << "{ // " << n->get_name() << " 3\n";
TU.indent++;
TU << "EigenMatrix<" << arg_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ") = \n"
<< " EigenMatrix<" << arg_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides())
<< ").block(" << to_string(lower_bounds[0]) << ", " << to_string(lower_bounds[1])
<< ",\n"
TU << "EigenMatrix<" << arg_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(out_layout->get_shape(), out_layout->get_strides()) << ") = \n"
<< " EigenMatrix<" << arg_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ").block(" << to_string(lower_bounds[0]) << ", " << to_string(lower_bounds[1]) << ",\n"
<< " " << to_string(upper_bounds[0] - lower_bounds[0]) << ",\n"
<< " " << to_string(upper_bounds[1] - lower_bounds[1]) << ");\n";
TU.indent--;
......@@ -1335,10 +995,7 @@ void Emitter::EmitSlice(const ngraph::Node* n,
}
}
void Emitter::EmitSum(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitSum(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
auto s = static_cast<const op::Sum*>(n);
auto s_tensor_view_type = dynamic_pointer_cast<const TensorViewType>(s->get_value_type());
......@@ -1360,26 +1017,17 @@ void Emitter::EmitSum(const ngraph::Node* n,
{
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", "
<< inputs[0].get_tensor().get_name() << ", "
<< outputs[0].get_tensor_view_layout()->get_size() *
outputs[0].get_tensor_view_layout()->get_element_type().size()
<< ");\n";
TU << "memcpy(" << outputs[0].get_tensor().get_name() << ", " << inputs[0].get_tensor().get_name() << ", " << outputs[0].get_tensor_view_layout()->get_size() * outputs[0].get_tensor_view_layout()->get_element_type().size() << ");\n";
TU.indent--;
TU << "}\n";
}
// Full reduction? Then sum to scalar.
else if ((arg_rank == 1 && reduction_axes == AxisSet{0}) ||
(arg_rank == 2 && reduction_axes == AxisSet{0, 1}))
else if ((arg_rank == 1 && reduction_axes == AxisSet{0}) || (arg_rank == 2 && reduction_axes == AxisSet{0, 1}))
{
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << s_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenArray1d<" << s_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0])
<< ").sum();\n";
TU << "EigenArray1d<" << s_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << s_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_vector_format(inputs[0]) << ").sum();\n";
TU.indent--;
TU << "}\n";
}
......@@ -1389,13 +1037,8 @@ void Emitter::EmitSum(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenVector<" << s_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenMatrix<" << s_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides())
<< ").rowwise().sum();\n";
TU << "EigenVector<" << s_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenMatrix<" << s_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ").rowwise().sum();\n";
TU.indent--;
TU << "}\n";
}
......@@ -1405,13 +1048,8 @@ void Emitter::EmitSum(const ngraph::Node* n,
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenVector<" << s_element_type.c_type_string() << ">("
<< outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0])
<< ") =\n"
<< " EigenMatrix<" << s_element_type.c_type_string() << ">("
<< inputs[0].get_tensor().get_name() << ", "
<< eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides())
<< ").colwise().sum();\n";
TU << "EigenVector<" << s_element_type.c_type_string() << ">(" << outputs[0].get_tensor().get_name() << ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenMatrix<" << s_element_type.c_type_string() << ">(" << inputs[0].get_tensor().get_name() << ", " << eigen_matrix_format(arg0_layout->get_shape(), arg0_layout->get_strides()) << ").colwise().sum();\n";
TU.indent--;
TU << "}\n";
}
......@@ -1421,124 +1059,79 @@ void Emitter::EmitSum(const ngraph::Node* n,
}
}
void Emitter::EmitExp(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitExp(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").exp();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".exp();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitSin(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitSin(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").sin();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".sin();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitSinh(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitSinh(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").sinh();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".sinh();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitCos(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitCos(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").cos();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".cos();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitCosh(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitCosh(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").cosh();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".cosh();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitTan(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitTan(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").tan();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".tan();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitTanh(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitTanh(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
// Eigen's generic_fast_tanh_float<float> is currently miscompiled by Clang/LLVM
// so we fall-back to std::tanh
......@@ -1548,66 +1141,44 @@ void Emitter::EmitTanh(const ngraph::Node* n,
TU.indent++;
TU << "for (size_t i=0; i<" << outputs[0].get_tensor_view_layout()->get_size() << "; i++)\n";
TU << "{\n";
TU << " " << outputs[0].get_tensor().get_name() << "[i] = std::tanh("
<< inputs[0].get_tensor().get_name() << "[i]);\n";
TU << " " << outputs[0].get_tensor().get_name() << "[i] = std::tanh(" << inputs[0].get_tensor().get_name() << "[i]);\n";
TU << "}\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitAsin(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitAsin(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").asin();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".asin();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitAcos(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitAcos(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").acos();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".acos();\n";
TU.indent--;
TU << "}\n";
}
void Emitter::EmitAtan(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)
void Emitter::EmitAtan(const ngraph::Node* n, ExternalFunction* ef, const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs)
{
const element::Type& et =
(dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))
->get_element_type();
const element::Type& et = (dynamic_pointer_cast<const TensorViewType>(n->get_arguments().at(0)->get_value_type()))->get_element_type();
TU << "{ // " << n->get_name() << "\n";
TU.indent++;
TU << "EigenArray1d<" << et.c_type_string() << ">(" << outputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(outputs[0]) << ") =\n"
<< " EigenArray1d<" << et.c_type_string() << ">(" << inputs[0].get_tensor().get_name()
<< ", " << eigen_vector_format(inputs[0]) << ").atan();\n";
TU << emit_array1d(outputs[0]) << " =\n"
<< " " << emit_array1d(inputs[0]) << ".atan();\n";
TU.indent--;
TU << "}\n";
}
......@@ -1616,9 +1187,7 @@ void Emitter::EmitAtan(const ngraph::Node* n,
// Utility methods
//------------------------------------------------------------------------------------------------
void Emitter::generate_call(const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs,
shared_ptr<Function> function)
void Emitter::generate_call(const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& outputs, shared_ptr<Function> function)
{
vector<string> input_names;
vector<string> output_names;
......@@ -1653,8 +1222,7 @@ string Emitter::emit_vector(const TensorViewInfo& tvi)
{
stringstream ss;
const element::Type& et = tvi.get_tensor_view()->get_value_type()->get_element_type();
ss << "EigenVector<" << et.c_type_string() << ">(" << tvi.get_tensor().get_name() << ", "
<< eigen_vector_format(tvi) << ")";
ss << "EigenVector<" << et.c_type_string() << ">(" << tvi.get_tensor().get_name() << ", " << eigen_vector_format(tvi) << ")";
return ss.str();
}
......@@ -1662,7 +1230,6 @@ string Emitter::emit_array1d(const TensorViewInfo& tvi)
{
stringstream ss;
const element::Type& et = tvi.get_tensor_view()->get_value_type()->get_element_type();
ss << "EigenArray1d<" << et.c_type_string() << ">(" << tvi.get_tensor().get_name() << ", "
<< eigen_vector_format(tvi) << ")";
ss << "EigenArray1d<" << et.c_type_string() << ">(" << tvi.get_tensor().get_name() << ", " << eigen_vector_format(tvi) << ")";
return ss.str();
}
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