[IE TESTS] Extend EvaluatorMaps by Greater, If, Equal (#10026)
* [IE TESTS] Extend EvaluatesMap * fix code style
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <ngraph/runtime/reference/embedding_bag_offsets_sum.hpp>
|
||||
#include <ngraph/runtime/reference/embedding_bag_packed_sum.hpp>
|
||||
#include <ngraph/runtime/reference/embedding_segments_sum.hpp>
|
||||
#include <ngraph/runtime/reference/equal.hpp>
|
||||
#include <ngraph/runtime/reference/exp.hpp>
|
||||
#include <ngraph/runtime/reference/experimental_detectron_detection_output.hpp>
|
||||
#include <ngraph/runtime/reference/experimental_detectron_prior_grid_generator.hpp>
|
||||
@@ -40,6 +41,7 @@
|
||||
#include <ngraph/runtime/reference/gather_nd.hpp>
|
||||
#include <ngraph/runtime/reference/gather_tree.hpp>
|
||||
#include <ngraph/runtime/reference/gelu.hpp>
|
||||
#include <ngraph/runtime/reference/greater.hpp>
|
||||
#include <ngraph/runtime/reference/grn.hpp>
|
||||
#include <ngraph/runtime/reference/group_convolution.hpp>
|
||||
#include <ngraph/runtime/reference/group_convolution_backprop_data.hpp>
|
||||
@@ -399,6 +401,42 @@ bool evaluate(const shared_ptr<op::v1::DeformableConvolution>& op,
|
||||
return true;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const shared_ptr<op::v1::Greater>& op, const HostTensorVector& outputs, const HostTensorVector& inputs) {
|
||||
const auto in0_data_ptr = inputs[0]->get_data_ptr<ET>();
|
||||
const auto in1_data_ptr = inputs[1]->get_data_ptr<ET>();
|
||||
const auto out_data_ptr = outputs[0]->get_data_ptr<element::Type_t::boolean>();
|
||||
const auto in0_shape = inputs[0]->get_shape();
|
||||
const auto in1_shape = inputs[1]->get_shape();
|
||||
const auto broadcast_spec = op->get_autob();
|
||||
runtime::reference::greater<typename element_type_traits<ET>::value_type,
|
||||
typename element_type_traits<element::Type_t::boolean>::value_type>(in0_data_ptr,
|
||||
in1_data_ptr,
|
||||
out_data_ptr,
|
||||
in0_shape,
|
||||
in1_shape,
|
||||
broadcast_spec);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const shared_ptr<op::v1::Equal>& op, const HostTensorVector& outputs, const HostTensorVector& inputs) {
|
||||
const auto in0_data_ptr = inputs[0]->get_data_ptr<ET>();
|
||||
const auto in1_data_ptr = inputs[1]->get_data_ptr<ET>();
|
||||
const auto out_data_ptr = outputs[0]->get_data_ptr<element::Type_t::boolean>();
|
||||
const auto in0_shape = inputs[0]->get_shape();
|
||||
const auto in1_shape = inputs[1]->get_shape();
|
||||
const auto broadcast_spec = op->get_autob();
|
||||
runtime::reference::equal<typename element_type_traits<ET>::value_type,
|
||||
typename element_type_traits<element::Type_t::boolean>::value_type>(in0_data_ptr,
|
||||
in1_data_ptr,
|
||||
out_data_ptr,
|
||||
in0_shape,
|
||||
in1_shape,
|
||||
broadcast_spec);
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace cum_sum_v0 {
|
||||
template <element::Type_t t1, element::Type_t t2>
|
||||
inline void evaluate(const shared_ptr<op::v0::CumSum>& op,
|
||||
@@ -428,6 +466,145 @@ bool evaluate(const shared_ptr<op::v0::CumSum>& op, const HostTensorVector& outp
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace if_op {
|
||||
bool call(const HostTensorVector& func_outputs,
|
||||
const HostTensorVector& func_inputs,
|
||||
const std::shared_ptr<ngraph::Function>& function) {
|
||||
// map function params -> HostTensor
|
||||
std::unordered_map<descriptor::Tensor*, std::shared_ptr<HostTensor>> tensor_map;
|
||||
size_t input_count = 0;
|
||||
for (const auto& param : function->get_parameters()) {
|
||||
for (size_t i = 0; i < param->get_output_size(); ++i) {
|
||||
descriptor::Tensor* tensor = ¶m->output(i).get_tensor();
|
||||
tensor_map.insert({tensor, func_inputs[input_count++]});
|
||||
}
|
||||
}
|
||||
|
||||
std::unordered_map<std::shared_ptr<ngraph::Node>, size_t> results_map;
|
||||
// map function outputs -> HostTensor
|
||||
for (size_t output_count = 0; output_count < function->get_results().size(); ++output_count) {
|
||||
auto output = function->get_results()[output_count];
|
||||
results_map[output] = output_count;
|
||||
}
|
||||
|
||||
// for each ordered op in the graph
|
||||
for (const auto& op : function->get_ordered_ops()) {
|
||||
if (op::is_parameter(op)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get op inputs from map
|
||||
std::vector<std::shared_ptr<HostTensor>> op_inputs;
|
||||
for (auto input : op->inputs()) {
|
||||
descriptor::Tensor* tensor = &input.get_tensor();
|
||||
op_inputs.push_back(tensor_map.at(tensor));
|
||||
}
|
||||
|
||||
// get op outputs from map or create
|
||||
std::vector<std::shared_ptr<HostTensor>> op_outputs;
|
||||
for (size_t i = 0; i < op->get_output_size(); ++i) {
|
||||
descriptor::Tensor* tensor = &op->output(i).get_tensor();
|
||||
std::shared_ptr<HostTensor> host_tensor;
|
||||
auto it = tensor_map.find(tensor);
|
||||
if (op::is_output(op)) {
|
||||
host_tensor = func_outputs[results_map[op]];
|
||||
} else if (it == tensor_map.end()) {
|
||||
host_tensor = std::make_shared<HostTensor>(op->output(i));
|
||||
tensor_map.insert({tensor, host_tensor});
|
||||
} else {
|
||||
host_tensor = it->second;
|
||||
}
|
||||
op_outputs.push_back(host_tensor);
|
||||
}
|
||||
op->validate_and_infer_types();
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
if (!op->evaluate(op_outputs, op_inputs)) {
|
||||
auto evaluates_map = ngraph::runtime::interpreter::get_evaluators_map();
|
||||
auto it = evaluates_map.find(op->get_type_info());
|
||||
if (!it->second(op, op_outputs, op_inputs)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void function(const std::shared_ptr<ngraph::Function>& function,
|
||||
const HostTensorVector& inputs,
|
||||
HostTensorVector& outputs) {
|
||||
const auto& parameters = function->get_parameters();
|
||||
const auto& parametersNumber = parameters.size();
|
||||
const auto& inputsNumber = inputs.size();
|
||||
NGRAPH_CHECK(parametersNumber == inputsNumber,
|
||||
"Got function (",
|
||||
function->get_friendly_name(),
|
||||
") with ",
|
||||
parametersNumber,
|
||||
" parameters, but ",
|
||||
inputsNumber,
|
||||
" input blobs");
|
||||
|
||||
for (const auto& parameter : parameters) {
|
||||
const auto& parameterIndex = function->get_parameter_index(parameter);
|
||||
const auto& parameterShape = parameter->get_shape();
|
||||
const auto& parameterType = parameter->get_element_type();
|
||||
const auto& parameterSize = shape_size(parameterShape) * parameterType.size();
|
||||
|
||||
const auto& input = inputs[parameterIndex];
|
||||
const auto& inputSize = input->get_size_in_bytes();
|
||||
NGRAPH_CHECK(parameterSize == inputSize,
|
||||
"Got parameter (",
|
||||
parameter->get_friendly_name(),
|
||||
") of size ",
|
||||
parameterSize,
|
||||
" bytes, but corresponding input with index ",
|
||||
parameterIndex,
|
||||
" has ",
|
||||
inputSize,
|
||||
" bytes");
|
||||
}
|
||||
|
||||
const auto& results = function->get_results();
|
||||
outputs.reserve(results.size());
|
||||
for (size_t i = 0; i < results.size(); ++i) {
|
||||
outputs.push_back(std::make_shared<HostTensor>());
|
||||
}
|
||||
call(outputs, inputs, function);
|
||||
}
|
||||
|
||||
void if_reference(const std::vector<std::shared_ptr<Function>>& bodies,
|
||||
const std::vector<op::util::MultiSubgraphOutputDescriptionVector>& out_descs,
|
||||
const std::vector<op::util::MultiSubgraphInputDescriptionVector>& input_descs,
|
||||
const HostTensorVector& out,
|
||||
const HostTensorVector& args) {
|
||||
NGRAPH_CHECK(args.size() > 0, "If operation must have input condition value");
|
||||
|
||||
auto condition_value = args[0]->get_data_ptr<bool>()[0];
|
||||
auto branch_index = (condition_value) ? op::v8::If::THEN_BODY_INDEX : op::v8::If::ELSE_BODY_INDEX;
|
||||
HostTensorVector inputs_to_body;
|
||||
HostTensorVector outs_from_body;
|
||||
inputs_to_body.resize(input_descs[branch_index].size());
|
||||
auto inputs_size = args.size();
|
||||
auto output_size = out.size();
|
||||
for (const auto& input_desc : input_descs[branch_index]) {
|
||||
NGRAPH_CHECK(inputs_size > input_desc->m_input_index,
|
||||
"Incorrect associating! If has not input with id ",
|
||||
input_desc->m_input_index);
|
||||
inputs_to_body[input_desc->m_body_parameter_index] = args[input_desc->m_input_index];
|
||||
}
|
||||
function(bodies[branch_index], inputs_to_body, outs_from_body);
|
||||
for (const auto& out_descr : out_descs[branch_index]) {
|
||||
NGRAPH_CHECK(output_size > out_descr->m_output_index,
|
||||
"Incorrect associating! If has not output with id ",
|
||||
out_descr->m_output_index);
|
||||
auto res = outs_from_body[out_descr->m_body_value_index];
|
||||
out[out_descr->m_output_index]->set_shape(res->get_shape());
|
||||
out[out_descr->m_output_index]->write(res->get_data_ptr(), res->get_size_in_bytes());
|
||||
}
|
||||
}
|
||||
} // namespace if_op
|
||||
|
||||
template <element::Type_t ET>
|
||||
bool evaluate(const shared_ptr<op::v8::If>& op, const HostTensorVector& outputs, const HostTensorVector& inputs) {
|
||||
std::vector<std::shared_ptr<Function>> bodies;
|
||||
@@ -442,7 +619,11 @@ bool evaluate(const shared_ptr<op::v8::If>& op, const HostTensorVector& outputs,
|
||||
for (size_t i = 0; i < op->get_output_descriptions_size(); i++) {
|
||||
out_descs.emplace_back(op->get_output_descriptions(i));
|
||||
}
|
||||
runtime::reference::if_reference(bodies, out_descs, in_descs, outputs, inputs);
|
||||
try {
|
||||
runtime::reference::if_reference(bodies, out_descs, in_descs, outputs, inputs);
|
||||
} catch (...) {
|
||||
if_op::if_reference(bodies, out_descs, in_descs, outputs, inputs);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3430,7 +3611,7 @@ bool evaluate(const shared_ptr<op::v0::Interpolate>& op,
|
||||
template <typename T>
|
||||
bool evaluate_node(std::shared_ptr<Node> node, const HostTensorVector& outputs, const HostTensorVector& inputs) {
|
||||
auto element_type = node->get_output_element_type(0);
|
||||
if (ov::is_type<op::v1::Select>(node))
|
||||
if (ov::is_type<op::v1::Select>(node) || ov::is_type<op::util::BinaryElementwiseComparison>(node))
|
||||
element_type = node->get_input_element_type(1);
|
||||
|
||||
switch (element_type) {
|
||||
|
||||
@@ -45,6 +45,8 @@ NGRAPH_OP(ConvertLike, op::v1)
|
||||
NGRAPH_OP(Convolution, ngraph::op::v1)
|
||||
NGRAPH_OP(ConvolutionBackpropData, ngraph::op::v1)
|
||||
NGRAPH_OP(DeformablePSROIPooling, ngraph::op::v1)
|
||||
NGRAPH_OP(Equal, ngraph::op::v1)
|
||||
NGRAPH_OP(Greater, ngraph::op::v1)
|
||||
NGRAPH_OP(GroupConvolution, ngraph::op::v1)
|
||||
NGRAPH_OP(GroupConvolutionBackpropData, ngraph::op::v1)
|
||||
NGRAPH_OP(DeformableConvolution, ngraph::op::v1)
|
||||
|
||||
Reference in New Issue
Block a user