Commit 06b82355 authored by Jaikrishnan Menon's avatar Jaikrishnan Menon

CPU: Implement op::Greater and op::GreaterEq

parent 871290c0
......@@ -365,3 +365,41 @@ void Emitter::EMITTER_DECL(EmitEqual)
EIGEN_VECTOR_FORMAT(inputs[1].get_layout<DenseTensorViewLayout>()->get_size()) ")).template cast<char>();\n"
" }\n";
}
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();
TU += " {\n"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
" auto arg1 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[1].get_index()) + ");\n"
" auto out = call_frame->get_tensor_view_data<Bool>(" + to_string(outputs[0].get_index()) + ");\n"
" EigenArray1d<Bool>(out, "
EIGEN_VECTOR_FORMAT(outputs[0].get_layout<DenseTensorViewLayout>()->get_size()) ") =\n"
" (EigenArray1d<" + element_type_names[TI(et)] + ">(arg0, "
EIGEN_VECTOR_FORMAT(inputs[0].get_layout<DenseTensorViewLayout>()->get_size()) ") >\n"
" EigenArray1d<" + element_type_names[TI(et)] + ">(arg1, "
EIGEN_VECTOR_FORMAT(inputs[1].get_layout<DenseTensorViewLayout>()->get_size()) ")).template cast<char>();\n"
" }\n";
}
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();
TU += " {\n"
" auto arg0 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[0].get_index()) + ");\n"
" auto arg1 = call_frame->get_tensor_view_data<" + element_type_names[TI(et)] + ">(" + to_string(inputs[1].get_index()) + ");\n"
" auto out = call_frame->get_tensor_view_data<Bool>(" + to_string(outputs[0].get_index()) + ");\n"
" EigenArray1d<Bool>(out, "
EIGEN_VECTOR_FORMAT(outputs[0].get_layout<DenseTensorViewLayout>()->get_size()) ") =\n"
" (EigenArray1d<" + element_type_names[TI(et)] + ">(arg0, "
EIGEN_VECTOR_FORMAT(inputs[0].get_layout<DenseTensorViewLayout>()->get_size()) ") >=\n"
" EigenArray1d<" + element_type_names[TI(et)] + ">(arg1, "
EIGEN_VECTOR_FORMAT(inputs[1].get_layout<DenseTensorViewLayout>()->get_size()) ")).template cast<char>();\n"
" }\n";
}
......@@ -53,6 +53,8 @@ namespace ngraph
void EMITTER_DECL(EmitConcat);
void EMITTER_DECL(EmitDivide);
void EMITTER_DECL(EmitEqual);
void EMITTER_DECL(EmitGreater);
void EMITTER_DECL(EmitGreaterEq);
};
}
......
......@@ -79,7 +79,9 @@ static const OpMap dispatcher{{TI(ngraph::op::Add), &Emitter::EmitAdd},
{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::Equal), &Emitter::EmitEqual},
{TI(ngraph::op::Greater), &Emitter::EmitGreater},
{TI(ngraph::op::GreaterEq), &Emitter::EmitGreaterEq}
};
#undef TI
......
......@@ -779,8 +779,7 @@ TEST(cpu, dot_matrix_vector_int64)
ASSERT_EQ((vector<element::Int64::type>{190, 486, 782, 1078}), result->get_vector());
}
/*
TEST(execute, greater)
TEST(cpu, greater)
{
auto shape = Shape{2, 2, 2};
auto A = make_shared<op::Parameter>(element::Float32::element_type(), shape);
......@@ -788,7 +787,7 @@ TEST(execute, greater)
auto rt = make_shared<TensorViewType>(element::Bool::element_type(), shape);
auto f = make_shared<Function>(make_shared<op::Greater>(A, B), rt, op::Parameters{A, B});
auto manager = runtime::Manager::get("NGVM");
auto manager = runtime::Manager::get("CPU");
auto external = manager->compile(f);
auto backend = manager->allocate_backend();
auto cf = backend->make_call_frame(external);
......@@ -804,7 +803,8 @@ TEST(execute, greater)
ASSERT_EQ((vector<char>{0, 1, 0, 1, 0, 1, 1, 0}), result->get_vector());
}
TEST(execute, greatereq)
TEST(cpu, greatereq)
{
auto shape = Shape{2, 2, 2};
auto A = make_shared<op::Parameter>(element::Float32::element_type(), shape);
......@@ -812,7 +812,7 @@ TEST(execute, greatereq)
auto rt = make_shared<TensorViewType>(element::Bool::element_type(), shape);
auto f = make_shared<Function>(make_shared<op::GreaterEq>(A, B), rt, op::Parameters{A, B});
auto manager = runtime::Manager::get("NGVM");
auto manager = runtime::Manager::get("CPU");
auto external = manager->compile(f);
auto backend = manager->allocate_backend();
auto cf = backend->make_call_frame(external);
......@@ -828,6 +828,7 @@ TEST(execute, greatereq)
ASSERT_EQ((vector<char>{1, 1, 1, 1, 0, 1, 1, 0}), result->get_vector());
}
/*
TEST(execute, less)
{
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