Commit 22e1368a authored by Jaikrishnan Menon's avatar Jaikrishnan Menon

CPU: Apply formatting fixes from clang-format

parent 75623f48
......@@ -46,10 +46,8 @@ public:
void enable_pch() { pch_enabled = true; }
void disable_pch() { pch_enabled = false; }
void enable_debuginfo() { debuginfo_enabled = true; }
void disable_debuginfo() { debuginfo_enabled = false; }
std::unique_ptr<llvm::Module> compile(const std::string& source, const std::string& name = "");
bool add_module(std::unique_ptr<llvm::Module>&);
......
......@@ -14,9 +14,9 @@
#pragma once
#include <functional>
#include <memory>
#include <vector>
#include <functional>
#include "ngraph/function.hpp"
#include "ngraph/runtime/call_frame.hpp"
......@@ -31,17 +31,17 @@ namespace ngraph
namespace cpu
{
class CallFrame;
using EntryPoint = std::function<void(ngraph::runtime::cpu::CallFrame*, ngraph::runtime::TensorViewPtrs&)>;
using EntryPoint = std::function<void(ngraph::runtime::cpu::CallFrame*,
ngraph::runtime::TensorViewPtrs&)>;
// Compile and execute graphs
class CallFrame : public ngraph::runtime::CallFrame
{
public:
CallFrame(
EntryPoint compiled_function,
size_t n_inputs,
size_t n_outputs,
const TensorViewPtrs& temps);
CallFrame(EntryPoint compiled_function,
size_t n_inputs,
size_t n_outputs,
const TensorViewPtrs& temps);
/// @brief Invoke the function with values matching the signature of the function.
///
......
......@@ -14,9 +14,9 @@
#include <memory>
#include "ngraph/runtime/cpu/external_function.hpp"
#include "ngraph/runtime/cpu/cpu_backend.hpp"
#include "ngraph/runtime/cpu/cpu_manager.hpp"
#include "ngraph/runtime/cpu/external_function.hpp"
using namespace ngraph::runtime::cpu;
......
......@@ -16,8 +16,8 @@
#include <memory>
#include "ngraph/runtime/manager.hpp"
#include "ngraph/codegen/compiler.hpp"
#include "ngraph/runtime/manager.hpp"
namespace ngraph
{
......@@ -34,6 +34,7 @@ namespace ngraph
{
protected:
ngraph::codegen::execution_state exec_state;
public:
virtual std::shared_ptr<Backend> allocate_backend() override;
......
......@@ -13,19 +13,19 @@
// ----------------------------------------------------------------------------
#include <iostream>
#include <vector>
#include <typeindex>
#include <string>
#include <typeindex>
#include <unordered_map>
#include <vector>
#include "ngraph/node.hpp"
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/node.hpp"
#include "ngraph/ops/concatenate.hpp"
#include "ngraph/ops/constant.hpp"
#include "ngraph/ops/get_tuple_element.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/cpu/external_function.hpp"
#include "ngraph/runtime/cpu/emitter.hpp"
#include "ngraph/runtime/cpu/external_function.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
using namespace std;
using namespace ngraph::runtime::cpu;
......@@ -34,21 +34,19 @@ using ngraph::descriptor::layout::DenseTensorViewLayout;
#define TI(x) type_index(typeid(x))
static unordered_map<type_index, string> element_type_names = {{TI(ngraph::element::Bool), "Bool"},
{TI(ngraph::element::Float32), "Float32"},
{TI(ngraph::element::Int8), "Int8"},
{TI(ngraph::element::Int32), "Int32"},
{TI(ngraph::element::Int64), "Int64"},
{TI(ngraph::element::UInt8), "UInt8"},
{TI(ngraph::element::UInt32), "UInt32"},
{TI(ngraph::element::UInt64), "UInt64"}
};
static unordered_map<type_index, string> element_type_names = {
{TI(ngraph::element::Bool), "Bool"},
{TI(ngraph::element::Float32), "Float32"},
{TI(ngraph::element::Int8), "Int8"},
{TI(ngraph::element::Int32), "Int32"},
{TI(ngraph::element::Int64), "Int64"},
{TI(ngraph::element::UInt8), "UInt8"},
{TI(ngraph::element::UInt32), "UInt32"},
{TI(ngraph::element::UInt64), "UInt64"}};
#define EIGEN_VECTOR_FORMAT(x) "fmt::V{" + to_string(x) + "}"
static std::string EIGEN_MATRIX_FORMAT(const ngraph::Shape& shape,
const ngraph::Strides& strides)
static std::string EIGEN_MATRIX_FORMAT(const ngraph::Shape& shape, const ngraph::Strides& strides)
{
std::string I;
for (size_t i = 0; i < shape.size(); i++)
......@@ -84,9 +82,9 @@ void Emitter::EMITTER_DECL(EmitNop)
void Emitter::EMITTER_DECL(EmitAdd)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -178,20 +176,30 @@ void Emitter::EMITTER_DECL(EmitDot)
auto arg1_layout = inputs[1].get_layout<DenseTensorViewLayout>();
auto out_layout = outputs[0].get_layout<DenseTensorViewLayout>();
TU += " {\n"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(arg0_element_type)] + ">(" +
to_string(inputs[0].get_index()) + ");\n"
" auto arg1 = call_frame->get_tensor_view_data<" + element_type_names[TI(arg0_element_type)] + ">(" +
to_string(inputs[1].get_index()) + ");\n"
" auto out = call_frame->get_tensor_view_data<" + element_type_names[TI(arg0_element_type)] + ">(" +
to_string(outputs[0].get_index()) + ");\n"
" EigenMatrix<" + element_type_names[TI(arg0_element_type)] + ">(out, " +
EIGEN_MATRIX_FORMAT(out_layout->get_shape(), out_layout->get_strides()) + ") = \n"
" EigenMatrix<" + element_type_names[TI(arg0_element_type)] + ">(arg0, " +
EIGEN_MATRIX_FORMAT(arg0_layout->get_shape(), arg0_layout->get_strides()) + ") * "
"EigenMatrix<" + element_type_names[TI(arg0_element_type)] + ">(arg1, " +
EIGEN_MATRIX_FORMAT(arg1_layout->get_shape(), arg1_layout->get_strides()) + ");\n"
" }\n";
TU +=
" {\n"
" auto arg0 = call_frame->get_tensor_view_data<" +
element_type_names[TI(arg0_element_type)] + ">(" + to_string(inputs[0].get_index()) +
");\n"
" auto arg1 = call_frame->get_tensor_view_data<" +
element_type_names[TI(arg0_element_type)] + ">(" + to_string(inputs[1].get_index()) +
");\n"
" auto out = call_frame->get_tensor_view_data<" +
element_type_names[TI(arg0_element_type)] + ">(" + to_string(outputs[0].get_index()) +
");\n"
" EigenMatrix<" +
element_type_names[TI(arg0_element_type)] + ">(out, " +
EIGEN_MATRIX_FORMAT(out_layout->get_shape(), out_layout->get_strides()) +
") = \n"
" EigenMatrix<" +
element_type_names[TI(arg0_element_type)] + ">(arg0, " +
EIGEN_MATRIX_FORMAT(arg0_layout->get_shape(), arg0_layout->get_strides()) +
") * "
"EigenMatrix<" +
element_type_names[TI(arg0_element_type)] + ">(arg1, " +
EIGEN_MATRIX_FORMAT(arg1_layout->get_shape(), arg1_layout->get_strides()) +
");\n"
" }\n";
}
else
{
......@@ -201,9 +209,9 @@ void Emitter::EMITTER_DECL(EmitDot)
void Emitter::EMITTER_DECL(EmitMultiply)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -221,17 +229,20 @@ void Emitter::EMITTER_DECL(EmitMultiply)
void Emitter::EMITTER_DECL(EmitGetTupleElement)
{
auto get_tuple_element = static_cast<const op::GetTupleElement*>(n);
auto result_tensor_type =
dynamic_pointer_cast<const TensorViewType>(n->get_value_type());
auto result_tensor_type = dynamic_pointer_cast<const TensorViewType>(n->get_value_type());
assert(result_tensor_type);
auto& result_element_type = result_tensor_type->get_element_type();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(result_element_type)] + ">(" +
to_string(outputs.at(0).get_index()) + ")->get_vector() =\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(result_element_type)] + ">(" +
to_string(inputs.at(get_tuple_element->get_n()).get_index()) + ")->get_vector();\n"
" }\n";
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(result_element_type)] + ">(" + to_string(outputs.at(0).get_index()) +
")->get_vector() =\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(result_element_type)] + ">(" +
to_string(inputs.at(get_tuple_element->get_n()).get_index()) +
")->get_vector();\n"
" }\n";
}
void Emitter::EMITTER_DECL(EmitTuple)
......@@ -242,19 +253,21 @@ void Emitter::EMITTER_DECL(EmitTuple)
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<" + element_type_names[TI(et)] + ">(" +
to_string(outputs.at(i).get_index()) + ")->get_vector() =\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(et)] + ">(" +
to_string(inputs.at(i).get_index()) + ")->get_vector();\n";
TU += " call_frame->get_parameterized_tensor_view<" + element_type_names[TI(et)] +
">(" + to_string(outputs.at(i).get_index()) +
")->get_vector() =\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(et)] + ">(" + to_string(inputs.at(i).get_index()) +
")->get_vector();\n";
}
TU += " }\n";
}
void Emitter::EMITTER_DECL(EmitAbs)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -268,8 +281,7 @@ void Emitter::EMITTER_DECL(EmitAbs)
void Emitter::EMITTER_DECL(EmitConcat)
{
auto result_tensor_type =
dynamic_pointer_cast<const TensorViewType>(n->get_value_type());
auto result_tensor_type = dynamic_pointer_cast<const TensorViewType>(n->get_value_type());
assert(result_tensor_type);
auto result_shape = result_tensor_type->get_shape();
......@@ -277,21 +289,30 @@ void Emitter::EMITTER_DECL(EmitConcat)
if (result_shape.size() == 1)
{
TU += " {\n"
" auto out = call_frame->get_tensor_view_data<" + element_type_names[TI(result_element_type)] +
">(" + to_string(outputs[0].get_index()) + ");\n"
" EigenVector<" + element_type_names[TI(result_element_type)] + "> out_vector(out, "
EIGEN_VECTOR_FORMAT(outputs[0].get_layout<DenseTensorViewLayout>()->get_size()) ");\n";
TU +=
" {\n"
" auto out = call_frame->get_tensor_view_data<" +
element_type_names[TI(result_element_type)] + ">(" + to_string(outputs[0].get_index()) +
");\n"
" EigenVector<" +
element_type_names[TI(result_element_type)] +
"> out_vector(out, " EIGEN_VECTOR_FORMAT(
outputs[0].get_layout<DenseTensorViewLayout>()->get_size()) ");\n";
size_t concat_pos = 0;
for (size_t i = 0; i < inputs.size(); i++)
{
TU += " out_vector.segment(" + to_string(concat_pos) + ", " +
to_string(inputs[i].get_tensor_view_layout()->get_shape().at(0)) + ") << "
"EigenVector<" + element_type_names[TI(result_element_type)] + ">(call_frame->"
"get_tensor_view_data<" + element_type_names[TI(result_element_type)] + ">(" +
to_string(inputs[i].get_index()) + "), "
EIGEN_VECTOR_FORMAT(inputs[i].get_layout<DenseTensorViewLayout>()->get_size()) ");\n";
to_string(inputs[i].get_tensor_view_layout()->get_shape().at(0)) +
") << "
"EigenVector<" +
element_type_names[TI(result_element_type)] +
">(call_frame->"
"get_tensor_view_data<" +
element_type_names[TI(result_element_type)] + ">(" +
to_string(inputs[i].get_index()) +
"), " EIGEN_VECTOR_FORMAT(
inputs[i].get_layout<DenseTensorViewLayout>()->get_size()) ");\n";
concat_pos += inputs[i].get_tensor_view_layout()->get_shape().at(0);
}
......@@ -302,11 +323,14 @@ void Emitter::EMITTER_DECL(EmitConcat)
auto out_layout = outputs[0].get_layout<DenseTensorViewLayout>();
auto axis = (dynamic_cast<const op::Concat*>(n))->get_concatenation_axis();
TU += " {\n"
" auto out = call_frame->get_tensor_view_data<" + element_type_names[TI(result_element_type)] +
">(" + to_string(outputs[0].get_index()) + ");\n"
" EigenMatrix<" + element_type_names[TI(result_element_type)] + "> out_matrix(out, " +
EIGEN_MATRIX_FORMAT(out_layout->get_shape(), out_layout->get_strides()) + ");\n";
TU +=
" {\n"
" auto out = call_frame->get_tensor_view_data<" +
element_type_names[TI(result_element_type)] + ">(" + to_string(outputs[0].get_index()) +
");\n"
" EigenMatrix<" +
element_type_names[TI(result_element_type)] + "> out_matrix(out, " +
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++)
......@@ -316,9 +340,13 @@ void Emitter::EMITTER_DECL(EmitConcat)
TU += " out_matrix.block(" + to_string(concat_pos[0]) + ", " +
to_string(concat_pos[1]) + ", " + to_string(arg_shape.at(0)) + ", " +
to_string(arg_shape.at(1)) + ") << "
"EigenMatrix<" + element_type_names[TI(result_element_type)] + ">(call_frame->"
"get_tensor_view_data<" + element_type_names[TI(result_element_type)] + ">(" +
to_string(arg_shape.at(1)) +
") << "
"EigenMatrix<" +
element_type_names[TI(result_element_type)] +
">(call_frame->"
"get_tensor_view_data<" +
element_type_names[TI(result_element_type)] + ">(" +
to_string(inputs[i].get_index()) + "), " +
EIGEN_MATRIX_FORMAT(arg_layout->get_shape(), arg_layout->get_strides()) + ");\n";
......@@ -331,9 +359,9 @@ void Emitter::EMITTER_DECL(EmitConcat)
void Emitter::EMITTER_DECL(EmitDivide)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -350,9 +378,9 @@ void Emitter::EMITTER_DECL(EmitDivide)
void Emitter::EMITTER_DECL(EmitEqual)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -369,9 +397,9 @@ void Emitter::EMITTER_DECL(EmitEqual)
void Emitter::EMITTER_DECL(EmitGreater)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -388,9 +416,9 @@ void Emitter::EMITTER_DECL(EmitGreater)
void Emitter::EMITTER_DECL(EmitGreaterEq)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -407,9 +435,9 @@ void Emitter::EMITTER_DECL(EmitGreaterEq)
void Emitter::EMITTER_DECL(EmitLess)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -426,9 +454,9 @@ void Emitter::EMITTER_DECL(EmitLess)
void Emitter::EMITTER_DECL(EmitLessEq)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -445,9 +473,9 @@ void Emitter::EMITTER_DECL(EmitLessEq)
void Emitter::EMITTER_DECL(EmitLog)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -461,9 +489,9 @@ void Emitter::EMITTER_DECL(EmitLog)
void Emitter::EMITTER_DECL(EmitMaximum)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -480,9 +508,9 @@ void Emitter::EMITTER_DECL(EmitMaximum)
void Emitter::EMITTER_DECL(EmitNegative)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -496,9 +524,9 @@ void Emitter::EMITTER_DECL(EmitNegative)
void Emitter::EMITTER_DECL(EmitNotEqual)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -515,9 +543,9 @@ void Emitter::EMITTER_DECL(EmitNotEqual)
void Emitter::EMITTER_DECL(EmitSelect)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<Bool>(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -536,9 +564,9 @@ void Emitter::EMITTER_DECL(EmitSelect)
void Emitter::EMITTER_DECL(EmitSubtract)
{
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"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
......@@ -555,12 +583,16 @@ void Emitter::EMITTER_DECL(EmitSubtract)
void Emitter::EMITTER_DECL(EmitParameterizedConstantBool)
{
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();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(ngraph::element::Bool)] +
">(" + to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Bool)] +
"::type>{";
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(ngraph::element::Bool)] + ">(" + to_string(outputs[0].get_index()) +
")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Bool)] +
"::type>{";
for (size_t i = 0; i < value.size(); i++)
{
......@@ -581,12 +613,16 @@ void Emitter::EMITTER_DECL(EmitParameterizedConstantBool)
void Emitter::EMITTER_DECL(EmitParameterizedConstantFloat32)
{
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();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(ngraph::element::Float32)] +
">(" + to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Float32)] +
"::type>{";
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(ngraph::element::Float32)] + ">(" +
to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" +
element_type_names[TI(ngraph::element::Float32)] + "::type>{";
for (size_t i = 0; i < value.size(); i++)
{
......@@ -600,12 +636,16 @@ void Emitter::EMITTER_DECL(EmitParameterizedConstantFloat32)
void Emitter::EMITTER_DECL(EmitParameterizedConstantInt8)
{
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();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(ngraph::element::Int8)] +
">(" + to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Int8)] +
"::type>{";
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(ngraph::element::Int8)] + ">(" + to_string(outputs[0].get_index()) +
")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Int8)] +
"::type>{";
for (size_t i = 0; i < value.size(); i++)
{
......@@ -619,12 +659,16 @@ void Emitter::EMITTER_DECL(EmitParameterizedConstantInt8)
void Emitter::EMITTER_DECL(EmitParameterizedConstantInt32)
{
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();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(ngraph::element::Int32)] +
">(" + to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Int32)] +
"::type>{";
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(ngraph::element::Int32)] + ">(" + to_string(outputs[0].get_index()) +
")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Int32)] +
"::type>{";
for (size_t i = 0; i < value.size(); i++)
{
......@@ -638,12 +682,16 @@ void Emitter::EMITTER_DECL(EmitParameterizedConstantInt32)
void Emitter::EMITTER_DECL(EmitParameterizedConstantInt64)
{
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();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(ngraph::element::Int64)] +
">(" + to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Int64)] +
"::type>{";
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(ngraph::element::Int64)] + ">(" + to_string(outputs[0].get_index()) +
")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::Int64)] +
"::type>{";
for (size_t i = 0; i < value.size(); i++)
{
......@@ -657,12 +705,16 @@ void Emitter::EMITTER_DECL(EmitParameterizedConstantInt64)
void Emitter::EMITTER_DECL(EmitParameterizedConstantUInt8)
{
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();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(ngraph::element::UInt8)] +
">(" + to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::UInt8)] +
"::type>{";
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(ngraph::element::UInt8)] + ">(" + to_string(outputs[0].get_index()) +
")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::UInt8)] +
"::type>{";
for (size_t i = 0; i < value.size(); i++)
{
......@@ -676,12 +728,16 @@ void Emitter::EMITTER_DECL(EmitParameterizedConstantUInt8)
void Emitter::EMITTER_DECL(EmitParameterizedConstantUInt32)
{
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();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(ngraph::element::UInt32)] +
">(" + to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::UInt32)] +
"::type>{";
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(ngraph::element::UInt32)] + ">(" + to_string(outputs[0].get_index()) +
")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::UInt32)] +
"::type>{";
for (size_t i = 0; i < value.size(); i++)
{
......@@ -695,12 +751,16 @@ void Emitter::EMITTER_DECL(EmitParameterizedConstantUInt32)
void Emitter::EMITTER_DECL(EmitParameterizedConstantUInt64)
{
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::UInt64>*>(n)->get_value()->get_vector();
TU += " {\n"
" call_frame->get_parameterized_tensor_view<" + element_type_names[TI(ngraph::element::UInt64)] +
">(" + to_string(outputs[0].get_index()) + ")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::UInt64)] +
"::type>{";
auto value = dynamic_cast<const op::ParameterizedConstant<ngraph::element::UInt64>*>(n)
->get_value()
->get_vector();
TU +=
" {\n"
" call_frame->get_parameterized_tensor_view<" +
element_type_names[TI(ngraph::element::UInt64)] + ">(" + to_string(outputs[0].get_index()) +
")->get_vector() = std::vector<" + element_type_names[TI(ngraph::element::UInt64)] +
"::type>{";
for (size_t i = 0; i < value.size(); i++)
{
......
......@@ -14,19 +14,19 @@
#pragma once
#include <vector>
#include <string>
#include <vector>
#include "ngraph/node.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/cpu/external_function.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#define EMITTER_DECL(E) E(const ngraph::Node* n, \
ExternalFunction* ef, \
FunctionMap& function_map, \
const std::vector<TensorViewInfo>& inputs, \
const std::vector<TensorViewInfo>& outputs)
#define EMITTER_DECL(E) \
E(const ngraph::Node* n, \
ExternalFunction* ef, \
FunctionMap& function_map, \
const std::vector<TensorViewInfo>& inputs, \
const std::vector<TensorViewInfo>& outputs)
namespace ngraph
{
......@@ -40,9 +40,11 @@ namespace ngraph
std::string TU;
public:
Emitter() : TU("") { }
Emitter()
: TU("")
{
}
std::string& GetTU() { return TU; }
void EMITTER_DECL(EmitNop);
void EMITTER_DECL(EmitAdd);
void EMITTER_DECL(EmitDot);
......@@ -71,7 +73,6 @@ namespace ngraph
void EMITTER_DECL(EmitParameterizedConstantUInt8);
void EMITTER_DECL(EmitParameterizedConstantUInt32);
void EMITTER_DECL(EmitParameterizedConstantUInt64);
};
}
}
......
......@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include <fstream>
#include <memory>
#include <string>
#include <tuple>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <string>
#include <fstream>
#include "ngraph/codegen/compiler.hpp"
#include "ngraph/descriptor/input.hpp"
......@@ -70,36 +70,45 @@ using ngraph::descriptor::layout::DenseTensorViewLayout;
#define TI(x) type_index(typeid(x))
static const OpMap dispatcher{{TI(ngraph::op::Add), &Emitter::EmitAdd},
{TI(ngraph::op::Dot), &Emitter::EmitDot},
{TI(ngraph::op::Multiply), &Emitter::EmitMultiply},
{TI(ngraph::op::Parameter), &Emitter::EmitNop},
{TI(ngraph::op::GetTupleElement), &Emitter::EmitGetTupleElement},
{TI(ngraph::op::Tuple), &Emitter::EmitTuple},
{TI(ngraph::op::Abs), &Emitter::EmitAbs},
{TI(ngraph::op::Concat), &Emitter::EmitConcat},
{TI(ngraph::op::Divide), &Emitter::EmitDivide},
{TI(ngraph::op::Equal), &Emitter::EmitEqual},
{TI(ngraph::op::Greater), &Emitter::EmitGreater},
{TI(ngraph::op::GreaterEq), &Emitter::EmitGreaterEq},
{TI(ngraph::op::Less), &Emitter::EmitLess},
{TI(ngraph::op::LessEq), &Emitter::EmitLessEq},
{TI(ngraph::op::Log), &Emitter::EmitLog},
{TI(ngraph::op::Maximum), &Emitter::EmitMaximum},
{TI(ngraph::op::Negative), &Emitter::EmitNegative},
{TI(ngraph::op::NotEqual), &Emitter::EmitNotEqual},
{TI(ngraph::op::Select), &Emitter::EmitSelect},
{TI(ngraph::op::Subtract), &Emitter::EmitSubtract},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Bool>), &Emitter::EmitParameterizedConstantBool},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Float32>), &Emitter::EmitParameterizedConstantFloat32},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Int8>), &Emitter::EmitParameterizedConstantInt8},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Int32>), &Emitter::EmitParameterizedConstantInt32},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Int64>), &Emitter::EmitParameterizedConstantInt64},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::UInt8>), &Emitter::EmitParameterizedConstantUInt8},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::UInt32>), &Emitter::EmitParameterizedConstantUInt32},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::UInt64>), &Emitter::EmitParameterizedConstantUInt64},
};
static const OpMap dispatcher{
{TI(ngraph::op::Add), &Emitter::EmitAdd},
{TI(ngraph::op::Dot), &Emitter::EmitDot},
{TI(ngraph::op::Multiply), &Emitter::EmitMultiply},
{TI(ngraph::op::Parameter), &Emitter::EmitNop},
{TI(ngraph::op::GetTupleElement), &Emitter::EmitGetTupleElement},
{TI(ngraph::op::Tuple), &Emitter::EmitTuple},
{TI(ngraph::op::Abs), &Emitter::EmitAbs},
{TI(ngraph::op::Concat), &Emitter::EmitConcat},
{TI(ngraph::op::Divide), &Emitter::EmitDivide},
{TI(ngraph::op::Equal), &Emitter::EmitEqual},
{TI(ngraph::op::Greater), &Emitter::EmitGreater},
{TI(ngraph::op::GreaterEq), &Emitter::EmitGreaterEq},
{TI(ngraph::op::Less), &Emitter::EmitLess},
{TI(ngraph::op::LessEq), &Emitter::EmitLessEq},
{TI(ngraph::op::Log), &Emitter::EmitLog},
{TI(ngraph::op::Maximum), &Emitter::EmitMaximum},
{TI(ngraph::op::Negative), &Emitter::EmitNegative},
{TI(ngraph::op::NotEqual), &Emitter::EmitNotEqual},
{TI(ngraph::op::Select), &Emitter::EmitSelect},
{TI(ngraph::op::Subtract), &Emitter::EmitSubtract},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Bool>),
&Emitter::EmitParameterizedConstantBool},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Float32>),
&Emitter::EmitParameterizedConstantFloat32},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Int8>),
&Emitter::EmitParameterizedConstantInt8},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Int32>),
&Emitter::EmitParameterizedConstantInt32},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::Int64>),
&Emitter::EmitParameterizedConstantInt64},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::UInt8>),
&Emitter::EmitParameterizedConstantUInt8},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::UInt32>),
&Emitter::EmitParameterizedConstantUInt32},
{TI(ngraph::op::ParameterizedConstant<ngraph::element::UInt64>),
&Emitter::EmitParameterizedConstantUInt64},
};
#undef TI
......@@ -183,15 +192,15 @@ void ExternalFunction::compile(FunctionMap& function_map)
Emitter emitter;
auto& TU = emitter.GetTU();
TU += R"(
#include <vector>
#include <memory>
#include <vector>
#include <Eigen/Dense>
#include "ngraph/descriptor/layout/dense_tensor_view_layout.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
#include "ngraph/runtime/cpu/call_frame.hpp"
#include "ngraph/runtime/cpu/eigen_utils.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
void *__dso_handle = 0;
......@@ -247,8 +256,8 @@ extern "C" void __entrypoint(ngraph::runtime::cpu::CallFrame* call_frame,
assert(llvm_module);
estate.add_module(llvm_module);
estate.finalize();
compiled_function = estate.find_function<void(ngraph::runtime::cpu::CallFrame*,
ngraph::runtime::TensorViewPtrs&)>("__entrypoint");
compiled_function = estate.find_function<void(
ngraph::runtime::cpu::CallFrame*, ngraph::runtime::TensorViewPtrs&)>("__entrypoint");
assert(compiled_function);
m_is_compiled = true;
......
......@@ -14,14 +14,14 @@
#pragma once
#include <functional>
#include <memory>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <functional>
#include "ngraph/function.hpp"
#include "ngraph/codegen/compiler.hpp"
#include "ngraph/function.hpp"
#include "ngraph/runtime/external_function.hpp"
#include "ngraph/runtime/tensor_view_info.hpp"
......@@ -35,8 +35,8 @@ namespace ngraph
class Emitter;
class CallFrame;
using FunctionMap = std::unordered_map<std::shared_ptr<Function>,
std::shared_ptr<ExternalFunction>>;
using FunctionMap =
std::unordered_map<std::shared_ptr<Function>, std::shared_ptr<ExternalFunction>>;
using OpFunction = std::function<void(Emitter*,
const ngraph::Node*,
......@@ -47,7 +47,8 @@ namespace ngraph
using OpMap = std::unordered_map<std::type_index, OpFunction>;
using EntryPoint = std::function<void(ngraph::runtime::cpu::CallFrame*, ngraph::runtime::TensorViewPtrs&)>;
using EntryPoint = std::function<void(ngraph::runtime::cpu::CallFrame*,
ngraph::runtime::TensorViewPtrs&)>;
class ExternalFunction : public ngraph::runtime::ExternalFunction
{
......@@ -55,6 +56,7 @@ namespace ngraph
ExternalFunction(const std::shared_ptr<ngraph::Function>& function,
bool release_function = true);
std::shared_ptr<ngraph::runtime::CallFrame> make_call_frame();
protected:
void compile(FunctionMap& function_map);
......
......@@ -803,7 +803,6 @@ TEST(cpu, greater)
ASSERT_EQ((vector<char>{0, 1, 0, 1, 0, 1, 1, 0}), result->get_vector());
}
TEST(cpu, greatereq)
{
auto shape = Shape{2, 2, 2};
......
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