From fcbb80d37259738d65c426aea3e8d00f84843573 Mon Sep 17 00:00:00 2001 From: Tingqian Li Date: Mon, 4 Dec 2023 20:18:01 +0800 Subject: [PATCH 01/20] [CPU] Support chatglm RoPE (#21295) --- src/plugins/intel_cpu/src/nodes/rope.cpp | 58 ++++++- src/plugins/intel_cpu/src/nodes/rope.h | 2 + .../cpu_opset/common/op/rope.cpp | 15 ++ .../cpu_opset/common/op/rope.hpp | 3 + .../cpu_opset/common/pass/rope_fusion.cpp | 137 +++++++++++++++- .../cpu_opset/common/pass/rope_fusion.hpp | 9 +- .../intel_cpu/src/utils/gen_pattern.hpp | 17 +- .../intel_cpu/src/utils/print_model.hpp | 4 + .../subgraph_tests/src/rotary_pos_emb.cpp | 151 +++++++++++++++++- .../unit/transformations/convert_to_rope.cpp | 123 ++++++++++++++ 10 files changed, 511 insertions(+), 8 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/rope.cpp b/src/plugins/intel_cpu/src/nodes/rope.cpp index 5ec1aaa2183104..dafd7f2829a58c 100644 --- a/src/plugins/intel_cpu/src/nodes/rope.cpp +++ b/src/plugins/intel_cpu/src/nodes/rope.cpp @@ -54,6 +54,13 @@ struct RoPE::RoPEExecutorRotateHalf : public RoPE::Executor { gather.reset(inputs[config.gather_position_arg_id]); } + if (t_cos.m_rank == 2) { + t_cos = t_cos.reshape({1, 1, t_cos.size(0), t_cos.size(1)}); + } + if (t_sin.m_rank == 2) { + t_sin = t_sin.reshape({1, 1, t_sin.size(0), t_sin.size(1)}); + } + auto batch_size = t_src.size(0); auto head_cnt = t_src.size(1); auto seq_len = t_src.size(2); @@ -124,6 +131,48 @@ struct RoPE::RoPEExecutorInterleaved : public RoPE::Executor { } }; +template +struct RoPE::RoPEExecutorChatGLM : public RoPE::Executor { + void execute(dnnl::stream strm, + const RoPENode::Config& config, + const std::vector& inputs, + const std::vector& outputs) override { + ov::intel_cpu::PlainTensor t_src(inputs[0]); + ov::intel_cpu::PlainTensor t_cos_sin(inputs[1]); + ov::intel_cpu::PlainTensor t_dst(outputs[0]); + + // [seq_len, batch_size, (hidden_states_q + hidden_states_k + hidden_states_v)] + if (config.slice_stop - config.slice_start > 0) { + t_src = t_src.slice(2, config.slice_start, config.slice_stop); + } + auto seq_len = t_src.size(0); + auto batch_size = t_src.size(1); + + auto head_cnt = config.head_cnt; + auto head_size = config.head_size; + + auto rotary_dims = config.rotary_ndims; + + parallel_for3d(seq_len, batch_size, head_cnt, [&](size_t p, size_t b, size_t h) { + auto* src = &t_src.at({p, b, h * head_size}); + // [length, batch_size, ndims//2, 2] + auto* cos_sin = &t_cos_sin.at({p, b, 0, 0}, true); + auto* dst = &t_dst.at({p, b, h, 0}); + + size_t i = 0; + for (; i < rotary_dims; i += 2) { + auto cosv = cos_sin[i]; + auto sinv = cos_sin[i + 1]; + dst[i] = cosv * src[i] - sinv * src[i + 1]; + dst[i + 1] = sinv * src[i] + cosv * src[i + 1]; + } + for (; i < head_size; i++) { + dst[i] = src[i]; + } + }); + } +}; + void RoPE::initSupportedPrimitiveDescriptors() { if (!supportedPrimitiveDescriptors.empty()) return; @@ -132,7 +181,14 @@ void RoPE::initSupportedPrimitiveDescriptors() { auto rtPrecision = srcPrecision; auto CosSinPrecision = ov::element::f32; - if (m_config.is_interleaved) { + if (m_config.is_chatglm) { + if (rtPrecision == ov::element::bf16) { + m_executor = std::make_shared>(); + } else { + m_executor = std::make_shared>(); + rtPrecision = ov::element::f32; + } + } else if (m_config.is_interleaved) { OPENVINO_ASSERT(m_config.input_trans0213 == false); OPENVINO_ASSERT(m_config.slice_start == 0); OPENVINO_ASSERT(m_config.slice_stop == 0); diff --git a/src/plugins/intel_cpu/src/nodes/rope.h b/src/plugins/intel_cpu/src/nodes/rope.h index c1b2bbda3b3c0f..1f81ddf214322e 100644 --- a/src/plugins/intel_cpu/src/nodes/rope.h +++ b/src/plugins/intel_cpu/src/nodes/rope.h @@ -45,6 +45,8 @@ class RoPE : public Node { struct RoPEExecutorRotateHalf; template struct RoPEExecutorInterleaved; + template + struct RoPEExecutorChatGLM; RoPENode::Config m_config; std::shared_ptr m_executor; }; diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.cpp index 8b4461b479ee7b..fd78f4f3bffafd 100644 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.cpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.cpp @@ -22,6 +22,18 @@ void ov::intel_cpu::RoPENode::validate_and_infer_types() { INTERNAL_OP_SCOPE(RoPENode_validate_and_infer_types); auto input_pshape = get_input_partial_shape(0); auto input_slice_size = m_config.slice_stop - m_config.slice_start; + + if (m_config.is_chatglm) { + // chatGLM specific RoPE + // input [length, batch_size, (hidden_states_q + hidden_states_k + hidden_states_v)] + // output [length, batch_size, head_cnt, hidden_states_k] + set_output_type( + 0, + get_input_element_type(0), + {input_pshape[0], input_pshape[1], ov::Dimension(m_config.head_cnt), ov::Dimension(m_config.head_size)}); + return; + } + if (input_slice_size > 0) { input_pshape[3] = input_slice_size; } @@ -44,6 +56,9 @@ bool ov::intel_cpu::RoPENode::visit_attributes(ngraph::AttributeVisitor& visitor visitor.on_attribute("input_trans0213", m_config.input_trans0213); visitor.on_attribute("is_interleaved", m_config.is_interleaved); visitor.on_attribute("rotary_ndims", m_config.rotary_ndims); + visitor.on_attribute("is_chatglm", m_config.is_chatglm); + visitor.on_attribute("head_cnt", m_config.head_cnt); + visitor.on_attribute("head_size", m_config.head_size); visitor.on_attribute("gather_position_arg_id", m_config.gather_position_arg_id); visitor.finish_structure(); return true; diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.hpp index cc6df7ec2b107f..61f93ad787ad0d 100644 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.hpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.hpp @@ -70,6 +70,9 @@ class RoPENode : public ngraph::op::Op { bool input_trans0213 = false; // transpose input dim 1&2 bool is_interleaved = false; // interleaved mode, implies trans0213 happens after RoPE size_t rotary_ndims = 0; // dimensions to be embedded (d in the description) + bool is_chatglm = false; // chatglm is special which overrides other setting + size_t head_cnt = 0; + size_t head_size = 0; int gather_position_arg_id = 0; // arg id of position tensor, ==3 when gather from sin/cos inputs according to position is required }; diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/rope_fusion.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/rope_fusion.cpp index fca105c07a475b..07cd8076d52040 100644 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/rope_fusion.cpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/rope_fusion.cpp @@ -132,7 +132,17 @@ ov::intel_cpu::RoPEFusionCosSinPreprocess::RoPEFusionCosSinPreprocess() { {"ellipsis_mask", {}}}); auto squeeze = makePattern({slice_Slice, {-1, head_dims}}); auto index_Gather = makePattern({squeeze, gather_positions_2d, 0}, {{"batch_dims", 0}}); - auto unsqueeze = makePattern({index_Gather, {1, 1, -1, head_dims}}); + + // another simplified pattern for gathering at position_ids + auto slice_Slice2 = makePattern({const_tab, {0}, seq_len, {1}}, + {{"begin_mask", {0}}, + {"end_mask", {0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto index_Gather2 = makePattern({slice_Slice2, gather_positions_2d, 0}, {{"batch_dims", 0}}); + + auto unsqueeze = makePattern({index_Gather | index_Gather2, {1, 1, -1, head_dims}}); return unsqueeze; }; @@ -439,6 +449,131 @@ ov::intel_cpu::RoPEFusionGPTJ::RoPEFusionGPTJ() { return true; }; + auto m = std::make_shared(result, matcher_name); + this->register_matcher(m, callback); +} + +ov::intel_cpu::RoPEFusionChatGLM::RoPEFusionChatGLM(int split_output_id) { + MATCHER_SCOPE(RoPEFusionChatGLM); + + auto qkv_linear = makePattern("f32[?,?,?]"); // f32[seq_length, batch_size, 4608] + auto seq_length = makePattern("i32[1]"); + auto cos_sin_cache = makePattern("f32[?,?,?,?]"); // [max_pos_embeddings, batch_size, 32, 2] + + auto ndims = Symbol("ndims"); + auto head_cnt = Symbol("head_cnt"); + auto head_size = Symbol("head_size"); + auto total_size_q = Symbol("total_size_q"); + auto total_size_k = Symbol("total_size_k"); + auto total_size_v = Symbol("total_size_v"); + + auto qkv_proj = makePattern({qkv_linear, -1, {total_size_q, total_size_k, total_size_v}}); + qkv_proj->set_output_size(3); + + // get key [L, B, Hkv, S] + auto cur_key = makePattern({qkv_proj->output(split_output_id), {0, 0, head_cnt, head_size}}, + {{"special_zero", true}}); + + auto slice_Slice_437 = makePattern({cur_key, {0, 0, 0, 0}, {0, 0, 0, ndims}, {1, 1, 1, 1}}, + {{"begin_mask", {1, 1, 1, 0}}, + {"end_mask", {1, 1, 1, 0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + + // rotate half + auto ListConstruct_452_Concat = + makePattern({seq_length, {-1}, {head_cnt}, {ndims / 2}, {2}}, {{"axis", 0}}); + auto ListConstruct_379_Concat = + makePattern({seq_length, {-1}, {1}, {ndims / 2}, {2}}, {{"axis", 0}}); + + auto reshape_Reshape_453 = + makePattern({slice_Slice_437, ListConstruct_452_Concat}, {{"special_zero", false}}); + auto x_even = makePattern({reshape_Reshape_453, 0, -1}, {{"batch_dims", 0}}); + auto slice_Slice_449 = makePattern({cos_sin_cache, {0}, seq_length, {1}}, + {{"begin_mask", {0}}, + {"end_mask", {0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto view_Reshape_460 = + makePattern({slice_Slice_449, ListConstruct_379_Concat}, {{"special_zero", false}}); + auto cos_tab = makePattern({view_Reshape_460, 0, -1}, {{"batch_dims", 0}}); + auto x_even_cos = makePattern({x_even, cos_tab}, {{"auto_broadcast", "numpy"}}); + auto x_odd = makePattern({reshape_Reshape_453, 1, -1}, {{"batch_dims", 0}}); + auto sin_tab = makePattern({view_Reshape_460, 1, -1}, {{"batch_dims", 0}}); + auto x_odd_sin = makePattern({x_odd, sin_tab}, {{"auto_broadcast", "numpy"}}); + auto neg_x_odd_sin = makePattern({x_odd_sin, -1.000000f}, {{"auto_broadcast", "numpy"}}); + auto sub_Subtract_469 = makePattern({x_even_cos, neg_x_odd_sin}, {{"auto_broadcast", "numpy"}}); + + auto y_even = makePattern({sub_Subtract_469, -1}); + auto x_odd_cos = makePattern({x_odd, cos_tab}, {{"auto_broadcast", "numpy"}}); + auto x_even_sin = makePattern({x_even, sin_tab}, {{"auto_broadcast", "numpy"}}); + auto add_Add_476 = makePattern({x_odd_cos, x_even_sin}, {{"auto_broadcast", "numpy"}}); + auto y_odd = makePattern({add_Add_476, -1}); + + auto stack_481 = makePattern({y_even, y_odd}, {{"axis", -1}}); + + auto ShapeOf_135133 = makePattern({stack_481}); + auto flatten_Slice_497 = makePattern({ShapeOf_135133, {0}, {3}, {1}}, + {{"begin_mask", {0}}, + {"end_mask", {0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto flatten_Concat_500 = makePattern({flatten_Slice_497, {-1}}, {{"axis", 0}}); + auto const_target_shape = makeConst({0, 0, head_cnt, ndims}); + // [length, batch, head_cnt, half_rotary_dims, 2] + auto flatten_Reshape_501 = + makePattern({stack_481, flatten_Concat_500 | const_target_shape}, {{"special_zero", true}}); + auto slice_Slice_443 = + makePattern({cur_key, {0, 0, 0, ndims}, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}}, + {{"begin_mask", {1, 1, 1, 0}}, + {"end_mask", {1, 1, 1, 0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto cat_Concat_505 = makePattern({flatten_Reshape_501, slice_Slice_443}, {{"axis", -1}}); + + auto result = cat_Concat_505; + + matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) { + const auto& pattern_map = m.get_pattern_value_map(); + auto root = m.get_match_root(); + PatternValidator validator(m); + if (!validator) { + return false; + } + + RoPENode::Config config; + OutputVector new_args; + config.rotary_ndims = validator["ndims"]; + config.is_chatglm = true; + config.head_cnt = validator["head_cnt"]; + config.head_size = validator["head_size"]; + + if (split_output_id == 0) { + // query : split_output_id == 0 + config.slice_start = 0; + config.slice_stop = validator["total_size_q"]; + } else { + // key : split_output_id == 1 + config.slice_start = validator["total_size_q"]; + config.slice_stop = config.slice_start + validator["total_size_k"]; + } + + new_args.push_back(pattern_map.at(qkv_linear)); + new_args.push_back(pattern_map.at(cos_sin_cache)); + new_args.push_back(pattern_map.at(cos_sin_cache)); + + auto old_node = root; + + auto new_node = std::make_shared(new_args, config); + new_node->set_friendly_name(old_node->get_friendly_name()); + ov::replace_node(old_node, new_node); + return true; + }; + auto m = std::make_shared(result, matcher_name); this->register_matcher(m, callback); } \ No newline at end of file diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/rope_fusion.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/rope_fusion.hpp index 58bab527504096..666366e02c0a47 100644 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/rope_fusion.hpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/rope_fusion.hpp @@ -20,7 +20,11 @@ class RoPEFusionGPTJ : public ngraph::pass::MatcherPass { OPENVINO_RTTI("RoPEFusionGPTJ", "0"); RoPEFusionGPTJ(); }; - +class RoPEFusionChatGLM : public ngraph::pass::MatcherPass { +public: + OPENVINO_RTTI("RoPEFusionChatGLM", "0"); + RoPEFusionChatGLM(int split_output_id); +}; class RoPEFusionIOSlicing : public ngraph::pass::MatcherPass { public: OPENVINO_RTTI("RoPEFusionIOSlicing", "0"); @@ -56,6 +60,9 @@ class RoPEFusion : public ngraph::pass::GraphRewrite { add_matcher(); add_matcher(); add_matcher(); + + add_matcher(0); + add_matcher(1); } }; diff --git a/src/plugins/intel_cpu/src/utils/gen_pattern.hpp b/src/plugins/intel_cpu/src/utils/gen_pattern.hpp index c562190494ed4e..a7b29c7f6c78e1 100644 --- a/src/plugins/intel_cpu/src/utils/gen_pattern.hpp +++ b/src/plugins/intel_cpu/src/utils/gen_pattern.hpp @@ -357,7 +357,7 @@ struct AttrAny { return any.as>(); } - template + template std::vector as_T_vector() { if (any.empty()) return {}; @@ -574,6 +574,10 @@ class GenericPattern : public ov::pass::pattern::op::Pattern { bool match_value(ov::pass::pattern::Matcher* matcher, const Output& pattern_value, const Output& graph_value) override { + // strictly requires pattern & graph value to come from output port with same index, + // this is absolute necessary when pattern contains split node connections. + if (pattern_value.get_index() != graph_value.get_index()) + return false; if (m_predicate(graph_value)) { auto& pattern_map = matcher->get_pattern_value_map(); pattern_map[shared_from_this()] = graph_value; @@ -858,7 +862,7 @@ class AttrMatcher : public ov::AttributeVisitor { } else if (auto a = ov::as_type>(&adapter)) { is_matched = m_attr_map[name].equal_to(a->get()); } else { - OPENVINO_THROW("AttrSetter met unsupported AttributeAdapter"); + OPENVINO_THROW("AttrMatcher met unsupported AttributeAdapter ", name); } add_match_result(name, is_matched); } @@ -919,6 +923,13 @@ std::shared_ptr makeConst(const ov::element::Type& type, return std::make_shared(type, shape, std::vector(values)); } +inline std::shared_ptr makeConst(const std::vector& v) { + auto node = ov::pass::pattern::wrap_type(); + auto& rt_info = node->get_rt_info(); + rt_info["symbolic_const_value"] = v; + return node; +} + template std::shared_ptr makeConst(const ov::element::Type& type, const ov::Shape& shape, const std::vector& values) { return std::make_shared(type, shape, values); @@ -1198,7 +1209,7 @@ class PatternValidator { auto byte_size = shape_size(vconst_node->get_output_shape(0)) * vconst_node->get_output_element_type(0).size(); if (std::memcmp(pconst_node->get_data_ptr(), vconst_node->get_data_ptr(), byte_size) != 0) { - _VERBOSE_LOG("Constant value mismatch."); + _VERBOSE_LOG("Constant value mismatch on ", pconst_node, " vs ", vconst_node); return false; } continue; diff --git a/src/plugins/intel_cpu/src/utils/print_model.hpp b/src/plugins/intel_cpu/src/utils/print_model.hpp index 6b4eb01180a264..2b4eb31d5671e2 100644 --- a/src/plugins/intel_cpu/src/utils/print_model.hpp +++ b/src/plugins/intel_cpu/src/utils/print_model.hpp @@ -319,6 +319,10 @@ void dump_cpp_style(std::ostream& os, const std::shared_ptr& model) { const auto& type_info = op->get_type_info(); auto version_info = std::string(type_info.get_version()); auto type = version_info + "::" + type_info.name; + auto& rt_info = op->get_rt_info(); + if (rt_info.count("opset") && rt_info["opset"] == "type_relaxed_opset") { + type = std::string("ov::op::TypeRelaxed<") + type + ">"; + } auto name = opname[op.get()]; os << prefix << " "; diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/rotary_pos_emb.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/rotary_pos_emb.cpp index edfce4dcc9520e..28ed4371c6262d 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/rotary_pos_emb.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/rotary_pos_emb.cpp @@ -131,7 +131,7 @@ static std::shared_ptr buildROPE_Llama2(const int batch, namespace CPULayerTestsDefinitions { -class RoPECPUTest : public SubgraphBaseTest { +class RoPECPUTestLlama2 : public SubgraphBaseTest { public: ov::Tensor create_i32_tensor(const ov::Shape& shape, int start, int step = 1) { auto tensor = ov::Tensor(ov::element::i32, shape); @@ -177,8 +177,155 @@ class RoPECPUTest : public SubgraphBaseTest { } }; -TEST_F(RoPECPUTest, smoke_CompareWithRefs) { +TEST_F(RoPECPUTestLlama2, smoke_CompareWithRefs) { run(); + CheckNumberOfNodesWithType(compiledModel, "RoPE", 1); +} + +class RoPECPUTestChatGLM : public SubgraphBaseTest { +public: + ov::Tensor create_i32_tensor(const ov::Shape& shape, int start, int step = 1) { + auto tensor = ov::Tensor(ov::element::i32, shape); + auto* ptr = static_cast(tensor.data()); + for (size_t i = 0; i < tensor.get_size(); i++) { + ptr[i] = start; + start += step; + } + return tensor; + } + + void generate_inputs(const std::vector& targetInputStaticShapes) override { + const auto& funcInputs = function->inputs(); + + auto& input_shape = targetInputStaticShapes[0]; + auto seq_length = input_shape[0]; + // auto batch = input_shape[1]; + + ov::Tensor t_input = + utils::create_and_fill_tensor(funcInputs[0].get_element_type(), input_shape, 2, -1.0f, 32768); + ov::Tensor t_cos_sin_cache = + utils::create_and_fill_tensor(funcInputs[1].get_element_type(), {32768, 32, 2}, 2, -1.0f, 32768); + ov::Tensor t_position_ids = create_i32_tensor(ov::Shape({1, seq_length}), 15); + + inputs.clear(); + inputs.insert({funcInputs[0].get_node_shared_ptr(), t_input}); + inputs.insert({funcInputs[1].get_node_shared_ptr(), t_cos_sin_cache}); + inputs.insert({funcInputs[2].get_node_shared_ptr(), t_position_ids}); + } + +protected: + std::shared_ptr buildROPE_ChatGLM(int batch, int head_cnt, int rotary_dims) { + auto input = + std::make_shared(ov::element::f32, PartialShape{-1, batch, 4096 + 256 + 256}); + auto cos_sin_cache = std::make_shared(ov::element::f32, PartialShape{32768, 32, 2}); + auto position_ids = std::make_shared(ov::element::i32, PartialShape{-1, -1}); + + auto __module_transformer_index_67_Gather = + makeOP({cos_sin_cache, position_ids, 0}, {{"batch_dims", 0}}); + auto __module_transformer_transpose_Transpose = + makeOP({__module_transformer_index_67_Gather, {1, 0, 2, 3}}); + auto size_ShapeOf_110 = + makeOP({__module_transformer_transpose_Transpose}, {{"output_type", "i32"}}); + auto __getitem___Gather = makeOP({size_ShapeOf_110, -2, 0}, {{"batch_dims", 0}}); + auto mul_Multiply = makeOP({__getitem___Gather, 2}, {{"auto_broadcast", "numpy"}}); + auto slice_Unsqueeze_112 = makeOP({mul_Multiply, 0}); + + auto floordiv_Divide = + makeOP({mul_Multiply, 2}, {{"auto_broadcast", "numpy"}, {"m_pythondiv", true}}); + auto floordiv_Floor = makeOP({floordiv_Divide}); + auto ListConstruct_126_Reshape_2 = makeOP({floordiv_Floor, {-1}}, {{"special_zero", false}}); + + auto ListUnpack_321 = makeOP({input, -1, {4096, 256, 256}}); + auto view_Reshape = + makeOP({ListUnpack_321->output(0), {0, 0, 32, 128}}, {{"special_zero", true}}); + + auto ScatterUpdate_229053 = makeOP({{0, 0, 0, 0}, {3}, slice_Unsqueeze_112, {0}}); + auto slice_Slice_357 = + makeOP({view_Reshape, {0, 0, 0, 0}, ScatterUpdate_229053, {1, 1, 1, 1}}, + {{"begin_mask", {1, 1, 1, 0}}, + {"end_mask", {1, 1, 1, 0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto size_ShapeOf_346 = makeOP({view_Reshape}, {{"output_type", "i32"}}); + auto size_Gather_348 = makeOP({size_ShapeOf_346, 0, 0}, {{"batch_dims", 0}}); + auto ListConstruct_372_Reshape = makeOP({size_Gather_348, {-1}}, {{"special_zero", false}}); + auto size_Gather_351 = makeOP({size_ShapeOf_346, {2}, 0}, {{"batch_dims", 0}}); + auto ListConstruct_372_Concat = + makeOP({ListConstruct_372_Reshape, {-1}, size_Gather_351, ListConstruct_126_Reshape_2, {2}}, + {{"axis", 0}}); + auto reshape_Reshape_373 = + makeOP({slice_Slice_357, ListConstruct_372_Concat}, {{"special_zero", false}}); + auto select_Gather_381 = makeOP({reshape_Reshape_373, 0, -1}, {{"batch_dims", 0}}); + auto slice_Unsqueeze_367 = makeOP({size_Gather_348, 0}); + auto slice_Slice_369 = + makeOP({__module_transformer_transpose_Transpose, {0}, slice_Unsqueeze_367, {1}}, + {{"begin_mask", {0}}, + {"end_mask", {0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto size_ShapeOf_374 = makeOP({reshape_Reshape_373}, {{"output_type", "i32"}}); + auto size_Gather_376 = makeOP({size_ShapeOf_374, {3}, 0}, {{"batch_dims", 0}}); + auto ListConstruct_379_Concat = + makeOP({ListConstruct_372_Reshape, {-1}, {1}, size_Gather_376, {2}}, {{"axis", 0}}); + auto view_Reshape_380 = + makeOP({slice_Slice_369, ListConstruct_379_Concat}, {{"special_zero", false}}); + auto select_Gather_382 = makeOP({view_Reshape_380, 0, -1}, {{"batch_dims", 0}}); + auto mul_Multiply_383 = + makeOP({select_Gather_381, select_Gather_382}, {{"auto_broadcast", "numpy"}}); + auto select_Gather_384 = makeOP({reshape_Reshape_373, 1, -1}, {{"batch_dims", 0}}); + auto select_Gather_385 = makeOP({view_Reshape_380, 1, -1}, {{"batch_dims", 0}}); + auto mul_Multiply_386 = + makeOP({select_Gather_384, select_Gather_385}, {{"auto_broadcast", "numpy"}}); + auto sub_Subtract_389 = + makeOP({mul_Multiply_383, mul_Multiply_386}, {{"auto_broadcast", "numpy"}}); + auto Unsqueeze_62716 = makeOP({sub_Subtract_389, -1}); + auto mul_Multiply_391 = + makeOP({select_Gather_384, select_Gather_382}, {{"auto_broadcast", "numpy"}}); + auto mul_Multiply_393 = + makeOP({select_Gather_381, select_Gather_385}, {{"auto_broadcast", "numpy"}}); + auto add_Add_396 = makeOP({mul_Multiply_391, mul_Multiply_393}, {{"auto_broadcast", "numpy"}}); + auto Unsqueeze_62717 = makeOP({add_Add_396, -1}); + auto stack_401 = makeOP({Unsqueeze_62716, Unsqueeze_62717}, {{"axis", -1}}); + auto flatten_ShapeOf_402 = makeOP({stack_401}, {{"output_type", "i32"}}); + auto flatten_Slice_417 = makeOP({flatten_ShapeOf_402, {0}, {3}, {1}}, + {{"begin_mask", {0}}, + {"end_mask", {0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto flatten_Concat_420 = makeOP({flatten_Slice_417, {-1}}, {{"axis", 0}}); + auto flatten_Reshape_421 = makeOP({stack_401, flatten_Concat_420}, {{"special_zero", true}}); + auto ScatterUpdate_229067 = makeOP({{0, 0, 0, 0}, {3}, slice_Unsqueeze_112, {0}}); + auto slice_Slice_363 = + makeOP({view_Reshape, ScatterUpdate_229067, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}}, + {{"begin_mask", {1, 1, 1, 0}}, + {"end_mask", {1, 1, 1, 0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto cat_Concat_425 = makeOP({flatten_Reshape_421, slice_Slice_363}, {{"axis", -1}}); + return std::make_shared(ov::NodeVector{cat_Concat_425}, + ov::ParameterVector{input, cos_sin_cache, position_ids}); + } + void SetUp() override { + targetDevice = ov::test::utils::DEVICE_CPU; + + const int batch = 2; + const int seq_length = 7; + const int num_head = 32; + const int rotary_dims = 64; + + InputShape inpShape = {{-1, batch, 4096 + 256 + 256}, {{seq_length, batch, 4096 + 256 + 256}}}; + init_input_shapes({inpShape}); + function = buildROPE_ChatGLM(batch, num_head, rotary_dims); + } +}; + +TEST_F(RoPECPUTestChatGLM, smoke_CompareWithRefs) { + run(); + CheckNumberOfNodesWithType(compiledModel, "RoPE", 1); } } // namespace CPULayerTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/unit/transformations/convert_to_rope.cpp b/src/plugins/intel_cpu/tests/unit/transformations/convert_to_rope.cpp index 91fae33253a494..6001e3539a1759 100644 --- a/src/plugins/intel_cpu/tests/unit/transformations/convert_to_rope.cpp +++ b/src/plugins/intel_cpu/tests/unit/transformations/convert_to_rope.cpp @@ -139,6 +139,9 @@ TEST_F(TransformationTestsF, ConvertToROPE_LLama2_no_gather) { {"config.slice_stop", 0}, {"config.input_trans0213", true}, {"config.is_interleaved", false}, + {"config.is_chatglm", false}, + {"config.head_cnt", 0}, + {"config.head_size", 0}, {"config.rotary_ndims", static_cast(ndims)}, {"config.gather_position_arg_id", 0}}); @@ -170,6 +173,9 @@ TEST_F(TransformationTestsF, ConvertToROPE_LLama2_with_gather) { {"config.slice_stop", 0}, {"config.input_trans0213", true}, {"config.is_interleaved", false}, + {"config.is_chatglm", false}, + {"config.head_cnt", 0}, + {"config.head_size", 0}, {"config.rotary_ndims", static_cast(ndims)}, {"config.gather_position_arg_id", 3}}); @@ -304,6 +310,9 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_no_gather) { {"config.slice_stop", ndims}, {"config.input_trans0213", true}, {"config.is_interleaved", false}, + {"config.is_chatglm", false}, + {"config.head_cnt", 0}, + {"config.head_size", 0}, {"config.rotary_ndims", rotary_ndims}, {"config.gather_position_arg_id", 0}}); model_ref = std::make_shared(ov::NodeVector{rope}, ov::ParameterVector{input, param_cos, param_sin}); @@ -334,6 +343,9 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_with_gather) { {"config.slice_stop", ndims}, {"config.input_trans0213", true}, {"config.is_interleaved", false}, + {"config.is_chatglm", false}, + {"config.head_cnt", 0}, + {"config.head_size", 0}, {"config.rotary_ndims", rotary_ndims}, {"config.gather_position_arg_id", 3}}); model_ref = @@ -445,8 +457,119 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTJ) { {"config.slice_stop", 0}, {"config.input_trans0213", false}, {"config.is_interleaved", true}, + {"config.is_chatglm", false}, + {"config.head_cnt", 0}, + {"config.head_size", 0}, {"config.rotary_ndims", rotary_ndims}, {"config.gather_position_arg_id", 0}}); model_ref = std::make_shared(ov::NodeVector{rope}, ov::ParameterVector{input, cos_sin}); } +} + +TEST_F(TransformationTestsF, ConvertToROPE_chatGML) { + disable_rt_info_check(); + const int batch = 2; + const int seq_len = 7; + const int num_heads = 32; + const int ndims = 128; + const int rotary_ndims = 64; + const int max_pos_length = 2048; + { + auto input = std::make_shared(ov::element::f32, ov::Shape{seq_len, batch, 4608}); + auto seq_length = std::make_shared(ov::element::i32, ov::Shape{1}); + auto cos_sin_cache = + std::make_shared(ov::element::f32, + ov::Shape{max_pos_length, batch, rotary_ndims / 2, 2}); + + auto ListUnpack_321 = makeOP({input, -1, {4096, 256, 256}}); + auto view_Reshape = makeOP({ListUnpack_321->output(0), {0, 0, num_heads, ndims}}, + {{"special_zero", true}}); + auto aten_slice_Slice_357 = + makeOP({view_Reshape, {0, 0, 0, 0}, {0, 0, 0, rotary_ndims}, {1, 1, 1, 1}}, + {{"begin_mask", {1, 1, 1, 0}}, + {"end_mask", {1, 1, 1, 0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto ListConstruct_372_Concat = + makeOP({seq_length, {-1}, {num_heads}, {rotary_ndims / 2}, {2}}, {{"axis", 0}}); + auto aten_reshape_Reshape_373 = + makeOP({aten_slice_Slice_357, ListConstruct_372_Concat}, {{"special_zero", false}}); + auto aten_select_Gather_381 = + makeOP({aten_reshape_Reshape_373, 0, -1}, {{"batch_dims", 0}}); + auto aten_slice_Slice_369 = makeOP({cos_sin_cache, {0}, seq_length, {1}}, + {{"begin_mask", {0}}, + {"end_mask", {0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto ListConstruct_379_Concat = + makeOP({seq_length, {-1}, {1}, {rotary_ndims / 2}, {2}}, {{"axis", 0}}); + auto aten_view_Reshape_380 = + makeOP({aten_slice_Slice_369, ListConstruct_379_Concat}, {{"special_zero", false}}); + auto aten_select_Gather_382 = makeOP({aten_view_Reshape_380, 0, -1}, {{"batch_dims", 0}}); + auto aten_mul_Multiply_383 = makeOP({aten_select_Gather_381, aten_select_Gather_382}, + {{"auto_broadcast", "numpy"}}); + auto aten_select_Gather_384 = + makeOP({aten_reshape_Reshape_373, 1, -1}, {{"batch_dims", 0}}); + auto aten_select_Gather_385 = makeOP({aten_view_Reshape_380, 1, -1}, {{"batch_dims", 0}}); + auto aten_mul_Multiply_386 = makeOP({aten_select_Gather_384, aten_select_Gather_385}, + {{"auto_broadcast", "numpy"}}); + auto Multiply_101315 = + makeOP({aten_mul_Multiply_386, -1.000000f}, {{"auto_broadcast", "numpy"}}); + auto aten_sub_Subtract_389 = + makeOP({aten_mul_Multiply_383, Multiply_101315}, {{"auto_broadcast", "numpy"}}); + auto Unsqueeze_62716 = makeOP({aten_sub_Subtract_389, -1}); + auto aten_mul_Multiply_391 = makeOP({aten_select_Gather_384, aten_select_Gather_382}, + {{"auto_broadcast", "numpy"}}); + auto aten_mul_Multiply_393 = makeOP({aten_select_Gather_381, aten_select_Gather_385}, + {{"auto_broadcast", "numpy"}}); + auto aten_add_Add_396 = + makeOP({aten_mul_Multiply_391, aten_mul_Multiply_393}, {{"auto_broadcast", "numpy"}}); + auto Unsqueeze_62717 = makeOP({aten_add_Add_396, -1}); + auto aten_stack_401 = makeOP({Unsqueeze_62716, Unsqueeze_62717}, {{"axis", -1}}); + auto ShapeOf_134820 = makeOP>( + {aten_stack_401}, + {{"type_relax", true}, {"input_data_types", {}}, {"output_data_types", {ov::element::i32}}}); + auto aten_flatten_Slice_417 = makeOP({ShapeOf_134820, {0}, {3}, {1}}, + {{"begin_mask", {0}}, + {"end_mask", {0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto aten_flatten_Concat_420 = makeOP({aten_flatten_Slice_417, {-1}}, {{"axis", 0}}); + auto aten_flatten_Reshape_421 = + makeOP({aten_stack_401, aten_flatten_Concat_420}, {{"special_zero", true}}); + auto aten_slice_Slice_363 = + makeOP({view_Reshape, {0, 0, 0, rotary_ndims}, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}}, + {{"begin_mask", {1, 1, 1, 0}}, + {"end_mask", {1, 1, 1, 0}}, + {"new_axis_mask", {}}, + {"shrink_axis_mask", {}}, + {"ellipsis_mask", {}}}); + auto aten_cat_Concat_425 = + makeOP({aten_flatten_Reshape_421, aten_slice_Slice_363}, {{"axis", -1}}); + model = std::make_shared(ov::NodeVector{aten_cat_Concat_425}, + ov::ParameterVector{input, seq_length, cos_sin_cache}); + } + manager.register_pass(); + { + auto input = std::make_shared(ov::element::f32, ov::Shape{seq_len, batch, 4608}); + auto seq_length = std::make_shared(ov::element::i32, ov::Shape{1}); + auto cos_sin_cache = + std::make_shared(ov::element::f32, + ov::Shape{max_pos_length, batch, rotary_ndims / 2, 2}); + auto rope = makeOP({input, cos_sin_cache, cos_sin_cache}, + {{"config.slice_start", 0}, + {"config.slice_stop", 4096}, + {"config.input_trans0213", false}, + {"config.is_interleaved", false}, + {"config.rotary_ndims", rotary_ndims}, + {"config.is_chatglm", true}, + {"config.head_cnt", num_heads}, + {"config.head_size", ndims}, + {"config.gather_position_arg_id", 0}}); + model_ref = + std::make_shared(ov::NodeVector{rope}, ov::ParameterVector{input, seq_length, cos_sin_cache}); + } } \ No newline at end of file From ca87784a29ad8d150b49b8ace8093fc9e257765d Mon Sep 17 00:00:00 2001 From: Anastasia Kuporosova Date: Mon, 4 Dec 2023 15:44:23 +0100 Subject: [PATCH 02/20] [PyOV] Missed variable API in Model class (#21434) * [PyOV] Missed variable API in Model class * fixes in model docstr and codestyle * add test * fix ci * fix ci --- docs/sphinx_setup/api/ie_python_api/api.rst | 6 + .../python/src/pyopenvino/graph/model.cpp | 103 ++++++++++++++---- .../tests/test_runtime/test_infer_request.py | 14 +-- .../python/tests/test_runtime/test_model.py | 21 +++- src/bindings/python/tests/utils/helpers.py | 10 ++ 5 files changed, 117 insertions(+), 37 deletions(-) diff --git a/docs/sphinx_setup/api/ie_python_api/api.rst b/docs/sphinx_setup/api/ie_python_api/api.rst index f0f835c51aa35e..50fa863ef6a623 100644 --- a/docs/sphinx_setup/api/ie_python_api/api.rst +++ b/docs/sphinx_setup/api/ie_python_api/api.rst @@ -17,6 +17,12 @@ OpenVINO Python API openvino.runtime.op +.. autosummary:: + :toctree: _autosummary + :template: custom-module-template.rst + + openvino.runtime.op.util + .. autosummary:: :toctree: _autosummary :template: custom-module-template.rst diff --git a/src/bindings/python/src/pyopenvino/graph/model.cpp b/src/bindings/python/src/pyopenvino/graph/model.cpp index 08c30afd7d217d..6f5e1d2ff3d13a 100644 --- a/src/bindings/python/src/pyopenvino/graph/model.cpp +++ b/src/bindings/python/src/pyopenvino/graph/model.cpp @@ -111,7 +111,7 @@ void regclass_graph_Model(py::module m) { Create user-defined Model which is a representation of a model. :param results: List of results. - :type results: List[op.Result] + :type results: List[openvino.runtime.Node] :param sinks: List of Nodes to be used as Sinks (e.g. Assign ops). :type sinks: List[openvino.runtime.Node] :param parameters: List of parameters. @@ -221,7 +221,7 @@ void regclass_graph_Model(py::module m) { Create user-defined Model which is a representation of a model :param results: List of results. - :type results: List[op.Result] + :type results: List[openvino.runtime.Node] :param sinks: List of Nodes to be used as Sinks (e.g. Assign ops). :type sinks: List[openvino.runtime.Node] :param parameters: List of parameters. @@ -274,7 +274,7 @@ void regclass_graph_Model(py::module m) { Create user-defined Model which is a representation of a model :param results: List of results. - :type results: List[op.Result] + :type results: List[openvino.runtime.Node] :param parameters: List of parameters. :type parameters: List[op.Parameter] :param variables: List of variables. @@ -521,33 +521,33 @@ void regclass_graph_Model(py::module m) { R"( Return the model parameters. - :return: ParameterVector containing model parameters. - :rtype: ParameterVector + :return: a list of model's parameters. + :rtype: List[op.Parameter] )"); model.def_property_readonly("parameters", &ov::Model::get_parameters, R"( Return the model parameters. - :return: ParameterVector containing model parameters. - :rtype: ParameterVector + :return: a list of model's parameters. + :rtype: List[op.Parameter] )"); model.def("get_results", &ov::Model::get_results, R"( Return a list of model outputs. - :return: ResultVector containing model parameters. - :rtype: ResultVector - )"); + :return: a list of model's result nodes. + :rtype: List[openvino.runtime.Node] + )"); model.def_property_readonly("results", &ov::Model::get_results, R"( - Return a list of model outputs. + Return a list of model outputs. - :return: ResultVector containing model parameters. - :rtype: ResultVector - )"); + :return: a list of model's result nodes. + :rtype: List[openvino.runtime.Node] + )"); model.def("get_result", &ov::Model::get_result, R"( @@ -555,7 +555,7 @@ void regclass_graph_Model(py::module m) { :return: Node object representing result. :rtype: openvino.runtime.Node - )"); + )"); model.def_property_readonly("result", &ov::Model::get_result, R"( @@ -747,6 +747,7 @@ void regclass_graph_Model(py::module m) { Delete Result node from the list of results. Method will not delete node from graph. :param result: Result node to delete. + :type result: openvino.runtime.Node )"); model.def("remove_parameter", @@ -765,6 +766,7 @@ void regclass_graph_Model(py::module m) { * call graph validation to check all changes :param parameter: Parameter node to delete. + :type parameter: op.Parameter )"); model.def( @@ -785,8 +787,20 @@ void regclass_graph_Model(py::module m) { Delete sink node from the list of sinks. Method doesn't delete node from graph. :param sink: Sink to delete. + :type sink: openvino.runtime.Node )"); + model.def("remove_variable", + &ov::Model::remove_variable, + py::arg("variable"), + R"( + Delete variable from the list of variables. + Method doesn't delete nodes that used this variable from the graph. + + :param variable: Variable to delete. + :type variable: op.util.Variable + )"); + model.def("add_parameters", &ov::Model::add_parameters, py::arg("parameters"), @@ -813,8 +827,8 @@ void regclass_graph_Model(py::module m) { Method doesn't validate graph, it should be done manually after all changes. :param results: new Result nodes. - :type results: List[op.Result] - )"); + :type results: List[openvino.runtime.Node] + )"); model.def( "add_sinks", @@ -830,13 +844,54 @@ void regclass_graph_Model(py::module m) { }, py::arg("sinks"), R"( - Add new sink nodes to the list. + Add new sink nodes to the list. + + Method doesn't validate graph, it should be done manually after all changes. + + :param sinks: new sink nodes. + :type sinks: List[openvino.runtime.Node] + )"); + + model.def("add_variables", + &ov::Model::add_variables, + py::arg("variables"), + R"( + Add new variables to the list. Method doesn't validate graph, it should be done manually after all changes. - :param sinks: new sink nodes. - :type sinks: List[openvino.runtime.Node] - )"); + :param variables: new variables to add. + :type variables: List[op.util.Variable] + )"); + + model.def("get_variables", + &ov::Model::get_variables, + R"( + Return a list of model's variables. + + :return: a list of model's variables. + :rtype: List[op.util.Variable] + )"); + + model.def_property_readonly("variables", + &ov::Model::get_variables, + R"( + Return a list of model's variables. + + :return: a list of model's variables. + :rtype: List[op.util.Variable] + )"); + + model.def("get_variable_by_id", + &ov::Model::get_variable_by_id, + R"( + Return a variable by specified variable_id. + + :param variable_id: a variable id to get variable node. + :type variable_id: str + :return: a variable node. + :rtype: op.util.Variable + )"); model.def( "get_sinks", @@ -858,10 +913,10 @@ void regclass_graph_Model(py::module m) { return cast_to_node_vector(sinks); }, R"( - Return a list of model outputs. + Return a list of model's sinks. - :return: ResultVector containing model parameters. - :rtype: ResultVector + :return: a list of model's sinks. + :rtype: List[openvino.runtime.Node] )"); model.def( diff --git a/src/bindings/python/tests/test_runtime/test_infer_request.py b/src/bindings/python/tests/test_runtime/test_infer_request.py index cc0bce2073da04..632c63355fb2bf 100644 --- a/src/bindings/python/tests/test_runtime/test_infer_request.py +++ b/src/bindings/python/tests/test_runtime/test_infer_request.py @@ -27,17 +27,7 @@ from openvino.preprocess import PrePostProcessor from tests import skip_need_mock_op -from tests.utils.helpers import generate_image, get_relu_model - - -def create_model_with_memory(input_shape, data_type): - input_data = ops.parameter(input_shape, name="input_data", dtype=data_type) - rv = ops.read_value(input_data, "var_id_667", data_type, input_shape) - add = ops.add(rv, input_data, name="MemoryAdd") - node = ops.assign(add, "var_id_667") - res = ops.result(add, "res") - model = Model(results=[res], sinks=[node], parameters=[input_data], name="name") - return model +from tests.utils.helpers import generate_image, get_relu_model, generate_model_with_memory def create_simple_request_and_inputs(device): @@ -677,7 +667,7 @@ def test_query_state_write_buffer(device, input_shape, data_type, mode): from openvino import Tensor from openvino.runtime.utils.types import get_dtype - model = create_model_with_memory(input_shape, data_type) + model = generate_model_with_memory(input_shape, data_type) model.validate_nodes_and_infer_types() compiled_model = core.compile_model(model=model, device_name=device) request = compiled_model.create_infer_request() diff --git a/src/bindings/python/tests/test_runtime/test_model.py b/src/bindings/python/tests/test_runtime/test_model.py index 228a5c6c88ee49..0e0529d7494a13 100644 --- a/src/bindings/python/tests/test_runtime/test_model.py +++ b/src/bindings/python/tests/test_runtime/test_model.py @@ -23,8 +23,9 @@ serialize, ) from openvino.runtime import Output +from openvino.runtime.op.util import VariableInfo, Variable -from tests.utils.helpers import generate_add_model, create_filename_for_test +from tests.utils.helpers import generate_add_model, generate_model_with_memory, create_filename_for_test def test_descriptor_tensor(): @@ -547,3 +548,21 @@ def test_model_get_raw_address(): assert model._get_raw_address() == model_with_same_addr._get_raw_address() assert model._get_raw_address() != model_different._get_raw_address() + + +def test_model_add_remove_variable(): + model = generate_model_with_memory(input_shape=Shape([2, 1]), data_type=Type.f32) + + var_info = VariableInfo() + var_info.data_shape = PartialShape([2, 1]) + var_info.data_type = Type.f32 + var_info.variable_id = "v1" + variable_1 = Variable(var_info) + + assert len(model.get_variables()) == 1 + model.add_variables([variable_1]) + assert len(model.get_variables()) == 2 + variable_by_id = model.get_variable_by_id("var_id_667") + assert variable_by_id.info.variable_id == "var_id_667" + model.remove_variable(variable_1) + assert len(model.get_variables()) == 1 diff --git a/src/bindings/python/tests/utils/helpers.py b/src/bindings/python/tests/utils/helpers.py index 38246446876fda..ed687b33f52f9d 100644 --- a/src/bindings/python/tests/utils/helpers.py +++ b/src/bindings/python/tests/utils/helpers.py @@ -209,6 +209,16 @@ def generate_add_model() -> openvino._pyopenvino.Model: return Model(add, [param1, param2], "TestModel") +def generate_model_with_memory(input_shape, data_type) -> openvino._pyopenvino.Model: + input_data = ops.parameter(input_shape, name="input_data", dtype=data_type) + rv = ops.read_value(input_data, "var_id_667", data_type, input_shape) + add = ops.add(rv, input_data, name="MemoryAdd") + node = ops.assign(add, "var_id_667") + res = ops.result(add, "res") + model = Model(results=[res], sinks=[node], parameters=[input_data], name="TestModel") + return model + + def create_filename_for_test(test_name, tmp_path, is_xml_path=False, is_bin_path=False): """Return a tuple with automatically generated paths for xml and bin files. From 94d1d7a0336f211070bcb13a4dc9b453d3c473b4 Mon Sep 17 00:00:00 2001 From: Tatiana Savina Date: Mon, 4 Dec 2023 16:36:03 +0100 Subject: [PATCH 03/20] [DOCS] Add legacy notes pot (#21449) * add note to pot * change header --- .../post_training_optimization_tool.rst | 8 ++++---- .../post_training_optimization_tool/pot_api_reference.rst | 6 ++++-- .../post_training_optimization_tool/pot_cli.rst | 7 ++++--- .../pot_cli/configuration_file_description.rst | 6 ++++-- .../pot_cli/simplified_mode.rst | 6 ++++-- .../post_training_optimization_tool/pot_examples.rst | 5 +++-- .../pot_examples/pot_api_examples.rst | 6 ++++-- .../pot_api_examples/pot_example_3d_segmentation.rst | 6 ++++-- .../pot_api_examples/pot_example_classification.rst | 6 ++++-- .../pot_api_examples/pot_example_face_detection.rst | 6 ++++-- .../pot_api_examples/pot_example_object_detection.rst | 6 ++++-- .../pot_api_examples/pot_example_segmentation.rst | 6 ++++-- .../pot_examples/pot_api_examples/pot_example_speech.rst | 6 ++++-- .../pot_examples/pot_cli_example.rst | 6 ++++-- .../post_training_optimization_tool/pot_faq.rst | 6 +++--- .../post_training_optimization_tool/protecting_model.rst | 8 ++++++-- .../quantization_best_practices.rst | 5 +++-- .../quantization_best_practices/saturation_issue.rst | 6 ++++-- .../post_training_optimization_tool/quantizing_models.rst | 6 ++++-- .../quantizing_models/default_quantization_algorithm.rst | 6 ++++-- .../quantizing_models_with_accuracy.rst | 5 +++-- .../accuracy_aware_algorithm.rst | 6 ++++-- 22 files changed, 86 insertions(+), 48 deletions(-) diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool.rst index 234f6dca2493e6..840a53b5c237b6 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool.rst @@ -1,6 +1,6 @@ .. {#pot_introduction} -(Deprecated) Post-training Quantization with POT +[Deprecated] Post-training Quantization with POT ================================================ @@ -14,15 +14,15 @@ API Reference Command-line Interface Examples - pot_docs_FrequentlyAskedQuestions + Post-training Optimization Tool FAQ (Experimental) Protecting Model -.. note:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. -For the needs of post-training optimization, OpenVINO™ provides a **Post-training Optimization Tool (POT)** +For the needs of post-training optimization, OpenVINO provides a **Post-training Optimization Tool (POT)** which supports the **uniform integer quantization** method. This method allows moving from floating-point precision to integer precision (for example, 8-bit) for weights and activations during inference time. It helps to reduce the model size, memory footprint and latency, as well as improve the computational efficiency, using integer arithmetic. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_api_reference.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_api_reference.rst index a837398e652f08..bbbf724b0431f3 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_api_reference.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_api_reference.rst @@ -1,7 +1,9 @@ .. {#pot_compression_api_README} -API Reference -============= +[Deprecated] API Reference +================================= + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. Post-training Optimization Tool API provides a full set of interfaces and helpers that allow users to implement a custom optimization pipeline for various types of DL models including cascaded or compound models. Below is a full specification of this API: diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli.rst index a0b2887536bb90..d893a683b2d841 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli.rst @@ -1,7 +1,7 @@ .. {#pot_compression_cli_README} -Use Post-Training Optimization Tool Command-Line Interface (Model Zoo flow) -=========================================================================== +[Deprecated] Use Post-Training Optimization Tool Command-Line Interface (Model Zoo flow) +==================================================================================================== .. toctree:: @@ -9,9 +9,10 @@ Use Post-Training Optimization Tool Command-Line Interface (Model Zoo flow) :hidden: Simplified Mode - pot_configs_README + Configuration File Description +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. Introduction #################### diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli/configuration_file_description.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli/configuration_file_description.rst index 4f0729fb4d6759..d4f41bc14e1397 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli/configuration_file_description.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli/configuration_file_description.rst @@ -1,7 +1,9 @@ .. {#pot_configs_README} -Configuration File Description -============================== +[Deprecated] Configuration File Description +============================================== + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. The tool is designed to work with the configuration file where all the parameters required for the optimization are specified. These parameters are organized as a dictionary and stored in diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli/simplified_mode.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli/simplified_mode.rst index a7b9465aaab859..de5fccd0af7b54 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli/simplified_mode.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_cli/simplified_mode.rst @@ -1,7 +1,9 @@ .. {#pot_docs_simplified_mode} -Optimization with Simplified Mode -================================= +[Deprecated] Optimization with Simplified Mode +==================================================== + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. Introduction diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples.rst index 0693a9bdf49383..8d0cb6f0444c46 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples.rst @@ -1,7 +1,7 @@ .. {#pot_examples_description} -Examples -======== +[Deprecated] Examples +======================== .. toctree:: @@ -11,6 +11,7 @@ Examples API Examples Command-line Example +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. This section provides a set of examples that demonstrate how to apply the post-training optimization methods to optimize various models from different domains. It contains optimization recipes for concrete models, that unnecessarily cover your case, but which should be sufficient to reuse these recipes to optimize custom models: diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples.rst index 19cb0616e32767..f4eea83bed5b07 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples.rst @@ -1,7 +1,7 @@ .. {#pot_example_README} -Post-training Optimization Tool API Examples -============================================ +[Deprecated] Post-training Optimization Tool API Examples +=============================================================== .. toctree:: @@ -15,6 +15,8 @@ Post-training Optimization Tool API Examples Quantizing 3D Segmentation Model Quantizing for GNA Device +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. + The Post-training Optimization Tool contains multiple examples that demonstrate how to use its :doc:`API ` to optimize DL models. All available examples can be found on `GitHub `__. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_3d_segmentation.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_3d_segmentation.rst index 7217d51314210e..a80701ad9c54aa 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_3d_segmentation.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_3d_segmentation.rst @@ -1,7 +1,9 @@ .. {#pot_example_3d_segmentation_README} -Quantizing 3D Segmentation Model -================================ +[Deprecated] Quantizing 3D Segmentation Model +================================================================ + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. This example demonstrates the use of the :doc:`Post-training Optimization Tool API ` for the task of quantizing a 3D segmentation model. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_classification.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_classification.rst index fe7f79a8c3177b..6bf8d2ec310447 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_classification.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_classification.rst @@ -1,7 +1,9 @@ .. {#pot_example_classification_README} -Quantizing Image Classification Model -===================================== +[Deprecated] Quantizing Image Classification Model +======================================================== + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. This example demonstrates the use of the :doc:`Post-training Optimization Tool API ` for the task of quantizing a classification model. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_face_detection.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_face_detection.rst index 587f7f6e2bc541..2f3964bbcd44e9 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_face_detection.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_face_detection.rst @@ -1,7 +1,9 @@ .. {#pot_example_face_detection_README} -Quantizing Cascaded Face detection Model -======================================== +[Deprecated] Quantizing Cascaded Face detection Model +============================================================ + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. This example demonstrates the use of the :doc:`Post-training Optimization Tool API ` for the task of quantizing a face detection model. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_object_detection.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_object_detection.rst index ce158f201956cc..860d60058d1ba5 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_object_detection.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_object_detection.rst @@ -1,7 +1,9 @@ .. {#pot_example_object_detection_README} -Quantizing Object Detection Model with Accuracy Control -======================================================= +[Deprecated] Quantizing Object Detection Model with Accuracy Control +================================================================================ + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. This example demonstrates the use of the :doc:`Post-training Optimization Toolkit API ` to quantize an object detection model in the :doc:`accuracy-aware mode `. The `MobileNetV1 FPN `__ model from TensorFlow for object detection task is used for this purpose. A custom ``DataLoader`` is created to load the `COCO `__ dataset for object detection task and the implementation of mAP COCO is used for the model evaluation. The code of the example is available on `GitHub `__. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_segmentation.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_segmentation.rst index 5b13e99ec098db..5c6cf59696203f 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_segmentation.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_segmentation.rst @@ -1,7 +1,9 @@ .. {#pot_example_segmentation_README} -Quantizing Semantic Segmentation Model -====================================== +[Deprecated] Quantizing Semantic Segmentation Model +============================================================= + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. This example demonstrates the use of the :doc:`Post-training Optimization Tool API ` for the task of quantizing a segmentation model. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_speech.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_speech.rst index 6ac3962c283954..56f153b46652c2 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_speech.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_api_examples/pot_example_speech.rst @@ -1,7 +1,9 @@ .. {#pot_example_speech_README} -Quantizing for GNA Device -========================= +[Deprecated] Quantizing for GNA Device +========================================= + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. This example demonstrates the use of the :doc:`Post-training Optimization Tool API ` for the task of quantizing a speech model for :doc:`GNA ` device. Quantization for GNA is different from CPU quantization due to device specifics: GNA supports quantized inputs in INT16 and INT32 (for activations) precision and quantized weights in INT8 and INT16 precision. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_cli_example.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_cli_example.rst index 7d0e016647f39a..c5fd319d988ef2 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_cli_example.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_examples/pot_cli_example.rst @@ -1,7 +1,9 @@ .. {#pot_configs_examples_README} -End-to-end Command-line Interface Example -========================================= +[Deprecated] End-to-end Command-line Interface Example +========================================================= + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. This tutorial describes an example of running post-training quantization for the **MobileNet v2 model from PyTorch** framework, diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_faq.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_faq.rst index bfc2f0276fb172..5a495d77c63334 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_faq.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/pot_faq.rst @@ -1,10 +1,10 @@ .. {#pot_docs_FrequentlyAskedQuestions} -Post-training Optimization Tool FAQ -=================================== +[Deprecated] Post-training Optimization Tool FAQ +=========================================================== -.. note:: +.. danger:: Post-training Optimization Tool has been deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for post-training quantization instead. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/protecting_model.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/protecting_model.rst index 9ce1b2bf0ceea7..1eeeddfe0a293e 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/protecting_model.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/protecting_model.rst @@ -1,8 +1,12 @@ .. {#pot_ranger_README} -Experimental: Protecting Deep Learning Model through Range Supervision ("RangeSupervision") -=========================================================================================== +[Deprecated] Experimental: Protecting Deep Learning Model through Range Supervision ("RangeSupervision") +================================================================================================================ +.. danger:: + + Post-training Optimization Tool has been deprecated since OpenVINO 2023.0. + :doc:`Neural Network Compression Framework (NNCF) ` is recommended for post-training quantization instead. Introduction #################### diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantization_best_practices.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantization_best_practices.rst index a2b31b35fc85d9..f5f4e3d08ec255 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantization_best_practices.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantization_best_practices.rst @@ -1,7 +1,7 @@ .. {#pot_docs_BestPractices} -Post-Training Quantization Best Practices -========================================= +[Deprecated] Post-Training Quantization Best Practices +======================================================== .. toctree:: @@ -10,6 +10,7 @@ Post-Training Quantization Best Practices Saturation Issue +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. The :doc:`Default Quantization ` of the Post-training Optimization Tool (POT) is the fastest and easiest way to get a quantized model. It requires only some unannotated representative dataset to be provided in most cases. Therefore, it is recommended to use it as a starting point when it comes to model optimization. However, it can lead to significant accuracy deviation in some cases. The purpose of this article is to provide tips to address this issue. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantization_best_practices/saturation_issue.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantization_best_practices/saturation_issue.rst index d78a29ed03e817..369adc5b981869 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantization_best_practices/saturation_issue.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantization_best_practices/saturation_issue.rst @@ -1,7 +1,9 @@ .. {#pot_saturation_issue} -Saturation (overflow) Issue Workaround -====================================== +[Deprecated] Saturation (overflow) Issue Workaround +======================================================= + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. Introduction diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models.rst index 9005f296d585ad..48bfb24fe9ce66 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models.rst @@ -1,7 +1,7 @@ .. {#pot_default_quantization_usage} -Quantizing Models -================= +[Deprecated] Quantizing Models +====================================== @@ -12,6 +12,8 @@ Quantizing Models DefaultQuantization Method +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. + This guide describes how to apply model quantization with the Default Quantization method without accuracy control, using an unannotated dataset. To use this method, create a Python script using an API of Post-Training Optimization Tool (POT) and implement data preparation logic and quantization pipeline. If you are not familiar with Python, try :doc:`command-line interface ` of POT which is designed to quantize models from diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models/default_quantization_algorithm.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models/default_quantization_algorithm.rst index 20793e7e8f8290..78c5f34df09f02 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models/default_quantization_algorithm.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models/default_quantization_algorithm.rst @@ -1,7 +1,9 @@ .. {#pot_compression_algorithms_quantization_default_README} -DefaultQuantization Parameters -============================== +[Deprecated] DefaultQuantization Parameters +======================================================== + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. The DefaultQuantization Algorithm is designed to perform fast and accurate quantization. It does not offer direct control over the accuracy metric itself but provides many options that can be used to improve it. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models_with_accuracy.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models_with_accuracy.rst index 679394d6a53559..0cac04e0e61d77 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models_with_accuracy.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models_with_accuracy.rst @@ -1,7 +1,7 @@ .. {#pot_accuracyaware_usage} -Quantizing Models with Accuracy Control -======================================= +[Deprecated] Quantizing Models with Accuracy Control +================================================================ .. toctree:: @@ -10,6 +10,7 @@ Quantizing Models with Accuracy Control AccuracyAwareQuantization Method +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. The Accuracy-aware Quantization algorithm allows performing quantization while maintaining accuracy within a pre-defined range. Note that it should be used only if the :doc:`Default Quantization ` introduces a significant accuracy degradation. The reason for it not being the primary choice is its potential for performance degradation, due to some layers getting reverted to the original precision. diff --git a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models_with_accuracy/accuracy_aware_algorithm.rst b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models_with_accuracy/accuracy_aware_algorithm.rst index f47bf5f8743112..42ba337e79b896 100644 --- a/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models_with_accuracy/accuracy_aware_algorithm.rst +++ b/docs/articles_en/documentation/openvino_legacy_features/post_training_optimization_tool/quantizing_models_with_accuracy/accuracy_aware_algorithm.rst @@ -1,7 +1,9 @@ .. {#accuracy_aware_README} -AccuracyAwareQuantization Parameters -==================================== +[Deprecated] AccuracyAwareQuantization Parameters +======================================================== + +.. danger:: Post-training Optimization Tool is deprecated since OpenVINO 2023.0. :doc:`Neural Network Compression Framework (NNCF) ` is recommended for the post-training quantization instead. Introduction From 0d05f87004258c0b2e269309f2c68c2dee326ea1 Mon Sep 17 00:00:00 2001 From: Yuan Hu Date: Tue, 5 Dec 2023 01:23:42 +0800 Subject: [PATCH 04/20] [CPU] fix issue that reshape node didn't update last second input value (#21369) * fix didn't udpate last second input issue Signed-off-by: HU Yuan2 * to match master code Signed-off-by: HU Yuan2 * fix review comment use parametrized test case instead of creating new test case Signed-off-by: HU Yuan2 --------- Signed-off-by: HU Yuan2 --- src/plugins/intel_cpu/src/nodes/reshape.cpp | 6 +++--- .../functional/single_layer_tests/shape_ops.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/reshape.cpp b/src/plugins/intel_cpu/src/nodes/reshape.cpp index d399b5bb5b58aa..4b9aea6967b132 100644 --- a/src/plugins/intel_cpu/src/nodes/reshape.cpp +++ b/src/plugins/intel_cpu/src/nodes/reshape.cpp @@ -65,9 +65,6 @@ Reshape::Reshape(const std::shared_ptr& op, const GraphContext::CPtr c } bool Reshape::needShapeInfer() const { - if (inputShapesModified()) { - return true; - } const auto& mem = getParentEdgesAtPort(1)[0]->getMemory(); if (lastSecondInputValues.empty()) { lastSecondInputValues.resize(mem.getStaticDims()[0], 0); @@ -81,6 +78,9 @@ bool Reshape::needShapeInfer() const { return true; } } + if (inputShapesModified()) { + return true; + } return false; } diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/shape_ops.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/shape_ops.cpp index a4be376f857f41..c7ddbab6e5c27d 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/shape_ops.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/shape_ops.cpp @@ -280,6 +280,20 @@ const auto params_EmptyTensor = ::testing::Combine(::testing::Values(shape_Empty INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_EmptyTensor, ShapeOpsCPUTest, params_EmptyTensor, ShapeOpsCPUTest::getTestCaseName); +// test cases about NeedShapeInfer return right result +inputDescription shape_NeedShapeInfer{{{-1, -1}, + {ngraph::Shape{640, 80}, ngraph::Shape{640, 80}, ngraph::Shape{1280, 40}, ngraph::Shape{1280, 40}}}, + {std::vector{320, 160}, std::vector{640, 80}, std::vector{320, 160}, std::vector{640, 80}}}; + +const auto params_NeedShapeInfer = ::testing::Combine(::testing::Values(shape_NeedShapeInfer), + ::testing::Values(ngraph::helpers::InputLayerType::PARAMETER), + ::testing::Values(shapeNodeType::Reshape), + ::testing::Values(Precision::FP32), + ::testing::ValuesIn(secondInPrcs), + ::testing::Values(false)); + +INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_NeedShapeInfer, ShapeOpsCPUTest, params_NeedShapeInfer, ShapeOpsCPUTest::getTestCaseName); + } // namespace reshapeTest namespace squeezeTest { From 5dda9f333b910a72cf990164725a9d8785f3e1b2 Mon Sep 17 00:00:00 2001 From: Xuejun Zhai Date: Tue, 5 Dec 2023 13:44:42 +0800 Subject: [PATCH 05/20] Upgrade CPU func tests to 2.0 (#21384) * [CPU Plugin][Func Test] Upgrade NonInputInPlaceTest to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade InputOutputTensorReuse to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade InputTensorROI to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade IntertactionCPUTest to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade EdgeWithSameNameInTwoModels to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade MHATest to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade NgramCPUTest to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade ParameterResultCustomBlobTest to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade RemoveUselessBF16ConvertCPUTest to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] remove ngraph & opset Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] fix review comments Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] fix snippets mode error Signed-off-by: Zhai, Xuejun --------- Signed-off-by: Zhai, Xuejun --- .../subgraph_tests/src/inplace_edge.cpp | 56 +- .../src/input_output_tensor_reuse.cpp | 59 ++- .../subgraph_tests/src/input_tensor_roi.cpp | 61 ++- .../subgraph_tests/src/interaction.cpp | 158 +++--- .../src/memory_sharing_test.cpp | 46 +- .../functional/subgraph_tests/src/mha.cpp | 480 ++++++++++-------- .../functional/subgraph_tests/src/ngram.cpp | 144 +++--- .../src/param_result_custom_blob.cpp | 16 +- .../subgraph_tests/src/remove_convert.cpp | 41 +- 9 files changed, 562 insertions(+), 499 deletions(-) diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp index 1385313ce88d41..7d5c1ebb8a9e2b 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/inplace_edge.cpp @@ -2,16 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include +#include "common_test_utils/node_builders/eltwise.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "ov_models/builders.hpp" using namespace CPUTestUtils; -using namespace InferenceEngine; - -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { // If a node (CumSum) with constant parents has several non-constant nodes (Eltwises) than the edge is broken. // The fix is to check node type - is should be Input. // Subgraph: @@ -24,16 +21,13 @@ namespace SubgraphTestsDefinitions { * \ / \ / * \ / \ / * Eltwise Eltwise - * \ / + * \ / * Eltwise * | * Result */ -using namespace ov::test; - -class NonInputInPlaceTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest { +class NonInputInPlaceTest : public testing::WithParamInterface, virtual public SubgraphBaseTest { public: static std::string getTestCaseName(testing::TestParamInfo obj) { std::ostringstream result; @@ -44,34 +38,36 @@ class NonInputInPlaceTest : public testing::WithParamInterface, void SetUp() override { targetDevice = utils::DEVICE_CPU; configuration.insert({ov::hint::inference_precision.name(), ov::element::f16.to_string()}); - const std::vector inputShape = {1, 11, 3, 3}; + const ov::Shape inputShape = {1, 11, 3, 3}; targetStaticShapes = {{inputShape, inputShape}}; ElementType prc = this->GetParam(); - ov::ParameterVector inputParams {std::make_shared(prc, ov::Shape(inputShape)), - std::make_shared(prc, ov::Shape(inputShape))}; + ov::ParameterVector inputParams{std::make_shared(prc, ov::Shape(inputShape)), + std::make_shared(prc, ov::Shape(inputShape))}; - auto cumsum_tensor = ngraph::opset8::Constant::create(prc, inputShape, {10.0f}); - auto axis_node = ngraph::opset8::Constant::create(ngraph::element::i32, {}, {0}); + auto cumsum_tensor = ov::op::v0::Constant::create(prc, inputShape, {10.0f}); + auto axis_node = ov::op::v0::Constant::create(ov::element::i32, {}, {0}); const auto cumsum = std::make_shared(cumsum_tensor, axis_node); - auto eltwiseMul = ngraph::builder::makeEltwise(inputParams[0], cumsum, ngraph::helpers::EltwiseTypes::MULTIPLY); - auto eltwiseAdd1 = ngraph::builder::makeEltwise(inputParams[1], cumsum, ngraph::helpers::EltwiseTypes::ADD); - auto eltwiseAdd2 = ngraph::builder::makeEltwise(eltwiseAdd1, eltwiseMul, ngraph::helpers::EltwiseTypes::ADD); + auto eltwiseMul = ov::test::utils::makeEltwise(inputParams[0], cumsum, ov::test::utils::EltwiseTypes::MULTIPLY); + auto eltwiseAdd1 = ov::test::utils::makeEltwise(inputParams[1], cumsum, ov::test::utils::EltwiseTypes::ADD); + auto eltwiseAdd2 = ov::test::utils::makeEltwise(eltwiseAdd1, eltwiseMul, ov::test::utils::EltwiseTypes::ADD); - ngraph::ResultVector results{std::make_shared(eltwiseAdd2)}; - function = std::make_shared(results, inputParams, "NonInputInPlaceT"); + ov::ResultVector results{std::make_shared(eltwiseAdd2)}; + function = std::make_shared(results, inputParams, "NonInputInPlaceT"); } }; namespace { - TEST_P(NonInputInPlaceTest, CompareWithRefs) { - run(); - } +TEST_P(NonInputInPlaceTest, CompareWithRefs) { + run(); +} -INSTANTIATE_TEST_SUITE_P(smoke_NonInputInPlaceTest_CPU, NonInputInPlaceTest, - testing::Values(ngraph::element::f32, ngraph::element::f16), - NonInputInPlaceTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_NonInputInPlaceTest_CPU, + NonInputInPlaceTest, + testing::Values(ov::element::f32, ov::element::f16), + NonInputInPlaceTest::getTestCaseName); -} // namespace -} // namespace SubgraphTestsDefinitions +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_output_tensor_reuse.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_output_tensor_reuse.cpp index ee09a571dbd690..1173eb7df3f3a4 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_output_tensor_reuse.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_output_tensor_reuse.cpp @@ -3,11 +3,9 @@ // #include "shared_test_classes/base/ov_subgraph.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "ov_models/builders.hpp" -using namespace InferenceEngine; -using namespace ov::test; +namespace ov { +namespace test { /*This test runs the following subgraph: @@ -22,14 +20,13 @@ using namespace ov::test; Softmax | Output_1 - + Output_1 -> Param_1 The main purpose of this test is checking the code path when the output tensor is reused as an input tensor of the next infer request. */ -namespace SubgraphTestsDefinitions { class InputOutputTensorReuse : public SubgraphBaseTest { public: void SetUp() override { @@ -45,16 +42,17 @@ class InputOutputTensorReuse : public SubgraphBaseTest { input_params[1]->set_friendly_name("Param_1"); auto first_soft_max = std::make_shared(input_params[1], softmax_axis); - auto concat = std::make_shared(ov::NodeVector{input_params[0], first_soft_max}, concat_axis); + auto concat = + std::make_shared(ov::NodeVector{input_params[0], first_soft_max}, concat_axis); auto last_soft_max = std::make_shared(concat, softmax_axis); - ngraph::ResultVector results; + ov::ResultVector results; for (size_t i = 0; i < last_soft_max->get_output_size(); i++) - results.push_back(std::make_shared(last_soft_max->output(i))); + results.push_back(std::make_shared(last_soft_max->output(i))); results.front()->set_friendly_name("Output_1"); - function = std::make_shared(results, input_params, "InputOutputTensorReuseTest"); + function = std::make_shared(results, input_params, "InputOutputTensorReuseTest"); } }; @@ -68,9 +66,11 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Binding) { for (size_t i = 0; i < num_iter; i++) { auto outputTensor = inferRequest.get_output_tensor(0); inputShapes.back() = outputTensor.get_shape(); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = std::find_if(inputs.begin(), + inputs.end(), + [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = outputTensor; const auto& expectedOutputs = calculate_refs(); @@ -91,9 +91,10 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once) { auto outputTensor = inferRequest.get_output_tensor(0); inputShapes.back() = outputTensor.get_shape(); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = + std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = outputTensor; @@ -107,9 +108,11 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once) { inferRequest.infer(); compare(expectedOutputs, {outputTensor}); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = std::find_if(inputs.begin(), + inputs.end(), + [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = expectedOutputs.front(); } @@ -123,9 +126,10 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once_Empty_Tensor) { auto outputTensor = inferRequest.get_output_tensor(0); inputShapes.back() = outputTensor.get_shape(); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = + std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = outputTensor; @@ -139,12 +143,15 @@ TEST_F(InputOutputTensorReuse, smoke_Input_Output_Bind_Once_Empty_Tensor) { inferRequest.infer(); compare(expectedOutputs, {outputTensor}); - auto itr = std::find_if(inputs.begin(), inputs.end(), [](const std::pair, ov::Tensor>& item) { - return item.first->get_friendly_name() == "Param_1"; - }); + auto itr = std::find_if(inputs.begin(), + inputs.end(), + [](const std::pair, ov::Tensor>& item) { + return item.first->get_friendly_name() == "Param_1"; + }); ASSERT_NE(itr, inputs.end()); itr->second = expectedOutputs.front(); } } -} // namespace SubgraphTestsDefinitions \ No newline at end of file +} // namespace test +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_tensor_roi.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_tensor_roi.cpp index 02f5c3e9b0e292..32095fbbc7d546 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_tensor_roi.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_tensor_roi.cpp @@ -2,16 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ov_models/builders.hpp" -#include "test_utils/cpu_test_utils.hpp" #include "functional_test_utils/ov_plugin_cache.hpp" +#include "test_utils/cpu_test_utils.hpp" -using namespace ngraph; -using namespace ngraph::op; -using namespace InferenceEngine; using namespace CPUTestUtils; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { struct InputTensorROIParamType { ov::PartialShape shape; @@ -30,24 +27,23 @@ class InputTensorROI : public ::testing::TestWithParam } protected: - std::shared_ptr - create_test_function(element::Type type, - const ov::PartialShape & shape, - const ov::Layout & layout) { + std::shared_ptr create_test_function(element::Type type, + const ov::PartialShape& shape, + const ov::Layout& layout) { ResultVector res; ParameterVector params; - auto param = std::make_shared(type, shape); + auto param = std::make_shared(type, shape); param->set_friendly_name("input_0"); param->get_output_tensor(0).set_names({"tensor_input_0"}); param->set_layout(layout); - auto constant = opset8::Constant::create(type, {1}, {1}); + auto constant = ov::op::v0::Constant::create(type, {1}, {1}); - auto add = std::make_shared(param, constant); + auto add = std::make_shared(param, constant); add->set_friendly_name("Add"); - auto result = std::make_shared(add); + auto result = std::make_shared(add); result->set_friendly_name("result_0"); result->get_output_tensor(0).set_names({"tensor_output_0"}); @@ -57,7 +53,7 @@ class InputTensorROI : public ::testing::TestWithParam return std::make_shared(res, params); } - template + template void Run() { std::shared_ptr ie = ov::test::utils::PluginCache::get().core(); @@ -70,14 +66,14 @@ class InputTensorROI : public ::testing::TestWithParam ov::InferRequest req = compiled_model.create_infer_request(); // Create input tensor - auto input_shape = Shape{ 1, 4, 4, 4 }; + auto input_shape = Shape{1, 4, 4, 4}; auto input_shape_size = ov::shape_size(input_shape); std::vector data(input_shape_size); std::iota(data.begin(), data.end(), 0); auto input_tensor = ov::Tensor(GetParam().type, input_shape, &data[0]); // Set ROI - auto roi = ov::Tensor(input_tensor, { 0, 1, 1, 1 }, { 1, 3, 3, 3 }); + auto roi = ov::Tensor(input_tensor, {0, 1, 1, 1}, {1, 3, 3, 3}); req.set_tensor("tensor_input_0", roi); // Infer @@ -99,24 +95,24 @@ class InputTensorROI : public ::testing::TestWithParam TEST_P(InputTensorROI, SetInputTensorROI) { switch (GetParam().type) { - case ov::element::Type_t::f32: { - Run(); - break; - } - case ov::element::Type_t::u8: { - Run(); - break; - } - default: - break; + case ov::element::Type_t::f32: { + Run(); + break; + } + case ov::element::Type_t::u8: { + Run(); + break; + } + default: + break; } } static InputTensorROI::ParamType InputTensorROIParams[] = { - { ov::PartialShape{ 1, 2, 2, 2 }, element::f32, "NCHW" }, - { ov::PartialShape{ 1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic() }, element::f32, "NCHW" }, - { ov::PartialShape{ 1, 2, 2, 2 }, element::u8, "NCHW" }, - { ov::PartialShape{ 1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic() }, element::u8, "NCHW" }, + {ov::PartialShape{1, 2, 2, 2}, element::f32, "NCHW"}, + {ov::PartialShape{1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, element::f32, "NCHW"}, + {ov::PartialShape{1, 2, 2, 2}, element::u8, "NCHW"}, + {ov::PartialShape{1, 2, ov::Dimension::dynamic(), ov::Dimension::dynamic()}, element::u8, "NCHW"}, }; INSTANTIATE_TEST_SUITE_P(smoke_InputTensorROI, @@ -124,4 +120,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_InputTensorROI, ::testing::ValuesIn(InputTensorROIParams), InputTensorROI::getTestCaseName); -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/interaction.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/interaction.cpp index 1a3874378536ef..572c4e80706f2a 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/interaction.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/interaction.cpp @@ -2,49 +2,37 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "shared_test_classes/base/ov_subgraph.hpp" -#include "ie_precision.hpp" -#include "test_utils/fusing_test_utils.hpp" -#include -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include -#include "functional_test_utils/skip_tests_config.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" using namespace CPUTestUtils; using namespace ov::test; -using namespace ov; - -static std::shared_ptr createFQ(const std::shared_ptr& input) { - auto input_low = std::make_shared(element::f32, ov::Shape{1}, std::vector{0}); - auto input_high = std::make_shared(element::f32, ov::Shape{1}, std::vector{49.4914f}); - auto output_low = std::make_shared(element::f32, ov::Shape{1}, std::vector{0}); - auto output_high = std::make_shared(element::f32, ov::Shape{1}, std::vector{49.4914f}); - return std::make_shared(input, input_low, input_high, output_low, output_high, 256); + +static std::shared_ptr createFQ(const std::shared_ptr& input) { + auto input_low = std::make_shared(ov::element::f32, ov::Shape{1}, std::vector{0}); + auto input_high = std::make_shared(ov::element::f32, ov::Shape{1}, std::vector{49.4914f}); + auto output_low = std::make_shared(ov::element::f32, ov::Shape{1}, std::vector{0}); + auto output_high = std::make_shared(ov::element::f32, ov::Shape{1}, std::vector{49.4914f}); + return std::make_shared(input, input_low, input_high, output_low, output_high, 256); } static std::shared_ptr makeInteraction(const ElementType inType, const ov::PartialShape& inputShape) { bool intraFQ = inType == ElementType::i8; auto paramType = intraFQ ? ElementType::f32 : inType; - std::shared_ptr input = std::make_shared(paramType, inputShape); + std::shared_ptr input = std::make_shared(paramType, inputShape); std::shared_ptr dense_feature = nullptr; if (intraFQ) { dense_feature = createFQ(input); } else { dense_feature = input; } - NodeVector features{dense_feature}; - ParameterVector inputsParams{input}; + ov::NodeVector features{dense_feature}; + ov::ParameterVector inputsParams{input}; const size_t sparse_feature_num = 26; for (size_t i = 0; i < sparse_feature_num; i++) { - auto sparse_input = std::make_shared(paramType, inputShape); + auto sparse_input = std::make_shared(paramType, inputShape); std::shared_ptr sparse_feat = nullptr; if (intraFQ) { sparse_feat = createFQ(sparse_input); @@ -55,23 +43,24 @@ static std::shared_ptr makeInteraction(const ElementType inType, cons inputsParams.push_back(sparse_input); } auto shapeof = std::make_shared(dense_feature); - auto gather_batch_indices = std::make_shared(element::i32, ov::Shape{1}, std::vector{0}); - auto gather_batch_axis = std::make_shared(element::i32, ov::Shape{}, 0); - auto gather_batch = std::make_shared(shapeof, gather_batch_indices, gather_batch_axis); + auto gather_batch_indices = std::make_shared(ov::element::i32, ov::Shape{1}, std::vector{0}); + auto gather_batch_axis = std::make_shared(ov::element::i32, ov::Shape{}, 0); + auto gather_batch = std::make_shared(shapeof, gather_batch_indices, gather_batch_axis); - auto gather_feature_indices = std::make_shared(element::i32, ov::Shape{1}, std::vector{1}); - auto gather_feature_axis = std::make_shared(element::i32, ov::Shape{1}, 0); - auto gather_feature = std::make_shared(shapeof, gather_feature_indices, gather_feature_axis); + auto gather_feature_indices = + std::make_shared(ov::element::i32, ov::Shape{1}, std::vector{1}); + auto gather_feature_axis = std::make_shared(ov::element::i32, ov::Shape{1}, 0); + auto gather_feature = std::make_shared(shapeof, gather_feature_indices, gather_feature_axis); - auto reshape_dim2 = std::make_shared(element::i64, ov::Shape{1}, std::vector{-1}); - auto reshape_shape = std::make_shared(NodeVector{gather_batch, reshape_dim2, gather_feature}, 0); + auto reshape_dim2 = std::make_shared(ov::element::i64, ov::Shape{1}, std::vector{-1}); + auto reshape_shape = std::make_shared(ov::NodeVector{gather_batch, reshape_dim2, gather_feature}, 0); - auto concat1 = std::make_shared(features, 1); - auto reshape = std::make_shared(concat1, reshape_shape, true); + auto concat1 = std::make_shared(features, 1); + auto reshape = std::make_shared(concat1, reshape_shape, true); std::vector transpose1_value = {0, 2, 1}; - auto transpose1_shape = std::make_shared(element::i32, ov::Shape{3}, transpose1_value); - auto transpose1 = std::make_shared(reshape, transpose1_shape); - auto matmul = std::make_shared(reshape, transpose1); + auto transpose1_shape = std::make_shared(ov::element::i32, ov::Shape{3}, transpose1_value); + auto transpose1 = std::make_shared(reshape, transpose1_shape); + auto matmul = std::make_shared(reshape, transpose1); std::shared_ptr inter = nullptr; if (intraFQ) { inter = createFQ(matmul); @@ -79,42 +68,42 @@ static std::shared_ptr makeInteraction(const ElementType inType, cons inter = matmul; } std::vector transpose2_value = {1, 2, 0}; - auto transpose2_shape = std::make_shared(element::i32, ov::Shape{3}, transpose2_value); - auto transpose2 = std::make_shared(inter, transpose2_shape); + auto transpose2_shape = std::make_shared(ov::element::i32, ov::Shape{3}, transpose2_value); + auto transpose2 = std::make_shared(inter, transpose2_shape); std::vector reshape2_value = {729, -1}; - auto reshape2_shape = std::make_shared(element::i32, ov::Shape{2}, reshape2_value); - auto reshape2 = std::make_shared(transpose2, reshape2_shape, true); + auto reshape2_shape = std::make_shared(ov::element::i32, ov::Shape{2}, reshape2_value); + auto reshape2 = std::make_shared(transpose2, reshape2_shape, true); std::vector gather_indices_value; for (int i = 1; i < 27; i++) { - for (int j = 0; j < i; j ++) { + for (int j = 0; j < i; j++) { gather_indices_value.push_back(i * 27 + j); } } - auto gather_indices = std::make_shared(element::i32, ov::Shape{351}, gather_indices_value); - auto gather_axis = std::make_shared(element::i32, ov::Shape{}, 0); - auto gather = std::make_shared(reshape2, gather_indices, gather_axis); - auto reshape3_dim1 = std::make_shared(element::i64, ov::Shape{1}, std::vector{-1}); - auto reshape3_shape = std::make_shared(NodeVector{reshape3_dim1, gather_batch}, 0); - auto reshape3 = std::make_shared(gather, reshape3_shape, true); + auto gather_indices = std::make_shared(ov::element::i32, ov::Shape{351}, gather_indices_value); + auto gather_axis = std::make_shared(ov::element::i32, ov::Shape{}, 0); + auto gather = std::make_shared(reshape2, gather_indices, gather_axis); + auto reshape3_dim1 = std::make_shared(ov::element::i64, ov::Shape{1}, std::vector{-1}); + auto reshape3_shape = std::make_shared(ov::NodeVector{reshape3_dim1, gather_batch}, 0); + auto reshape3 = std::make_shared(gather, reshape3_shape, true); std::vector transpose3_value = {1, 0}; - auto transpose3_shape = std::make_shared(element::i32, ov::Shape{2}, transpose3_value); - auto transpose3 = std::make_shared(reshape3, transpose3_shape); + auto transpose3_shape = std::make_shared(ov::element::i32, ov::Shape{2}, transpose3_value); + auto transpose3 = std::make_shared(reshape3, transpose3_shape); std::vector reshape4_value = {-1, 351}; - auto reshape4_shape = std::make_shared(element::i32, ov::Shape{2}, reshape4_value); - auto reshape4 = std::make_shared(transpose3, reshape4_shape, true); - auto concat2 = std::make_shared(NodeVector{dense_feature, reshape4}, 1); + auto reshape4_shape = std::make_shared(ov::element::i32, ov::Shape{2}, reshape4_value); + auto reshape4 = std::make_shared(transpose3, reshape4_shape, true); + auto concat2 = std::make_shared(ov::NodeVector{dense_feature, reshape4}, 1); std::shared_ptr model; if (intraFQ) { - auto add_const = std::make_shared(element::i8, ov::Shape{355, 1}, 3); - auto convert = std::make_shared(add_const, element::f32); - auto zp_const = std::make_shared(element::f32, ov::Shape{1}, 0); - auto scale_const = std::make_shared(element::f32, ov::Shape{1}, 1); - auto sub = std::make_shared(convert, zp_const); - auto multipy = std::make_shared(sub, scale_const); - const auto matmul = std::make_shared(concat2, multipy); + auto add_const = std::make_shared(ov::element::i8, ov::Shape{355, 1}, 3); + auto convert = std::make_shared(add_const, ov::element::f32); + auto zp_const = std::make_shared(ov::element::f32, ov::Shape{1}, 0); + auto scale_const = std::make_shared(ov::element::f32, ov::Shape{1}, 1); + auto sub = std::make_shared(convert, zp_const); + auto multipy = std::make_shared(sub, scale_const); + const auto matmul = std::make_shared(concat2, multipy); model = std::make_shared(matmul, inputsParams, "interaction"); } else { model = std::make_shared(concat2, inputsParams, "interaction"); @@ -122,7 +111,6 @@ static std::shared_ptr makeInteraction(const ElementType inType, cons return model; } -namespace CPULayerTestsDefinitions { using InteractionLayerCPUTestParams = std::tuple; class IntertactionCPUTest : public testing::WithParamInterface, @@ -146,7 +134,11 @@ class IntertactionCPUTest : public testing::WithParamInterfaceGetParam(); - bool with_bf16 = InferenceEngine::with_cpu_x86_bfloat16(); + bool with_bf16 = ov::with_cpu_x86_bfloat16(); if (with_bf16 && (inType == ov::element::bf16 || inType == ov::element::i32)) { selectedType = makeSelectedTypeStr("ref_any", ov::element::bf16); } else { @@ -166,7 +158,7 @@ class IntertactionCPUTest : public testing::WithParamInterface(27, targetInput[i])); } @@ -180,15 +172,10 @@ TEST_P(IntertactionCPUTest, CompareWithRefs) { } namespace { -const std::vector inPrecisions = { - ElementType::f32, - ElementType::bf16, - ElementType::i32, - ElementType::i8 -}; +const std::vector inPrecisions = {ElementType::f32, ElementType::bf16, ElementType::i32, ElementType::i8}; // the model has 27 inputs with same shape const std::vector input_shapes = { -// temporarily disable dynamic shape for performance issue + // temporarily disable dynamic shape for performance issue // // dynamic batch // { // {-1, 4}, @@ -200,22 +187,11 @@ const std::vector input_shapes = { // {{3, 4}, {5, 6}, {7, 8}} // }, // static shape - { - {6, 4}, - {{6, 4}} - }, - { - {3, 4}, - {{3, 4}} - } -}; - -INSTANTIATE_TEST_SUITE_P(smoke_Interaction, IntertactionCPUTest, - ::testing::Combine( - ::testing::ValuesIn(inPrecisions), - ::testing::ValuesIn(input_shapes)), - IntertactionCPUTest::getTestCaseName); -} // namespace - - -} // namespace CPULayerTestsDefinitions + {{6, 4}, {{6, 4}}}, + {{3, 4}, {{3, 4}}}}; + +INSTANTIATE_TEST_SUITE_P(smoke_Interaction, + IntertactionCPUTest, + ::testing::Combine(::testing::ValuesIn(inPrecisions), ::testing::ValuesIn(input_shapes)), + IntertactionCPUTest::getTestCaseName); +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/memory_sharing_test.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/memory_sharing_test.cpp index ccd09e50da2e47..e693270a807b99 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/memory_sharing_test.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/memory_sharing_test.cpp @@ -2,14 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "common_test_utils/node_builders/convolution.hpp" #include "openvino/openvino.hpp" -#include "test_utils/cpu_test_utils.hpp" -#include "ov_models/builders.hpp" #include "test_utils/convolution_params.hpp" +#include "test_utils/cpu_test_utils.hpp" using namespace CPUTestUtils; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { class EdgeWithSameNameInTwoModels : public ::testing::Test, public CPUTestsBase {}; @@ -24,36 +25,52 @@ TEST_F(EdgeWithSameNameInTwoModels, smoke_CompareWithRef) { const std::vector padsBegin{0, 0}; const std::vector padsEnd{0, 0}; const std::vector dilations{1, 1}; - const ngraph::op::PadType autoPad(ngraph::op::PadType::EXPLICIT); + const ov::op::PadType autoPad(ov::op::PadType::EXPLICIT); - if (InferenceEngine::with_cpu_x86_avx512f()) { + if (ov::with_cpu_x86_avx512f()) { std::tie(inFmts, outFmts, priority, selectedType) = conv_avx512_2D; - } else if (InferenceEngine::with_cpu_x86_avx2()) { + } else if (ov::with_cpu_x86_avx2()) { std::tie(inFmts, outFmts, priority, selectedType) = conv_avx2_2D; - } else if (InferenceEngine::with_cpu_x86_sse42()) { + } else if (ov::with_cpu_x86_sse42()) { std::tie(inFmts, outFmts, priority, selectedType) = conv_sse42_2D; } // first model - const std::vector> shapes1{{1, 16, 720, 1280}}; + const std::vector shapes1{{1, 16, 720, 1280}}; ov::ParameterVector params1; for (auto&& shape : shapes1) { - params1.push_back(std::make_shared(type, ov::Shape(shape))); + params1.push_back(std::make_shared(type, shape)); } const size_t convOutCh1 = 32; - auto conv1 = ngraph::builder::makeConvolution(params1.front(), type, kernel, strides, padsBegin, padsEnd, dilations, autoPad, convOutCh1); + auto conv1 = ov::test::utils::make_convolution(params1.front(), + type, + kernel, + strides, + padsBegin, + padsEnd, + dilations, + autoPad, + convOutCh1); conv1->set_friendly_name(convName); conv1->get_input_node_shared_ptr(1)->set_friendly_name(weightName); auto model1 = makeNgraphFunction(type, params1, conv1, "Model1"); // second model - const std::vector> shapes2{{1, 32, 24, 24}}; + const std::vector shapes2{{1, 32, 24, 24}}; ov::ParameterVector params2; for (auto&& shape : shapes2) { - params2.push_back(std::make_shared(type, ov::Shape(shape))); + params2.push_back(std::make_shared(type, shape)); } const size_t convOutCh2 = 16; - auto conv2 = ngraph::builder::makeConvolution(params2.front(), type, kernel, strides, padsBegin, padsEnd, dilations, autoPad, convOutCh2); + auto conv2 = ov::test::utils::make_convolution(params2.front(), + type, + kernel, + strides, + padsBegin, + padsEnd, + dilations, + autoPad, + convOutCh2); conv2->set_friendly_name(convName); conv2->get_input_node_shared_ptr(1)->set_friendly_name(weightName); auto model2 = makeNgraphFunction(type, params2, conv2, "Model2"); @@ -78,4 +95,5 @@ TEST_F(EdgeWithSameNameInTwoModels, smoke_CompareWithRef) { inferReq2.infer(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/mha.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/mha.cpp index 068585b2ca9029..66bcb7baf5b744 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/mha.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/mha.cpp @@ -2,49 +2,41 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include +#include "common_test_utils/ov_tensor_utils.hpp" #include "functional_test_utils/skip_tests_config.hpp" +#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" using namespace CPUTestUtils; using namespace ov::test; -using namespace ngraph::helpers; - -namespace CPUSubgraphTestsDefinitions { using ExpectedNodes = std::vector>; -typedef std::tuple< - std::vector, // Input shapes - std::vector, // Input precisions - std::vector, // MatMul input #0 precisions - size_t, // pattern type # - ExpectedNodes, // Expected node -> count - std::string // Device name -> MHATuple; +typedef std::tuple, // Input shapes + std::vector, // Input precisions + std::vector, // MatMul input #0 precisions + size_t, // pattern type # + ExpectedNodes, // Expected node -> count + std::string // Device name + > + MHATuple; -static std::shared_ptr initMHASubgraph0(std::vector& inputDynamicShapes, std::vector& inputPrecisions) { - ngraph::ParameterVector ngraphParam; +static std::shared_ptr initMHASubgraph0(std::vector& inputDynamicShapes, + std::vector& inputPrecisions) { + ov::ParameterVector ngraphParam; - auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); + auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); ngraphParam.push_back(transpose0Param); - auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); + auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); ngraphParam.push_back(transpose1Param); - auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); + auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); ngraphParam.push_back(addParam); - auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); + auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); ngraphParam.push_back(transpose2Param); std::vector constantShapes; @@ -62,12 +54,13 @@ static std::shared_ptr initMHASubgraph0(std::vector std::vector transpose1ConstData = {0, 2, 3, 1}; auto transpose1Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[1], transpose1ConstData); - std::vector mulConstData(ngraph::shape_size(constantShapes[2])); + std::vector mulConstData(ov::shape_size(constantShapes[2])); auto mulConst = ngraph::builder::makeConstant(inputPrecisions[0], constantShapes[2], mulConstData, true); - std::vector reshape0ConstData = {static_cast(inputDynamicShapes[0].get_shape()[0] * - inputDynamicShapes[0].get_shape()[1] * inputDynamicShapes[0].get_shape()[2]), - -1}; + std::vector reshape0ConstData = { + static_cast(inputDynamicShapes[0].get_shape()[0] * inputDynamicShapes[0].get_shape()[1] * + inputDynamicShapes[0].get_shape()[2]), + -1}; auto reshape0Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[3], reshape0ConstData); std::vector reshape1ConstData = {static_cast(inputDynamicShapes[0].get_shape()[0]), @@ -86,33 +79,34 @@ static std::shared_ptr initMHASubgraph0(std::vector float transB = false; const auto transpose0 = std::make_shared(transpose0Param, transpose0Const); const auto transpose1 = std::make_shared(transpose1Param, transpose1Const); - const auto mul = std::make_shared(transpose1, mulConst); - const auto matMul0 = std::make_shared(transpose0, mul, transA, transB); - const auto add = std::make_shared(matMul0, addParam); - const auto reshape0 = std::make_shared(add, reshape0Const, true); - const auto softMax = std::make_shared(reshape0, 1); - const auto reshape1 = std::make_shared(softMax, reshape1Const, true); + const auto mul = std::make_shared(transpose1, mulConst); + const auto matMul0 = std::make_shared(transpose0, mul, transA, transB); + const auto add = std::make_shared(matMul0, addParam); + const auto reshape0 = std::make_shared(add, reshape0Const, true); + const auto softMax = std::make_shared(reshape0, 1); + const auto reshape1 = std::make_shared(softMax, reshape1Const, true); const auto transpose2 = std::make_shared(transpose2Param, transpose2Const); - const auto matMul1 = std::make_shared(reshape1, transpose2, transA, transB); + const auto matMul1 = std::make_shared(reshape1, transpose2, transA, transB); const auto transpose3 = std::make_shared(matMul1, transpose3Const); - ngraph::ResultVector results{std::make_shared(transpose3)}; - return std::make_shared(results, ngraphParam, "mha"); + ov::ResultVector results{std::make_shared(transpose3)}; + return std::make_shared(results, ngraphParam, "mha"); } -static std::shared_ptr initMHASubgraph1(std::vector& inputDynamicShapes, std::vector& inputPrecisions) { - ngraph::ParameterVector ngraphParam; +static std::shared_ptr initMHASubgraph1(std::vector& inputDynamicShapes, + std::vector& inputPrecisions) { + ov::ParameterVector ngraphParam; - auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); + auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); ngraphParam.push_back(transpose0Param); - auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); + auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); ngraphParam.push_back(transpose1Param); - auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); + auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); ngraphParam.push_back(addParam); - auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); + auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); ngraphParam.push_back(transpose2Param); std::vector constantShapes; @@ -140,21 +134,20 @@ static std::shared_ptr initMHASubgraph1(std::vector float transB = false; const auto transpose0 = std::make_shared(transpose0Param, transpose0Const); const auto transpose1 = std::make_shared(transpose1Param, transpose1Const); - const auto matMul0 = std::make_shared(transpose0, transpose1, transA, transB); - const auto add = std::make_shared(matMul0, addParam); - const auto softMax = std::make_shared(add, 3); + const auto matMul0 = std::make_shared(transpose0, transpose1, transA, transB); + const auto add = std::make_shared(matMul0, addParam); + const auto softMax = std::make_shared(add, 3); const auto transpose2 = std::make_shared(transpose2Param, transpose2Const); - const auto matMul1 = std::make_shared(softMax, transpose2, transA, transB); + const auto matMul1 = std::make_shared(softMax, transpose2, transA, transB); const auto transpose3 = std::make_shared(matMul1, transpose3Const); - ngraph::ResultVector results{std::make_shared(transpose3)}; - return std::make_shared(results, ngraphParam, "mha"); + ov::ResultVector results{std::make_shared(transpose3)}; + return std::make_shared(results, ngraphParam, "mha"); } -class MHATest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, public CPUTestsBase { +class MHATest : public testing::WithParamInterface, virtual public SubgraphBaseTest, public CPUTestsBase { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj) { + static std::string getTestCaseName(const testing::TestParamInfo& obj) { std::vector inputShapes; std::vector inputPrecisions; std::vector matMulIn0Precisions; @@ -180,23 +173,31 @@ class MHATest : public testing::WithParamInterface, results << "patternType=" << patternType; results << "expect="; for (const auto& node : expectedNodes) { - results << node.first << "[" << node.second << "]" << "_"; + results << node.first << "[" << node.second << "]" + << "_"; } results << "targetDevice=" << targetName; return results.str(); } - void generate_inputs(const std::vector& targetInputStaticShapes) override { + void generate_inputs(const std::vector& targetInputStaticShapes) override { inputs.clear(); const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { const auto& funcInput = funcInputs[i]; ov::Tensor tensor; if (funcInput.get_element_type() == ov::element::bf16) - tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 2, -1, 256); + tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), + targetInputStaticShapes[i], + 2, + -1, + 256); else - tensor = ov::test::utils::create_and_fill_tensor_unique_sequence(funcInput.get_element_type(), targetInputStaticShapes[i], -1, 5); + tensor = ov::test::utils::create_and_fill_tensor_unique_sequence(funcInput.get_element_type(), + targetInputStaticShapes[i], + -1, + 5); inputs.insert({funcInput.get_node_shared_ptr(), tensor}); inputs.insert({funcInput.get_node_shared_ptr(), tensor}); } @@ -209,7 +210,8 @@ class MHATest : public testing::WithParamInterface, std::vector inputShapes; std::vector inputPrecisions; std::vector matMulIn0Precisions; - std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam(); + std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = + this->GetParam(); init_input_shapes(inputShapes); @@ -227,14 +229,14 @@ class MHATest : public testing::WithParamInterface, abs_threshold = 0.1f; rel_threshold = 10.f; - configuration.insert({{ InferenceEngine::PluginConfigParams::KEY_ENFORCE_BF16, InferenceEngine::PluginConfigParams::YES }}); + configuration.insert({ov::hint::inference_precision(ov::element::bf16)}); } - // Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on target machine. - // Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all machines for validation. - if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { - configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, - InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + // Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on + // target machine. Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all + // machines for validation. + if (!configuration.count("SNIPPETS_MODE")) { + configuration.insert({"SNIPPETS_MODE", "IGNORE_CALLBACK"}); } } }; @@ -245,12 +247,13 @@ TEST_P(MHATest, CompareWithRefs) { std::vector matMulIn0Precisions; size_t patternType; ExpectedNodes expectedNodes; - std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam(); + std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = + this->GetParam(); - if (inputPrecisions[0] == ElementType::bf16 && !InferenceEngine::with_cpu_x86_bfloat16()) + if (inputPrecisions[0] == ElementType::bf16 && !ov::with_cpu_x86_bfloat16()) GTEST_SKIP(); - if (!InferenceEngine::with_cpu_x86_avx512_core()) + if (!ov::with_cpu_x86_avx512_core()) GTEST_SKIP(); run(); @@ -262,61 +265,66 @@ TEST_P(MHATest, CompareWithRefs) { namespace { -std::vector> inputShapes = { +std::vector> inputShapes = { {{2, 8, 16, 64}, {2, 8, 16, 64}, {2, 1, 1, 8}, {2, 8, 16, 64}}, {{1, 384, 16, 64}, {1, 384, 16, 64}, {1, 1, 1, 384}, {1, 384, 16, 64}}, {{2, 64, 16, 80}, {2, 64, 16, 80}, {2, 1, 1, 64}, {2, 64, 16, 80}}, {{3, 96, 16, 64}, {3, 96, 16, 64}, {3, 1, 1, 96}, {3, 96, 16, 64}}, {{2, 192, 16, 160}, {2, 192, 16, 160}, {2, 1, 1, 192}, {2, 192, 16, 160}}, {{2, 4, 16, 8}, {2, 4, 16, 8}, {2, 1, 1, 4}, {2, 4, 16, 8}}, - {{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}}, + {{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}}, }; std::vector> matMulIn0Precisions = { {}, }; -std::vector patternTypes = { - 0, 1 -}; - -INSTANTIATE_TEST_SUITE_P(smoke_MHA, MHATest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), - ::testing::Values(std::vector{ ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32 }), - ::testing::ValuesIn(matMulIn0Precisions), - ::testing::ValuesIn(patternTypes), - ::testing::Values(ExpectedNodes{{"Subgraph", 1}}), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MHATest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MHA_BF16, MHATest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), - ::testing::Values(std::vector{ ElementType::bf16, ElementType::bf16, ElementType::bf16, ElementType::bf16 }), - ::testing::ValuesIn(matMulIn0Precisions), - ::testing::ValuesIn(patternTypes), - ::testing::Values(ExpectedNodes{{"Subgraph", 1}, - {"Transpose", 1}}), // Plugin disables tokenization of Transpose on output - ::testing::Values(ov::test::utils::DEVICE_CPU)), +std::vector patternTypes = {0, 1}; + +INSTANTIATE_TEST_SUITE_P(smoke_MHA, + MHATest, + ::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), + ::testing::Values(std::vector{ElementType::f32, + ElementType::f32, + ElementType::f32, + ElementType::f32}), + ::testing::ValuesIn(matMulIn0Precisions), + ::testing::ValuesIn(patternTypes), + ::testing::Values(ExpectedNodes{{"Subgraph", 1}}), + ::testing::Values(ov::test::utils::DEVICE_CPU)), MHATest::getTestCaseName); -} // namespace - -static std::shared_ptr initMHAQuantSubgraph0(std::vector& inputDynamicShapes, std::vector& inputPrecisions, +INSTANTIATE_TEST_SUITE_P( + smoke_MHA_BF16, + MHATest, + ::testing::Combine( + ::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), + ::testing::Values( + std::vector{ElementType::bf16, ElementType::bf16, ElementType::bf16, ElementType::bf16}), + ::testing::ValuesIn(matMulIn0Precisions), + ::testing::ValuesIn(patternTypes), + ::testing::Values(ExpectedNodes{{"Subgraph", 1}, + {"Transpose", 1}}), // Plugin disables tokenization of Transpose on output + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MHATest::getTestCaseName); + +} // namespace + +static std::shared_ptr initMHAQuantSubgraph0(std::vector& inputDynamicShapes, + std::vector& inputPrecisions, std::vector& matMulIn0Precisions) { - ngraph::ParameterVector ngraphParam; + ov::ParameterVector ngraphParam; - auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); + auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); ngraphParam.push_back(transpose0Param); - auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); + auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); ngraphParam.push_back(transpose1Param); - auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); + auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); ngraphParam.push_back(addParam); - auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); + auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); ngraphParam.push_back(transpose2Param); std::vector constantShapes; @@ -333,9 +341,10 @@ static std::shared_ptr initMHAQuantSubgraph0(std::vector transpose1ConstData = {0, 2, 3, 1}; auto transpose1Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[1], transpose1ConstData); - std::vector reshape0ConstData = {static_cast(inputDynamicShapes[0].get_shape()[0] * - inputDynamicShapes[0].get_shape()[1] * inputDynamicShapes[0].get_shape()[2]), - -1}; + std::vector reshape0ConstData = { + static_cast(inputDynamicShapes[0].get_shape()[0] * inputDynamicShapes[0].get_shape()[1] * + inputDynamicShapes[0].get_shape()[2]), + -1}; auto reshape0Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[2], reshape0ConstData); std::vector reshape1ConstData = {static_cast(inputDynamicShapes[0].get_shape()[0]), @@ -355,52 +364,96 @@ static std::shared_ptr initMHAQuantSubgraph0(std::vector fakeQuantize0; if (matMulIn0Precisions[0] == ElementType::u8) - fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f}); + fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, + inputPrecisions[0], + 256, + {}, + {0.0f}, + {2.55f}, + {0.0f}, + {2.55f}); else - fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); - - const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1Param, inputPrecisions[1], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); - const auto fakeQuantize2 = ngraph::builder::makeFakeQuantize(transpose2Param, inputPrecisions[3], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, + inputPrecisions[0], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); + + const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1Param, + inputPrecisions[1], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); + const auto fakeQuantize2 = ngraph::builder::makeFakeQuantize(transpose2Param, + inputPrecisions[3], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); std::shared_ptr fakeQuantize4; const auto transpose0 = std::make_shared(fakeQuantize0, transpose0Const); const auto transpose1 = std::make_shared(fakeQuantize1, transpose1Const); - const auto matMul0 = std::make_shared(transpose0, transpose1, transA, transB); - const auto fakeQuantize3 = ngraph::builder::makeFakeQuantize(matMul0, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); - const auto add = std::make_shared(fakeQuantize3, addParam); - const auto reshape0 = std::make_shared(add, reshape0Const, true); - const auto softMax = std::make_shared(reshape0, 1); - const auto reshape1 = std::make_shared(softMax, reshape1Const, true); + const auto matMul0 = std::make_shared(transpose0, transpose1, transA, transB); + const auto fakeQuantize3 = + ngraph::builder::makeFakeQuantize(matMul0, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + const auto add = std::make_shared(fakeQuantize3, addParam); + const auto reshape0 = std::make_shared(add, reshape0Const, true); + const auto softMax = std::make_shared(reshape0, 1); + const auto reshape1 = std::make_shared(softMax, reshape1Const, true); if (matMulIn0Precisions[1] == ElementType::u8) - fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, inputPrecisions[0], 256, {}, {0.0f}, {0.255f}, {0.0f}, {0.255f}); + fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, + inputPrecisions[0], + 256, + {}, + {0.0f}, + {0.255f}, + {0.0f}, + {0.255f}); else - fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, inputPrecisions[0], 256, {}, {-0.128f}, {0.127f}, {-0.128f}, {0.127f}); + fakeQuantize4 = ngraph::builder::makeFakeQuantize(reshape1, + inputPrecisions[0], + 256, + {}, + {-0.128f}, + {0.127f}, + {-0.128f}, + {0.127f}); const auto transpose2 = std::make_shared(fakeQuantize2, transpose2Const); - const auto matMul1 = std::make_shared(fakeQuantize4, transpose2, transA, transB); - const auto fakeQuantize5 = ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + const auto matMul1 = std::make_shared(fakeQuantize4, transpose2, transA, transB); + const auto fakeQuantize5 = + ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); const auto transpose3 = std::make_shared(fakeQuantize5, transpose3Const); - ngraph::ResultVector results{std::make_shared(transpose3)}; - return std::make_shared(results, ngraphParam, "mha"); + ov::ResultVector results{std::make_shared(transpose3)}; + return std::make_shared(results, ngraphParam, "mha"); } static std::shared_ptr initMHAQuantSubgraph1(const std::vector& inputDynamicShapes, const std::vector& inputPrecisions, const std::vector& matMulIn0Precisions, const bool fakeQuantize3Exists) { - ngraph::ParameterVector ngraphParam; + ov::ParameterVector ngraphParam; - auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); + auto transpose0Param = std::make_shared(inputPrecisions[0], inputDynamicShapes[0]); ngraphParam.push_back(transpose0Param); - auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); + auto transpose1Param = std::make_shared(inputPrecisions[1], inputDynamicShapes[1]); ngraphParam.push_back(transpose1Param); - auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); + auto addParam = std::make_shared(inputPrecisions[2], inputDynamicShapes[2]); ngraphParam.push_back(addParam); - auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); + auto transpose2Param = std::make_shared(inputPrecisions[3], inputDynamicShapes[3]); ngraphParam.push_back(transpose2Param); std::vector constantShapes; @@ -422,7 +475,7 @@ static std::shared_ptr initMHAQuantSubgraph1(const std::vector transpose3ConstData = {0, 2, 1, 3}; auto transpose3Const = ngraph::builder::makeConstant(ElementType::i64, constantShapes[3], transpose3ConstData); - std::vector mulConstData(ngraph::shape_size(constantShapes[4])); + std::vector mulConstData(ov::shape_size(constantShapes[4])); auto mulConst = ngraph::builder::makeConstant(inputPrecisions[0], constantShapes[4], mulConstData, true); float transA = false; @@ -430,33 +483,55 @@ static std::shared_ptr initMHAQuantSubgraph1(const std::vector fakeQuantize0; if (matMulIn0Precisions[0] == ElementType::u8) - fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f}); + fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, + inputPrecisions[0], + 256, + {}, + {0.0f}, + {2.55f}, + {0.0f}, + {2.55f}); else - fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, inputPrecisions[0], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); + fakeQuantize0 = ngraph::builder::makeFakeQuantize(transpose0Param, + inputPrecisions[0], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); const auto transpose0 = std::make_shared(fakeQuantize0, transpose0Const); const auto transpose1 = std::make_shared(transpose1Param, transpose1Const); - const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1, inputPrecisions[1], 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); - const auto matMul0 = std::make_shared(transpose0, fakeQuantize1, transA, transB); - const auto mul = std::make_shared(addParam, mulConst); - const auto add = std::make_shared(matMul0, mul); - const auto softMax = std::make_shared(add, 3); + const auto fakeQuantize1 = ngraph::builder::makeFakeQuantize(transpose1, + inputPrecisions[1], + 256, + {}, + {-1.28f}, + {1.27f}, + {-1.28f}, + {1.27f}); + const auto matMul0 = std::make_shared(transpose0, fakeQuantize1, transA, transB); + const auto mul = std::make_shared(addParam, mulConst); + const auto add = std::make_shared(matMul0, mul); + const auto softMax = std::make_shared(add, 3); const auto transpose2 = std::make_shared(transpose2Param, transpose2Const); - const auto matMul1 = std::make_shared(softMax, transpose2, transA, transB); + const auto matMul1 = std::make_shared(softMax, transpose2, transA, transB); const auto transpose3 = std::make_shared( - fakeQuantize3Exists ? - ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, { 0.0f }, { 2.55f }, { 0.0f }, { 2.55f }) : - matMul1, + fakeQuantize3Exists + ? ngraph::builder::makeFakeQuantize(matMul1, inputPrecisions[0], 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f}) + : matMul1, transpose3Const); - ngraph::ResultVector results{std::make_shared(transpose3)}; - return std::make_shared(results, ngraphParam, "mha"); + ov::ResultVector results{std::make_shared(transpose3)}; + return std::make_shared(results, ngraphParam, "mha"); } class MHAQuantTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, public CPUTestsBase { + virtual public SubgraphBaseTest, + public CPUTestsBase { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj) { + static std::string getTestCaseName(const testing::TestParamInfo& obj) { std::vector inputShapes; std::vector inputPrecisions; std::vector matMulIn0Precisions; @@ -485,24 +560,31 @@ class MHAQuantTest : public testing::WithParamInterface, results << "patternType=" << patternType; results << "expect="; for (const auto& node : expectedNodes) { - results << node.first << "[" << node.second << "]" << "_"; + results << node.first << "[" << node.second << "]" + << "_"; } results << "targetDevice=" << targetName; return results.str(); } - void generate_inputs(const std::vector& targetInputStaticShapes) override { + void generate_inputs(const std::vector& targetInputStaticShapes) override { inputs.clear(); const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { const auto& funcInput = funcInputs[i]; ov::Tensor tensor; if (funcInput.get_element_type().is_real()) - tensor = ov::test::utils::create_and_fill_tensor_normal_distribution(funcInput.get_element_type(), targetInputStaticShapes[i], 0.0f, 1.5f); + tensor = ov::test::utils::create_and_fill_tensor_normal_distribution(funcInput.get_element_type(), + targetInputStaticShapes[i], + 0.0f, + 1.5f); else - tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 255, 0, 1); - + tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), + targetInputStaticShapes[i], + 255, + 0, + 1); inputs.insert({funcInput.get_node_shared_ptr(), tensor}); } @@ -517,7 +599,8 @@ class MHAQuantTest : public testing::WithParamInterface, std::vector matMulIn0Precisions; size_t patternType; ExpectedNodes expectedNodes; - std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam(); + std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = + this->GetParam(); init_input_shapes(inputShapes); @@ -531,11 +614,11 @@ class MHAQuantTest : public testing::WithParamInterface, FAIL() << "Unsupported MHA pattern type"; } - // Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on target machine. - // Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all machines for validation. - if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { - configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, - InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + // Snippets MHA tokenization has limitations to avoid performance degradations. These limitations depend on + // target machine. Just for testing, we disable these limitations to allow Snippets to tokenize pattern on all + // machines for validation. + if (!configuration.count("SNIPPETS_MODE")) { + configuration.insert({"SNIPPETS_MODE", "IGNORE_CALLBACK"}); } } }; @@ -546,12 +629,13 @@ TEST_P(MHAQuantTest, CompareWithRefs) { std::vector matMulIn0Precisions; size_t patternType; ExpectedNodes expectedNodes; - std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = this->GetParam(); + std::tie(inputShapes, inputPrecisions, matMulIn0Precisions, patternType, expectedNodes, targetDevice) = + this->GetParam(); - if (inputPrecisions[0] == ElementType::bf16 && !InferenceEngine::with_cpu_x86_bfloat16()) + if (inputPrecisions[0] == ElementType::bf16 && !ov::with_cpu_x86_bfloat16()) GTEST_SKIP(); - if (!InferenceEngine::with_cpu_x86_avx512_core_vnni()) + if (!ov::with_cpu_x86_avx512_core_vnni()) GTEST_SKIP(); run(); @@ -563,7 +647,7 @@ TEST_P(MHAQuantTest, CompareWithRefs) { namespace { -std::vector> inputShapesQuant = { +std::vector> inputShapesQuant = { {{2, 7, 16, 9}, {2, 7, 16, 9}, {2, 1, 1, 7}, {2, 7, 16, 9}}, {{2, 8, 16, 64}, {2, 8, 16, 64}, {2, 1, 1, 8}, {2, 8, 16, 64}}, {{1, 384, 16, 64}, {1, 384, 16, 64}, {1, 1, 1, 384}, {1, 384, 16, 64}}, @@ -571,52 +655,52 @@ std::vector> inputShapesQuant = { {{3, 96, 16, 64}, {3, 96, 16, 64}, {3, 1, 1, 96}, {3, 96, 16, 64}}, {{2, 192, 16, 160}, {2, 192, 16, 160}, {2, 1, 1, 192}, {2, 192, 16, 160}}, {{2, 4, 16, 8}, {2, 4, 16, 8}, {2, 1, 1, 4}, {2, 4, 16, 8}}, - {{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}}, - {{1, 207, 13, 211}, {1, 207, 13, 211}, {1, 1, 1, 207}, {1, 207, 13, 211}}, + {{1, 204, 13, 212}, {1, 204, 13, 212}, {1, 1, 1, 204}, {1, 204, 13, 212}}, + {{1, 207, 13, 211}, {1, 207, 13, 211}, {1, 1, 1, 207}, {1, 207, 13, 211}}, }; std::vector> inputPrecisionsQuant = { - { ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32 }, + {ElementType::f32, ElementType::f32, ElementType::f32, ElementType::f32}, }; std::vector> matMulIn0PrecisionsQuant = { - { ElementType::i8, ElementType::i8 }, - { ElementType::i8, ElementType::u8 }, + {ElementType::i8, ElementType::i8}, + {ElementType::i8, ElementType::u8}, }; -INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern0, MHAQuantTest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), - ::testing::ValuesIn(inputPrecisionsQuant), - ::testing::ValuesIn(matMulIn0PrecisionsQuant), - ::testing::Values(0), - ::testing::Values(ExpectedNodes{{"Subgraph", 5}, // FQs on inputs x 3 + MHA + Deq Mul - {"Transpose", 1}}), // Transpose between MHA and Deq Mul - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MHAQuantTest::getTestCaseName); - - -INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern1, MHAQuantTest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), - ::testing::ValuesIn(inputPrecisionsQuant), - ::testing::ValuesIn(matMulIn0PrecisionsQuant), - ::testing::Values(1), - ::testing::Values(ExpectedNodes{{"Subgraph", 3}, // FQ on input + MHA + Deq Mul - {"Transpose", 1}}), // Transpose between MHA and Deq Mul - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MHAQuantTest::getTestCaseName); - -INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern2, MHAQuantTest, - ::testing::Combine( - ::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), - ::testing::ValuesIn(inputPrecisionsQuant), - ::testing::ValuesIn(matMulIn0PrecisionsQuant), - ::testing::Values(2), - ::testing::Values(ExpectedNodes{{"Subgraph", 2}, // MHA + Deq Mul - {"Transpose", 0}}), // Transpose is fused - ::testing::Values(ov::test::utils::DEVICE_CPU)), - MHAQuantTest::getTestCaseName); - -} // namespace -} // namespace CPUSubgraphTestsDefinitions +INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern0, + MHAQuantTest, + ::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), + ::testing::ValuesIn(inputPrecisionsQuant), + ::testing::ValuesIn(matMulIn0PrecisionsQuant), + ::testing::Values(0), + ::testing::Values(ExpectedNodes{ + {"Subgraph", 5}, // FQs on inputs x 3 + MHA + Deq Mul + {"Transpose", 1}}), // Transpose between MHA and Deq Mul + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MHAQuantTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern1, + MHAQuantTest, + ::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), + ::testing::ValuesIn(inputPrecisionsQuant), + ::testing::ValuesIn(matMulIn0PrecisionsQuant), + ::testing::Values(1), + ::testing::Values(ExpectedNodes{ + {"Subgraph", 3}, // FQ on input + MHA + Deq Mul + {"Transpose", 1}}), // Transpose between MHA and Deq Mul + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MHAQuantTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_MHAQuant_Pattern2, + MHAQuantTest, + ::testing::Combine(::testing::ValuesIn(static_shapes_to_test_representation(inputShapesQuant)), + ::testing::ValuesIn(inputPrecisionsQuant), + ::testing::ValuesIn(matMulIn0PrecisionsQuant), + ::testing::Values(2), + ::testing::Values(ExpectedNodes{{"Subgraph", 2}, // MHA + Deq Mul + {"Transpose", 0}}), // Transpose is fused + ::testing::Values(ov::test::utils::DEVICE_CPU)), + MHAQuantTest::getTestCaseName); + +} // namespace diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/ngram.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/ngram.cpp index 58edce33fcda60..865268c500a31b 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/ngram.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/ngram.cpp @@ -2,46 +2,37 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include +#include "common_test_utils/ov_tensor_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" using namespace CPUTestUtils; -using namespace ov::test; -using namespace ngraph::helpers; -namespace CPUSubgraphTestsDefinitions { +namespace ov { +namespace test { -typedef std::tuple< - std::vector, - ElementType, - ElementType, - size_t -> NgramTestParams; +typedef std::tuple, ElementType, ElementType, size_t> NgramTestParams; static std::shared_ptr getStridedSlice(const std::shared_ptr& data, const std::shared_ptr& begin, const std::shared_ptr& end, const std::vector& shrink_axis_mask = {}) { std::vector default_mask(begin->get_shape()[0], 0); - return std::make_shared(data, begin, end, default_mask, default_mask, - std::vector{}, shrink_axis_mask); + return std::make_shared(data, + begin, + end, + default_mask, + default_mask, + std::vector{}, + shrink_axis_mask); } static std::shared_ptr getReshape(const std::shared_ptr& data, const std::vector& requested_shape, const ov::element::Type& prc) { - auto requested_shape_node = ov::opset1::Constant::create(prc, {requested_shape.size()}, requested_shape); - return std::make_shared(data, requested_shape_node, true); + auto requested_shape_node = ov::op::v0::Constant::create(prc, {requested_shape.size()}, requested_shape); + return std::make_shared(data, requested_shape_node, true); } static std::shared_ptr initNgram(std::vector& input_shapes, @@ -58,78 +49,80 @@ static std::shared_ptr initNgram(std::vector& input auto param_node = std::make_shared(input_precisions[i], input_shapes[i]); params.push_back(param_node); } - auto shape_of = std::make_shared(params[0], idces_et); - auto shape_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {0}); - auto shape_ss_end = ov::opset1::Constant::create(idces_et, {1}, {1}); + auto shape_of = std::make_shared(params[0], idces_et); + auto shape_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {0}); + auto shape_ss_end = ov::op::v0::Constant::create(idces_et, {1}, {1}); auto shape_ss = getStridedSlice(shape_of, shape_ss_begin, shape_ss_end, {1}); auto getInputsToPad = [&](const ov::Output data, const int pad_value) { const size_t length = data.get_partial_shape()[1].get_length(); ov::OutputVector inputs; if (left_pad > 0) { - inputs.push_back(ov::opset1::Constant::create(data.get_element_type(), {left_pad, length}, {pad_value})); + inputs.push_back(ov::op::v0::Constant::create(data.get_element_type(), {left_pad, length}, {pad_value})); } inputs.push_back(data); if (right_pad > 0) { - inputs.push_back(ov::opset1::Constant::create(data.get_element_type(), {right_pad, length}, {pad_value})); + inputs.push_back(ov::op::v0::Constant::create(data.get_element_type(), {right_pad, length}, {pad_value})); } return inputs; }; - auto data_padded = std::make_shared(getInputsToPad(params[0], 0), 0); - auto idces_padded = std::make_shared(getInputsToPad(params[1], -1), 0); + auto data_padded = std::make_shared(getInputsToPad(params[0], 0), 0); + auto idces_padded = std::make_shared(getInputsToPad(params[1], -1), 0); std::shared_ptr as_is_bias = shape_ss; if (mid_idx != 0) { - auto bias_const = ov::opset1::Constant::create(idces_et, {}, {mid_idx}); - as_is_bias = std::make_shared(shape_ss, bias_const); + auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {mid_idx}); + as_is_bias = std::make_shared(shape_ss, bias_const); } - auto as_is_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {mid_idx}); + auto as_is_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {mid_idx}); auto as_is_ss_end = getReshape(as_is_bias, {1}, idces_et); auto as_is_ss = getStridedSlice(data_padded, as_is_ss_begin, as_is_ss_end); auto getSelectBranch = [&](const size_t cur_idx, const size_t mid_idx) { std::shared_ptr eq_left_bias = shape_ss; if (cur_idx != 0) { - auto bias_const = ov::opset1::Constant::create(idces_et, {}, {cur_idx}); - eq_left_bias = std::make_shared(shape_ss, bias_const); + auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {cur_idx}); + eq_left_bias = std::make_shared(shape_ss, bias_const); } auto eq_left_reshape = getReshape(eq_left_bias, {1}, idces_et); - auto eq_left_concat_const = ov::opset1::Constant::create(idces_et, {1}, {1}); - auto eq_left_concat = std::make_shared(ov::OutputVector{eq_left_reshape, eq_left_concat_const}, 0); - auto eq_left_ss_begin = ov::opset1::Constant::create(idces_et, {2}, std::vector{cur_idx, 0ul}); + auto eq_left_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {1}); + auto eq_left_concat = + std::make_shared(ov::OutputVector{eq_left_reshape, eq_left_concat_const}, 0); + auto eq_left_ss_begin = ov::op::v0::Constant::create(idces_et, {2}, std::vector{cur_idx, 0ul}); auto eq_left_ss = getStridedSlice(idces_padded, eq_left_ss_begin, eq_left_concat, {0, 1}); std::shared_ptr eq_right_bias = shape_ss; if (mid_idx != 0) { - auto bias_const = ov::opset1::Constant::create(idces_et, {}, {mid_idx}); - eq_right_bias = std::make_shared(shape_ss, bias_const); + auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {mid_idx}); + eq_right_bias = std::make_shared(shape_ss, bias_const); } auto eq_right_reshape = getReshape(eq_right_bias, {1}, idces_et); - auto eq_right_concat_const = ov::opset1::Constant::create(idces_et, {1}, {1}); - auto eq_right_concat = std::make_shared(ov::OutputVector{eq_right_reshape, eq_right_concat_const}, 0); - auto eq_right_ss_begin = ov::opset1::Constant::create(idces_et, {2}, std::vector{mid_idx, 0ul}); + auto eq_right_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {1}); + auto eq_right_concat = + std::make_shared(ov::OutputVector{eq_right_reshape, eq_right_concat_const}, 0); + auto eq_right_ss_begin = ov::op::v0::Constant::create(idces_et, {2}, std::vector{mid_idx, 0ul}); auto eq_right_ss = getStridedSlice(idces_padded, eq_right_ss_begin, eq_right_concat, {0, 1}); - auto equal = std::make_shared(eq_left_ss, eq_right_ss); + auto equal = std::make_shared(eq_left_ss, eq_right_ss); auto cond = getReshape(equal, {-1, 1}, idces_et); std::shared_ptr then_bias = shape_ss; if (cur_idx != 0) { - auto bias_const = ov::opset1::Constant::create(idces_et, {}, {cur_idx}); - then_bias = std::make_shared(shape_ss, bias_const); + auto bias_const = ov::op::v0::Constant::create(idces_et, {}, {cur_idx}); + then_bias = std::make_shared(shape_ss, bias_const); } auto then_reshape = getReshape(then_bias, {1}, idces_et); - auto then_ss_begin = ov::opset1::Constant::create(idces_et, {1}, {cur_idx}); + auto then_ss_begin = ov::op::v0::Constant::create(idces_et, {1}, {cur_idx}); auto then = getStridedSlice(data_padded, then_ss_begin, then_reshape); auto else_reshape = getReshape(shape_ss, {1}, idces_et); - auto else_concat_const = ov::opset1::Constant::create(idces_et, {1}, {input_shapes[0][1].get_length()}); - auto else_concat = std::make_shared(ov::OutputVector{else_reshape, else_concat_const}, 0); - auto else_bcast_const = ov::opset1::Constant::create(data_et, {}, {0}); - auto else_bcast = std::make_shared(else_bcast_const, else_concat); + auto else_concat_const = ov::op::v0::Constant::create(idces_et, {1}, {input_shapes[0][1].get_length()}); + auto else_concat = std::make_shared(ov::OutputVector{else_reshape, else_concat_const}, 0); + auto else_bcast_const = ov::op::v0::Constant::create(data_et, {}, {0}); + auto else_bcast = std::make_shared(else_bcast_const, else_concat); - auto select = std::make_shared(cond, then, else_bcast); + auto select = std::make_shared(cond, then, else_bcast); return select; }; @@ -141,13 +134,15 @@ static std::shared_ptr initNgram(std::vector& input concat_inputs[i] = getSelectBranch(i, mid_idx); } - auto final_concat = std::make_shared(concat_inputs, 1); + auto final_concat = std::make_shared(concat_inputs, 1); return std::make_shared(final_concat, params, "ngram"); } -class NgramCPUTest : public testing::WithParamInterface, virtual public SubgraphBaseTest, public CPUTestsBase { +class NgramCPUTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest, + public CPUTestsBase { public: - static std::string getTestCaseName(const testing::TestParamInfo &obj) { + static std::string getTestCaseName(const testing::TestParamInfo& obj) { std::vector input_shapes; size_t k; ElementType data_et; @@ -178,7 +173,6 @@ class NgramCPUTest : public testing::WithParamInterface, virtua auto embeddings_tensor = ov::test::utils::create_and_fill_tensor_consistently(data_et, data_shape, 100, 1, 1); inputs.insert({model_inputs[0].get_node_shared_ptr(), embeddings_tensor}); - const auto& indices_et = model_inputs[1].get_element_type(); const auto& indices_shape = targetInputStaticShapes[1]; const size_t batch_size = data_shape[0]; @@ -207,9 +201,8 @@ class NgramCPUTest : public testing::WithParamInterface, virtua init_input_shapes(inputShapes); function = initNgram(inputDynamicShapes, data_et, idces_et, k); - if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { - configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, - InferenceEngine::PluginConfigInternalParams::DISABLE}); + if (!configuration.count("SNIPPETS_MODE")) { + configuration.insert({"SNIPPETS_MODE", "DISABLE"}); } } }; @@ -222,28 +215,21 @@ TEST_P(NgramCPUTest, CompareWithRefs) { namespace { std::vector> inputShapes = { - { - InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}, - InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}} - }, - { - InputShape{{-1, 256}, {{12, 256}, {25, 256}}}, - InputShape{{-1, 2}, {{12, 2}, {25, 2}}} - }, - { - InputShape{{-1, 1}, {{12, 1}}}, - InputShape{{-1, 2}, {{12, 2}}} - }, + {InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}, InputShape{{-1, 2}, {{3, 2}, {5, 2}, {7, 2}}}}, + {InputShape{{-1, 256}, {{12, 256}, {25, 256}}}, InputShape{{-1, 2}, {{12, 2}, {25, 2}}}}, + {InputShape{{-1, 1}, {{12, 1}}}, InputShape{{-1, 2}, {{12, 2}}}}, }; std::vector k_values = {2, 3, 5, 7}; std::vector idces_precisions = {ElementType::i32, ElementType::i64}; -INSTANTIATE_TEST_SUITE_P(smoke_Ngram, NgramCPUTest, - ::testing::Combine(::testing::ValuesIn(inputShapes), - ::testing::Values(ElementType::f32), - ::testing::ValuesIn(idces_precisions), - ::testing::ValuesIn(k_values)), - NgramCPUTest::getTestCaseName); -} // namespace -} // namespace CPUSubgraphTestsDefinitions +INSTANTIATE_TEST_SUITE_P(smoke_Ngram, + NgramCPUTest, + ::testing::Combine(::testing::ValuesIn(inputShapes), + ::testing::Values(ElementType::f32), + ::testing::ValuesIn(idces_precisions), + ::testing::ValuesIn(k_values)), + NgramCPUTest::getTestCaseName); +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/param_result_custom_blob.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/param_result_custom_blob.cpp index b762671a66d610..8b086d0833ecf5 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/param_result_custom_blob.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/param_result_custom_blob.cpp @@ -6,10 +6,9 @@ #include "shared_test_classes/subgraph/parameter_result.hpp" using namespace SubgraphTestsDefinitions; -using namespace ov::test; -using namespace InferenceEngine; -namespace CPULayerTestsDefinitions { +namespace ov { +namespace test { class ParameterResultCustomBlobTest : public ParameterResultSubgraphTestLegacyApi { protected: @@ -21,7 +20,7 @@ class ParameterResultCustomBlobTest : public ParameterResultSubgraphTestLegacyAp auto inputBlob = inputs.front(); const size_t elementsCount = inputBlob->size(); for (size_t i = 0; i < inferIterations; ++i) { - ov::test::utils::fill_data_random(inputBlob, 10, 0, 1, i); + ov::test::utils::fill_data_random(inputBlob, 10, 0, 1, i); auto inputsInfo = cnnNetwork.getInputsInfo().begin()->second; std::string inputName = cnnNetwork.getInputsInfo().begin()->first; @@ -30,7 +29,7 @@ class ParameterResultCustomBlobTest : public ParameterResultSubgraphTestLegacyAp std::copy(inpBlobData, inpBlobData + elementsCount, customInpData.begin()); auto& tensorDesc = inputsInfo->getTensorDesc(); - auto customBlob = make_shared_blob(tensorDesc, customInpData.data(), elementsCount); + auto customBlob = InferenceEngine::make_shared_blob(tensorDesc, customInpData.data(), elementsCount); inferRequest.SetBlob(inputName, customBlob); inferRequest.Infer(); @@ -46,8 +45,8 @@ class ParameterResultCustomBlobTest : public ParameterResultSubgraphTestLegacyAp TEST_P(ParameterResultCustomBlobTest, CompareWithRefs) { // Just to show that it is not possible to set different precisions for inputs and outputs with the same name. // If it was possible, the input would have I8 precision and couldn't store data from the custom blob. - inPrc = Precision::I8; - outPrc = Precision::FP32; + inPrc = InferenceEngine::Precision::I8; + outPrc = InferenceEngine::Precision::FP32; Run(); } @@ -84,4 +83,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_Check_Same_Blob, ::testing::Values(ov::test::utils::DEVICE_CPU)), ParameterResultSubgraphTestBase::getTestCaseName); } // namespace -} // namespace CPULayerTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/remove_convert.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/remove_convert.cpp index 5a214177867311..8ba11aedcb6544 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/remove_convert.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/remove_convert.cpp @@ -2,24 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ov_models/builders.hpp" -#include "ov_models/utils/ov_helpers.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" +#include "common_test_utils/node_builders/activation.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" #include "test_utils/fusing_test_utils.hpp" -using namespace ov::test; -using namespace ngraph; using namespace CPUTestUtils; -using namespace InferenceEngine; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { using RemoveConvertCPUTestParams = std::tuple; class RemoveUselessBF16ConvertCPUTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, - public CPUTestsBase { + virtual public SubgraphBaseTest, + public CPUTestsBase { public: static std::string getTestCaseName(const testing::TestParamInfo& obj) { ElementType inType; @@ -44,9 +40,9 @@ class RemoveUselessBF16ConvertCPUTest : public testing::WithParamInterface(inType, inputShape.first); auto convert = std::make_shared(input_params, element::f32); - auto begin = builder::makeConstant(element::i64, ov::Shape{4}, std::vector{0, 0, 0, 0}); - auto end = builder::makeConstant(element::i64, ov::Shape{4}, std::vector{0, 0, 16, 0}); - auto stride = builder::makeConstant(element::i64, ov::Shape{4}, std::vector{1, 1, 1, 1}); + auto begin = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector{0, 0, 0, 0}); + auto end = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector{0, 0, 16, 0}); + auto stride = ngraph::builder::makeConstant(element::i64, ov::Shape{4}, std::vector{1, 1, 1, 1}); auto slice = std::make_shared(convert, begin, end, @@ -84,17 +80,19 @@ class RemoveUselessConvertCPUTest : public testing::WithParamInterface(inType, inputShape.first); - // Such complicated graph is necessary to cover the case when Convert has several children and connected to non zero output - const auto split_axis = builder::makeConstant(element::i64, ov::Shape{}, std::vector{1}); - const auto split_lengths = builder::makeConstant(element::i64, ov::Shape{2}, std::vector{-1, 1}); - const auto split = std::make_shared(input_params, split_axis, split_lengths); + // Such complicated graph is necessary to cover the case when Convert has several children and connected to non + // zero output + const auto split_axis = ngraph::builder::makeConstant(element::i64, ov::Shape{}, std::vector{1}); + const auto split_lengths = + ngraph::builder::makeConstant(element::i64, ov::Shape{2}, std::vector{-1, 1}); + const auto split = std::make_shared(input_params, split_axis, split_lengths); auto convert = std::make_shared(split->output(1), inType); - auto relu = builder::makeActivation(convert, inType, ::helpers::ActivationTypes::Relu); + auto relu = ov::test::utils::make_activation(convert, inType, ov::test::utils::ActivationTypes::Relu); ov::ResultVector results{ - std::make_shared(split->output(0)), - std::make_shared(convert), - std::make_shared(relu), + std::make_shared(split->output(0)), + std::make_shared(convert), + std::make_shared(relu), }; function = std::make_shared(results, ov::ParameterVector{input_params}, "remove_convert"); @@ -131,4 +129,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_RemoveConvert, ::testing::Combine(::testing::Values(ElementType::f32), ::testing::Values(inputShapes[0])), RemoveUselessConvertCPUTest::getTestCaseName); } // namespace -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov From 9c9487384263a7621de223e8c5fe1782b1c34fcf Mon Sep 17 00:00:00 2001 From: Xuejun Zhai Date: Tue, 5 Dec 2023 14:24:55 +0800 Subject: [PATCH 06/20] Upgrade CPU func tests to 2.o (#21357) * [CPU Plugin][Func Test] Upgrade AddConvertToReorderTest to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade AlignMatMulInputRanksTest to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade GatherAddAvgpool to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Upgrade InputNoReorderEltwiseBF16 to API 2.0 Signed-off-by: Zhai, Xuejun * [CPU Plugin][Func Test] Fix review comments Signed-off-by: Zhai, Xuejun --------- Signed-off-by: Zhai, Xuejun --- .../src/transformations/convert_precision.cpp | 2 + .../src/add_convert_to_reorder.cpp | 61 ++++++++------- .../src/align_matmul_input_ranks.cpp | 76 ++++++++++--------- .../subgraph_tests/src/gather_add_avgpool.cpp | 43 ++++++----- .../src/input_noreorder_eltwise_bf16.cpp | 44 +++++------ 5 files changed, 119 insertions(+), 107 deletions(-) diff --git a/src/common/transformations/src/transformations/convert_precision.cpp b/src/common/transformations/src/transformations/convert_precision.cpp index 5e8436508009b1..8878cb182b9992 100644 --- a/src/common/transformations/src/transformations/convert_precision.cpp +++ b/src/common/transformations/src/transformations/convert_precision.cpp @@ -1267,6 +1267,8 @@ bool fuse_type_to_constant(const std::shared_ptr& node, new_const = change_constant_precision(constant); } else if (from == ov::element::boolean && to == ov::element::i32) { new_const = change_constant_precision(constant); + } else if (from == ov::element::i8 && to == ov::element::i64) { + new_const = change_constant_precision(constant); } else if (from == ov::element::i4 || from == ov::element::u4 || from == ov::element::u1) { new_const = convert_low_precisions_int(constant, to); } else { diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/add_convert_to_reorder.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/add_convert_to_reorder.cpp index 645b85e9816ea0..cac8cb98fb81cf 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/add_convert_to_reorder.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/add_convert_to_reorder.cpp @@ -2,53 +2,51 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "test_utils/cpu_test_utils.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ov_models/utils/ov_helpers.hpp" #include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "test_utils/cpu_test_utils.hpp" -using namespace InferenceEngine; using namespace CPUTestUtils; -namespace LayerTestsDefinitions { +namespace ov { +namespace test { -class AddConvertToReorderTest : virtual public LayerTestsUtils::LayerTestsCommon { +class AddConvertToReorderTest : virtual public SubgraphBaseStaticTest { public: - void BuildGraph(const ngraph::element::Type& secondInpType) { + void BuildGraph(const ov::element::Type& secondInpType) { secondConstantType = secondInpType; int axis = 2; std::vector indices = {0, 3, 2, 1}; std::vector indicesShape = {2, 2}; std::vector inputShape = {10, 20, 30, 40}; - InferenceEngine::Precision netPrecision = inPrc = outPrc = Precision::FP32; + ov::element::Type netPrecision = inType = outType = ov::element::f32; targetDevice = ov::test::utils::DEVICE_CPU; - ASSERT_EQ(ngraph::shape_size(indicesShape), indices.size()) - << "Indices vector size and provided indices shape doesn't fit each other"; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector params{std::make_shared(ngPrc, ov::Shape(inputShape))}; - auto indicesNode = ngraph::opset3::Constant::create(secondConstantType, ngraph::Shape(indicesShape), indices); - auto axisNode = ngraph::opset3::Constant::create(ngraph::element::i64, ngraph::Shape({}), {axis}); - auto gather = std::make_shared(params[0], indicesNode, axisNode); - ngraph::ResultVector results{std::make_shared(gather)}; - function = std::make_shared(results, params, "gather"); + ASSERT_EQ(ov::shape_size(indicesShape), indices.size()) + << "Indices vector size and provided indices shape doesn't fit each other"; + ov::ParameterVector params{std::make_shared(netPrecision, ov::Shape(inputShape))}; + auto indicesNode = ov::op::v0::Constant::create(secondConstantType, ov::Shape(indicesShape), indices); + auto axisNode = ov::op::v0::Constant::create(ov::element::i64, ov::Shape({}), {axis}); + auto gather = std::make_shared(params[0], indicesNode, axisNode); + ov::ResultVector results{std::make_shared(gather)}; + function = std::make_shared(results, params, "gather"); } - std::vector>> CalculateRefs() override { + std::vector calculate_refs() override { // Convert the second input constant precision to i64 to run the reference function - if (ngraph::element::Type_t::i8 == secondConstantType) { - ngraph::pass::ConvertPrecision().run_on_model(functionRefs); - } else if (ngraph::element::Type_t::bf16 == secondConstantType) { - ngraph::pass::ConvertPrecision().run_on_model(functionRefs); + if (ov::element::i8 == secondConstantType) { + convert_precisions.insert({ov::element::i8, ov::element::i64}); + } else if (ov::element::bf16 == secondConstantType) { + convert_precisions.insert({ov::element::bf16, ov::element::i64}); } - return LayerTestsUtils::LayerTestsCommon::CalculateRefs(); + return SubgraphBaseTest::calculate_refs(); } private: - ngraph::element::Type secondConstantType; + ov::element::Type secondConstantType; }; -namespace { +namespace { /* Test insertion of the Reorder layer if there is one. @@ -63,10 +61,11 @@ namespace { Output[FP32] */ TEST_F(AddConvertToReorderTest, smoke_TestAddReorder_CPU) { - BuildGraph(ngraph::element::i8); - Run(); - CheckNumberOfNodesWithType(executableNetwork, "Convert", 0); - CheckNumberOfNodesWithType(executableNetwork, "Reorder", 1); + BuildGraph(ov::element::i8); + run(); + CheckNumberOfNodesWithType(compiledModel, "Convert", 0); + CheckNumberOfNodesWithType(compiledModel, "Reorder", 1); } -} // namespace -} // namespace LayerTestsDefinitions +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/align_matmul_input_ranks.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/align_matmul_input_ranks.cpp index f5c6a6abb09ef5..5f77d49f8e14a6 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/align_matmul_input_ranks.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/align_matmul_input_ranks.cpp @@ -2,35 +2,37 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "test_utils/cpu_test_utils.hpp" -#include "test_utils/fusing_test_utils.hpp" -#include "ov_models/builders.hpp" -#include "common_test_utils/common_utils.hpp" - #include #include -using namespace ngraph; -using namespace InferenceEngine; +#include "common_test_utils/common_utils.hpp" +#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "test_utils/cpu_test_utils.hpp" +#include "test_utils/fusing_test_utils.hpp" + using namespace CPUTestUtils; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -using AlignMatMulInputRanksTestParams = std::tuple, // IS fully connected - fusingSpecificParams>; +using AlignMatMulInputRanksTestParams = std::tuple, // IS fully connected + fusingSpecificParams>; -class AlignMatMulInputRanksTest : public testing::WithParamInterface, public CpuTestWithFusing, - virtual public LayerTestsUtils::LayerTestsCommon { +class AlignMatMulInputRanksTest : public testing::WithParamInterface, + public CpuTestWithFusing, + virtual public SubgraphBaseStaticTest { public: static std::string getTestCaseName(testing::TestParamInfo obj) { - std::pair supportedInputShapes; + std::pair supportedInputShapes; fusingSpecificParams fusingParams; std::tie(supportedInputShapes, fusingParams) = obj.param; - SizeVector inputShapeA = supportedInputShapes.first; SizeVector inputShapeB = supportedInputShapes.second; + ov::Shape inputShapeA = supportedInputShapes.first; + ov::Shape inputShapeB = supportedInputShapes.second; std::ostringstream result; - result << "IS_A=" << ov::test::utils::vec2str(inputShapeA) << "_"; - result << "IS_B=" << ov::test::utils::vec2str(inputShapeB) << "_"; + result << "IS_A=" << inputShapeA << "_"; + result << "IS_B=" << inputShapeB << "_"; result << CpuTestWithFusing::getTestCaseName(fusingParams); return result.str(); @@ -39,7 +41,7 @@ class AlignMatMulInputRanksTest : public testing::WithParamInterface inShapes; + std::pair inShapes; fusingSpecificParams fusingParams; std::tie(inShapes, fusingParams) = this->GetParam(); @@ -48,14 +50,14 @@ class AlignMatMulInputRanksTest : public testing::WithParamInterface(ngPrec, ov::Shape(inShapes.first)), - std::make_shared(ngPrec, ov::Shape(inShapes.second))}; + ov::ParameterVector inputParams{std::make_shared(ngPrec, inShapes.first), + std::make_shared(ngPrec, inShapes.second)}; const auto matMul = std::make_shared(inputParams[0], inputParams[1], false, false); selectedType = makeSelectedTypeStr(with_cpu_x86_avx512_core() ? "brgemm_avx512" : "jit_gemm", ngPrec); @@ -67,18 +69,20 @@ class AlignMatMulInputRanksTest : public testing::WithParamInterface> supportedInputShapes = { - {{4, 10, 5}, {1, 5, 10}}, // nothing to be done - {{3}, {3}}, // 3x1 * 1x3 -> 1 - {{18}, {1, 5, 18, 20}}, // 1x1x1x18 * 1x5x18x20 -> 1x5x20 - {{2, 3, 4, 4, 4, 10, 5}, {5}}, // 2x3x4x4x4x10x5 * 1x1x1x1x1x5x1 -> 1x1x1x1x1x5 +const std::vector> supportedInputShapes = { + {{4, 10, 5}, {1, 5, 10}}, // nothing to be done + {{3}, {3}}, // 3x1 * 1x3 -> 1 + {{18}, {1, 5, 18, 20}}, // 1x1x1x18 * 1x5x18x20 -> 1x5x20 + {{2, 3, 4, 4, 4, 10, 5}, {5}}, // 2x3x4x4x4x10x5 * 1x1x1x1x1x5x1 -> 1x1x1x1x1x5 {{1, 18}, {1, 5, 18, 20}}, {{1, 70, 18}, {1, 5, 18, 20}}, {{7, 1, 10, 3, 2, 7}, {1, 7, 5}}, @@ -86,16 +90,18 @@ const std::vector> supportedInputShapes = { }; // verify fusing just in case -std::vector fusingParamsSet { - emptyFusingSpec, - fusingElu, +std::vector fusingParamsSet{ + emptyFusingSpec, + fusingElu, }; -INSTANTIATE_TEST_SUITE_P(smoke_Check, AlignMatMulInputRanksTest, +INSTANTIATE_TEST_SUITE_P(smoke_Check, + AlignMatMulInputRanksTest, ::testing::Combine(::testing::ValuesIn(supportedInputShapes), ::testing::ValuesIn(fusingParamsSet)), AlignMatMulInputRanksTest::getTestCaseName); -} // namespace +} // namespace -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/gather_add_avgpool.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/gather_add_avgpool.cpp index f145b2a0586659..cc9a325ae1f72c 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/gather_add_avgpool.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/gather_add_avgpool.cpp @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "shared_test_classes/base/layer_test_utils.hpp" #include -#include +#include "openvino/runtime/exec_model_info.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { using namespace ngraph; @@ -25,30 +26,33 @@ using namespace ngraph; input's precision if its child has Subgraph consumers. Same scenario happens when we have Eltwise instead of Subgraph - to be addressed in #78939. */ -class GatherAddAvgpool : virtual public LayerTestsUtils::LayerTestsCommon { +class GatherAddAvgpool : virtual public SubgraphBaseStaticTest { protected: void SetUp() override { targetDevice = ov::test::utils::DEVICE_CPU; - inPrc = InferenceEngine::Precision::U8; - outPrc = InferenceEngine::Precision::FP32; - auto type = element::f32; - auto param = std::make_shared(type, Shape{1, 3, 64, 64}); - auto gather = std::make_shared(param, - op::Constant::create(element::i32, Shape{3}, {2, 1, 0}), - op::Constant::create(element::i32, Shape{1}, {1})); - auto add = std::make_shared(gather, op::Constant::create(type, Shape{1, 3, 1, 1}, {3})); - auto avgpool = std::make_shared(add, Strides{1, 1}, Shape{0, 0}, Shape{0, 0}, Shape{2, 2}, false); - function = std::make_shared(avgpool, ParameterVector{param}); + inType = ov::element::u8; + outType = ov::element::f32; + auto type = ov::element::f32; + auto param = std::make_shared(type, Shape{1, 3, 64, 64}); + auto gather = + std::make_shared(param, + ov::op::v0::Constant::create(element::i32, Shape{3}, {2, 1, 0}), + ov::op::v0::Constant::create(element::i32, Shape{1}, {1})); + auto add = + std::make_shared(gather, ov::op::v0::Constant::create(type, Shape{1, 3, 1, 1}, {3})); + auto avgpool = + std::make_shared(add, Strides{1, 1}, Shape{0, 0}, Shape{0, 0}, Shape{2, 2}, false); + function = std::make_shared(avgpool, ov::ParameterVector{param}); } void TearDown() override { - auto exec_model = executableNetwork.GetExecGraphInfo().getFunction(); + auto exec_model = compiledModel.get_runtime_model(); int eltwise_nodes_found = 0; int pool_nodes_found = 0; for (const auto& n : exec_model->get_ordered_ops()) { - auto layer_type = n->get_rt_info().at(ExecGraphInfoSerialization::LAYER_TYPE).as(); - auto output_layout = n->get_rt_info().at(ExecGraphInfoSerialization::OUTPUT_LAYOUTS).as(); + auto layer_type = n->get_rt_info().at(ov::exec_model_info::LAYER_TYPE).as(); + auto output_layout = n->get_rt_info().at(ov::exec_model_info::OUTPUT_LAYOUTS).as(); if (layer_type == "Subgraph") { eltwise_nodes_found++; ASSERT_EQ("abcd", output_layout); @@ -63,7 +67,8 @@ class GatherAddAvgpool : virtual public LayerTestsUtils::LayerTestsCommon { }; TEST_F(GatherAddAvgpool, smoke_CompareWithRefs) { - Run(); + run(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_noreorder_eltwise_bf16.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_noreorder_eltwise_bf16.cpp index 8371c336bacff0..6579aacded8873 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_noreorder_eltwise_bf16.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/input_noreorder_eltwise_bf16.cpp @@ -2,39 +2,38 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "ie_common.h" +#include "common_test_utils/node_builders/eltwise.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "ov_models/builders.hpp" #include "ov_models/utils/ov_helpers.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include "common_test_utils/ov_tensor_utils.hpp" -using namespace InferenceEngine; using namespace CPUTestUtils; -namespace CPULayerTestsDefinitions { +namespace ov { +namespace test { -class InputNoReorderEltwiseBF16 : virtual public LayerTestsUtils::LayerTestsCommon, - public CPUTestsBase { +class InputNoReorderEltwiseBF16 : virtual public SubgraphBaseStaticTest, public CPUTestsBase { protected: void SetUp() override { - auto netPrecision = inPrc = Precision::FP32; - outPrc = Precision::BF16; + auto netPrecision = inType = ov::element::f32; + outType = ov::element::bf16; targetDevice = ov::test::utils::DEVICE_CPU; - std::map additional_config{{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}; + ov::AnyMap additional_config{ov::hint::inference_precision(ov::element::bf16)}; configuration.insert(additional_config.begin(), additional_config.end()); - std::vector inputShape {2, 4, 4, 1}; - auto eltwiseType = ngraph::helpers::EltwiseTypes::ADD; + ov::Shape inputShape{2, 4, 4, 1}; + auto eltwiseType = ov::test::utils::EltwiseTypes::ADD; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - ov::ParameterVector input {std::make_shared(ngPrc, ov::Shape(inputShape))}; + ov::ParameterVector input{std::make_shared(netPrecision, inputShape)}; - auto tensor = ov::test::utils::create_and_fill_tensor(ngPrc, inputShape); + auto tensor = ov::test::utils::create_and_fill_tensor(netPrecision, inputShape); auto secondaryInput = std::make_shared(tensor); - auto eltwise = ngraph::builder::makeEltwise(input[0], secondaryInput, eltwiseType); + auto eltwise = ov::test::utils::makeEltwise(input[0], secondaryInput, eltwiseType); - function = makeNgraphFunction(ngPrc, input, eltwise, "Eltwise"); + function = makeNgraphFunction(netPrecision, input, eltwise, "Eltwise"); } }; @@ -53,10 +52,11 @@ class InputNoReorderEltwiseBF16 : virtual public LayerTestsUtils::LayerTestsComm Output[BF16] */ TEST_F(InputNoReorderEltwiseBF16, smoke_CompareWithRefs) { - Run(); + run(); - CheckNumberOfNodesWithType(executableNetwork, "Reorder", 0); - CheckNumberOfNodesWithType(executableNetwork, "Convert", 0); - CheckNumberOfNodesWithTypes(executableNetwork, {"Eltwise", "Subgraph"}, 1); + CheckNumberOfNodesWithType(compiledModel, "Reorder", 0); + CheckNumberOfNodesWithType(compiledModel, "Convert", 0); + CheckNumberOfNodesWithTypes(compiledModel, {"Eltwise", "Subgraph"}, 1); } -} // namespace CPULayerTestsDefinitions +} // namespace test +} // namespace ov From 2c6a2a1102ac24333b86a202b9b4d74e478a1a35 Mon Sep 17 00:00:00 2001 From: River Li Date: Tue, 5 Dec 2023 14:55:55 +0800 Subject: [PATCH 07/20] [CPU tests] migrate sub_graph test cases to be 2.0 - part 3 (#21386) --- .../subgraph_tests/src/any_layout.cpp | 59 ++--- .../subgraph_tests/src/split_concat_add.cpp | 34 +-- .../src/split_matmul_concat.cpp | 13 +- .../src/strided_slice_zero_dims.cpp | 24 +- .../subgraph_tests/src/subgraph_serialize.cpp | 6 +- .../test_utils/arm/filter_cpu_info.cpp | 2 - .../functional/test_utils/cpu_test_utils.cpp | 53 ++-- .../functional/test_utils/cpu_test_utils.hpp | 24 +- .../test_utils/fusing_test_utils.cpp | 21 +- .../test_utils/fusing_test_utils.hpp | 238 +++++++++--------- .../test_utils/x64/filter_cpu_info.cpp | 1 - 11 files changed, 229 insertions(+), 246 deletions(-) diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/any_layout.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/any_layout.cpp index 5d7bcbfbdfcc2f..84984dda2bf972 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/any_layout.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/any_layout.cpp @@ -4,9 +4,8 @@ #include "test_utils/cpu_test_utils.hpp" -using namespace InferenceEngine; - -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { class AnyLayoutOnInputsAndOutputs : public ::testing::TestWithParam { public: @@ -17,18 +16,18 @@ class AnyLayoutOnInputsAndOutputs : public ::testing::TestWithParam { } protected: - std::shared_ptr + std::shared_ptr create_test_function(const ov::Shape & shape) { - auto param = std::make_shared(ov::element::f32, shape); + auto param = std::make_shared(ov::element::f32, shape); float shift = 1.0f; - auto shift_node = std::make_shared(ov::element::f32, ov::Shape{1}, &shift); + auto shift_node = std::make_shared(ov::element::f32, ov::Shape{1}, &shift); - auto add = std::make_shared(param, shift_node); + auto add = std::make_shared(param, shift_node); - auto result = std::make_shared(add); + auto result = std::make_shared(add); - return std::make_shared(ngraph::ResultVector{result}, ngraph::ParameterVector{param}); + return std::make_shared(ov::ResultVector{result}, ov::ParameterVector{param}); } void Run() { @@ -39,38 +38,21 @@ class AnyLayoutOnInputsAndOutputs : public ::testing::TestWithParam { std::vector output_data(shape_size); std::vector expected_output(shape_size, 3); - // Create CNNNetwork - auto ngraph_function = create_test_function(shape); - auto cnn = InferenceEngine::CNNNetwork(ngraph_function); - - // Fill inputs and outputs - std::vector input_names; - std::vector out_names; - for (const auto& it : cnn.getInputsInfo()) { - input_names.push_back(it.first); - } - for (const auto& it : cnn.getOutputsInfo()) { - out_names.push_back(it.first); - } - - BlobMap inputBlobs; - BlobMap outputBlobs; - - TensorDesc tensorDescInp1(Precision::FP32, shape, Layout::ANY); - TensorDesc tensorDescOut(Precision::FP32, shape, Layout::ANY); + // Create model + auto function = create_test_function(shape); - inputBlobs[input_names[0]] = make_shared_blob(tensorDescInp1, input_data.data()); - outputBlobs[out_names[0]] = make_shared_blob(tensorDescOut, output_data.data()); + auto input = ov::Tensor(ov::element::f32, shape, input_data.data()); + auto output = ov::Tensor(ov::element::f32, shape, output_data.data()); - // Load network - Core ie; - ExecutableNetwork executable_network = ie.LoadNetwork(cnn, "CPU"); + // Load model + Core core; + auto compiled_model = core.compile_model(function, "CPU"); // Infer - InferRequest infer_request = executable_network.CreateInferRequest(); - infer_request.SetInput(inputBlobs); - infer_request.SetOutput(outputBlobs); - infer_request.Infer(); + auto infer_req = compiled_model.create_infer_request(); + infer_req.set_input_tensor(input); + infer_req.set_output_tensor(output); + infer_req.infer(); ASSERT_EQ(output_data, expected_output); } @@ -91,4 +73,5 @@ INSTANTIATE_TEST_SUITE_P(AnyLayoutOnInputsAndOutputs, ::testing::ValuesIn(AnyLayoutOnInputsAndOutputsParams), AnyLayoutOnInputsAndOutputs::getTestCaseName); -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/split_concat_add.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/split_concat_add.cpp index 12c5588ac7fcf5..82beb9341ae99d 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/split_concat_add.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/split_concat_add.cpp @@ -2,9 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "shared_test_classes/base/ov_subgraph.hpp" -#include "ov_models/utils/ov_helpers.hpp" +#include "common_test_utils/node_builders/eltwise.hpp" #include "ov_models/builders.hpp" +#include "ov_models/utils/ov_helpers.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" /*This test runs the following subgraph: @@ -29,10 +30,8 @@ The main purpose of the test is to check the memory sharing between result and in_place edges. */ -using namespace InferenceEngine; -using namespace ov::test; - -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { class SplitConcatAddInPlace : virtual public ov::test::SubgraphBaseTest { protected: @@ -50,17 +49,17 @@ class SplitConcatAddInPlace : virtual public ov::test::SubgraphBaseTest { auto split = std::make_shared(params.front(), split_axis_op, 3); auto add_const = ngraph::builder::makeConstant(precision, {1}, std::vector({1.0f})); - auto add_1 = ngraph::builder::makeEltwise(split->output(0), add_const, ngraph::helpers::EltwiseTypes::ADD); - auto result_add_1 = std::make_shared(add_1); - auto add_2 = ngraph::builder::makeEltwise(split->output(1), add_const, ngraph::helpers::EltwiseTypes::ADD); - auto add_3 = ngraph::builder::makeEltwise(split->output(2), add_const, ngraph::helpers::EltwiseTypes::ADD); + auto add_1 = utils::makeEltwise(split->output(0), add_const, utils::EltwiseTypes::ADD); + auto result_add_1 = std::make_shared(add_1); + auto add_2 = utils::makeEltwise(split->output(1), add_const, utils::EltwiseTypes::ADD); + auto add_3 = utils::makeEltwise(split->output(2), add_const, utils::EltwiseTypes::ADD); auto concat = std::make_shared(ov::NodeVector{add_1, add_2, add_3}, 1); - auto result_concat = std::make_shared(concat); - auto add_4 = ngraph::builder::makeEltwise(concat, add_const, ngraph::helpers::EltwiseTypes::ADD); - auto add_5 = ngraph::builder::makeEltwise(concat, add_const, ngraph::helpers::EltwiseTypes::ADD); - auto result_1 = std::make_shared(add_4); - auto result_2 = std::make_shared(add_5); - ngraph::ResultVector results = {result_1, result_2, result_add_1, result_concat}; + auto result_concat = std::make_shared(concat); + auto add_4 = utils::makeEltwise(concat, add_const, utils::EltwiseTypes::ADD); + auto add_5 = utils::makeEltwise(concat, add_const, utils::EltwiseTypes::ADD); + auto result_1 = std::make_shared(add_4); + auto result_2 = std::make_shared(add_5); + ov::ResultVector results = {result_1, result_2, result_add_1, result_concat}; function = std::make_shared(results, params, "Subgraph"); } }; @@ -69,4 +68,5 @@ TEST_F(SplitConcatAddInPlace, smoke_CompareWithRefs) { run(); } -} // namespace SubgraphTestsDefinitions \ No newline at end of file +} // namespace test +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/split_matmul_concat.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/split_matmul_concat.cpp index 6a77c027e9df97..b1cdb1c258b581 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/split_matmul_concat.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/split_matmul_concat.cpp @@ -6,12 +6,10 @@ #include "ov_models/builders.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" -using namespace ngraph; -using namespace InferenceEngine; using namespace CPUTestUtils; -using namespace ov::test; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { /* --------------- @@ -107,9 +105,9 @@ class SplitMatMulConcatTest : public testing::WithParamInterface(ElementType::f32, inShapeA)}; - std::shared_ptr inputB = builder::makeConstant(ElementType::f32, inShapeB.get_shape(), {}, true); + std::shared_ptr inputB = ngraph::builder::makeConstant(ElementType::f32, inShapeB.get_shape(), {}, true); - auto split = builder::makeVariadicSplit(params[0], {1, 1}, 0); + auto split = ngraph::builder::makeVariadicSplit(params[0], {1, 1}, 0); auto matMul = std::make_shared(split->output(0), inputB, transpA, transpB); @@ -143,4 +141,5 @@ INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP32, SplitMatMulConcatTest, testParams2D_F } // namespace -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/strided_slice_zero_dims.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/strided_slice_zero_dims.cpp index 6d888bbba8d9f6..976c4d7de463bb 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/strided_slice_zero_dims.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/strided_slice_zero_dims.cpp @@ -6,11 +6,8 @@ #include "ov_models/utils/ov_helpers.hpp" #include "ov_models/builders.hpp" -using namespace InferenceEngine; -using namespace ov::test; -using namespace ngraph; - -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { /* param1 [56] param2 [-1, -1, 768] (dynamic shape) @@ -40,12 +37,12 @@ class StridedSliceZeroDimsTest : public SubgraphBaseTest { for (auto&& shape : inputDynamicShapes) { inputParams.push_back(std::make_shared(ov::element::f32, shape)); } - auto end = builder::makeConstant(element::i64, {1}, std::vector{2147483647}); - auto stride = builder::makeConstant(element::i64, {1}, std::vector{1}); - auto indices = builder::makeConstant(element::i64, {1}, std::vector{1}); - auto axes = builder::makeConstant(element::i64, {1}, std::vector{0}); - auto shapeOf = std::make_shared(inputParams[1]); - auto gather = std::make_shared(shapeOf, indices, axes); + auto end = ngraph::builder::makeConstant(element::i64, {1}, std::vector{2147483647}); + auto stride = ngraph::builder::makeConstant(element::i64, {1}, std::vector{1}); + auto indices = ngraph::builder::makeConstant(element::i64, {1}, std::vector{1}); + auto axes = ngraph::builder::makeConstant(element::i64, {1}, std::vector{0}); + auto shapeOf = std::make_shared(inputParams[1]); + auto gather = std::make_shared(shapeOf, indices, axes); auto strided_slice = std::make_shared(inputParams.front(), gather, end, @@ -56,7 +53,7 @@ class StridedSliceZeroDimsTest : public SubgraphBaseTest { std::vector{}, std::vector{}); NodeVector results{strided_slice}; - function = std::make_shared(results, inputParams, "StridedSliceStaticShape"); + function = std::make_shared(results, inputParams, "StridedSliceStaticShape"); } }; @@ -64,4 +61,5 @@ TEST_F(StridedSliceZeroDimsTest, smoke_CompareWithRefs) { run(); } -} // namespace SubgraphTestsDefinitions \ No newline at end of file +} // namespace test +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/subgraph_serialize.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/subgraph_serialize.cpp index b3e2912855dbe3..8432cf90a46d7c 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/subgraph_serialize.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/subgraph_serialize.cpp @@ -12,7 +12,8 @@ using namespace CPUTestUtils; using namespace ov::opset9; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { class SubgraphSnippetSerializationTest : public ::testing::Test, public CPUTestsBase {}; @@ -146,4 +147,5 @@ TEST_F(SubgraphSnippetSerializationTest, smoke_SerializeSubgraphWithResultAs1stO ASSERT_TRUE(results.valid) << results.message; } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/test_utils/arm/filter_cpu_info.cpp b/src/plugins/intel_cpu/tests/functional/test_utils/arm/filter_cpu_info.cpp index bb16db068b01ec..34f1575d9bb3f3 100644 --- a/src/plugins/intel_cpu/tests/functional/test_utils/arm/filter_cpu_info.cpp +++ b/src/plugins/intel_cpu/tests/functional/test_utils/arm/filter_cpu_info.cpp @@ -4,11 +4,9 @@ #include "test_utils/cpu_test_utils.hpp" #include "test_utils/filter_cpu_info.hpp" -#include "ie_ngraph_utils.hpp" #include "openvino/core/type/element_type.hpp" #include "utils/rt_info/memory_formats_attribute.hpp" #include "utils/general_utils.h" -#include namespace CPUTestUtils { diff --git a/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.cpp b/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.cpp index 95a49eaa979762..23a92ce3c5ac13 100644 --- a/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.cpp +++ b/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.cpp @@ -3,12 +3,11 @@ // #include "cpu_test_utils.hpp" -#include "ie_ngraph_utils.hpp" + #include "openvino/core/type/element_type.hpp" -#include "utils/rt_info/memory_formats_attribute.hpp" #include "transformations/rt_info/primitives_priority_attribute.hpp" #include "utils/general_utils.h" -#include +#include "utils/rt_info/memory_formats_attribute.hpp" namespace CPUTestUtils { const char* CPUTestsBase::any_type = "any_type"; @@ -147,14 +146,14 @@ void CPUTestsBase::CheckPluginRelatedResultsImpl(const std::shared_ptrsecond.as(); }; - auto getExecValueOutputsLayout = [] (const std::shared_ptr& node) -> std::string { + auto getExecValueOutputsLayout = [] (const std::shared_ptr& node) -> std::string { auto rtInfo = node->get_rt_info(); - auto it = rtInfo.find(ExecGraphInfoSerialization::OUTPUT_LAYOUTS); + auto it = rtInfo.find(ov::exec_model_info::OUTPUT_LAYOUTS); OPENVINO_ASSERT(rtInfo.end() != it); return it->second.as(); }; // skip policy - auto should_be_skipped = [] (const ngraph::PartialShape &partialShape, cpu_memory_format_t fmt) { + auto should_be_skipped = [] (const ov::PartialShape &partialShape, cpu_memory_format_t fmt) { if (partialShape.is_dynamic()) { return false; } @@ -165,7 +164,7 @@ void CPUTestsBase::CheckPluginRelatedResultsImpl(const std::shared_ptrget_input_size()); ASSERT_LE(outFmts.size(), node->get_output_size()); for (size_t i = 0; i < inFmts.size(); i++) { @@ -211,7 +210,7 @@ void CPUTestsBase::CheckPluginRelatedResultsImpl(const std::shared_ptrget_output_partial_shape(i); if (should_be_skipped(shape, outFmts[i])) @@ -219,7 +218,7 @@ void CPUTestsBase::CheckPluginRelatedResultsImpl(const std::shared_ptr& inFmts, return cpuInfo; } -std::shared_ptr -CPUTestsBase::makeNgraphFunction(const ngraph::element::Type &ngPrc, ngraph::ParameterVector ¶ms, - const std::shared_ptr &lastNode, std::string name) { +std::shared_ptr +CPUTestsBase::makeNgraphFunction(const ov::element::Type &ngPrc, ov::ParameterVector ¶ms, + const std::shared_ptr &lastNode, std::string name) { auto newLastNode = modifyGraph(ngPrc, params, lastNode); - ngraph::ResultVector results; + ov::ResultVector results; for (size_t i = 0; i < newLastNode->get_output_size(); i++) - results.push_back(std::make_shared(newLastNode->output(i))); + results.push_back(std::make_shared(newLastNode->output(i))); - return std::make_shared(results, params, name); + return std::make_shared(results, params, name); } -std::shared_ptr -CPUTestsBase::modifyGraph(const ngraph::element::Type &ngPrc, ngraph::ParameterVector ¶ms, const std::shared_ptr &lastNode) { +std::shared_ptr +CPUTestsBase::modifyGraph(const ov::element::Type &ngPrc, ov::ParameterVector ¶ms, const std::shared_ptr &lastNode) { lastNode->get_rt_info() = getCPUInfo(); return lastNode; } -std::string CPUTestsBase::makeSelectedTypeStr(std::string implString, ngraph::element::Type_t elType) { +std::string CPUTestsBase::makeSelectedTypeStr(std::string implString, ov::element::Type_t elType) { implString.push_back('_'); implString += ov::element::Type(elType).get_type_name(); return implString; @@ -418,7 +417,7 @@ std::vector filterCPUSpecificParams(const std::vector filteredParamsVector = paramsVector; - if (!InferenceEngine::with_cpu_x86_avx512f()) { + if (!ov::with_cpu_x86_avx512f()) { for (auto& param : filteredParamsVector) { adjustBlockedFormatByIsa(std::get<0>(param)); adjustBlockedFormatByIsa(std::get<1>(param)); @@ -441,7 +440,7 @@ inline void CheckNumberOfNodesWithTypeImpl(std::shared_ptr func return it->second.as(); }; - if (nodeTypes.count(getExecValue(ExecGraphInfoSerialization::LAYER_TYPE))) { + if (nodeTypes.count(getExecValue(ov::exec_model_info::LAYER_TYPE))) { actualNodeCount++; } } diff --git a/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp b/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp index 8777314f4980bf..99299059e28197 100644 --- a/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp +++ b/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp @@ -4,13 +4,15 @@ #pragma once -#include -#include "ie_system_conf.h" +#include "openvino/runtime/compiled_model.hpp" +#include "openvino/runtime/exec_model_info.hpp" +#include "openvino/runtime/system_conf.hpp" #include "shared_test_classes/base/layer_test_utils.hpp" #include "transformations/rt_info/primitives_priority_attribute.hpp" -#include -#include + +// To be removed #include "ie_system_conf.h" +#include "exec_graph_info.hpp" namespace CPUTestUtils { typedef enum { @@ -128,13 +130,13 @@ class CPUTestsBase { const std::vector& outFmts, const std::vector& priority); //TODO: change to setter method - static std::string makeSelectedTypeStr(std::string implString, ngraph::element::Type_t elType); + static std::string makeSelectedTypeStr(std::string implString, ov::element::Type_t elType); void updateSelectedType(const std::string& primitiveType, const ov::element::Type netType, const ov::AnyMap& config); CPUInfo getCPUInfo() const; - std::shared_ptr makeNgraphFunction(const ngraph::element::Type &ngPrc, - ngraph::ParameterVector ¶ms, - const std::shared_ptr &lastNode, + std::shared_ptr makeNgraphFunction(const ov::element::Type &ngPrc, + ov::ParameterVector ¶ms, + const std::shared_ptr &lastNode, std::string name); void CheckPluginRelatedResults(InferenceEngine::ExecutableNetwork &execNet, const std::set& nodeType) const; @@ -153,9 +155,9 @@ class CPUTestsBase { * @param lastNode The last node of the initial graph. * @return The last node of the modified graph. */ - virtual std::shared_ptr modifyGraph(const ngraph::element::Type &ngPrc, - ngraph::ParameterVector ¶ms, - const std::shared_ptr &lastNode); + virtual std::shared_ptr modifyGraph(const ov::element::Type &ngPrc, + ov::ParameterVector ¶ms, + const std::shared_ptr &lastNode); virtual bool primTypeCheck(std::string primType) const; diff --git a/src/plugins/intel_cpu/tests/functional/test_utils/fusing_test_utils.cpp b/src/plugins/intel_cpu/tests/functional/test_utils/fusing_test_utils.cpp index c1aef766be4f86..1e03755270ac97 100644 --- a/src/plugins/intel_cpu/tests/functional/test_utils/fusing_test_utils.cpp +++ b/src/plugins/intel_cpu/tests/functional/test_utils/fusing_test_utils.cpp @@ -8,7 +8,6 @@ using namespace LayerTestsDefinitions; namespace CPUTestUtils { - std::string CpuTestWithFusing::getTestCaseName(fusingSpecificParams params) { std::ostringstream result; std::vector fusedOps; @@ -25,10 +24,10 @@ std::string CpuTestWithFusing::getTestCaseName(fusingSpecificParams params) { return result.str(); } -std::shared_ptr -CpuTestWithFusing::modifyGraph(const ngraph::element::Type &ngPrc, ngraph::ParameterVector ¶ms, const std::shared_ptr &lastNode) { +std::shared_ptr +CpuTestWithFusing::modifyGraph(const ov::element::Type &ngPrc, ov::ParameterVector ¶ms, const std::shared_ptr &lastNode) { CPUTestsBase::modifyGraph(ngPrc, params, lastNode); - std::shared_ptr retNode = lastNode; + std::shared_ptr retNode = lastNode; if (postOpMgrPtr) { retNode = postOpMgrPtr->addPostOps(ngPrc, params, lastNode); } @@ -42,7 +41,7 @@ void CpuTestWithFusing::CheckFusingResults(const std::shared_ptrget_ops()) { const auto &rtInfo = op->get_rt_info(); - auto getExecValue = [](const std::string ¶mName, const ngraph::Node::RTMap& rtInfo) -> std::string { + auto getExecValue = [](const std::string ¶mName, const ov::Node::RTMap& rtInfo) -> std::string { auto it = rtInfo.find(paramName); OPENVINO_ASSERT(rtInfo.end() != it); return it->second.as(); @@ -76,9 +75,9 @@ void CpuTestWithFusing::CheckPluginRelatedResultsImpl(const std::shared_ptr -postFunctionMgr::addPostOps(const ngraph::element::Type &ngPrc, ngraph::ParameterVector ¶ms, const std::shared_ptr &lastNode) const { - auto clonedPostFunction = ngraph::clone_function(*_pFunction); +std::shared_ptr +postFunctionMgr::addPostOps(const ov::element::Type &ngPrc, ov::ParameterVector ¶ms, const std::shared_ptr &lastNode) const { + auto clonedPostFunction = ov::clone_model(*_pFunction); clonedPostFunction->set_friendly_name(_pFunction->get_friendly_name()); clonedPostFunction->replace_node(clonedPostFunction->get_parameters()[0], lastNode); return clonedPostFunction->get_result()->get_input_node_shared_ptr(0); @@ -90,9 +89,9 @@ std::string postFunctionMgr::getFusedOpsNames() const { postNodesMgr::postNodesMgr(std::vector postNodes) : _postNodes(std::move(postNodes)) {} -std::shared_ptr -postNodesMgr::addPostOps(const ngraph::element::Type &ngPrc, ngraph::ParameterVector ¶ms, const std::shared_ptr &lastNode) const { - std::shared_ptr tmpNode = lastNode; +std::shared_ptr +postNodesMgr::addPostOps(const ov::element::Type &ngPrc, ov::ParameterVector ¶ms, const std::shared_ptr &lastNode) const { + std::shared_ptr tmpNode = lastNode; postNodeConfig cfg{lastNode, tmpNode, ngPrc, params}; diff --git a/src/plugins/intel_cpu/tests/functional/test_utils/fusing_test_utils.hpp b/src/plugins/intel_cpu/tests/functional/test_utils/fusing_test_utils.hpp index a11755f826c58e..c084a775509467 100644 --- a/src/plugins/intel_cpu/tests/functional/test_utils/fusing_test_utils.hpp +++ b/src/plugins/intel_cpu/tests/functional/test_utils/fusing_test_utils.hpp @@ -4,51 +4,55 @@ #pragma once +#include "common_test_utils/node_builders/activation.hpp" #include "cpu_test_utils.hpp" -#include -#include +#include "openvino/runtime/system_conf.hpp" +#include "ov_models/utils/data_utils.hpp" +#include "shared_test_classes/single_layer/activation.hpp" + +using namespace ov::test; namespace CPUTestUtils { struct postNodeConfig { - const std::shared_ptr target; - std::shared_ptr input; - const ngraph::element::Type& type; - ngraph::ParameterVector& params; + const std::shared_ptr target; + std::shared_ptr input; + const ov::element::Type& type; + ov::ParameterVector& params; }; struct postNodeBuilder { - std::function(postNodeConfig& cfg)> makeNode; + std::function(postNodeConfig& cfg)> makeNode; std::string name; }; class postOpMgr { public: - virtual std::shared_ptr addPostOps(const ngraph::element::Type &ngPrc, - ngraph::ParameterVector ¶ms, - const std::shared_ptr &lastNode) const = 0; + virtual std::shared_ptr addPostOps(const ov::element::Type& ngPrc, + ov::ParameterVector& params, + const std::shared_ptr& lastNode) const = 0; virtual std::string getFusedOpsNames() const = 0; virtual ~postOpMgr() = default; }; class postFunctionMgr : public postOpMgr { public: - postFunctionMgr(std::shared_ptr function) : _pFunction(std::move(function)) {} - std::shared_ptr addPostOps(const ngraph::element::Type &ngPrc, - ngraph::ParameterVector ¶ms, - const std::shared_ptr &lastNode) const override; + postFunctionMgr(std::shared_ptr function) : _pFunction(std::move(function)) {} + std::shared_ptr addPostOps(const ov::element::Type& ngPrc, + ov::ParameterVector& params, + const std::shared_ptr& lastNode) const override; std::string getFusedOpsNames() const override; private: - std::shared_ptr _pFunction; + std::shared_ptr _pFunction; }; class postNodesMgr : public postOpMgr { public: postNodesMgr(std::vector postNodes); - std::shared_ptr addPostOps(const ngraph::element::Type &ngPrc, - ngraph::ParameterVector ¶ms, - const std::shared_ptr &lastNode) const override; + std::shared_ptr addPostOps(const ov::element::Type& ngPrc, + ov::ParameterVector& params, + const std::shared_ptr& lastNode) const override; std::string getFusedOpsNames() const override; private: @@ -68,9 +72,9 @@ class CpuTestWithFusing : public CPUTestsBase { /** * @brief This function adds post operations. */ - std::shared_ptr modifyGraph(const ngraph::element::Type &ngPrc, - ngraph::ParameterVector ¶ms, - const std::shared_ptr &lastNode) override; + std::shared_ptr modifyGraph(const ov::element::Type& ngPrc, + ov::ParameterVector& params, + const std::shared_ptr& lastNode) override; void CheckPluginRelatedResultsImpl(const std::shared_ptr& function, const std::set& nodeType) const override; @@ -99,25 +103,25 @@ static int getChannelAxis(const ov::AxisSet &axes, bool keep_dims) { return channelAxis; } -static int getFusingAxis(const std::shared_ptr& node) { - if (std::dynamic_pointer_cast(node)) { +static int getFusingAxis(const std::shared_ptr& node) { + if (std::dynamic_pointer_cast(node)) { return node->get_output_partial_shape(0).size() - 1; // last dimension - } else if (const auto reduce = std::dynamic_pointer_cast(node)) { + } else if (const auto reduce = std::dynamic_pointer_cast(node)) { return getChannelAxis(reduce->get_reduction_axes(), reduce->get_keep_dims()); - } else if (const auto reduce = std::dynamic_pointer_cast(node)) { + } else if (const auto reduce = std::dynamic_pointer_cast(node)) { return getChannelAxis(reduce->get_reduction_axes(), reduce->get_keep_dims()); } else { return 1; // second dimension } } -static ngraph::Shape generatePerChannelShape(const std::shared_ptr& node) { +static ov::Shape generatePerChannelShape(const std::shared_ptr& node) { const auto shape = node->get_output_partial_shape(0); if (shape.size() == 0) OPENVINO_THROW("If shape.size() == 0 then PerTensor fusing tests are N/A"); if (shape.size() == 1) OPENVINO_THROW("If shape.size() == 1 then Granularity can be PerTensor only"); - ngraph::Shape perChannelShape(shape.size(), 1); + ov::Shape perChannelShape(shape.size(), 1); const auto channelAxis = getFusingAxis(node); if (channelAxis >= 0) perChannelShape[channelAxis] = shape[channelAxis].get_length(); @@ -130,176 +134,176 @@ const auto emptyFusingSpec = fusingSpecificParams{nullptr, {}}; const auto fusingRelu = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Relu); + return utils::make_activation(cfg.input, cfg.type, utils::Relu); }, "Relu"}}), {"Relu"}}; const auto fusingElu = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Elu, {}, {2.0f}); + return utils::make_activation(cfg.input, cfg.type, utils::Elu, {}, {2.0f}); }, "Elu"}}), {"Elu"}}; const auto fusingGelu = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Gelu); + return utils::make_activation(cfg.input, cfg.type, utils::Gelu); }, "Gelu"}}), {"Gelu"}}; const auto fusingSigmoid = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Sigmoid); + return utils::make_activation(cfg.input, cfg.type, utils::Sigmoid); }, "Sigmoid"}}), {"Sigmoid"}}; const auto fusingClamp = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Clamp, {}, {3.0f, 6.0f}); + return utils::make_activation(cfg.input, cfg.type, utils::Clamp, {}, {3.0f, 6.0f}); }, "Clamp"}}), {"Clamp"}}; const auto fusingTanh = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Tanh); + return utils::make_activation(cfg.input, cfg.type, utils::Tanh); }, "Tanh"}}), {"Tanh"}}; const auto fusingAbs = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Abs); + return utils::make_activation(cfg.input, cfg.type, utils::Abs); }, "Abs"}}), {"Abs"}}; const auto fusingSqrt = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Sqrt); + return utils::make_activation(cfg.input, cfg.type, utils::Sqrt); }, "Sqrt"}}), {"Sqrt"}}; const auto fusingPReluPerChannel = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape newShape = generatePerChannelShape(cfg.target); - auto data = NGraphFunctions::Utils::generateVector(ngraph::shape_size(newShape)); - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::LeakyRelu, newShape, data); + ov::Shape newShape = generatePerChannelShape(cfg.target); + auto data = NGraphFunctions::Utils::generateVector(ov::shape_size(newShape)); + return utils::make_activation(cfg.input, cfg.type, utils::LeakyRelu, newShape, data); }, "PRelu(PerChannel)"}}), {"PRelu"}}; const auto fusingPReluPerTensor = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape shape(1, 1); - auto data = NGraphFunctions::Utils::generateVector(ngraph::shape_size(shape)); - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::LeakyRelu, shape, data); + ov::Shape shape(1, 1); + auto data = NGraphFunctions::Utils::generateVector(ov::shape_size(shape)); + return utils::make_activation(cfg.input, cfg.type, utils::LeakyRelu, shape, data); }, "PRelu(PerTensor)"}}), {"PRelu"}}; const auto fusingSwish = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Swish, {}, {1.0f}); + return utils::make_activation(cfg.input, cfg.type, utils::Swish, {}, {1.0f}); }, "Swish"}}), {"Swish"}}; const auto fusingSoftPlus = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::SoftPlus, {}, {}); + return utils::make_activation(cfg.input, cfg.type, utils::SoftPlus, {}, {}); }, "SoftPlus"}}), {"SoftPlus"}}; const auto fusingHSwish = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::HSwish, {}, {}); + return utils::make_activation(cfg.input, cfg.type, utils::HSwish, {}, {}); }, "HSwish"}}), {"HSwish"}}; const auto fusingMish = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Mish, {}, {}); + return utils::make_activation(cfg.input, cfg.type, utils::Mish, {}, {}); }, "Mish"}}), {"Mish"}}; const auto fusingHSigmoid = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::HSigmoid); + return utils::make_activation(cfg.input, cfg.type, utils::HSigmoid); }, "HSigmoid"}}), {"HSigmoid"}}; const auto fusingReluAdd = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Relu); + return utils::make_activation(cfg.input, cfg.type, utils::Relu); }, "Relu"}, {[](postNodeConfig& cfg){ - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Add(PerChannel)"}}), {"Relu", "Add"}}; const auto fusingReluScaleShift = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Relu); + return utils::make_activation(cfg.input, cfg.type, utils::Relu); }, "Relu"}, {[](postNodeConfig& cfg){ - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Multiply(PerChannel)"}, {[](postNodeConfig& cfg){ - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Add(PerChannel)"}}), {"Relu", "Add"}}; const auto fusingScaleShift = fusingSpecificParams{ std::make_shared(std::vector{ {[](postNodeConfig& cfg) { - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Multiply(PerChannel)"}, {[](postNodeConfig& cfg) { - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Add(PerChannel)"}}), {"Add"} }; const auto fusingClampRoundAddRelu = fusingSpecificParams{ std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Clamp, {}, {3.0f, 6.0f}); + return utils::make_activation(cfg.input, cfg.type, utils::Clamp, {}, {3.0f, 6.0f}); }, "Clamp"}, {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::RoundHalfToEven); + return utils::make_activation(cfg.input, cfg.type, utils::RoundHalfToEven); }, "RoundHalfToEven"}, {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape(1, 1); + ov::Shape secondMultInShape(1, 1); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "AddPerTensor"}, {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Relu); + return utils::make_activation(cfg.input, cfg.type, utils::Relu); }, "Relu"}}), {"Clamp", "Round", "Add", "Relu"}}; const auto fusingScaleShiftAndFakeQuantizePerChannel = fusingSpecificParams{ std::make_shared(std::vector{ {[](postNodeConfig& cfg) { - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Multiply(PerChannel)"}, {[](postNodeConfig& cfg) { - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Add(PerChannel)"}, {[](postNodeConfig& cfg){ auto localPrc = cfg.input->get_element_type(); - ngraph::Shape newShape = generatePerChannelShape(cfg.target); - // auto newShape = ngraph::Shape(cfg.inputNode->get_output_partial_shape(0).size(), 1); + ov::Shape newShape = generatePerChannelShape(cfg.target); + // auto newShape = ov::Shape(cfg.inputNode->get_output_partial_shape(0).size(), 1); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerChannel)"}}), {"FakeQuantize"}}; const auto fusingFakeQuantizePerTensor = fusingSpecificParams{ std::make_shared(std::vector{ {[](postNodeConfig& cfg){ auto localPrc = cfg.input->get_element_type(); - ngraph::Shape newShape(cfg.input->get_output_partial_shape(0).size(), 1); + ov::Shape newShape(cfg.input->get_output_partial_shape(0).size(), 1); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerTensor)"}}), {"FakeQuantize"} }; const auto fusingFakeQuantizePerChannel = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ auto localPrc = cfg.input->get_element_type(); - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerChannel)"}}), {"FakeQuantize"}}; const auto fusingFakeQuantizePerChannelRelu = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ auto localPrc = cfg.input->get_element_type(); - ngraph::Shape newShape = generatePerChannelShape(cfg.target); + ov::Shape newShape = generatePerChannelShape(cfg.target); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerChannel)"}, {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Relu); + return utils::make_activation(cfg.input, cfg.type, utils::Relu); }, "Relu"}}), {"FakeQuantize", "Relu"}}; const auto fusingFQPerChannelSigmoidFQPerChannel = fusingSpecificParams{std::make_shared(std::vector{ @@ -308,19 +312,19 @@ const auto fusingFQPerChannelSigmoidFQPerChannel = fusingSpecificParams{std::mak auto shape = cfg.input->get_output_partial_shape(0); if (shape.size() == 1) OPENVINO_THROW("If shape.size() == 1 then Granularity can be PerTensor only"); - ngraph::Shape newShape(shape.size(), 1); + ov::Shape newShape(shape.size(), 1); newShape[1] = shape[1].get_length(); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerChannel)"}, {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Sigmoid); + return utils::make_activation(cfg.input, cfg.type, utils::Sigmoid); }, "Sigmoid"}, {[](postNodeConfig& cfg){ auto localPrc = cfg.input->get_element_type(); auto shape = cfg.input->get_output_partial_shape(0); if (shape.size() == 1) OPENVINO_THROW("If shape.size() == 1 then Granularity can be PerTensor only"); - ngraph::Shape newShape(shape.size(), 1); + ov::Shape newShape(shape.size(), 1); newShape[1] = shape[1].get_length(); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerChannel)"}}), {"FakeQuantize", "Sigmoid", "FakeQuantize"}}; @@ -331,30 +335,30 @@ const auto fusingFQPerChannelSigmoidFQPerTensor = fusingSpecificParams{std::make auto shape = cfg.input->get_output_partial_shape(0); if (shape.size() == 1) OPENVINO_THROW("If shape.size() == 1 then Granularity can be PerTensor only"); - ngraph::Shape newShape(shape.size(), 1); + ov::Shape newShape(shape.size(), 1); newShape[1] = shape[1].get_length(); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerChannel)"}, {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Sigmoid); + return utils::make_activation(cfg.input, cfg.type, utils::Sigmoid); }, "Sigmoid"}, {[](postNodeConfig& cfg){ auto localPrc = cfg.input->get_element_type(); auto shape = cfg.input->get_output_partial_shape(0); if (shape.size() == 1) OPENVINO_THROW("If shape.size() == 1 then Granularity can be PerTensor only"); - ngraph::Shape newShape(shape.size(), 1); + ov::Shape newShape(shape.size(), 1); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerTensor)"}}), {"FakeQuantize", "Sigmoid", "FakeQuantize"}}; const auto fusingFakeQuantizePerTensorRelu = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg) { auto localPrc = cfg.input->get_element_type(); - auto newShape = ngraph::Shape(cfg.input->get_output_partial_shape(0).size(), 1); + auto newShape = ov::Shape(cfg.input->get_output_partial_shape(0).size(), 1); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerTensor)"}, {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Relu); + return utils::make_activation(cfg.input, cfg.type, utils::Relu); }, "Relu"}}), {"FakeQuantize", "Relu"}}; const auto fusingSum = fusingSpecificParams{std::make_shared(std::vector{ @@ -362,7 +366,7 @@ const auto fusingSum = fusingSpecificParams{std::make_shared(std:: auto shape = cfg.input->get_output_partial_shape(0); ov::ParameterVector newParams{std::make_shared(cfg.type, shape)}; cfg.params.insert(cfg.params.end(), newParams.begin(), newParams.end()); - return std::make_shared(cfg.input, newParams[0]); + return std::make_shared(cfg.input, newParams[0]); }, "Add(Parameters)"}}), {"Add"}}; const auto fusingSumEluFQ = fusingSpecificParams{std::make_shared(std::vector{ @@ -370,116 +374,116 @@ const auto fusingSumEluFQ = fusingSpecificParams{std::make_shared( auto shape = cfg.input->get_output_partial_shape(0); ov::ParameterVector newParams{std::make_shared(cfg.type, shape)}; cfg.params.insert(cfg.params.end(), newParams.begin(), newParams.end()); - return std::make_shared(cfg.input, newParams[0]); + return std::make_shared(cfg.input, newParams[0]); }, "Add(Parameters)"}, {[](postNodeConfig& cfg){ - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::Elu, {}, {2.0f}); + return utils::make_activation(cfg.input, cfg.type, utils::Elu, {}, {2.0f}); }, "Elu"}, {[](postNodeConfig& cfg) { auto localPrc = cfg.input->get_element_type(); - auto newShape = ngraph::Shape(cfg.input->get_output_partial_shape(0).size(), 1); + auto newShape = ov::Shape(cfg.input->get_output_partial_shape(0).size(), 1); return ngraph::builder::makeFakeQuantize(cfg.input, localPrc, 256, newShape); }, "FakeQuantize(PerTensor)"}}), {"Add", "Elu", "FakeQuantize"}}; const auto fusingMultiplyPerTensor = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape(1, 1); + ov::Shape secondMultInShape(1, 1); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "Multiply(PerTensor)"}}), {"Multiply"}}; const auto fusingMultiplyPerChannel = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape = generatePerChannelShape(cfg.target); + ov::Shape secondMultInShape = generatePerChannelShape(cfg.target); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "Multiply(PerChannel)"}}), {"Multiply"}}; const auto fusingMultiplyAddPerChannel = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg) { - ngraph::Shape newShape = generatePerChannelShape(cfg.input); + ov::Shape newShape = generatePerChannelShape(cfg.input); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Multiply(PerChannel)"}, {[](postNodeConfig& cfg) { - ngraph::Shape newShape = generatePerChannelShape(cfg.input); + ov::Shape newShape = generatePerChannelShape(cfg.input); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Add(PerChannel)"}}), {"Add"} }; const auto fusingAddPerTensor = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape(1, 1); + ov::Shape secondMultInShape(1, 1); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "Add(PerTensor)"}}), {"Add"}}; const auto fusingAddPerChannel = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape = generatePerChannelShape(cfg.target); + ov::Shape secondMultInShape = generatePerChannelShape(cfg.target); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "Add(PerChannel)"}}), {"Add"}}; const auto fusingSubtractPerTensor = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape(1, 1); + ov::Shape secondMultInShape(1, 1); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "Subtract(PerTensor)"}}), {"Subtract"}}; const auto fusingSubtractPerChannel = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape = generatePerChannelShape(cfg.target); + ov::Shape secondMultInShape = generatePerChannelShape(cfg.target); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "Subtract(PerChannel)"}}), {"Subtract"}}; const auto fusingDividePerTensor = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape(1, 1); + ov::Shape secondMultInShape(1, 1); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "Divide(PerTensor)"}}), {"Divide"}}; const auto fusingDividePerChannel = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ - ngraph::Shape secondMultInShape = generatePerChannelShape(cfg.target); + ov::Shape secondMultInShape = generatePerChannelShape(cfg.target); auto secondMultInput = ngraph::builder::makeConstant(cfg.type, secondMultInShape, std::vector{}, true); - return std::make_shared(cfg.input, secondMultInput); + return std::make_shared(cfg.input, secondMultInput); }, "Divide(PerChannel)"}}), {"Divide"}}; const auto fusingPRelu1D = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ auto shape = cfg.input->get_output_partial_shape(0); - ngraph::Shape newShape({static_cast(shape[1].get_length())}); - auto data = NGraphFunctions::Utils::generateVector(ngraph::shape_size(newShape)); - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::LeakyRelu, newShape, data); + ov::Shape newShape({static_cast(shape[1].get_length())}); + auto data = NGraphFunctions::Utils::generateVector(ov::shape_size(newShape)); + return utils::make_activation(cfg.input, cfg.type, utils::LeakyRelu, newShape, data); }, "PRelu1D"}}), {"PRelu"}}; const auto fusingPRelu1DScaleShift = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg){ auto shape = cfg.input->get_output_partial_shape(0); - ngraph::Shape newShape({static_cast(shape[1].get_length())}); - auto data = NGraphFunctions::Utils::generateVector(ngraph::shape_size(newShape)); - return ngraph::builder::makeActivation(cfg.input, cfg.type, ngraph::helpers::LeakyRelu, newShape, data); + ov::Shape newShape({static_cast(shape[1].get_length())}); + auto data = NGraphFunctions::Utils::generateVector(ov::shape_size(newShape)); + return utils::make_activation(cfg.input, cfg.type, utils::LeakyRelu, newShape, data); }, "PRelu1D"}, {[](postNodeConfig& cfg) { - ngraph::Shape newShape = generatePerChannelShape(cfg.input); + ov::Shape newShape = generatePerChannelShape(cfg.input); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Multiply(PerChannel)"}, {[](postNodeConfig& cfg) { - ngraph::Shape newShape = generatePerChannelShape(cfg.input); + ov::Shape newShape = generatePerChannelShape(cfg.input); auto constNode = ngraph::builder::makeConstant(cfg.type, newShape, std::vector{}, true); - return std::make_shared(cfg.input, constNode); + return std::make_shared(cfg.input, constNode); }, "Add(PerChannel)"}}), {"Add"} }; const auto fusingBias = fusingSpecificParams{std::make_shared(std::vector{ {[](postNodeConfig& cfg) { size_t last_dim = cfg.input->get_output_partial_shape(0).rbegin()->get_length(); - auto bias = ngraph::builder::makeConstant(cfg.type, ngraph::Shape{last_dim}, std::vector{}, true); - return std::make_shared(cfg.input, bias); + auto bias = ngraph::builder::makeConstant(cfg.type, ov::Shape{last_dim}, std::vector{}, true); + return std::make_shared(cfg.input, bias); }, "fusingBias"}}), {"Add"}}; } // namespace CPUTestUtils diff --git a/src/plugins/intel_cpu/tests/functional/test_utils/x64/filter_cpu_info.cpp b/src/plugins/intel_cpu/tests/functional/test_utils/x64/filter_cpu_info.cpp index 1e22e6e1cd08c6..9944ddba9b1dfa 100644 --- a/src/plugins/intel_cpu/tests/functional/test_utils/x64/filter_cpu_info.cpp +++ b/src/plugins/intel_cpu/tests/functional/test_utils/x64/filter_cpu_info.cpp @@ -4,7 +4,6 @@ #include "test_utils/cpu_test_utils.hpp" #include "test_utils/filter_cpu_info.hpp" -#include "ie_ngraph_utils.hpp" #include "openvino/core/type/element_type.hpp" #include "utils/rt_info/memory_formats_attribute.hpp" #include "utils/general_utils.h" From f9d20d5aa0bdca18f9c342928f7d85a35a1d8afb Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Tue, 5 Dec 2023 11:08:46 +0400 Subject: [PATCH 08/20] [TF FE] Support different types: tf.i8, u8, i16, u16, i32, u32, i64, u64, f16, f32, bf16 (#21439) * [TF FE] Support different types: u16, u64, u32, boolean Support constants of different types and dtype attribute values Signed-off-by: Kazantsev, Roman * Use map instead of unordered_map Signed-off-by: Kazantsev, Roman * Add tests with different types Signed-off-by: Kazantsev, Roman --------- Signed-off-by: Kazantsev, Roman --- .../tensorflow/src/graph_iterator_meta.cpp | 17 +-- .../src/graph_iterator_saved_model.cpp | 17 +-- src/frontends/tensorflow/src/tf_utils.cpp | 142 +++++++++++++----- .../tensorflow_tests/test_tf_AddTypes.py | 51 +++++++ 4 files changed, 158 insertions(+), 69 deletions(-) create mode 100644 tests/layer_tests/tensorflow_tests/test_tf_AddTypes.py diff --git a/src/frontends/tensorflow/src/graph_iterator_meta.cpp b/src/frontends/tensorflow/src/graph_iterator_meta.cpp index 06f2d31f389a27..499a5478d4ff1b 100644 --- a/src/frontends/tensorflow/src/graph_iterator_meta.cpp +++ b/src/frontends/tensorflow/src/graph_iterator_meta.cpp @@ -18,25 +18,12 @@ namespace frontend { namespace tensorflow { bool GraphIteratorMeta::is_valid_signature(const ::tensorflow::SignatureDef& signature) const { - const std::map<::tensorflow::DataType, ov::element::Type> types{ - {::tensorflow::DataType::DT_BOOL, ov::element::boolean}, - {::tensorflow::DataType::DT_INT16, ov::element::i16}, - {::tensorflow::DataType::DT_INT32, ov::element::i32}, - {::tensorflow::DataType::DT_INT64, ov::element::i64}, - {::tensorflow::DataType::DT_HALF, ov::element::f16}, - {::tensorflow::DataType::DT_FLOAT, ov::element::f32}, - {::tensorflow::DataType::DT_DOUBLE, ov::element::f64}, - {::tensorflow::DataType::DT_UINT8, ov::element::u8}, - {::tensorflow::DataType::DT_INT8, ov::element::i8}, - {::tensorflow::DataType::DT_BFLOAT16, ov::element::bf16}, - {::tensorflow::DataType::DT_STRING, ov::element::dynamic}}; - for (const auto& it : signature.inputs()) { - if (it.second.name().empty() || types.find(it.second.dtype()) == types.end()) + if (it.second.name().empty()) return false; } for (const auto& it : signature.outputs()) { - if (it.second.name().empty() || types.find(it.second.dtype()) == types.end()) + if (it.second.name().empty()) return false; } return true; diff --git a/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp b/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp index 803e7d694bc69a..8f31bef0de7af3 100644 --- a/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp +++ b/src/frontends/tensorflow/src/graph_iterator_saved_model.cpp @@ -18,25 +18,12 @@ namespace frontend { namespace tensorflow { bool GraphIteratorSavedModel::is_valid_signature(const ::tensorflow::SignatureDef& signature) const { - const std::map<::tensorflow::DataType, ov::element::Type> types{ - {::tensorflow::DataType::DT_BOOL, ov::element::boolean}, - {::tensorflow::DataType::DT_INT16, ov::element::i16}, - {::tensorflow::DataType::DT_INT32, ov::element::i32}, - {::tensorflow::DataType::DT_INT64, ov::element::i64}, - {::tensorflow::DataType::DT_HALF, ov::element::f16}, - {::tensorflow::DataType::DT_FLOAT, ov::element::f32}, - {::tensorflow::DataType::DT_DOUBLE, ov::element::f64}, - {::tensorflow::DataType::DT_UINT8, ov::element::u8}, - {::tensorflow::DataType::DT_INT8, ov::element::i8}, - {::tensorflow::DataType::DT_BFLOAT16, ov::element::bf16}, - {::tensorflow::DataType::DT_STRING, ov::element::dynamic}}; - for (const auto& it : signature.inputs()) { - if (it.second.name().empty() || types.find(it.second.dtype()) == types.end()) + if (it.second.name().empty()) return false; } for (const auto& it : signature.outputs()) { - if (it.second.name().empty() || types.find(it.second.dtype()) == types.end()) + if (it.second.name().empty()) return false; } return true; diff --git a/src/frontends/tensorflow/src/tf_utils.cpp b/src/frontends/tensorflow/src/tf_utils.cpp index 7354b871f3a370..c3f1c7cf0d13dd 100644 --- a/src/frontends/tensorflow/src/tf_utils.cpp +++ b/src/frontends/tensorflow/src/tf_utils.cpp @@ -82,17 +82,17 @@ void extract_tensor_content(const std::string& tensor_content, Tensor* values) { # pragma warning(disable : 4244) // possible loss of data # pragma warning(disable : 4267) // possible loss of data #endif -template +template void extract_compressed_tensor_content(const ::tensorflow::TensorProto& tensor_proto, int64_t val_size, Tensor* values) { - auto val_lastsaved = static_cast(0); - auto values_data = values->data(); + auto val_lastsaved = static_cast(0); + auto values_data = values->data(); for (size_t i = 0; i < values->get_size(); i++) { if (val_size == 0) { - values_data[i] = static_cast(0); + values_data[i] = static_cast(0); } else if (static_cast(i) < val_size) { - auto val_i = static_cast(0); + auto val_i = static_cast(0); switch (values->get_element_type()) { // TODO: there are more element types to support here case boolean: @@ -113,13 +113,34 @@ void extract_compressed_tensor_content(const ::tensorflow::TensorProto& tensor_p case f64: val_i = tensor_proto.double_val()[i]; break; + case u8: + val_i = tensor_proto.int_val()[i]; + break; + case u16: + val_i = tensor_proto.int_val()[i]; + break; + case u64: + val_i = tensor_proto.uint64_val()[i]; + break; + case i8: + val_i = tensor_proto.int_val()[i]; + break; + case bf16: + val_i = bfloat16::from_bits(tensor_proto.half_val()[i]); + break; + case u32: + val_i = tensor_proto.uint32_val()[i]; + break; + case i16: + val_i = tensor_proto.int_val()[i]; + break; default: FRONT_END_THROW("Encountered unknown element type " + values->get_element_type().get_type_name()); } - values_data[i] = val_i; + values_data[i] = static_cast(val_i); val_lastsaved = val_i; } else { - values_data[i] = val_lastsaved; + values_data[i] = static_cast(val_lastsaved); } } } @@ -150,16 +171,18 @@ bool CfMarkerType::is_copyable() const { } Type get_ov_type(const ::tensorflow::DataType& type) { - static const map<::tensorflow::DataType, Type> type_map{{::tensorflow::DataType::DT_BOOL, boolean}, - {::tensorflow::DataType::DT_INT16, i16}, - {::tensorflow::DataType::DT_INT32, i32}, - {::tensorflow::DataType::DT_INT64, i64}, - {::tensorflow::DataType::DT_HALF, f16}, - {::tensorflow::DataType::DT_FLOAT, f32}, - {::tensorflow::DataType::DT_DOUBLE, f64}, - {::tensorflow::DataType::DT_UINT8, u8}, - {::tensorflow::DataType::DT_INT8, i8}, - {::tensorflow::DataType::DT_BFLOAT16, bf16}}; + using ::tensorflow::DataType; + + static map type_map{ + {DataType::DT_FLOAT, f32}, {DataType::DT_DOUBLE, f64}, {DataType::DT_INT32, i32}, + {DataType::DT_UINT8, u8}, {DataType::DT_INT16, i16}, {DataType::DT_INT8, i8}, + {DataType::DT_INT64, i64}, {DataType::DT_BOOL, boolean}, {DataType::DT_BFLOAT16, bf16}, + {DataType::DT_UINT16, u16}, {DataType::DT_HALF, f16}, {DataType::DT_UINT32, u32}, + {DataType::DT_UINT64, u64}, {DataType::DT_FLOAT_REF, f32}, {DataType::DT_DOUBLE_REF, f64}, + {DataType::DT_INT32_REF, i32}, {DataType::DT_UINT8_REF, u8}, {DataType::DT_INT16_REF, i16}, + {DataType::DT_INT8_REF, i8}, {DataType::DT_INT64_REF, i64}, {DataType::DT_BOOL_REF, boolean}, + {DataType::DT_BFLOAT16_REF, bf16}, {DataType::DT_UINT16_REF, u16}, {DataType::DT_HALF_REF, f16}, + {DataType::DT_UINT32_REF, u32}, {DataType::DT_UINT64_REF, u64}}; auto it = type_map.find(type); // for all unsupported types return dynamic type @@ -191,36 +214,49 @@ Any unpack_tensor_proto(const ::tensorflow::TensorProto& tensor_proto, } return data; } + Tensor res(ov_type, pshape.get_shape()); auto tensor_content = tensor_proto.tensor_content(); if (!tensor_content.empty() && tensor_proto.has_tensor_shape()) { switch (ov_type) { + case f32: + extract_tensor_content(tensor_content, &res); + break; case u8: extract_tensor_content(tensor_content, &res); break; - case i8: - extract_tensor_content(tensor_content, &res); + case i64: + extract_tensor_content(tensor_content, &res); break; - case i16: - extract_tensor_content(tensor_content, &res); + case u16: + extract_tensor_content(tensor_content, &res); + break; + case u64: + extract_tensor_content(tensor_content, &res); break; case i32: extract_tensor_content(tensor_content, &res); break; - case i64: - extract_tensor_content(tensor_content, &res); + case i8: + extract_tensor_content(tensor_content, &res); break; - case f16: - extract_tensor_content(tensor_content, &res); + case bf16: + extract_tensor_content(tensor_content, &res); break; - case f32: - extract_tensor_content(tensor_content, &res); + case u32: + extract_tensor_content(tensor_content, &res); break; case f64: extract_tensor_content(tensor_content, &res); break; - case bf16: - extract_tensor_content(tensor_content, &res); + case i16: + extract_tensor_content(tensor_content, &res); + break; + case boolean: + extract_tensor_content(tensor_content, &res); + break; + case f16: + extract_tensor_content(tensor_content, &res); break; default: FRONT_END_THROW("Encountered unknown element type " + ov_type.get_type_name()); @@ -228,30 +264,58 @@ Any unpack_tensor_proto(const ::tensorflow::TensorProto& tensor_proto, } else { int64_t val_size = 0; switch (ov_type) { - case boolean: - val_size = tensor_proto.bool_val_size(); - extract_compressed_tensor_content(tensor_proto, val_size, &res); + case f32: + val_size = tensor_proto.float_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); break; - case i32: + case u8: val_size = tensor_proto.int_val_size(); - extract_compressed_tensor_content(tensor_proto, val_size, &res); + extract_compressed_tensor_content(tensor_proto, val_size, &res); break; case i64: val_size = tensor_proto.int64_val_size(); extract_compressed_tensor_content(tensor_proto, val_size, &res); break; - case f16: + case u16: + val_size = tensor_proto.int_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); + break; + case u64: + val_size = tensor_proto.uint64_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); + break; + case i32: + val_size = tensor_proto.int_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); + break; + case i8: + val_size = tensor_proto.int_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); + break; + case bf16: val_size = tensor_proto.half_val_size(); - extract_compressed_tensor_content(tensor_proto, val_size, &res); + extract_compressed_tensor_content(tensor_proto, val_size, &res); break; - case f32: - val_size = tensor_proto.float_val_size(); - extract_compressed_tensor_content(tensor_proto, val_size, &res); + case u32: + val_size = tensor_proto.uint32_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); break; case f64: val_size = tensor_proto.double_val_size(); extract_compressed_tensor_content(tensor_proto, val_size, &res); break; + case i16: + val_size = tensor_proto.int_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); + break; + case boolean: + val_size = tensor_proto.bool_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); + break; + case f16: + val_size = tensor_proto.half_val_size(); + extract_compressed_tensor_content(tensor_proto, val_size, &res); + break; default: FRONT_END_THROW("Encountered unknown element type " + ov_type.get_type_name()); } diff --git a/tests/layer_tests/tensorflow_tests/test_tf_AddTypes.py b/tests/layer_tests/tensorflow_tests/test_tf_AddTypes.py new file mode 100644 index 00000000000000..76d61b3d3a936e --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_AddTypes.py @@ -0,0 +1,51 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + +rng = np.random.default_rng() + + +class TestAddTypes(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'x' in inputs_info, "Test error: inputs_info must contain `x`" + x_shape = inputs_info['x'] + inputs_data = {} + if np.issubdtype(self.input_type, np.signedinteger): + inputs_data['x'] = rng.integers(-8, 8, x_shape).astype(self.input_type) + else: + inputs_data['x'] = rng.integers(0, 8, x_shape).astype(self.input_type) + return inputs_data + + def create_add_types_net(self, const_shape, input_type): + self.input_type = input_type + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + x = tf.compat.v1.placeholder(input_type, [], 'x') + if np.issubdtype(self.input_type, np.signedinteger): + const_value = rng.integers(-8, 8, const_shape).astype(self.input_type) + else: + const_value = rng.integers(0, 8, const_shape).astype(self.input_type) + const_input = tf.constant(const_value, dtype=input_type) + tf.raw_ops.Add(x=x, y=const_input) + tf.compat.v1.global_variables_initializer() + + tf_net = sess.graph_def + + return tf_net, None + + @pytest.mark.parametrize("const_shape", [[], [2], [3, 4], [3, 2, 1, 4]]) + @pytest.mark.parametrize("input_type", [np.int8, np.uint8, np.int16, + np.int32, np.int64, + np.float16, np.float32, np.float64]) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_add_types(self, const_shape, input_type, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_add_types_net(const_shape, input_type), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend, use_old_api=use_old_api) From 24209239bf8fed1fc42253632332252fea9cd1aa Mon Sep 17 00:00:00 2001 From: Pawel Raasz Date: Tue, 5 Dec 2023 08:23:19 +0100 Subject: [PATCH 09/20] Restore CC feature in operators evaluate (#21446) --- src/core/src/op/abs.cpp | 11 +-- src/core/src/op/acos.cpp | 11 +-- src/core/src/op/acosh.cpp | 11 +-- src/core/src/op/add.cpp | 18 ++--- src/core/src/op/asin.cpp | 11 +-- src/core/src/op/asinh.cpp | 11 +-- src/core/src/op/atan.cpp | 11 +-- src/core/src/op/atanh.cpp | 11 +-- src/core/src/op/ceiling.cpp | 12 ++-- src/core/src/op/clamp.cpp | 16 +++-- src/core/src/op/cos.cpp | 11 +-- src/core/src/op/cosh.cpp | 11 +-- src/core/src/op/cum_sum.cpp | 15 +++-- src/core/src/op/divide.cpp | 19 +++--- src/core/src/op/equal.cpp | 18 ++--- src/core/src/op/erf.cpp | 11 +-- src/core/src/op/exp.cpp | 11 +-- src/core/src/op/eye.cpp | 11 +-- src/core/src/op/fake_convert.cpp | 13 ++-- src/core/src/op/fake_quantize.cpp | 31 +++++---- src/core/src/op/floor.cpp | 12 ++-- src/core/src/op/floor_mod.cpp | 18 ++--- src/core/src/op/gelu.cpp | 13 ++-- src/core/src/op/greater.cpp | 17 +++-- src/core/src/op/greater_eq.cpp | 17 +++-- src/core/src/op/grid_sample.cpp | 34 ++++++---- src/core/src/op/hsigmoid.cpp | 12 ++-- src/core/src/op/hswish.cpp | 11 +-- src/core/src/op/less.cpp | 17 +++-- src/core/src/op/less_eq.cpp | 17 +++-- src/core/src/op/log.cpp | 11 +-- src/core/src/op/logical_not.cpp | 12 ++-- src/core/src/op/matmul.cpp | 21 +++--- src/core/src/op/max_pool.cpp | 75 ++++++++++++--------- src/core/src/op/maximum.cpp | 17 +++-- src/core/src/op/minimum.cpp | 17 +++-- src/core/src/op/mish.cpp | 11 +-- src/core/src/op/mod.cpp | 17 +++-- src/core/src/op/multiply.cpp | 17 +++-- src/core/src/op/negative.cpp | 11 +-- src/core/src/op/non_zero.cpp | 22 ++++-- src/core/src/op/not_equal.cpp | 17 +++-- src/core/src/op/one_hot.cpp | 21 +++--- src/core/src/op/power.cpp | 17 +++-- src/core/src/op/prelu.cpp | 15 +++-- src/core/src/op/range.cpp | 26 ++++--- src/core/src/op/reduce_l1.cpp | 11 +-- src/core/src/op/reduce_l2.cpp | 11 +-- src/core/src/op/reduce_logical_and.cpp | 11 +-- src/core/src/op/reduce_logical_or.cpp | 11 +-- src/core/src/op/reduce_max.cpp | 11 +-- src/core/src/op/reduce_mean.cpp | 11 +-- src/core/src/op/reduce_min.cpp | 11 +-- src/core/src/op/reduce_prod.cpp | 11 +-- src/core/src/op/reduce_sum.cpp | 11 +-- src/core/src/op/relu.cpp | 11 +-- src/core/src/op/round.cpp | 14 ++-- src/core/src/op/scatter_elements_update.cpp | 48 +++++++------ src/core/src/op/scatter_nd_update.cpp | 38 ++++++----- src/core/src/op/sigmoid.cpp | 11 +-- src/core/src/op/sign.cpp | 11 +-- src/core/src/op/sin.cpp | 11 +-- src/core/src/op/sinh.cpp | 11 +-- src/core/src/op/softmax.cpp | 26 ++++--- src/core/src/op/softplus.cpp | 11 +-- src/core/src/op/softsign.cpp | 11 +-- src/core/src/op/sqrt.cpp | 11 +-- src/core/src/op/subtract.cpp | 17 +++-- src/core/src/op/swish.cpp | 13 ++-- src/core/src/op/tan.cpp | 11 +-- src/core/src/op/tanh.cpp | 11 +-- src/core/src/op/topk.cpp | 42 +++++++----- src/core/src/op/xor.cpp | 17 +++-- 73 files changed, 718 insertions(+), 475 deletions(-) diff --git a/src/core/src/op/abs.cpp b/src/core/src/op/abs.cpp index 43e034e3dc0560..8b87bd765794b0 100644 --- a/src/core/src/op/abs.cpp +++ b/src/core/src/op/abs.cpp @@ -42,10 +42,13 @@ bool Abs::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Abs_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i32, i64, u32, u64), + abs::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Abs::has_evaluate() const { diff --git a/src/core/src/op/acos.cpp b/src/core/src/op/acos.cpp index 8721960f53b1f7..1aab9570405544 100644 --- a/src/core/src/op/acos.cpp +++ b/src/core/src/op/acos.cpp @@ -41,10 +41,13 @@ bool ov::op::v0::Acos::evaluate(TensorVector& outputs, const TensorVector& input outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Acos_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + acos::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool ov::op::v0::Acos::has_evaluate() const { diff --git a/src/core/src/op/acosh.cpp b/src/core/src/op/acosh.cpp index 115ce76ac63335..85fbfb31115c61 100644 --- a/src/core/src/op/acosh.cpp +++ b/src/core/src/op/acosh.cpp @@ -41,10 +41,13 @@ bool ov::op::v3::Acosh::evaluate(TensorVector& outputs, const TensorVector& inpu outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v3_Acosh_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + acosh::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool ov::op::v3::Acosh::has_evaluate() const { diff --git a/src/core/src/op/add.cpp b/src/core/src/op/add.cpp index 0d09563b9ae201..ee81de632cf647 100644 --- a/src/core/src/op/add.cpp +++ b/src/core/src/op/add.cpp @@ -48,14 +48,16 @@ bool Add::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) co outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply( - inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Add_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i8, i16, i32, i64, u8, u16, u32, u64), + add::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Add::has_evaluate() const { diff --git a/src/core/src/op/asin.cpp b/src/core/src/op/asin.cpp index 00832dce255510..19183014f30bed 100644 --- a/src/core/src/op/asin.cpp +++ b/src/core/src/op/asin.cpp @@ -41,10 +41,13 @@ bool Asin::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Asin_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + asin::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Asin::has_evaluate() const { diff --git a/src/core/src/op/asinh.cpp b/src/core/src/op/asinh.cpp index 80e7396f27da61..aa2ecdd432f944 100644 --- a/src/core/src/op/asinh.cpp +++ b/src/core/src/op/asinh.cpp @@ -40,10 +40,13 @@ bool Asinh::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v3_Asinh_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + asinh::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Asinh::has_evaluate() const { diff --git a/src/core/src/op/atan.cpp b/src/core/src/op/atan.cpp index 6732d4b952a29e..2004a3a3679248 100644 --- a/src/core/src/op/atan.cpp +++ b/src/core/src/op/atan.cpp @@ -43,10 +43,13 @@ bool Atan::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Atan_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + atan::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Atan::has_evaluate() const { diff --git a/src/core/src/op/atanh.cpp b/src/core/src/op/atanh.cpp index b17431862fa997..c619f01796af96 100644 --- a/src/core/src/op/atanh.cpp +++ b/src/core/src/op/atanh.cpp @@ -40,10 +40,13 @@ bool op::v3::Atanh::evaluate(TensorVector& outputs, const TensorVector& inputs) outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v3_Atanh_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + atanh::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool op::v3::Atanh::has_evaluate() const { diff --git a/src/core/src/op/ceiling.cpp b/src/core/src/op/ceiling.cpp index c46ed21ae03ebc..17139143523ed4 100644 --- a/src/core/src/op/ceiling.cpp +++ b/src/core/src/op/ceiling.cpp @@ -44,11 +44,13 @@ bool Ceiling::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply( - inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Ceiling_evaluate, + OV_PP_ET_LIST(f16, f32, i8, i16, i32, i64, u8, u16, u32, u64), + ceiling::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Ceiling::has_evaluate() const { diff --git a/src/core/src/op/clamp.cpp b/src/core/src/op/clamp.cpp index f3b0d19af17b82..76350a49b24c42 100644 --- a/src/core/src/op/clamp.cpp +++ b/src/core/src/op/clamp.cpp @@ -68,13 +68,15 @@ bool Clamp::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply( - inputs[0].get_element_type(), - inputs[0], - outputs[0], - get_min(), - get_max(), - shape_size(in_shape)); + return IF_TYPE_OF(v0_Clamp_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i8, i16, i32, i64, u8, u16, u32, u64), + clamp::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + get_min(), + get_max(), + shape_size(in_shape)); } bool Clamp::has_evaluate() const { diff --git a/src/core/src/op/cos.cpp b/src/core/src/op/cos.cpp index 9fd6562838adf6..575d148f2d96cb 100644 --- a/src/core/src/op/cos.cpp +++ b/src/core/src/op/cos.cpp @@ -47,10 +47,13 @@ bool Cos::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Cos_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + cos::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Cos::has_evaluate() const { diff --git a/src/core/src/op/cosh.cpp b/src/core/src/op/cosh.cpp index 1792fba5c3e694..ebc05f7612770f 100644 --- a/src/core/src/op/cosh.cpp +++ b/src/core/src/op/cosh.cpp @@ -47,10 +47,13 @@ bool Cosh::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Cosh_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + cosh::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Cosh::has_evaluate() const { diff --git a/src/core/src/op/cum_sum.cpp b/src/core/src/op/cum_sum.cpp index 774e2be80c8fbc..a8737d59b7c82d 100644 --- a/src/core/src/op/cum_sum.cpp +++ b/src/core/src/op/cum_sum.cpp @@ -35,12 +35,15 @@ bool evaluate(TensorVector& outputs, const TensorVector& inputs, const bool excl const auto axis = ov::get_tensor_data_as(inputs[1]).front(); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - axis, - exclusive, - reverse); + return IF_TYPE_OF(CumSum_evaluate, + f32, + cumsum::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + axis, + exclusive, + reverse); } } // namespace } // namespace cumsum diff --git a/src/core/src/op/divide.cpp b/src/core/src/op/divide.cpp index c2a9020cb03654..67a0b6c7265b4a 100644 --- a/src/core/src/op/divide.cpp +++ b/src/core/src/op/divide.cpp @@ -242,14 +242,17 @@ bool Divide::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob(), - is_pythondiv()); + return IF_TYPE_OF(v1_Divide_evaluate, + OV_PP_ET_LIST(f16, bf16, f32, i32, i64, u32, u64), + divide::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob(), + is_pythondiv()); return true; } diff --git a/src/core/src/op/equal.cpp b/src/core/src/op/equal.cpp index 7f23b8970e204a..3460d1c7c2eb7a 100644 --- a/src/core/src/op/equal.cpp +++ b/src/core/src/op/equal.cpp @@ -101,14 +101,16 @@ bool Equal::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(ov::op::infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply( - inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Equal_evaluate, + OV_PP_ET_LIST(boolean, bf16, f16, f32, f64, i8, i16, i32, i64, u8, u16, u32, u64), + equal::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Equal::evaluate_lower(TensorVector& output_values) const { diff --git a/src/core/src/op/erf.cpp b/src/core/src/op/erf.cpp index 1315453b2d626a..4aa2dda2091ed0 100644 --- a/src/core/src/op/erf.cpp +++ b/src/core/src/op/erf.cpp @@ -43,10 +43,13 @@ bool Erf::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(in_shape)); + return IF_TYPE_OF(v0_Erf_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + erf::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Erf::has_evaluate() const { diff --git a/src/core/src/op/exp.cpp b/src/core/src/op/exp.cpp index ecd4d37913306b..c067c36748fce6 100644 --- a/src/core/src/op/exp.cpp +++ b/src/core/src/op/exp.cpp @@ -44,10 +44,13 @@ bool Exp::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(in_shape)); + return IF_TYPE_OF(v0_Exp_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + exp::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(in_shape)); } bool Exp::has_evaluate() const { diff --git a/src/core/src/op/eye.cpp b/src/core/src/op/eye.cpp index 86fe1c62bafffa..a3612c40e61c3f 100644 --- a/src/core/src/op/eye.cpp +++ b/src/core/src/op/eye.cpp @@ -123,10 +123,13 @@ bool Eye::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(output_shape); using namespace ov::element; - return IfTypeOf::apply(outputs[0].get_element_type(), - outputs[0], - output_shape, - diagonal_index); + return IF_TYPE_OF(v9_Eye_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, f64, i8, i32, i64, u8), + eye::Evaluate, + outputs[0].get_element_type(), + outputs[0], + output_shape, + diagonal_index); } } // namespace v9 } // namespace op diff --git a/src/core/src/op/fake_convert.cpp b/src/core/src/op/fake_convert.cpp index 48a857f5aa81da..0aad25b58917d2 100644 --- a/src/core/src/op/fake_convert.cpp +++ b/src/core/src/op/fake_convert.cpp @@ -135,10 +135,15 @@ bool FakeConvert::evaluate(ov::TensorVector& outputs, const ov::TensorVector& in outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - outputs, - inputs, - get_destination_type()); + return IF_TYPE_OF(v13_FakeConvert_evaluate, + OV_PP_ET_LIST(bf16, f16, f32), + fake_convert_details::Evaluate, + inputs[0].get_element_type(), + outputs, + inputs, + get_destination_type()); + + return true; } } // namespace v13 } // namespace op diff --git a/src/core/src/op/fake_quantize.cpp b/src/core/src/op/fake_quantize.cpp index 9b7ba0e991ae11..b15137e92038ed 100644 --- a/src/core/src/op/fake_quantize.cpp +++ b/src/core/src/op/fake_quantize.cpp @@ -113,20 +113,23 @@ bool FakeQuantize::evaluate(TensorVector& outputs, const TensorVector& inputs) c outputs[0].set_shape(shape0); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - inputs[2], - inputs[3], - inputs[4], - outputs[0], - shape0, - inputs[1].get_shape(), - inputs[2].get_shape(), - inputs[3].get_shape(), - inputs[4].get_shape(), - get_levels(), - get_auto_broadcast()); + return IF_TYPE_OF(v0_FakeQuantize_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + fake_quantize::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + inputs[2], + inputs[3], + inputs[4], + outputs[0], + shape0, + inputs[1].get_shape(), + inputs[2].get_shape(), + inputs[3].get_shape(), + inputs[4].get_shape(), + get_levels(), + get_auto_broadcast()); } bool FakeQuantize::has_evaluate() const { diff --git a/src/core/src/op/floor.cpp b/src/core/src/op/floor.cpp index c884dac18cab36..e84e42a9cd7884 100644 --- a/src/core/src/op/floor.cpp +++ b/src/core/src/op/floor.cpp @@ -44,11 +44,13 @@ bool Floor::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply( - inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(in_shape)); + return IF_TYPE_OF(v0_Floor_evaluate, + OV_PP_ET_LIST(f16, f32, i8, i16, i32, i64, u8, u16, u32, u64), + floor::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(in_shape)); } bool Floor::has_evaluate() const { diff --git a/src/core/src/op/floor_mod.cpp b/src/core/src/op/floor_mod.cpp index 225c70a5e5d5eb..1c45edf4af35d8 100644 --- a/src/core/src/op/floor_mod.cpp +++ b/src/core/src/op/floor_mod.cpp @@ -48,14 +48,16 @@ bool FloorMod::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply( - inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_FloorMod_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i8, i32, i64, u8, u32, u64), + floor_mod::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool FloorMod::has_evaluate() const { diff --git a/src/core/src/op/gelu.cpp b/src/core/src/op/gelu.cpp index cc261ca1650a1b..c8264e2ac76c9b 100644 --- a/src/core/src/op/gelu.cpp +++ b/src/core/src/op/gelu.cpp @@ -104,11 +104,14 @@ bool Gelu::evaluate(TensorVector& outputs, const TensorVector& inputs) const { const auto count = shape_size(input_shape); outputs[0].set_shape(input_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - m_approximation_mode, - count); + return IF_TYPE_OF(v7_Gelu_evaluate, + OV_PP_ET_LIST(f16, f32), + gelu::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + m_approximation_mode, + count); } bool Gelu::has_evaluate() const { diff --git a/src/core/src/op/greater.cpp b/src/core/src/op/greater.cpp index 76715745a5fba7..ed09e77f4b07d7 100644 --- a/src/core/src/op/greater.cpp +++ b/src/core/src/op/greater.cpp @@ -53,13 +53,16 @@ bool Greater::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Greater_evaluate, + OV_PP_ET_LIST(boolean, f16, f32, i32, i64, u32, u64), + greater::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Greater::has_evaluate() const { diff --git a/src/core/src/op/greater_eq.cpp b/src/core/src/op/greater_eq.cpp index a3bd099262a6b3..4f111431f8ab35 100644 --- a/src/core/src/op/greater_eq.cpp +++ b/src/core/src/op/greater_eq.cpp @@ -53,13 +53,16 @@ bool GreaterEqual::evaluate(TensorVector& outputs, const TensorVector& inputs) c outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_GreaterEqual_evaluate, + OV_PP_ET_LIST(boolean, f16, f32, i32, i64, u32, u64), + greater_equal::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool GreaterEqual::has_evaluate() const { diff --git a/src/core/src/op/grid_sample.cpp b/src/core/src/op/grid_sample.cpp index bb81c9778939cf..d5ed0790d4ae12 100644 --- a/src/core/src/op/grid_sample.cpp +++ b/src/core/src/op/grid_sample.cpp @@ -25,13 +25,16 @@ struct Evaluate : element::NoAction { const Shape& grid_shape, const GridSample::Attributes& attributes) { using namespace ov::element; - return IfTypeOf::apply(grid.get_element_type(), - output.data(), - data.data(), - grid, - data_shape, - grid_shape, - attributes); + return IF_TYPE_OF(eval_by_grid_type, + OV_PP_ET_LIST(f32), + EvalByGridType, + grid.get_element_type(), + output.data(), + data.data(), + grid, + data_shape, + grid_shape, + attributes); } private: @@ -100,13 +103,16 @@ bool GridSample::evaluate(TensorVector& outputs, const TensorVector& inputs) con outputs[0].set_shape(out_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - outputs[0], - inputs[0], - inputs[1], - inputs[0].get_shape(), - inputs[1].get_shape(), - m_attributes); + return IF_TYPE_OF(v9_GridSample_evaluate, + OV_PP_ET_LIST(f32), + Evaluate, + inputs[0].get_element_type(), + outputs[0], + inputs[0], + inputs[1], + inputs[0].get_shape(), + inputs[1].get_shape(), + m_attributes); } bool GridSample::has_evaluate() const { diff --git a/src/core/src/op/hsigmoid.cpp b/src/core/src/op/hsigmoid.cpp index 2abc4c02c5da9d..9ed9ac3aa79860 100644 --- a/src/core/src/op/hsigmoid.cpp +++ b/src/core/src/op/hsigmoid.cpp @@ -42,11 +42,15 @@ bool HSigmoid::evaluate(TensorVector& outputs, const TensorVector& inputs) const const auto& input_shape = inputs[0].get_shape(); const auto count = shape_size(input_shape); outputs[0].set_shape(input_shape); + using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - count); + return IF_TYPE_OF(v5_HSigmoid_evaluate, + OV_PP_ET_LIST(bf16, f16, f32), + hsigmoid::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + count); } bool HSigmoid::has_evaluate() const { diff --git a/src/core/src/op/hswish.cpp b/src/core/src/op/hswish.cpp index fd2d89896c0460..dbb7e744cad146 100644 --- a/src/core/src/op/hswish.cpp +++ b/src/core/src/op/hswish.cpp @@ -43,10 +43,13 @@ bool HSwish::evaluate(TensorVector& outputs, const TensorVector& inputs) const { const auto count = shape_size(input_shape); outputs[0].set_shape(input_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - count); + return IF_TYPE_OF(v4_HSwish_evaluate, + OV_PP_ET_LIST(bf16, f16, f32), + hswish::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + count); } bool HSwish::has_evaluate() const { diff --git a/src/core/src/op/less.cpp b/src/core/src/op/less.cpp index 910876c3a58853..1f7f27dc850ff2 100644 --- a/src/core/src/op/less.cpp +++ b/src/core/src/op/less.cpp @@ -52,13 +52,16 @@ bool Less::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Less_evaluate, + OV_PP_ET_LIST(boolean, f16, f32, i32, i64, u32, u64), + less::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Less::has_evaluate() const { diff --git a/src/core/src/op/less_eq.cpp b/src/core/src/op/less_eq.cpp index 76c94ad91cba65..5bc3837885fd1f 100644 --- a/src/core/src/op/less_eq.cpp +++ b/src/core/src/op/less_eq.cpp @@ -53,13 +53,16 @@ bool LessEqual::evaluate(TensorVector& outputs, const TensorVector& inputs) cons outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_LessEqual_evaluate, + OV_PP_ET_LIST(boolean, f16, f32, i32, i64, u32, u64), + less_equal::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool LessEqual::has_evaluate() const { diff --git a/src/core/src/op/log.cpp b/src/core/src/op/log.cpp index dacde7087e93d3..0bbaa1d250d65f 100644 --- a/src/core/src/op/log.cpp +++ b/src/core/src/op/log.cpp @@ -42,10 +42,13 @@ bool Log::evaluate(TensorVector& outputs, const TensorVector& inputs) const { const auto count = shape_size(input_shape); outputs[0].set_shape(input_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - count); + return IF_TYPE_OF(v0_Log_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + log::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + count); } bool Log::has_evaluate() const { diff --git a/src/core/src/op/logical_not.cpp b/src/core/src/op/logical_not.cpp index db9f939463651a..e3aab7c64a3c2f 100644 --- a/src/core/src/op/logical_not.cpp +++ b/src/core/src/op/logical_not.cpp @@ -51,11 +51,13 @@ bool LogicalNot::evaluate(TensorVector& outputs, const TensorVector& inputs) con outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply( - inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v1_LogicalNot_evaluate, + OV_PP_ET_LIST(boolean, i32, i64, u32, u64, f16, f32), + logical_not::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool LogicalNot::has_evaluate() const { diff --git a/src/core/src/op/matmul.cpp b/src/core/src/op/matmul.cpp index 06fd0a9f33e424..130b8a793d6f05 100644 --- a/src/core/src/op/matmul.cpp +++ b/src/core/src/op/matmul.cpp @@ -68,15 +68,18 @@ bool MatMul::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(out_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - out_shape, - m_transpose_a, - m_transpose_b); + return IF_TYPE_OF(v0_MatMul_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + matmul::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + out_shape, + m_transpose_a, + m_transpose_b); } bool MatMul::has_evaluate() const { diff --git a/src/core/src/op/max_pool.cpp b/src/core/src/op/max_pool.cpp index 4dab91221f91f0..c7afdb77187adb 100644 --- a/src/core/src/op/max_pool.cpp +++ b/src/core/src/op/max_pool.cpp @@ -93,15 +93,18 @@ bool MaxPool::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(output_shape.get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - inputs[0].get_shape(), - outputs[0].get_shape(), - get_kernel(), - get_strides(), - get_pads_begin(), - get_pads_end()); + return IF_TYPE_OF(v1_MaxPool_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + maxpool::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + inputs[0].get_shape(), + outputs[0].get_shape(), + get_kernel(), + get_strides(), + get_pads_begin(), + get_pads_end()); } bool MaxPool::has_evaluate() const { @@ -208,18 +211,21 @@ struct Evaluate : element::NoAction { const Shape& pads_end, const int64_t axis) { using namespace ov::element; - return IfTypeOf::apply(out_indices.get_element_type(), - in.data(), - out_values.data(), - out_indices, - in_shape, - out_shape, - kernel, - strides, - dilations, - pads_begin, - pads_end, - axis); + return IF_TYPE_OF(maxpool_eval_by_idx_type, + OV_PP_ET_LIST(i32, i64), + EvalByIdxType, + out_indices.get_element_type(), + in.data(), + out_values.data(), + out_indices, + in_shape, + out_shape, + kernel, + strides, + dilations, + pads_begin, + pads_end, + axis); } private: @@ -265,18 +271,21 @@ bool MaxPool::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(output_shape.get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - outputs[1], - inputs[0].get_shape(), - outputs[0].get_shape(), - get_kernel(), - get_strides(), - get_dilations(), - get_pads_begin(), - get_pads_end(), - get_axis()); + return IF_TYPE_OF(v8_MaxPool_evaluate, + OV_PP_ET_LIST(f16, f32, i8, i32, i64, u8, u32, u64), + maxpool::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + outputs[1], + inputs[0].get_shape(), + outputs[0].get_shape(), + get_kernel(), + get_strides(), + get_dilations(), + get_pads_begin(), + get_pads_end(), + get_axis()); } bool MaxPool::has_evaluate() const { diff --git a/src/core/src/op/maximum.cpp b/src/core/src/op/maximum.cpp index 90a038d0b540cb..5a9e832bbb2c99 100644 --- a/src/core/src/op/maximum.cpp +++ b/src/core/src/op/maximum.cpp @@ -48,13 +48,16 @@ bool Maximum::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Maximum_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + maximum::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Maximum::has_evaluate() const { diff --git a/src/core/src/op/minimum.cpp b/src/core/src/op/minimum.cpp index 1844c6e5b25e36..544f33e5055262 100644 --- a/src/core/src/op/minimum.cpp +++ b/src/core/src/op/minimum.cpp @@ -49,13 +49,16 @@ bool Minimum::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Minimum_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u8, u16, u32, u64), + minimum::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Minimum::has_evaluate() const { diff --git a/src/core/src/op/mish.cpp b/src/core/src/op/mish.cpp index 606ff6239f59a4..406692baccd112 100644 --- a/src/core/src/op/mish.cpp +++ b/src/core/src/op/mish.cpp @@ -58,10 +58,13 @@ bool Mish::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(in_shape)); + return IF_TYPE_OF(v4_Mish_evaluate, + OV_PP_ET_LIST(f16, f32), + mish::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(in_shape)); } bool Mish::has_evaluate() const { diff --git a/src/core/src/op/mod.cpp b/src/core/src/op/mod.cpp index 69ac9493052d20..b321b58d4c54a9 100644 --- a/src/core/src/op/mod.cpp +++ b/src/core/src/op/mod.cpp @@ -244,13 +244,16 @@ bool Mod::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) co outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Mod_evaluate, + OV_PP_ET_LIST(i8, i16, i32, i64, u8, u16, u32, u64), + mod::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Mod::evaluate_lower(TensorVector& outputs) const { diff --git a/src/core/src/op/multiply.cpp b/src/core/src/op/multiply.cpp index 2ae5f4304cfcbe..c1c47df1abd3ae 100644 --- a/src/core/src/op/multiply.cpp +++ b/src/core/src/op/multiply.cpp @@ -47,13 +47,16 @@ bool Multiply::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Multiply_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, f64, i32, i64, u32, u64), + multiply::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Multiply::has_evaluate() const { diff --git a/src/core/src/op/negative.cpp b/src/core/src/op/negative.cpp index a34d29a479d83d..8f8f6a2cc513e2 100644 --- a/src/core/src/op/negative.cpp +++ b/src/core/src/op/negative.cpp @@ -42,10 +42,13 @@ bool Negative::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Negative_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i32, i64), + negative::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Negative::has_evaluate() const { diff --git a/src/core/src/op/non_zero.cpp b/src/core/src/op/non_zero.cpp index 8257c05924fae4..06c0df37d585a0 100644 --- a/src/core/src/op/non_zero.cpp +++ b/src/core/src/op/non_zero.cpp @@ -26,7 +26,13 @@ struct Evaluate : public element::NoAction { out.set_shape(out_shape); using namespace ov::element; - return IfTypeOf::apply(out.get_element_type(), in_data, out, in_shape); + return IF_TYPE_OF(non_zero_out_type, + OV_PP_ET_LIST(i32, i64), + EvalByOutType, + out.get_element_type(), + in_data, + out, + in_shape); } private: @@ -114,12 +120,14 @@ bool NonZero::evaluate(TensorVector& outputs, const TensorVector& inputs) const auto& output = outputs[0]; using namespace ov::element; const auto& input_shape = input.get_shape(); - return IfTypeOf::apply( - input.get_element_type(), - input, - input_shape, - input_shape.size(), - output); + return IF_TYPE_OF(v3_NonZero_evaluate, + OV_PP_ET_LIST(boolean, bf16, f16, f32, f64, i8, i16, i32, i64, u8, u16, u32, u64), + non_zero::Evaluate, + input.get_element_type(), + input, + input_shape, + input_shape.size(), + output); } bool NonZero::has_evaluate() const { diff --git a/src/core/src/op/not_equal.cpp b/src/core/src/op/not_equal.cpp index 55c0f5a3d9fa44..920b79064cb86c 100644 --- a/src/core/src/op/not_equal.cpp +++ b/src/core/src/op/not_equal.cpp @@ -51,13 +51,16 @@ bool NotEqual::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_NotEqual_evaluate, + OV_PP_ET_LIST(boolean, f16, f32, i32, i64, u32, u64), + not_equal::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool NotEqual::has_evaluate() const { diff --git a/src/core/src/op/one_hot.cpp b/src/core/src/op/one_hot.cpp index 8a3cd26e6fd45a..ac9ba016a702f3 100644 --- a/src/core/src/op/one_hot.cpp +++ b/src/core/src/op/one_hot.cpp @@ -118,15 +118,18 @@ bool OneHot::evaluate(TensorVector& outputs, const TensorVector& inputs) const { auto& output = outputs[0]; output.set_shape(output_shape); using namespace ov::element; - return IfTypeOf::apply(indices.get_element_type(), - indices, - indices_shape, - static_cast(output.data()), - output.get_element_type().size(), - output.get_shape()[axis], - on_value, - off_value, - axis); + return IF_TYPE_OF(v1_OneHot_evaluate, + OV_PP_ET_LIST(i32, i64), + one_hot::Evaluate, + indices.get_element_type(), + indices, + indices_shape, + static_cast(output.data()), + output.get_element_type().size(), + output.get_shape()[axis], + on_value, + off_value, + axis); } bool OneHot::has_evaluate() const { diff --git a/src/core/src/op/power.cpp b/src/core/src/op/power.cpp index 7eda718951e80f..88460b36e33965 100644 --- a/src/core/src/op/power.cpp +++ b/src/core/src/op/power.cpp @@ -49,13 +49,16 @@ bool Power::evaluate(TensorVector& outputs, const TensorVector& inputs) const { out.set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - out, - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Power_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i32, i64, u32, u64), + power::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + out, + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Power::has_evaluate() const { diff --git a/src/core/src/op/prelu.cpp b/src/core/src/op/prelu.cpp index ee417602cf023f..7c65f5c15cfbd9 100644 --- a/src/core/src/op/prelu.cpp +++ b/src/core/src/op/prelu.cpp @@ -55,12 +55,15 @@ bool PRelu::evaluate(TensorVector& outputs, const TensorVector& inputs) const { out.set_shape(arg_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - out, - arg_shape, - inputs[1].get_shape()); + return IF_TYPE_OF(v0_PRelu_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i8), + prelu::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + out, + arg_shape, + inputs[1].get_shape()); } bool PRelu::has_evaluate() const { diff --git a/src/core/src/op/range.cpp b/src/core/src/op/range.cpp index f048f778c31bce..fef5f15aa4f787 100644 --- a/src/core/src/op/range.cpp +++ b/src/core/src/op/range.cpp @@ -119,11 +119,14 @@ bool Range::evaluate(TensorVector& outputs, const TensorVector& inputs) const { const auto step = get_tensor_data_as(inputs[2])[0]; using namespace ov::element; - return IfTypeOf::apply(out.get_element_type(), - start, - step, - shape_size(out_shape), - out); + return IF_TYPE_OF(v4_Range_evaluate, + RANGE_ET_LIST, + range::Evaluate, + out.get_element_type(), + start, + step, + shape_size(out_shape), + out); } bool Range::has_evaluate() const { @@ -199,11 +202,14 @@ bool Range::evaluate(TensorVector& outputs, const TensorVector& inputs) const { out.set_shape(out_shape); using namespace ov::element; - return IfTypeOf::apply(out.get_element_type(), - start, - step, - shape_size(out_shape), - out); + return IF_TYPE_OF(v0_Range_evaluate, + RANGE_ET_LIST, + range::Evaluate, + out.get_element_type(), + start, + step, + shape_size(out_shape), + out); } bool Range::has_evaluate() const { diff --git a/src/core/src/op/reduce_l1.cpp b/src/core/src/op/reduce_l1.cpp index 75f8a000580bc3..fb44d686764200 100644 --- a/src/core/src/op/reduce_l1.cpp +++ b/src/core/src/op/reduce_l1.cpp @@ -48,10 +48,13 @@ bool ReduceL1::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v4_ReduceL1_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i32, i64), + reduce_l1::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceL1::has_evaluate() const { diff --git a/src/core/src/op/reduce_l2.cpp b/src/core/src/op/reduce_l2.cpp index 5477a56986be16..9f3c48a21448f9 100644 --- a/src/core/src/op/reduce_l2.cpp +++ b/src/core/src/op/reduce_l2.cpp @@ -47,10 +47,13 @@ bool ReduceL2::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v4_ReduceL2_evaluate, + OV_PP_ET_LIST(bf16, f16, f32), + reduce_l2::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceL2::has_evaluate() const { diff --git a/src/core/src/op/reduce_logical_and.cpp b/src/core/src/op/reduce_logical_and.cpp index adcfed43626306..0178917aae3665 100644 --- a/src/core/src/op/reduce_logical_and.cpp +++ b/src/core/src/op/reduce_logical_and.cpp @@ -47,10 +47,13 @@ bool ReduceLogicalAnd::evaluate(TensorVector& outputs, const TensorVector& input outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v1_ReduceLogicalAnd_evaluate, + boolean, + reduce_and::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceLogicalAnd::has_evaluate() const { diff --git a/src/core/src/op/reduce_logical_or.cpp b/src/core/src/op/reduce_logical_or.cpp index a2e84d420e606d..b41c78fa859c58 100644 --- a/src/core/src/op/reduce_logical_or.cpp +++ b/src/core/src/op/reduce_logical_or.cpp @@ -48,10 +48,13 @@ bool ReduceLogicalOr::evaluate(TensorVector& outputs, const TensorVector& inputs outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v1_ReduceLogicalOr_evaluate, + boolean, + reduce_or::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceLogicalOr::has_evaluate() const { diff --git a/src/core/src/op/reduce_max.cpp b/src/core/src/op/reduce_max.cpp index 989f0a771f2b1c..f64b7b1e6ec6ca 100644 --- a/src/core/src/op/reduce_max.cpp +++ b/src/core/src/op/reduce_max.cpp @@ -47,10 +47,13 @@ bool ReduceMax::evaluate(TensorVector& outputs, const TensorVector& inputs) cons outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v1_ReduceMax_evaluate, + OV_PP_ET_LIST(f16, f32, i8, i32, i64, u8, u32, u64), + reduce_max::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceMax::has_evaluate() const { diff --git a/src/core/src/op/reduce_mean.cpp b/src/core/src/op/reduce_mean.cpp index 762bc1c09719ee..25f30d0235db3e 100644 --- a/src/core/src/op/reduce_mean.cpp +++ b/src/core/src/op/reduce_mean.cpp @@ -45,10 +45,13 @@ bool ReduceMean::evaluate(TensorVector& outputs, const TensorVector& inputs) con outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v1_ReduceMean_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + reduce_mean::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceMean::has_evaluate() const { diff --git a/src/core/src/op/reduce_min.cpp b/src/core/src/op/reduce_min.cpp index 3334b02d5fa3ea..b60b0e9889eeda 100644 --- a/src/core/src/op/reduce_min.cpp +++ b/src/core/src/op/reduce_min.cpp @@ -45,10 +45,13 @@ bool ReduceMin::evaluate(TensorVector& outputs, const TensorVector& inputs) cons outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v1_ReduceMin_evaluate, + OV_PP_ET_LIST(f16, f32, i8, i32, i64, u8, u32, u64), + reduce_min::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceMin::has_evaluate() const { diff --git a/src/core/src/op/reduce_prod.cpp b/src/core/src/op/reduce_prod.cpp index 9d2c4dee4a8c51..d80f040e5ef7ad 100644 --- a/src/core/src/op/reduce_prod.cpp +++ b/src/core/src/op/reduce_prod.cpp @@ -57,10 +57,13 @@ bool ReduceProd::evaluate(TensorVector& outputs, const TensorVector& inputs) con outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v1_ReduceProd_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + reduce_prod::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceProd::has_evaluate() const { diff --git a/src/core/src/op/reduce_sum.cpp b/src/core/src/op/reduce_sum.cpp index 33e7ced8204faf..b661fbc1ea4a80 100644 --- a/src/core/src/op/reduce_sum.cpp +++ b/src/core/src/op/reduce_sum.cpp @@ -45,10 +45,13 @@ bool ReduceSum::evaluate(TensorVector& outputs, const TensorVector& inputs) cons outputs[0].set_shape(ov::util::reduce(inputs[0].get_shape(), reduction_axes, get_keep_dims())); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - reduction_axes); + return IF_TYPE_OF(v1_ReduceSum_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + reduce_sum::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + reduction_axes); } bool ReduceSum::has_evaluate() const { diff --git a/src/core/src/op/relu.cpp b/src/core/src/op/relu.cpp index ebc8aa46d39053..eff1ecc0f755a3 100644 --- a/src/core/src/op/relu.cpp +++ b/src/core/src/op/relu.cpp @@ -42,10 +42,13 @@ bool Relu::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(in_shape)); + return IF_TYPE_OF(v0_Relu_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + relu::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(in_shape)); } bool Relu::has_evaluate() const { diff --git a/src/core/src/op/round.cpp b/src/core/src/op/round.cpp index 16643086e715d4..24adc7e9bfe469 100644 --- a/src/core/src/op/round.cpp +++ b/src/core/src/op/round.cpp @@ -59,12 +59,14 @@ bool Round::evaluate(TensorVector& outputs, const TensorVector& inputs) const { auto& out = outputs.front(); using namespace ov::element; - return IfTypeOf::apply( - arg0.get_element_type(), - arg0, - out, - shape_size(arg0.get_shape()), - get_mode()); + return IF_TYPE_OF(v5_Round_evaluate, + OV_PP_ET_LIST(boolean, i8, i16, i32, i64, u8, u16, u32, u64, bf16, f16, f32), + round::Evaluate, + arg0.get_element_type(), + arg0, + out, + shape_size(arg0.get_shape()), + get_mode()); } bool Round::has_evaluate() const { diff --git a/src/core/src/op/scatter_elements_update.cpp b/src/core/src/op/scatter_elements_update.cpp index c9dabd1a91d8e9..2cec3ff0762c8a 100644 --- a/src/core/src/op/scatter_elements_update.cpp +++ b/src/core/src/op/scatter_elements_update.cpp @@ -101,16 +101,19 @@ struct Evaluate : public element::NoAction { ) { using namespace ov::element; - return IfTypeOf::apply(indices.get_element_type(), - data.data(), - indices, - updates.data(), - output.data
(), - data_shape, - indices_shape, - axis, - reduction, - use_init_value); + return IF_TYPE_OF(scatter_el_update_idx_type, + OV_PP_ET_LIST(i8, i16, i32, i64, u8, u16, u32, u64), + EvaluateByIndicesType, + indices.get_element_type(), + data.data(), + indices, + updates.data(), + output.data
(), + data_shape, + indices_shape, + axis, + reduction, + use_init_value); } private: @@ -156,18 +159,21 @@ bool evaluate(TensorVector& outputs, const auto& data_shape = data.get_shape(); const auto& indices_shape = indices.get_shape(); output.set_shape(data_shape); + using namespace ov::element; - return IfTypeOf::apply( - data.get_element_type(), - data, - indices, - updates, - output, - data_shape, - indices_shape, - axis, - reduction, - use_init_value); + return IF_TYPE_OF(scatter_evaluate, + OV_PP_ET_LIST(boolean, f16, f32, i16, i32, i64, u32, u64), + scatter_elements_update::Evaluate, + data.get_element_type(), + data, + indices, + updates, + output, + data_shape, + indices_shape, + axis, + reduction, + use_init_value); } } // namespace } // namespace scatter_elements_update diff --git a/src/core/src/op/scatter_nd_update.cpp b/src/core/src/op/scatter_nd_update.cpp index 3ca0d83686a12d..e6d79f99366dfe 100644 --- a/src/core/src/op/scatter_nd_update.cpp +++ b/src/core/src/op/scatter_nd_update.cpp @@ -24,14 +24,17 @@ struct Evaluate : public element::NoAction { const Shape& indices_shape, const Shape& updates_shape) { using namespace ov::element; - return IfTypeOf::apply(indices.get_element_type(), - data.data(), - indices, - updates.data(), - output.data
(), - data_shape, - indices_shape, - updates_shape); + return IF_TYPE_OF(sctter_nd_eval_idx_type, + OV_PP_ET_LIST(i32, i64), + EvaluateByIndicesType, + indices.get_element_type(), + data.data(), + indices, + updates.data(), + output.data
(), + data_shape, + indices_shape, + updates_shape); } private: @@ -82,14 +85,17 @@ bool ScatterNDUpdate::evaluate(TensorVector& outputs, const TensorVector& inputs const auto& updates_shape = updates.get_shape(); output.set_shape(data_shape); using namespace ov::element; - return IfTypeOf::apply(data.get_element_type(), - data, - indices, - updates, - output, - data_shape, - indices_shape, - updates_shape); + return IF_TYPE_OF(v3_ScatterNDUpdate_evaluate, + OV_PP_ET_LIST(boolean, f16, f32, i32, i64, u32, u64), + scatter_nd_update::Evaluate, + data.get_element_type(), + data, + indices, + updates, + output, + data_shape, + indices_shape, + updates_shape); } bool ScatterNDUpdate::has_evaluate() const { diff --git a/src/core/src/op/sigmoid.cpp b/src/core/src/op/sigmoid.cpp index a4ce31db1e3a97..abe6105b45ddcd 100644 --- a/src/core/src/op/sigmoid.cpp +++ b/src/core/src/op/sigmoid.cpp @@ -44,10 +44,13 @@ bool Sigmoid::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(in_shape)); + return IF_TYPE_OF(v0_Sigmoid_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + sigmoid::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(in_shape)); } bool Sigmoid::has_evaluate() const { diff --git a/src/core/src/op/sign.cpp b/src/core/src/op/sign.cpp index f22798bfcdc79f..10aafb5f29a1ae 100644 --- a/src/core/src/op/sign.cpp +++ b/src/core/src/op/sign.cpp @@ -43,10 +43,13 @@ bool Sign::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(in_shape)); + return IF_TYPE_OF(v0_Sign_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + sign::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(in_shape)); } bool Sign::has_evaluate() const { diff --git a/src/core/src/op/sin.cpp b/src/core/src/op/sin.cpp index dc224ada7e071e..083b14645f2135 100644 --- a/src/core/src/op/sin.cpp +++ b/src/core/src/op/sin.cpp @@ -47,10 +47,13 @@ bool Sin::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Sin_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + sin::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Sin::has_evaluate() const { diff --git a/src/core/src/op/sinh.cpp b/src/core/src/op/sinh.cpp index f678118a0fa429..43cf622afcf6c0 100644 --- a/src/core/src/op/sinh.cpp +++ b/src/core/src/op/sinh.cpp @@ -45,10 +45,13 @@ bool Sinh::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Sinh_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + sinh::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Sinh::has_evaluate() const { diff --git a/src/core/src/op/softmax.cpp b/src/core/src/op/softmax.cpp index d2e1326d76c58b..5166a42446f74c 100644 --- a/src/core/src/op/softmax.cpp +++ b/src/core/src/op/softmax.cpp @@ -68,11 +68,14 @@ bool Softmax::evaluate(TensorVector& outputs, const TensorVector& inputs) const const auto& input_shape = inputs[0].get_shape(); outputs[0].set_shape(input_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - input_shape, - AxisSet{m_axis}); + return IF_TYPE_OF(v1_Softmax_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, f64), + softmax::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + input_shape, + AxisSet{m_axis}); } bool Softmax::has_evaluate() const { @@ -140,11 +143,14 @@ bool Softmax::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(input_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - input_shape, - AxisSet{axis}); + return IF_TYPE_OF(v8_Softmax_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, f64), + softmax::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + input_shape, + AxisSet{axis}); } bool Softmax::has_evaluate() const { diff --git a/src/core/src/op/softplus.cpp b/src/core/src/op/softplus.cpp index a5896c00795665..39fe5eb257c7f2 100644 --- a/src/core/src/op/softplus.cpp +++ b/src/core/src/op/softplus.cpp @@ -57,10 +57,13 @@ bool SoftPlus::evaluate(TensorVector& outputs, const TensorVector& inputs) const const auto count = shape_size(input_shape); outputs[0].set_shape(input_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - count); + return IF_TYPE_OF(v4_SoftPlus_evaluate, + OV_PP_ET_LIST(bf16, f16, f32), + softplus::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + count); } bool SoftPlus::has_evaluate() const { diff --git a/src/core/src/op/softsign.cpp b/src/core/src/op/softsign.cpp index 733b193b7248a4..37183363c78090 100644 --- a/src/core/src/op/softsign.cpp +++ b/src/core/src/op/softsign.cpp @@ -75,10 +75,13 @@ bool SoftSign::evaluate(TensorVector& outputs, const auto& input_shape = inputs[0].get_shape(); outputs[0].set_shape(input_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(input_shape)); + return IF_TYPE_OF(v9_SoftSign_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, f64), + softsign::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(input_shape)); } } // namespace v9 } // namespace op diff --git a/src/core/src/op/sqrt.cpp b/src/core/src/op/sqrt.cpp index 0c05c6833bfcf0..1a8c7501d7c2f9 100644 --- a/src/core/src/op/sqrt.cpp +++ b/src/core/src/op/sqrt.cpp @@ -41,10 +41,13 @@ bool Sqrt::evaluate(TensorVector& outputs, const TensorVector& inputs) const { const auto& in_shape = inputs[0].get_shape(); outputs[0].set_shape(in_shape); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(in_shape)); + return IF_TYPE_OF(v0_Sqrt_evaluate, + OV_PP_ET_LIST(f16, f32, f64, i32, i64, u32, u64), + sqrt::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(in_shape)); } bool Sqrt::has_evaluate() const { diff --git a/src/core/src/op/subtract.cpp b/src/core/src/op/subtract.cpp index 6b21fa00483b78..22de7fa20bfaff 100644 --- a/src/core/src/op/subtract.cpp +++ b/src/core/src/op/subtract.cpp @@ -48,13 +48,16 @@ bool Subtract::evaluate(TensorVector& outputs, const TensorVector& inputs) const outputs[0].set_shape(infer_broadcast_shape(this, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - get_autob()); + return IF_TYPE_OF(v1_Subtract_evaluate, + OV_PP_ET_LIST(bf16, f16, f32, i8, i32, i64, u8, u32, u64), + subtract::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + get_autob()); } bool Subtract::has_evaluate() const { diff --git a/src/core/src/op/swish.cpp b/src/core/src/op/swish.cpp index ccc3d82b682137..448aaa67e51274 100644 --- a/src/core/src/op/swish.cpp +++ b/src/core/src/op/swish.cpp @@ -88,11 +88,14 @@ bool Swish::evaluate(TensorVector& outputs, const TensorVector& inputs) const { const auto& arg1 = inputs.size() == 2 ? inputs[1] : Tensor(); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - arg1, - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v4_Swish_evaluate, + OV_PP_ET_LIST(f16, f32), + swish::Evaluate, + inputs[0].get_element_type(), + inputs[0], + arg1, + outputs[0], + shape_size(inputs[0].get_shape())); } bool Swish::has_evaluate() const { diff --git a/src/core/src/op/tan.cpp b/src/core/src/op/tan.cpp index 5fac393b36010f..2d3f2b5fa1e89d 100644 --- a/src/core/src/op/tan.cpp +++ b/src/core/src/op/tan.cpp @@ -45,10 +45,13 @@ bool Tan::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Tan_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + tan::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Tan::has_evaluate() const { diff --git a/src/core/src/op/tanh.cpp b/src/core/src/op/tanh.cpp index 6be5ef3e2bf5ce..26613d6818a281 100644 --- a/src/core/src/op/tanh.cpp +++ b/src/core/src/op/tanh.cpp @@ -46,10 +46,13 @@ bool Tanh::evaluate(TensorVector& outputs, const TensorVector& inputs) const { outputs[0].set_shape(inputs[0].get_shape()); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - shape_size(inputs[0].get_shape())); + return IF_TYPE_OF(v0_Tanh_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + tanh::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + shape_size(inputs[0].get_shape())); } bool Tanh::has_evaluate() const { diff --git a/src/core/src/op/topk.cpp b/src/core/src/op/topk.cpp index a84d0490d9bebd..3d11e5967d240a 100644 --- a/src/core/src/op/topk.cpp +++ b/src/core/src/op/topk.cpp @@ -59,16 +59,19 @@ struct Evaluate : public element::NoAction { const bool compute_max, const TopKSortType sort) { using namespace ov::element; - return IfTypeOf::apply(out_indices.get_element_type(), - in.data(), - out_values.data(), - out_indices, - in.get_shape(), - out_shape, - axis, - out_shape[axis], - compute_max, - sort); + return IF_TYPE_OF(topk_eval_by_idx_type, + OV_PP_ET_LIST(i32, i64), + EvalByIdxType, + out_indices.get_element_type(), + in.data(), + out_values.data(), + out_indices, + in.get_shape(), + out_shape, + axis, + out_shape[axis], + compute_max, + sort); } private: @@ -116,14 +119,17 @@ bool evaluate(const util::TopKBase* const node, TensorVector& outputs, const Ten } using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - outputs[0], - outputs[1], - output_shape, - axis, - (node->get_mode() == ov::op::TopKMode::MAX), - node->get_sort_type()); + return IF_TYPE_OF(topk_evaluate, + OV_PP_ET_LIST(f16, f32, i32, i64, u32, u64), + topk::Evaluate, + inputs[0].get_element_type(), + inputs[0], + outputs[0], + outputs[1], + output_shape, + axis, + (node->get_mode() == ov::op::TopKMode::MAX), + node->get_sort_type()); } } // namespace } // namespace topk diff --git a/src/core/src/op/xor.cpp b/src/core/src/op/xor.cpp index c96599d9de3cef..df5286d72b6d73 100644 --- a/src/core/src/op/xor.cpp +++ b/src/core/src/op/xor.cpp @@ -45,13 +45,16 @@ bool evaluate(const Node* const op, TensorVector& outputs, const TensorVector& i outputs[0].set_shape(infer_broadcast_shape(op, inputs)); using namespace ov::element; - return IfTypeOf::apply(inputs[0].get_element_type(), - inputs[0], - inputs[1], - outputs[0], - inputs[0].get_shape(), - inputs[1].get_shape(), - op->get_autob()); + return IF_TYPE_OF(Xor_evaluate, + boolean, + logxor::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + op->get_autob()); } } // namespace } // namespace logxor From a6903b8398ac71143c94a723163751af655dcb24 Mon Sep 17 00:00:00 2001 From: Evgenya Nugmanova Date: Tue, 5 Dec 2023 12:05:03 +0400 Subject: [PATCH 10/20] [Symbolic Transformation] DeReshape FullyConnected (#21419) --- .../dereshape_matmul.hpp | 26 ++++ .../dereshape_matmul.cpp | 66 +++++++++++ .../symbolic_optimizations.cpp | 1 + .../dereshape_fullyconnected.cpp | 112 ++++++++++++++++++ 4 files changed, 205 insertions(+) create mode 100644 src/common/transformations/tests/symbolic_transformations/dereshape_fullyconnected.cpp diff --git a/src/common/transformations/include/transformations/symbolic_transformations/dereshape_matmul.hpp b/src/common/transformations/include/transformations/symbolic_transformations/dereshape_matmul.hpp index 6df2e406ee8154..dbe44093623fe4 100644 --- a/src/common/transformations/include/transformations/symbolic_transformations/dereshape_matmul.hpp +++ b/src/common/transformations/include/transformations/symbolic_transformations/dereshape_matmul.hpp @@ -10,6 +10,7 @@ namespace ov { namespace pass { class TRANSFORMATIONS_API DeReshapeMatMul; +class TRANSFORMATIONS_API DeReshapeFullyConnected; } // namespace pass } // namespace ov @@ -64,3 +65,28 @@ class ov::pass::DeReshapeMatMul : public ov::pass::MatcherPass { OPENVINO_RTTI("DeReshapeMatMul", "0"); DeReshapeMatMul(); }; + +/** + * @ingroup ie_transformation_common_api + * @brief Transformation uses symbol / label information to optimize out Reshape operations surrounding special cases of + * MatMul. It checks that surrounding Reshapes are only manipulating with batch dimensions of tensor in a do-undo kind + * of way. The difference with previous optimization is that this case has Reshape only on one input of MatMul and the + * other input is strictly 2D. Such MatMuls are also called FullyConnected + * + * Example: + * Before: + * [A,B,4096] -> Reshape -> [A*B,4096] + * MatMul [A*B,4608] -> Reshape -> [A,B,4608] + * [4096,4608] + * + * After: + * [A,B,4096] -> + * MatMul -> [A,B,4608] + * [4096,4608] -> + * + */ +class ov::pass::DeReshapeFullyConnected : public ov::pass::MatcherPass { +public: + OPENVINO_RTTI("DeReshapeFullyConnected", "0"); + DeReshapeFullyConnected(); +}; diff --git a/src/common/transformations/src/transformations/symbolic_transformations/dereshape_matmul.cpp b/src/common/transformations/src/transformations/symbolic_transformations/dereshape_matmul.cpp index 2c7ee44c6328d9..943c912bf68cf9 100644 --- a/src/common/transformations/src/transformations/symbolic_transformations/dereshape_matmul.cpp +++ b/src/common/transformations/src/transformations/symbolic_transformations/dereshape_matmul.cpp @@ -8,6 +8,7 @@ #include "openvino/core/dimension_tracker.hpp" #include "openvino/core/validation_util.hpp" #include "openvino/op/concat.hpp" +#include "openvino/op/convert.hpp" #include "openvino/op/matmul.hpp" #include "openvino/op/reshape.hpp" #include "openvino/op/util/binary_elementwise_arithmetic.hpp" @@ -334,3 +335,68 @@ ov::pass::DeReshapeMatMul::DeReshapeMatMul() { auto m = std::make_shared(final_reshape, matcher_name); register_matcher(m, matcher_pass_callback); } + +ov::pass::DeReshapeFullyConnected::DeReshapeFullyConnected() { + MATCHER_SCOPE(DeReshapeFullyConnected); + + auto reshaped_input = pattern::wrap_type([](Output out) -> bool { + const auto& input_shape = out.get_node_shared_ptr()->get_input_partial_shape(0); + if (input_shape.rank().is_dynamic() || input_shape.size() < 3) + return false; + const auto& output_shape = out.get_partial_shape(); + if (output_shape.rank().is_dynamic() || output_shape.size() < 2) + return false; + return dims_are_equal(input_shape[input_shape.size() - 1], output_shape[output_shape.size() - 1]); + }); + auto converted = + pattern::wrap_type({reshaped_input}, pattern::consumers_count(1)); // optional convert + + auto dynamic_input = std::make_shared(OutputVector{reshaped_input, converted}); + auto static_input = pattern::any_input(pattern::rank_equals(2)); + auto mm_label = pattern::wrap_type({dynamic_input, static_input}, [](Output out) -> bool { + auto mm = ov::as_type_ptr(out.get_node_shared_ptr()); + return mm && !mm->get_transpose_a() && pattern::consumers_count(1)(out); + }); + + auto reshaped_output = + pattern::wrap_type({mm_label, pattern::any_input()}, [](Output out) -> bool { + const auto& input_shape = out.get_node_shared_ptr()->get_input_partial_shape(0); + if (input_shape.rank().is_dynamic() || input_shape.size() < 2) + return false; + const auto& output_shape = out.get_partial_shape(); + if (output_shape.rank().is_dynamic() || output_shape.size() < 3) + return false; + return dims_are_equal(input_shape[input_shape.size() - 1], output_shape[output_shape.size() - 1]); + }); + + ov::matcher_pass_callback matcher_pass_callback = [=](pattern::Matcher& m) { + const auto& pm = m.get_pattern_map(); + + const auto& in_reshape = pm.at(reshaped_input); + const auto& out_reshape = pm.at(reshaped_output); + const auto& matmul = pm.at(mm_label); + + const auto& in_shape = in_reshape->get_input_partial_shape(0); + const auto& out_shape = out_reshape->get_output_partial_shape(0); + + if (in_shape.size() != out_shape.size()) + return false; + + for (size_t i = 0; i < in_shape.size() - 1; ++i) + if (!dims_are_equal(in_shape[i], out_shape[i])) + return false; + if (pm.count(converted)) { + const auto& convert = pm.at(converted); + convert->input(0).replace_source_output(in_reshape->input_value(0)); + convert->validate_and_infer_types(); + } else { + matmul->input(0).replace_source_output(in_reshape->input_value(0)); + } + ov::replace_output_update_name(out_reshape->output(0), matmul->output(0)); + matmul->validate_and_infer_types(); + return true; + }; + + auto m = std::make_shared(reshaped_output, matcher_name); + register_matcher(m, matcher_pass_callback); +} diff --git a/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp b/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp index dc9799642996ff..1437845fb9ad60 100644 --- a/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp +++ b/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp @@ -202,6 +202,7 @@ ov::pass::SymbolicOptimizations::SymbolicOptimizations(bool full_run) { REGISTER_SYMBOLIC(OptimizeLabelsUsedAsValues) // reduce shape sub-graphs REGISTER_SYMBOLIC(LabelResolvingThroughSelect) // figures out that broadcasting didn't happen through Select op REGISTER_SYMBOLIC(DeReshapeMatMul) + REGISTER_SYMBOLIC(DeReshapeFullyConnected) REGISTER_SYMBOLIC(ReshapeOptimizations) REGISTER_SYMBOLIC(SimplifyShapeOfSubGraph) } diff --git a/src/common/transformations/tests/symbolic_transformations/dereshape_fullyconnected.cpp b/src/common/transformations/tests/symbolic_transformations/dereshape_fullyconnected.cpp new file mode 100644 index 00000000000000..8b2fc3075beb68 --- /dev/null +++ b/src/common/transformations/tests/symbolic_transformations/dereshape_fullyconnected.cpp @@ -0,0 +1,112 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "common_test_utils/ov_test_utils.hpp" +#include "openvino/core/dimension_tracker.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/matmul.hpp" +#include "openvino/op/parameter.hpp" +#include "openvino/op/reshape.hpp" +#include "transformations/symbolic_transformations/dereshape_matmul.hpp" +#include "transformations/utils/utils.hpp" + +using namespace ov; +using namespace ov::op; +using namespace std; + +namespace { +void label_shape(ov::PartialShape& shape) { + auto table = std::make_shared(42); + auto tracker = ov::DimensionTracker(table); + tracker.set_up_for_tracking(shape); +} +} // namespace + +TEST_F(TransformationTestsF, DeReshapeFC) { + { + auto shape = PartialShape{-1, -1, 40}; + label_shape(shape); // we label shape with consecutive labels: 42, 43, 44 + + auto data = make_shared(element::f32, shape); + auto in_reshape = make_shared(data, v0::Constant::create(element::i64, {2}, {-1, 40}), true); + auto second_input = make_shared(element::f32, Shape{40, 80}); + + auto matmul = make_shared(in_reshape, second_input); + + auto batch_dims = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(data, {0, 1}); + auto pattern = + make_shared(OutputVector{batch_dims, v0::Constant::create(element::i64, {1}, {80})}, 0); + auto out_reshape = make_shared(matmul, pattern, false); + + model = make_shared(NodeVector{out_reshape}, ParameterVector{data, second_input}); + manager.register_pass(); + } + { + auto shape = PartialShape{-1, -1, 40}; + label_shape(shape); // we label shape with consecutive labels: 42, 43, 44 + + auto data = make_shared(element::f32, shape); + auto second_input = make_shared(element::f32, Shape{40, 80}); + auto matmul = make_shared(data, second_input); + + model_ref = make_shared(NodeVector{matmul}, ParameterVector{data, second_input}); + } +} + +TEST_F(TransformationTestsF, DeReshapeFCWithConvert) { + { + auto shape = PartialShape{-1, -1, 40}; + label_shape(shape); // we label shape with consecutive labels: 42, 43, 44 + + auto data = make_shared(element::f16, shape); + auto in_reshape = make_shared(data, v0::Constant::create(element::i64, {2}, {-1, 40}), true); + auto convert = make_shared(in_reshape, element::f32); + auto second_input = make_shared(element::f32, Shape{40, 80}); + + auto matmul = make_shared(convert, second_input); + + auto batch_dims = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(data, {0, 1}); + auto pattern = + make_shared(OutputVector{batch_dims, v0::Constant::create(element::i64, {1}, {80})}, 0); + auto out_reshape = make_shared(matmul, pattern, false); + + model = make_shared(NodeVector{out_reshape}, ParameterVector{data, second_input}); + manager.register_pass(); + } + { + auto shape = PartialShape{-1, -1, 40}; + label_shape(shape); // we label shape with consecutive labels: 42, 43, 44 + + auto data = make_shared(element::f16, shape); + auto convert = make_shared(data, element::f32); + auto second_input = make_shared(element::f32, Shape{40, 80}); + auto matmul = make_shared(convert, second_input); + + model_ref = make_shared(NodeVector{matmul}, ParameterVector{data, second_input}); + } +} + +TEST_F(TransformationTestsF, DeReshapeFCNegative) { + { + auto shape = PartialShape{-1, -1, 40}; + label_shape(shape); // we label shape with consecutive labels: 42, 43, 44 + + auto data = make_shared(element::f16, shape); + auto in_reshape = make_shared(data, v0::Constant::create(element::i64, {2}, {-1, 40}), true); + auto convert = make_shared(in_reshape, element::f32); + auto second_input = make_shared(element::f32, Shape{40, 80}); + + auto matmul = make_shared(convert, second_input); + + auto pattern = v0::Constant::create(element::i64, {3}, {4, -1, 80}); + auto out_reshape = make_shared(matmul, pattern, false); + + model = make_shared(NodeVector{out_reshape}, ParameterVector{data, second_input}); + manager.register_pass(); + } +} \ No newline at end of file From 62f5bd657082d0fecef7aeeeb65eba2c4b58706e Mon Sep 17 00:00:00 2001 From: Andrey Kashchikhin Date: Tue, 5 Dec 2023 08:14:02 +0000 Subject: [PATCH 11/20] [CI] [GHA] Introduce the Linux ARM64 workflow (#20809) * add arm as a matrix for build job * uncomment * comment * try inside pipeline * check location * another dirs * try to privide correct action path * use corrected action * use newer commit * use newer commit * use newer commit * use newer action commit * add setting * rm from pipeline, adapt action iteslf * add missing deps * enable samples and debian jobs * correct yml * correct image name * correct syntax, use self-hosted option * enable onnx runtime and c++, use newer action * enable Python and CPU Func tests * add missing deps for arm64 * increase timeout for python tests * disable some tests, add more time * skip failing tests * skip speech sample test on arm * dummy chang * skip mxnet mo on arm, run all tests * rm quotes * separate linux x86 and arm64 workflows * rm unused matrix refs, add timeouts * add skips for c++ tests and some Python tests * correct cache keys, extend timeout * skip more python tests * add more skips: for python and CPU func * extend cpu func list with skips * disable cpu func tests and python api 2.0 tests * rm disable job * styling, rm pr trigger, rm always(), rm unnecessary changes * revert * use ifs instead of comments, provide better wording for skips --- .github/actions/setup_python/action.yml | 4 +- .github/workflows/linux_arm64.yml | 1472 +++++++++++++++++ .../tests/utils/compress_quantize_weights.cpp | 5 + src/frontends/onnx/tests/__init__.py | 4 + .../onnx/tests/runtime/ie/unit_test.manifest | 12 + .../onnx/tests/tests_python/test_backend.py | 10 + .../tensorflow/tests/compilation.cpp | 8 +- .../test_mo_convert_pytorch.py | 16 +- .../layer_tests/onnx_tests/test_reduce_lp.py | 6 +- .../layer_tests/onnx_tests/test_roi_align.py | 6 +- tests/layer_tests/pytorch_tests/test_all.py | 4 +- .../pytorch_tests/test_argmax_argmin.py | 4 +- tests/layer_tests/pytorch_tests/test_div.py | 4 +- .../test_native_multi_head_attention.py | 4 +- tests/layer_tests/pytorch_tests/test_norm.py | 4 +- .../tensorflow_tests/test_tf_ComplexFFT.py | 6 + .../test_tf_MaxPoolWithArgmax.py | 6 +- .../tensorflow_tests/test_tf_NormalizeL2.py | 6 +- .../tensorflow_tests/test_tf_TopKV2.py | 6 +- .../tensorflow_tests/test_tf_TruncateDiv.py | 6 +- .../smoke_tests/test_speech_sample.py | 7 +- 21 files changed, 1571 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/linux_arm64.yml diff --git a/.github/actions/setup_python/action.yml b/.github/actions/setup_python/action.yml index 0bbbf45522e0cd..d067842135cd9d 100644 --- a/.github/actions/setup_python/action.yml +++ b/.github/actions/setup_python/action.yml @@ -26,7 +26,7 @@ runs: - if: ${{ runner.os == 'Linux' && inputs.self-hosted-runner == 'true' }} name: Install 'actions/setup-python@v4' dependencies shell: bash - run: apt-get update && apt-get install -y ca-certificates + run: apt-get update && apt-get install -y ca-certificates software-properties-common - if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }} name: Setup sudo @@ -35,7 +35,7 @@ runs: - if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }} name: Setup Python ${{ inputs.version }} - uses: deadsnakes/action@v3.0.1 + uses: akashchi/deadsnakes-action@f01521a69eee61eaca3a34440bea3ce838317846 with: python-version: ${{ inputs.version }} diff --git a/.github/workflows/linux_arm64.yml b/.github/workflows/linux_arm64.yml new file mode 100644 index 00000000000000..a611f59db5a55c --- /dev/null +++ b/.github/workflows/linux_arm64.yml @@ -0,0 +1,1472 @@ +name: Linux ARM64 (Ubuntu 20.04, Python 3.11) +on: + workflow_dispatch: + # pull_request: + push: + branches: + - master + - 'releases/**' + +concurrency: + # github.ref is not unique in post-commit + group: ${{ github.event_name == 'push' && github.run_id || github.ref }}-linux-arm + cancel-in-progress: true + +env: + PIP_CACHE_PATH: /mount/caches/pip/linux + PYTHON_VERSION: '3.11' + +jobs: + Smart_CI: + runs-on: ubuntu-latest + outputs: + affected_components: "${{ steps.smart_ci.outputs.affected_components }}" + steps: + - name: checkout action + uses: actions/checkout@v4 + with: + sparse-checkout: .github/actions/smart-ci + + - name: Get affected components + id: smart_ci + uses: ./.github/actions/smart-ci + with: + repository: ${{ github.repository }} + pr: ${{ github.event.number }} + commit_sha: ${{ github.sha }} + component_pattern: "category: (.*)" + repo_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Show affected components + run: | + echo "${{ toJSON(steps.smart_ci.outputs.affected_components) }}" + shell: bash + + Build: + needs: Smart_CI + timeout-minutes: 150 + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches + options: -e SCCACHE_AZURE_BLOB_CONTAINER -e SCCACHE_AZURE_CONNECTION_STRING + env: + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + CMAKE_BUILD_TYPE: 'Release' + CMAKE_GENERATOR: 'Ninja Multi-Config' + CMAKE_CXX_COMPILER_LAUNCHER: sccache + CMAKE_C_COMPILER_LAUNCHER: sccache + GITHUB_WORKSPACE: '/__w/openvino/openvino' + OPENVINO_REPO: /__w/openvino/openvino/openvino + OPENVINO_CONTRIB_REPO: /__w/openvino/openvino/openvino_contrib + INSTALL_DIR: /__w/openvino/openvino/openvino_install + INSTALL_TEST_DIR: /__w/openvino/openvino/tests_install + DEVELOPER_PACKAGE_DIR: /__w/openvino/openvino/developer_package_install + BUILD_DIR: /__w/openvino/openvino/openvino_build + SCCACHE_AZURE_KEY_PREFIX: 'ubuntu20_aarch64_Release' + ONNX_RUNTIME_UTILS: /__w/openvino/openvino/openvino/.ci/azure/ci_utils/onnxruntime + if: "!fromJSON(needs.smart_ci.outputs.affected_components).docs_only" + + steps: + - name: Install git + run: apt-get update && apt-get install --assume-yes --no-install-recommends git ca-certificates + + - name: Clone OpenVINO + uses: actions/checkout@v4 + with: + path: ${{ env.OPENVINO_REPO }} + submodules: 'true' + + - name: Clone OpenVINO Contrib + uses: actions/checkout@v4 + with: + repository: 'openvinotoolkit/openvino_contrib' + path: ${{ env.OPENVINO_CONTRIB_REPO }} + submodules: 'true' + ref: 'master' + + # + # Print system info + # + + - name: System info + uses: ./openvino/.github/actions/system_info + + # + # Dependencies + # + + - name: Install build dependencies + run: | + bash ${OPENVINO_REPO}/install_build_dependencies.sh + # default-jdk - Java API + apt install --assume-yes --no-install-recommends default-jdk + + - name: Install sccache + uses: mozilla-actions/sccache-action@v0.0.3 + with: + version: "v0.5.4" + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: ./openvino/.github/actions/setup_python + with: + version: ${{ env.PYTHON_VERSION }} + pip-cache-path: ${{ env.PIP_CACHE_PATH }} + should-setup-pip-paths: 'true' + self-hosted-runner: 'true' + show-cache-info: 'true' + + - name: Install python dependencies + run: | + # For Python API: build and wheel packaging + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/wheel/requirements-dev.txt + python3 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt + + # For running ONNX frontend unit tests + python3 -m pip install --force-reinstall -r ${OPENVINO_REPO}/src/frontends/onnx/tests/requirements.txt + + # For running TensorFlow frontend unit tests + python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/tensorflow/tests/requirements.txt + + # For running TensorFlow Lite frontend unit tests + python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/tensorflow_lite/tests/requirements.txt + + # For running Paddle frontend unit tests + python3 -m pip install -r ${OPENVINO_REPO}/src/frontends/paddle/tests/requirements.txt + + # + # Build + # + + - name: CMake configure - OpenVINO + run: | + cmake \ + -G "${{ env.CMAKE_GENERATOR }}" \ + -DENABLE_CPPLINT=OFF \ + -DENABLE_NCC_STYLE=OFF \ + -DENABLE_TESTS=ON \ + -DENABLE_STRICT_DEPENDENCIES=OFF \ + -DENABLE_SYSTEM_TBB=ON \ + -DENABLE_SYSTEM_OPENCL=ON \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCPACK_GENERATOR=TGZ \ + -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ + -DCMAKE_CXX_COMPILER_LAUNCHER=${{ env.CMAKE_CXX_COMPILER_LAUNCHER }} \ + -DCMAKE_C_COMPILER_LAUNCHER=${{ env.CMAKE_C_COMPILER_LAUNCHER }} \ + -S ${OPENVINO_REPO} \ + -B ${BUILD_DIR} + + - name: Clean sccache stats + run: ${SCCACHE_PATH} --zero-stats + + - name: Cmake build - OpenVINO + run: cmake --build ${BUILD_DIR} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} + + - name: Show sccache stats + run: ${SCCACHE_PATH} --show-stats + + - name: Cmake install - OpenVINO + run: | + cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -P ${BUILD_DIR}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} -DCOMPONENT=tests -P ${BUILD_DIR}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${DEVELOPER_PACKAGE_DIR} -DCOMPONENT=developer_package -P ${BUILD_DIR}/cmake_install.cmake + cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DCOMPONENT=python_wheels -P ${BUILD_DIR}/cmake_install.cmake + + - name: Pack Artifacts + run: | + + # Add the ONNX Runtime version and skip tests list to the archive to use in the ONNX Runtime Job + # w/o the need to checkout repository + + cp -R ${ONNX_RUNTIME_UTILS} ${INSTALL_DIR} + + pushd ${INSTALL_DIR} + tar -czvf ${BUILD_DIR}/openvino_package.tar.gz * + popd + + pushd ${DEVELOPER_PACKAGE_DIR} + tar -czvf ${BUILD_DIR}/openvino_developer_package.tar.gz * + popd + + pushd ${INSTALL_TEST_DIR} + tar -czvf ${BUILD_DIR}/openvino_tests.tar.gz * + popd + + - name: Build Debian packages + run: | + /usr/bin/python3.8 -m pip install -U pip + /usr/bin/python3.8 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/wheel/requirements-dev.txt + /usr/bin/python3.8 -m pip install -r ${OPENVINO_REPO}/src/bindings/python/src/compatibility/openvino/requirements-dev.txt + cmake -UPYTHON* \ + -DENABLE_PYTHON_PACKAGING=ON \ + -DENABLE_TESTS=OFF \ + -DPython3_EXECUTABLE=/usr/bin/python3.8 \ + -DCPACK_GENERATOR=DEB \ + ${BUILD_DIR} + cmake --build ${BUILD_DIR} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --target package + + - name: Cmake & Build - OpenVINO Contrib + run: | + cmake \ + -DBUILD_nvidia_plugin=OFF \ + -DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" \ + -DOPENVINO_EXTRA_MODULES=${OPENVINO_CONTRIB_REPO}/modules \ + -S ${OPENVINO_REPO} \ + -B ${BUILD_DIR} + cmake --build ${BUILD_DIR} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} + + # + # Upload build artifacts + # + + - name: Upload openvino package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_package + path: ${{ env.BUILD_DIR }}/openvino_package.tar.gz + if-no-files-found: 'error' + + - name: Upload openvino developer package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_developer_package + path: ${{ env.BUILD_DIR }}/openvino_developer_package.tar.gz + if-no-files-found: 'error' + + - name: Upload openvino debian packages + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_debian_packages + path: ${{ env.BUILD_DIR }}/*.deb + if-no-files-found: 'error' + + - name: Upload openvino tests package + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: openvino_tests + path: ${{ env.BUILD_DIR }}/openvino_tests.tar.gz + if-no-files-found: 'error' + + Debian_Packages: + name: Debian Packages + needs: Build + timeout-minutes: 10 + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + container: + image: 'openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04' + env: + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + DEBIAN_PACKAGES_DIR: /__w/openvino/packages/ + + steps: + - name: Download OpenVINO debian packages + uses: actions/download-artifact@v3 + with: + name: openvino_debian_packages + path: ${{ env.DEBIAN_PACKAGES_DIR }} + + - name: Install debian packages & check conflicts + run: | + apt-get update -y + # install our local one + apt-get install --no-install-recommends -y dpkg-dev + dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz + echo "deb [trusted=yes] file:${DEBIAN_PACKAGES_DIR} ./" | tee /etc/apt/sources.list.d/openvino-local.list + apt-get update -y + apt-get install openvino -y + working-directory: ${{ env.DEBIAN_PACKAGES_DIR }} + + - name: Test debian packages + run: | + /usr/share/openvino/samples/cpp/build_samples.sh + /usr/share/openvino/samples/c/build_samples.sh + + ~/openvino_cpp_samples_build/aarch64/Release/hello_query_device + + python3 /usr/share/openvino/samples/python/hello_query_device/hello_query_device.py + python3 -c 'from openvino import Core; Core().get_property("CPU", "AVAILABLE_DEVICES")' + python3 -c 'from openvino import Core; Core().get_property("AUTO", "SUPPORTED_METRICS")' + python3 -c 'from openvino import Core; Core().get_property("MULTI", "SUPPORTED_METRICS")' + python3 -c 'from openvino import Core; Core().get_property("HETERO", "SUPPORTED_METRICS")' + python3 -c 'from openvino import Core; Core().get_property("BATCH", "SUPPORTED_METRICS")' + python3 -c 'from openvino.frontend import FrontEndManager; assert len(FrontEndManager().get_available_front_ends()) == 6' + benchmark_app --help + ovc --help + + Samples: + needs: [Build, Smart_CI] + timeout-minutes: 20 + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + container: + image: 'openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04' + env: + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests + BUILD_DIR: /__w/openvino/openvino/build + if: fromJSON(needs.smart_ci.outputs.affected_components).samples + + steps: + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} + popd + + - name: Install OpenVINO dependencies + run: ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -c=dev -y + + - name: Fetch setup_python action + uses: actions/checkout@v4 + with: + sparse-checkout: | + .github/actions/setup_python/action.yml + sparse-checkout-cone-mode: false + path: 'openvino' + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: ./openvino/.github/actions/setup_python + with: + version: ${{ env.PYTHON_VERSION }} + should-setup-pip-paths: 'false' + self-hosted-runner: 'true' + + - name: Build cpp samples - GCC + run: ${INSTALL_DIR}/samples/cpp/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/cpp_samples + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' + + - name: Build cpp samples - Clang + run: | + apt-get install -y clang + ${INSTALL_DIR}/samples/cpp/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/cpp_samples_clang + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' + CC: clang + CXX: clang++ + + - name: Build c samples + run: ${INSTALL_DIR}/samples/c/build_samples.sh -i ${INSTALL_DIR} -b ${BUILD_DIR}/c_samples + env: + CMAKE_COMPILE_WARNING_AS_ERROR: 'ON' + + # + # Tests + # + + - name: Samples tests + if: fromJSON(needs.smart_ci.outputs.affected_components).samples.test + run: | + export WORKSPACE=${INSTALL_DIR} + export IE_APP_PATH=${INSTALL_DIR}/samples_bin + export IE_APP_PYTHON_PATH=${INSTALL_DIR}/samples/python + export SHARE=${INSTALL_TEST_DIR}/smoke_tests/samples_smoke_tests_data + + python3 -m pip install --ignore-installed PyYAML -r ${INSTALL_TEST_DIR}/smoke_tests/requirements.txt + export LD_LIBRARY_PATH=${IE_APP_PATH}:$LD_LIBRARY_PATH + + source ${INSTALL_DIR}/setupvars.sh + + python3 -m pytest -sv ${INSTALL_TEST_DIR}/smoke_tests \ + --env_conf ${INSTALL_TEST_DIR}/smoke_tests/env_config.yml \ + --junitxml=${INSTALL_TEST_DIR}/TEST-SamplesSmokeTests.xml + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-samples + path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + if-no-files-found: 'warn' + + ONNX_Runtime: + name: ONNX Runtime Integration + needs: [Build, Smart_CI] + timeout-minutes: 30 + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches + options: -e SCCACHE_AZURE_BLOB_CONTAINER -e SCCACHE_AZURE_CONNECTION_STRING + env: + DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input + CMAKE_GENERATOR: 'Ninja Multi-Config' + CMAKE_CXX_COMPILER_LAUNCHER: sccache + CMAKE_C_COMPILER_LAUNCHER: sccache + OPENVINO_REPO: /__w/openvino/openvino/openvino + INSTALL_DIR: /__w/openvino/openvino/install + SCCACHE_AZURE_KEY_PREFIX: 'ubuntu20_aarch64_onnxruntime' + ONNX_RUNTIME_REPO: /__w/openvino/openvino/onnxruntime + ONNX_RUNTIME_UTILS: /__w/openvino/openvino/install/onnxruntime + ONNX_RUNTIME_BUILD_DIR: /__w/openvino/openvino/onnxruntime/build + if: fromJSON(needs.smart_ci.outputs.affected_components).ONNX_RT + + steps: + - name: Fetch install_build_dependencies.sh and setup_python action + uses: actions/checkout@v4 + with: + sparse-checkout: | + install_build_dependencies.sh + .github/actions/setup_python/action.yml + sparse-checkout-cone-mode: false + path: ${{ env.OPENVINO_REPO }} + + - name: Install git + run: | + apt-get update + apt-get install --assume-yes --no-install-recommends git ca-certificates + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: ./openvino/.github/actions/setup_python + with: + version: ${{ env.PYTHON_VERSION }} + should-setup-pip-paths: 'false' + + # + # Initialize OpenVINO + # + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package + path: ${{ env.INSTALL_DIR }} + + - name: Extract OpenVINO package + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + + - name: Install OpenVINO dependencies + run: ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -c=dev -y + + - name: Clone ONNX Runtime + run: | + branch=`tr -s '\n ' < ${ONNX_RUNTIME_UTILS}/version` + git clone --branch $branch --single-branch --recursive https://github.com/microsoft/onnxruntime.git ${ONNX_RUNTIME_REPO} + + # + # Tests + # + + - name: Install Build Dependencies + run: bash ${OPENVINO_REPO}/install_build_dependencies.sh + + - name: Install sccache + uses: mozilla-actions/sccache-action@v0.0.3 + with: + version: "v0.5.4" + + - name: Build Lin ONNX Runtime + run: | + source ${INSTALL_DIR}/setupvars.sh + + ${ONNX_RUNTIME_REPO}/build.sh \ + --config RelWithDebInfo \ + --use_openvino CPU_FP32 \ + --build_shared_lib \ + --parallel \ + --skip_tests \ + --compile_no_warning_as_error \ + --build_dir ${ONNX_RUNTIME_BUILD_DIR} + env: + CXXFLAGS: "-Wno-error=deprecated-declarations" + + - name: Show sccache stats + run: ${SCCACHE_PATH} --show-stats + + - name: Run onnxruntime_test_all + if: ${{ 'false' }} # Ticket: 126277 + run: | + source ${INSTALL_DIR}/setupvars.sh + skip_tests=$(tr -s '\n ' ':' < ${ONNX_RUNTIME_UTILS}/skip_tests) + + ./onnxruntime_test_all --gtest_filter=-$skip_tests + working-directory: ${{ env.ONNX_RUNTIME_BUILD_DIR }}/RelWithDebInfo/RelWithDebInfo + + - name: Run onnxruntime_shared_lib_test + run: | + source ${INSTALL_DIR}/setupvars.sh + ./onnxruntime_shared_lib_test --gtest_filter=-CApiTest.test_custom_op_openvino_wrapper_library + working-directory: ${{ env.ONNX_RUNTIME_BUILD_DIR }}/RelWithDebInfo/RelWithDebInfo + + - name: Run onnxruntime_global_thread_pools_test + run: | + source ${INSTALL_DIR}/setupvars.sh + ./onnxruntime_global_thread_pools_test + working-directory: ${{ env.ONNX_RUNTIME_BUILD_DIR }}/RelWithDebInfo/RelWithDebInfo + + - name: Run onnxruntime_api_tests_without_env + run: | + source ${INSTALL_DIR}/setupvars.sh + ./onnxruntime_api_tests_without_env + working-directory: ${{ env.ONNX_RUNTIME_BUILD_DIR }}/RelWithDebInfo/RelWithDebInfo + + - name: Run pytorch-converted tests + run: | + source ${INSTALL_DIR}/setupvars.sh + ./onnx_test_runner "${ONNX_RUNTIME_REPO}/cmake/external/onnx/onnx/backend/test/data/pytorch-converted" + working-directory: ${{ env.ONNX_RUNTIME_BUILD_DIR }}/RelWithDebInfo/RelWithDebInfo + + - name: Run pytorch-operator tests + run: | + source ${INSTALL_DIR}/setupvars.sh + ./onnx_test_runner "${ONNX_RUNTIME_REPO}/cmake/external/onnx/onnx/backend/test/data/pytorch-operator" + working-directory: ${{ env.ONNX_RUNTIME_BUILD_DIR }}/RelWithDebInfo/RelWithDebInfo + + CXX_Unit_Tests: + name: C++ unit tests + needs: [Build, Smart_CI] + timeout-minutes: 20 + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + env: + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests + + steps: + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} + popd + + - name: Install OpenVINO dependencies + run: ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -c=gpu -y + + # + # Tests + # + + - name: OpenVINO Core Unit Tests + if: fromJSON(needs.smart_ci.outputs.affected_components).Core.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_core_unit_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OVCoreUT.xml + + - name: OpenVINO Inference Functional Tests + if: fromJSON(needs.smart_ci.outputs.affected_components).inference.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_inference_functional_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-InferenceFunc.xml + + - name: OpenVINO Inference Unit Tests + if: fromJSON(needs.smart_ci.outputs.affected_components).inference.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_inference_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-InferenceUnit.xml + + - name: Low Precision Transformations Tests + if: fromJSON(needs.smart_ci.outputs.affected_components).LP_transformations.test + run: | + source ${INSTALL_DIR}/setupvars.sh + + # Skip filter ticket: 126279 + ${INSTALL_TEST_DIR}/ov_lp_transformations_tests --gtest_print_time=1 \ + --gtest_filter=-*smoke_LPT/FoldFakeQuantizeInTransformations.CompareFunctions* \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-LpTransformations.xml + + - name: OpenVINO Conditional compilation tests + if: fromJSON(needs.smart_ci.outputs.affected_components).Core.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_conditional_compilation_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ConditionalCompilation.xml + + - name: IR frontend tests + if: fromJSON(needs.smart_ci.outputs.affected_components).IR_FE.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_ir_frontend_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-IRFrontend.xml + + - name: PaddlePaddle frontend tests + if: ${{ 'false' }} + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/paddle_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-PaddleTests.xml + + - name: ONNX frontend tests + if: ${{ 'false' }} # Ticket: 126280 + #if: fromJSON(needs.smart_ci.outputs.affected_components).ONNX_FE.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_onnx_frontend_tests --gtest_print_time=1 \ + --gtest_filter=-*IE_GPU* \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ONNXFrontend.xml + + - name: TensorFlow Common frontend tests + if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test || + fromJSON(needs.smart_ci.outputs.affected_components).TFL_FE.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_tensorflow_common_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TensorFlowCommonFrontend.xml + + - name: TensorFlow frontend tests + if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_tensorflow_frontend_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TensorFlowFrontend.xml + + - name: TensorFlow Lite frontend tests + if: fromJSON(needs.smart_ci.outputs.affected_components).TFL_FE.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_tensorflow_lite_frontend_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TensorFlowLiteFrontend.xml + + - name: Transformations func tests + if: ${{ 'false' }} # Ticket: 126281 + #if: fromJSON(needs.smart_ci.outputs.affected_components).transformations.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_transformations_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-Transformations.xml + + - name: Common test utils tests + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_util_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-CommonUtilTests.xml + + - name: Snippets func tests + #if: fromJSON(needs.smart_ci.outputs.affected_components).CPU.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_snippets_func_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-SnippetsFuncTests.xml + + - name: CPU plugin unit tests + if: fromJSON(needs.smart_ci.outputs.affected_components).CPU.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_cpu_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-CPUUnitTests.xml + + - name: ov_subgraphs_dumper_tests tests + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_subgraphs_dumper_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ov_subgraphs_dumper_tests.xml + + - name: Template OpImpl tests + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_op_conformance_tests --gtest_print_time=1 --device=TEMPLATE --gtest_filter=*OpImpl*\ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OpImplTests.xml + + - name: AUTO unit tests + if: fromJSON(needs.smart_ci.outputs.affected_components).AUTO.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_auto_unit_tests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ov_auto_unit_tests.xml + + - name: AUTO func Tests + if: fromJSON(needs.smart_ci.outputs.affected_components).AUTO.test + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_auto_func_tests --gtest_print_time=1 \ + --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ov_auto_func_tests.xml + + - name: Template plugin func tests + if: fromJSON(needs.smart_ci.outputs.affected_components).TEMPLATE.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_template_func_tests --gtest_print_time=1 \ + --gtest_filter=*smoke* \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-TemplateFuncTests.xml + + - name: Inference Engine C API tests + if: fromJSON(needs.smart_ci.outputs.affected_components).C_API.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/InferenceEngineCAPITests --gtest_print_time=1 \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-InferenceEngineCAPITests.xml + + - name: OpenVINO C API tests + if: fromJSON(needs.smart_ci.outputs.affected_components).C_API.test + run: | + source ${INSTALL_DIR}/setupvars.sh + + # Skip filter ticket: 126283 + ${INSTALL_TEST_DIR}/ov_capi_test --gtest_print_time=1 \ + --gtest_filter=-*ov_core/ov_core_test.ov_core_compile_model_with_property* \ + --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OpenVINOCAPITests.xml + + - name: AutoBatch unit tests + if: fromJSON(needs.smart_ci.outputs.affected_components).AUTO_BATCH.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_auto_batch_unit_tests --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ov_auto_batch_unit_tests.xml + + - name: AutoBatch func tests + if: fromJSON(needs.smart_ci.outputs.affected_components).AUTO_BATCH.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_auto_batch_func_tests --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-ov_auto_batch_func_tests.xml + + - name: Proxy Plugin func tests + if: fromJSON(needs.smart_ci.outputs.affected_components).PROXY.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_proxy_plugin_tests --gtest_print_time=1 --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OVProxyTests.xml + + - name: Hetero unit tests + if: fromJSON(needs.smart_ci.outputs.affected_components).HETERO.test + run: | + source ${{ env.INSTALL_DIR }}/setupvars.sh + ${{ env.INSTALL_TEST_DIR }}/ov_hetero_unit_tests --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-OVHeteroUnitTests.xml + + - name: Hetero func tests + if: fromJSON(needs.smart_ci.outputs.affected_components).HETERO.test + run: | + source ${INSTALL_DIR}/setupvars.sh + ${INSTALL_TEST_DIR}/ov_hetero_func_tests --gtest_print_time=1 --gtest_output=xml:${INSTALL_TEST_DIR}/TEST-OVHeteroFuncTests.xml + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-cpp + path: ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + if-no-files-found: 'warn' + + Python_Unit_Tests: + name: Python unit tests + needs: [Build, Smart_CI] + timeout-minutes: 180 + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches + env: + OPENVINO_REPO: /__w/openvino/openvino/openvino + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests + LAYER_TESTS_INSTALL_DIR: /__w/openvino/openvino/install/tests/layer_tests + + steps: + # + # Initialize OpenVINO + # + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} + popd + + - name: Fetch setup_python action + uses: actions/checkout@v4 + with: + sparse-checkout: | + .github/actions/setup_python/action.yml + sparse-checkout-cone-mode: false + path: ${{ env.OPENVINO_REPO }} + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: ./openvino/.github/actions/setup_python + with: + version: ${{ env.PYTHON_VERSION }} + pip-cache-path: ${{ env.PIP_CACHE_PATH }} + should-setup-pip-paths: 'true' + + - name: Install OpenVINO dependencies + run: | + apt-get update && apt-get install -y gcc python3-dev # Needed for building `psutil` + ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -y + + - name: Install OpenVINO Python wheels + run: | + # Install the core OV wheel + python3 -m pip install ${INSTALL_DIR}/tools/openvino-*.whl + + # Find and install OV dev wheel + pushd ${INSTALL_DIR}/tools + ov_dev_wheel_name=$(find . -name 'openvino_dev*.whl') + python3 -m pip install $ov_dev_wheel_name[mxnet,caffe,kaldi,onnx,tensorflow2,pytorch] + popd + + - name: Install Python API tests dependencies + run: | + # To enable pytest parallel features + python3 -m pip install pytest-xdist[psutil] + # For torchvision to OpenVINO preprocessing converter + python3 -m pip install -r ${INSTALL_TEST_DIR}/python/preprocess/torchvision/requirements.txt + + # TODO: replace with Python API tests requirements + python3 -m pip install -r ${INSTALL_TEST_DIR}/mo/requirements_dev.txt + + # + # Tests + # + + - name: Python API 1.0 Tests + if: fromJSON(needs.smart_ci.outputs.affected_components).Python_API.test + run: | + python3 -m pytest -s ${INSTALL_TEST_DIR}/pyngraph \ + --junitxml=${INSTALL_TEST_DIR}/TEST-Pyngraph.xml \ + --ignore=${INSTALL_TEST_DIR}/pyngraph/tests_compatibility/test_onnx/test_zoo_models.py \ + --ignore=${INSTALL_TEST_DIR}/pyngraph/tests_compatibility/test_onnx/test_backend.py + + - name: Python API 2.0 Tests + timeout-minutes: 30 + if: ${{ 'false' }} # Ticket: 126380 + #if: fromJSON(needs.smart_ci.outputs.affected_components).Python_API.test + run: | + # for 'template' extension + export LD_LIBRARY_PATH=${INSTALL_TEST_DIR}:$LD_LIBRARY_PATH + python3 -m pytest -sv ${INSTALL_TEST_DIR}/pyopenvino \ + --junitxml=${INSTALL_TEST_DIR}/TEST-Pyngraph.xml \ + --ignore=${INSTALL_TEST_DIR}/pyopenvino/tests/test_utils/test_utils.py + + - name: Model Optimizer unit tests + if: fromJSON(needs.smart_ci.outputs.affected_components).MO.test + run: | + python3 -m pytest -s ${INSTALL_TEST_DIR}/mo/unit_tests \ + --junitxml=${INSTALL_TEST_DIR}/TEST-ModelOptimizer.xml \ + --ignore-glob="**/mo/front/mxnet/**" + + - name: Python ONNX operators tests + if: fromJSON(needs.smart_ci.outputs.affected_components).Python_API.test || + fromJSON(needs.smart_ci.outputs.affected_components).ONNX_FE.test + run: | + # Skip test_onnx/test_zoo_models and test_onnx/test_backend due to long execution time - ONNX Model Zoo tests are run separately + python3 -m pytest -sv ${INSTALL_TEST_DIR}/onnx -k 'not cuda' \ + --junitxml=${INSTALL_TEST_DIR}/TEST-onnx_frontend.xml \ + --ignore=${INSTALL_TEST_DIR}/onnx/test_python/test_zoo_models.py + + - name: OVC unit tests + if: fromJSON(needs.smart_ci.outputs.affected_components).MO.test + run: python3 -m pytest -s ${INSTALL_TEST_DIR}/ovc/unit_tests --junitxml=${INSTALL_TEST_DIR}/TEST-OpenVinoConversion.xml + + - name: Install Python Layer tests dependencies + if: ${{ always() }} + run: | + # layer test requirements + python3 -m pip install -r ${LAYER_TESTS_INSTALL_DIR}/requirements.txt + + - name: MO Python API Tests + if: fromJSON(needs.smart_ci.outputs.affected_components).MO.test + run: | + # Import 'test_utils' installed in '/tests/python/openvino' + export LD_LIBRARY_PATH=${PIP_INSTALL_PATH}/openvino/libs:$LD_LIBRARY_PATH + export PYTHONPATH=${INSTALL_TEST_DIR}/python + export LD_PRELOAD=${PIP_INSTALL_PATH}/torch/lib/../../torch.libs/libgomp-d22c30c5.so.1.0.0 + + echo ${PIP_INSTALL_PATH} + echo ${PIP_INSTALL_PATH} + echo ${PIP_INSTALL_PATH} + + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/mo_python_api_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_mo_convert.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: OVC Python API Tests + if: fromJSON(needs.smart_ci.outputs.affected_components).MO.test + run: | + # Import 'test_utils' installed in '/tests/python/openvino' + export PYTHONPATH=${INSTALL_TEST_DIR}/python + export LD_LIBRARY_PATH=${PIP_INSTALL_PATH}/openvino/libs:$LD_LIBRARY_PATH + export LD_PRELOAD=${PIP_INSTALL_PATH}/torch/lib/../../torch.libs/libgomp-d22c30c5.so.1.0.0 + + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/ovc_python_api_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_ovc_convert.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: Python Frontend tests + if: fromJSON(needs.smart_ci.outputs.affected_components).PyTorch_FE.test || + fromJSON(needs.smart_ci.outputs.affected_components).PDPD_FE.test + run: | + # to allow 'libtest_builtin_extensions.so' to find 'libopenvino_onnx_frontend.so' + export LD_LIBRARY_PATH=${PIP_INSTALL_PATH}/openvino/libs:$LD_LIBRARY_PATH + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/py_frontend_tests --junitxml=${INSTALL_TEST_DIR}/TEST-test_py_fontend.xml + + - name: PyTorch Layer Tests + timeout-minutes: 20 + if: ${{ 'false' }} # Ticket: 126287 + #if: fromJSON(needs.smart_ci.outputs.affected_components).PyTorch_FE.test + run: python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/pytorch_tests -n logical -m precommit --junitxml=${INSTALL_TEST_DIR}/TEST-pytorch.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP32 + + - name: PyTorch torch.compile TORCHFX Layer Tests + if: ${{ 'false' }} # RuntimeError: Python 3.11+ not yet supported for torch.compile, torch 2.0.1 is installed on Linux ARM64, it works in torch 2.1.1 + timeout-minutes: 20 + #if: fromJSON(needs.smart_ci.outputs.affected_components).PyTorch_FE.test + run: | + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/pytorch_tests -m precommit_fx_backend --junitxml=${INSTALL_TEST_DIR}/TEST-pytorch.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP32 + PYTORCH_TRACING_MODE: TORCHFX + + - name: PyTorch torch.compile TORCHSCRIPT Layer Tests + if: ${{ 'false' }} # RuntimeError: Python 3.11+ not yet supported for torch.compile, torch 2.0.1 is installed on Linux ARM64, it works in torch 2.1.1 + timeout-minutes: 20 + #if: fromJSON(needs.smart_ci.outputs.affected_components).PyTorch_FE.test + run: | + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/pytorch_tests -m precommit_ts_backend --junitxml=${INSTALL_TEST_DIR}/TEST-pytorch.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP32 + PYTORCH_TRACING_MODE: TORCHSCRIPT + + - name: ONNX Layer Tests + timeout-minutes: 30 + if: fromJSON(needs.smart_ci.outputs.affected_components).ONNX_FE.test + run: | + # requires 'unit_tests' from 'tools/mo' + export PYTHONPATH=${INSTALL_TEST_DIR}/mo:$PYTHONPATH + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/onnx_tests -m "not launch_only_if_manually_specified and precommit" --junitxml=${INSTALL_TEST_DIR}/TEST-onnx.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: TensorFlow 1 Layer Tests - TF FE + timeout-minutes: 30 + if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test + run: | + # requires 'unit_tests' from 'mo' + export PYTHONPATH=${INSTALL_TEST_DIR}/mo + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf_fe.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: TensorFlow 2 Layer Tests - TF FE + timeout-minutes: 30 + if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test + run: | + # requires 'unit_tests' from 'mo' + export PYTHONPATH=${INSTALL_TEST_DIR}/mo + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/ --use_new_frontend -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_fe.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: JAX Layer Tests - TF FE + timeout-minutes: 30 + if: ${{ 'false' }} + #if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test + run: python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/jax_tests/ -m precommit --junitxml=${INSTALL_TEST_DIR}/TEST-jax.xml + env: + TEST_DEVICE: CPU + + - name: TensorFlow 1 Layer Tests - Legacy FE + timeout-minutes: 30 + run: python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_tests/test_tf_Roll.py --ir_version=10 --junitxml=${INSTALL_TEST_DIR}/TEST-tf_Roll.xml + + - name: TensorFlow 2 Layer Tests - Legacy FE + timeout-minutes: 30 + if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test + run: python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_tests/test_tf_Roll.py --ir_version=10 --junitxml=${INSTALL_TEST_DIR}/TEST-tf_Roll.xml + + - name: TensorFlow 2 Layer Tests - Legacy FE + if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test + run: python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/test_tf2_keras_activation.py --ir_version=11 -k "sigmoid" --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_Activation.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: TensorFlow Lite Layer Tests - TFL FE + timeout-minutes: 30 + if: fromJSON(needs.smart_ci.outputs.affected_components).TFL_FE.test + run: python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow_lite_tests/ --junitxml=${INSTALL_TEST_DIR}/TEST-tfl_fe.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP16 + + - name: Clone API snippets + if: ${{ always() }} + uses: actions/checkout@v4 + with: + sparse-checkout: openvino/docs/snippets + path: ${{ env.OPENVINO_REPO }} + submodules: 'false' + + - name: Docs Python snippets + if: ${{ always() }} + run: | + # to find 'snippets' module in docs + export PYTHONPATH=${OPENVINO_REPO}/docs + # for 'template' extension + export LD_LIBRARY_PATH=${INSTALL_TEST_DIR}:$LD_LIBRARY_PATH + python3 ${OPENVINO_REPO}/docs/snippets/main.py + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-python + path: | + ${{ env.INSTALL_TEST_DIR }}/TEST*.html + ${{ env.INSTALL_TEST_DIR }}/TEST*.xml + if-no-files-found: 'warn' + + CPU_Functional_Tests: + name: CPU functional tests + needs: [Build, Smart_CI] + timeout-minutes: 60 + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + env: + OPENVINO_REPO: /__w/openvino/openvino/openvino + INSTALL_DIR: /__w/openvino/openvino/install + INSTALL_TEST_DIR: /__w/openvino/openvino/install/tests + PARALLEL_TEST_SCRIPT: /__w/openvino/openvino/install/tests/functional_test_utils/layer_tests_summary/run_parallel.py + PARALLEL_TEST_CACHE: /__w/openvino/openvino/install/tests/test_cache.lst + # if: fromJSON(needs.smart_ci.outputs.affected_components).CPU.test + if: ${{ 'false' }} # Ticket: 126379 + steps: + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} + popd + + - name: Install OpenVINO dependencies + run: bash ${INSTALL_DIR}/install_dependencies/install_openvino_dependencies.sh -c=core -y + + - name: Fetch setup_python action + uses: actions/checkout@v4 + with: + sparse-checkout: | + .github/actions/setup_python/action.yml + sparse-checkout-cone-mode: false + path: ${{ env.OPENVINO_REPO }} + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: ./openvino/.github/actions/setup_python + with: + version: ${{ env.PYTHON_VERSION }} + should-setup-pip-paths: 'false' + + - name: Install python dependencies for run_parallel.py + run: python3 -m pip install -r ${INSTALL_TEST_DIR}/functional_test_utils/layer_tests_summary/requirements.txt + + - name: Restore tests execution time + uses: actions/cache/restore@v3 + with: + path: ${{ env.PARALLEL_TEST_CACHE }} + key: ${{ runner.os }}-${{ runner.arch }}-tests-functional-cpu-stamp-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-${{ runner.arch }}-tests-functional-cpu-stamp + + - name: Intel CPU plugin func tests (parallel) + run: | + source ${INSTALL_DIR}/setupvars.sh + python3 ${PARALLEL_TEST_SCRIPT} -e ${INSTALL_TEST_DIR}/ov_cpu_func_tests -c ${PARALLEL_TEST_CACHE} -w ${INSTALL_TEST_DIR} -s suite -rf 0 -- --gtest_print_time=1 --gtest_filter=*smoke* + timeout-minutes: 40 + + - name: Save tests execution time + uses: actions/cache/save@v3 + if: github.ref_name == 'master' + with: + path: ${{ env.PARALLEL_TEST_CACHE }} + key: ${{ runner.os }}-${{ runner.arch }}-tests-functional-cpu-stamp-${{ github.sha }} + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-functional-cpu + path: | + ${{ env.INSTALL_TEST_DIR }}/temp/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/failed/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/crashed/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/hanged/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/interapted/*.log + ${{ env.INSTALL_TEST_DIR }}/logs/hash_table.csv + ${{ env.PARALLEL_TEST_CACHE }} + if-no-files-found: 'error' + + TensorFlow_Hub_Models_Tests: + name: TensorFlow Hub Models tests + needs: [Build, Smart_CI] + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + timeout-minutes: ${{ github.event_name == 'schedule' && 400 || 5 }} + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches + env: + OPENVINO_REPO: ${{ github.workspace }}/openvino + INSTALL_DIR: ${{ github.workspace }}/install + INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests + MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests + # if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test || + # fromJSON(needs.smart_ci.outputs.affected_components).TFL_FE.test + if: ${{ 'false' }} # TODO: Enable once the self-hosted runners are ready for them + + steps: + - name: Check sudo + run: if [ "$(id -u)" -eq 0 ]; then apt update && apt --assume-yes install sudo; fi + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package_x86_64 + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests_x86_64 + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} + popd + + - name: Fetch setup_python action + uses: actions/checkout@v4 + with: + sparse-checkout: | + .github/actions/setup_python/action.yml + sparse-checkout-cone-mode: false + path: 'openvino' + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: ./openvino/.github/actions/setup_python + with: + version: ${{ env.PYTHON_VERSION }} + should-setup-pip-paths: 'false' + self-hosted-runner: 'false' + + - name: Install OpenVINO Python wheels + run: python3 -m pip install ${INSTALL_DIR}/tools/openvino-* + + - name: Install TF Hub tests requirements + run: | + python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_hub_tests/requirements.txt + + - name: TensorFlow Hub Tests - TF FE + run: | + export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH + python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_hub_tests/ -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-tf_hub_tf_fe.html --self-contained-html -v + env: + TYPE: ${{ github.event_name == 'schedule' && 'nightly' || 'precommit'}} + TEST_DEVICE: CPU + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-tensorflow-hub-models + path: | + ${{ env.INSTALL_TEST_DIR }}/TEST*.html + if-no-files-found: 'error' + + TensorFlow_Hub_Performance_Models_Tests: + name: TensorFlow Hub Performance Models tests + needs: [Build, Smart_CI] + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + timeout-minutes: ${{ github.event_name == 'schedule' && 400 || 5 }} + env: + OPENVINO_REPO: ${{ github.workspace }}/openvino + INSTALL_DIR: ${{ github.workspace }}/install + INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests + MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests + # if: fromJSON(needs.smart_ci.outputs.affected_components).TF_FE.test || + # fromJSON(needs.smart_ci.outputs.affected_components).TFL_FE.test + if: ${{ 'false' }} # TODO: Enable once the self-hosted runners are ready for them + + steps: + - name: Check sudo + run: if [ "$(id -u)" -eq 0 ]; then apt update && apt --assume-yes install sudo; fi + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package_x86_64 + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests_x86_64 + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} + popd + + - name: Fetch setup_python action + uses: actions/checkout@v4 + with: + sparse-checkout: | + .github/actions/setup_python/action.yml + sparse-checkout-cone-mode: false + path: 'openvino' + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: ./openvino/.github/actions/setup_python + with: + version: ${{ env.PYTHON_VERSION }} + should-setup-pip-paths: 'false' + self-hosted-runner: 'false' + + - name: Install OpenVINO Python wheels + run: python3 -m pip install ${INSTALL_DIR}/tools/openvino-* + + - name: Install TF Hub tests requirements + run: | + python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/tf_hub_tests/requirements.txt + + - name: Install Hub Performance tests requirements + run: | + python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/performance_tests/requirements.txt + + - name: Performance Hub Tests + run: | + export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH + python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/performance_tests/ -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-tf_hub_performance.html --self-contained-html -v + env: + TYPE: ${{ github.event_name == 'schedule' && 'nightly' || 'precommit'}} + TEST_DEVICE: CPU + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-tensorflow-hub-performance-models + path: | + ${{ env.INSTALL_TEST_DIR }}/TEST*.html + if-no-files-found: 'error' + + # TODO: Enable once they are ready for self-hosted runners + PyTorch_Models_Tests: + name: PyTorch Models tests + needs: [Build, Smart_CI] + timeout-minutes: ${{ github.event_name == 'schedule' && 400 || 30 }} + defaults: + run: + shell: bash + runs-on: 'aks-linux-16-cores-arm' + container: + image: openvinogithubactions.azurecr.io/dockerhub/ubuntu:20.04 + volumes: + - /mount/caches:/mount/caches + env: + OPENVINO_REPO: ${{ github.workspace }}/openvino + INSTALL_DIR: ${{ github.workspace }}/install + INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests + MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests + # if: fromJSON(needs.smart_ci.outputs.affected_components).PyTorch_FE.test + if: ${{ 'false' }} # TODO: Enable once the self-hosted runners are ready for them + + steps: + - name: Check sudo + run: if [ "$(id -u)" -eq 0 ]; then apt update && apt --assume-yes install sudo; fi + + - name: Install dependencies + run: | + # install git (required to build pip deps from the sources) + # install 'g++' to build 'detectron2' and 'natten' wheels + sudo apt-get install --assume-yes --no-install-recommends g++ git ca-certificates + + - name: Download OpenVINO package + uses: actions/download-artifact@v3 + with: + name: openvino_package_x86_64 + path: ${{ env.INSTALL_DIR }} + + - name: Download OpenVINO tests package + uses: actions/download-artifact@v3 + with: + name: openvino_tests_x86_64 + path: ${{ env.INSTALL_TEST_DIR }} + + - name: Extract OpenVINO packages + run: | + pushd ${INSTALL_DIR} + tar -xzf openvino_package.tar.gz -C ${INSTALL_DIR} + popd + pushd ${INSTALL_TEST_DIR} + tar -xzf openvino_tests.tar.gz -C ${INSTALL_DIR} + popd + + - name: Fetch setup_python action + uses: actions/checkout@v4 + with: + sparse-checkout: | + .github/actions/setup_python/action.yml + sparse-checkout-cone-mode: false + path: 'openvino' + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: ./openvino/.github/actions/setup_python + with: + version: ${{ env.PYTHON_VERSION }} + should-setup-pip-paths: 'false' + self-hosted-runner: 'false' + + - name: Install OpenVINO Python wheels + run: python3 -m pip install ${INSTALL_DIR}/tools/openvino-* + + - name: Install PyTorch tests requirements + run: | + python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests/requirements.txt + python3 -m pip install -r ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests/requirements_secondary.txt + echo "Available storage:" + df -h + env: + CPLUS_INCLUDE_PATH: ${{ env.Python_ROOT_DIR }}/include/python${{ env.PYTHON_VERSION }} + + - name: PyTorch Models Tests + run: | + export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH + python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/torch_tests -m ${TYPE} --html=${INSTALL_TEST_DIR}/TEST-torch_model_tests.html --self-contained-html -v + env: + TYPE: ${{ github.event_name == 'schedule' && 'nightly' || 'precommit'}} + TEST_DEVICE: CPU + USE_SYSTEM_CACHE: False + + - name: Available storage after tests + run: | + echo "Available storage:" + df -h + + - name: Upload Test Results + uses: actions/upload-artifact@v3 + if: ${{ !cancelled() }} + with: + name: test-results-torch-models + path: | + ${{ env.INSTALL_TEST_DIR }}/TEST*.html + if-no-files-found: 'error' + + Overall_Status: + name: ci/gha_overall_status + needs: [Smart_CI, Build, Debian_Packages, Samples, ONNX_Runtime, CXX_Unit_Tests, Python_Unit_Tests] + if: ${{ always() }} + runs-on: ubuntu-latest + steps: + - name: Check status of all jobs + if: >- + ${{ + contains(needs.*.result, 'failure') || + contains(needs.*.result, 'cancelled') + }} + run: exit 1 diff --git a/src/common/transformations/tests/utils/compress_quantize_weights.cpp b/src/common/transformations/tests/utils/compress_quantize_weights.cpp index 15d07188f805f2..0b730d0b36be5a 100644 --- a/src/common/transformations/tests/utils/compress_quantize_weights.cpp +++ b/src/common/transformations/tests/utils/compress_quantize_weights.cpp @@ -82,7 +82,12 @@ class CompressQuantizeWeightsTests } }; +#ifdef OPENVINO_ARCH_ARM64 +// Ticket: CVS-122397 +TEST_P(CompressQuantizeWeightsTests, DISABLED_FusionTest) {} +#else TEST_P(CompressQuantizeWeightsTests, FusionTest) {} +#endif static std::vector params = { {Shape{2, 3, 1, 1}, diff --git a/src/frontends/onnx/tests/__init__.py b/src/frontends/onnx/tests/__init__.py index 452b03dc9b8fb8..48d058df016c01 100644 --- a/src/frontends/onnx/tests/__init__.py +++ b/src/frontends/onnx/tests/__init__.py @@ -164,3 +164,7 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True): xfail_issue_119922 = xfail_test(reason="ai.onnx.ml operators domain isn't supported") xfail_issue_119925 = xfail_test(reason="AveragePool AssertionError: Not equal to tolerance rtol=0.001, atol=1e-07") xfail_issue_119926 = xfail_test(reason="ROIAlign AssertionError: Not equal to tolerance rtol=0.001, atol=1e-07") +xfail_issue_122776 = xfail_test(reason="test_mish_expanded_cpu - " + "Not equal to tolerance") +xfail_issue_122775 = xfail_test(reason="test_resize_downsample_scales_linear_cpu - " + "Not equal to tolerance") diff --git a/src/frontends/onnx/tests/runtime/ie/unit_test.manifest b/src/frontends/onnx/tests/runtime/ie/unit_test.manifest index 6c8a302313f032..dabc8d7bfe95d4 100644 --- a/src/frontends/onnx/tests/runtime/ie/unit_test.manifest +++ b/src/frontends/onnx/tests/runtime/ie/unit_test.manifest @@ -392,3 +392,15 @@ IE_CPU.onnx_model_top_k_repeating_unsorted # Accuracy regression - Ticket 105909 IE_CPU.onnx_model_attention_qkv_hidden_sizes + +# Accuracy issues on ARM CPU - Ticket 122663 +IE_CPU.onnx_model_bias_gelu +IE_CPU.onnx_model_embed_layer_normalization_diff_seq_len_pos_embed_len +IE_CPU.onnx_model_embed_layer_normalization_with_position_ids +IE_CPU.onnx_resize10_down_scales_const_linear +IE_CPU.onnx_resize11_down_scales_linear_asymmetric +IE_CPU.onnx_model_softplus +IE_CPU.onnx_model_instance_normalization +IE_CPU.quant_dequant_pattern_axis +IE_CPU/GRUSequenceOp.onnx_model_gru_reverse_mixed_seq_len_const +IE_CPU/RNNSequenceOp.onnx_model_rnn_fwd_bias_initial_h_const diff --git a/src/frontends/onnx/tests/tests_python/test_backend.py b/src/frontends/onnx/tests/tests_python/test_backend.py index 27fbae1dbd3986..6a9e0fa78969e6 100644 --- a/src/frontends/onnx/tests/tests_python/test_backend.py +++ b/src/frontends/onnx/tests/tests_python/test_backend.py @@ -72,6 +72,8 @@ xfail_issue_119922, xfail_issue_119925, xfail_issue_119926, + xfail_issue_122775, + xfail_issue_122776 ) from tests.tests_python.utils.onnx_backend import OpenVinoTestBackend @@ -685,6 +687,14 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None )] ) +if platform.system() == 'Linux' and platform.machine() in ['arm', 'armv7l', 'aarch64', 'arm64', 'ARM64']: + tests_expected_to_fail.extend( + [ + (xfail_issue_122775, "OnnxBackendNodeModelTest.test_resize_downsample_scales_linear_cpu"), + (xfail_issue_122776, "OnnxBackendNodeModelTest.test_mish_expanded_cpu") + ] + ) + for test_group in tests_expected_to_fail: for test_case in test_group[1:]: expect_fail(f"{test_case}", test_group[0]) diff --git a/src/frontends/tensorflow/tests/compilation.cpp b/src/frontends/tensorflow/tests/compilation.cpp index 73a22ceed92644..e34a159a45dd06 100644 --- a/src/frontends/tensorflow/tests/compilation.cpp +++ b/src/frontends/tensorflow/tests/compilation.cpp @@ -26,7 +26,13 @@ TEST_F(CompileModelsTests, NgramCompilation) { EXPECT_EQ(runtime_model->get_results().size(), 1); } -TEST_F(CompileModelsTests, ModelWithSplitConvConcat) { +#ifdef OPENVINO_ARCH_ARM64 +// Ticket: CVS-122396 +TEST_F(CompileModelsTests, DISABLED_ModelWithSplitConvConcat) +#else +TEST_F(CompileModelsTests, ModelWithSplitConvConcat) +#endif +{ { auto model = convert_model("split_conv_concat/split_conv_concat.pbtxt"); ov::Core core; diff --git a/tests/layer_tests/mo_python_api_tests/test_mo_convert_pytorch.py b/tests/layer_tests/mo_python_api_tests/test_mo_convert_pytorch.py index 949910cad8c6f2..47bf252eed295b 100644 --- a/tests/layer_tests/mo_python_api_tests/test_mo_convert_pytorch.py +++ b/tests/layer_tests/mo_python_api_tests/test_mo_convert_pytorch.py @@ -1027,8 +1027,8 @@ class DataModel(torch.nn.Module): def __init__(self): super(DataModel, self).__init__() self.data = torch.tensor([1, 2, 3, 4]) - - def forward(self, x): + + def forward(self, x): return self.data, x data_model = DataModel() @@ -1051,13 +1051,13 @@ def forward(self, x): def test_sharing_memory_switched_on(self, ie_device, precision, ir_version, temp_dir): from openvino.tools.ovc import convert_model from openvino.runtime import Core - + class DataModel(torch.nn.Module): def __init__(self): super(DataModel, self).__init__() self.data = torch.tensor([1, 2, 3, 4]) - - def forward(self, x): + + def forward(self, x): return self.data, x data_model = DataModel() @@ -1236,8 +1236,10 @@ class TestPrecisionSensitive(): @pytest.mark.parametrize("create_model", test_data) @pytest.mark.nightly @pytest.mark.precommit - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', - reason='Ticket - 122714') + @pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), + reason='Ticket - 122714, 122710') def test_precision_sensitive(self, create_model, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): import numpy.testing as npt from pathlib import Path diff --git a/tests/layer_tests/onnx_tests/test_reduce_lp.py b/tests/layer_tests/onnx_tests/test_reduce_lp.py index 73cd86a2bbbc6f..fc9ba16859799d 100644 --- a/tests/layer_tests/onnx_tests/test_reduce_lp.py +++ b/tests/layer_tests/onnx_tests/test_reduce_lp.py @@ -234,8 +234,10 @@ def create_reduce_lp_const(self, shape, axes, keep_dims, reduce_p, ir_version): @pytest.mark.parametrize("keep_dims", [True, False]) @pytest.mark.parametrize("reduce_p", [1, 2]) @pytest.mark.precommit - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', - reason='Ticket - 122846') + @pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), + reason='Ticket - 122846, 122783, 126312') def test_reduce_lp_precommit(self, params, keep_dims, reduce_p, ie_device, precision, ir_version, temp_dir, use_old_api): self._test(*self.create_reduce_lp(**params, keep_dims=keep_dims, reduce_p=reduce_p, diff --git a/tests/layer_tests/onnx_tests/test_roi_align.py b/tests/layer_tests/onnx_tests/test_roi_align.py index a29ddc4c1d1213..88e6e9aef27808 100644 --- a/tests/layer_tests/onnx_tests/test_roi_align.py +++ b/tests/layer_tests/onnx_tests/test_roi_align.py @@ -136,8 +136,10 @@ def create_net(self, input_shape, rois_shape, indices_shape, output_shape, @pytest.mark.nightly @pytest.mark.precommit @pytest.mark.xfail(condition=platform.system() == 'Windows', reason="Ticket - 122731") - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', - reason='Ticket - 122846') + @pytest.mark.xfail(condition=platform.system() in ('Linux', 'Darwin') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), + reason='Ticket - 122846, 122783, 126312') def test_roi_alignv10(self, params, ie_device, precision, ir_version, temp_dir, use_old_api): # TODO: ticket for investigating GPU failures: CVS-86300 if ie_device != "GPU": diff --git a/tests/layer_tests/pytorch_tests/test_all.py b/tests/layer_tests/pytorch_tests/test_all.py index c8b79ee0ff5e3b..f4c2ed71ed4b54 100644 --- a/tests/layer_tests/pytorch_tests/test_all.py +++ b/tests/layer_tests/pytorch_tests/test_all.py @@ -73,7 +73,9 @@ def test_all_noparams(self, input_shape, d_type, ie_device, precision, ir_versio ]) @pytest.mark.nightly @pytest.mark.precommit - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + @pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), reason='Ticket - 122715') def test_all(self, input_shape, d_type, keepdim, ie_device, precision, ir_version): if type(input_shape) is list: diff --git a/tests/layer_tests/pytorch_tests/test_argmax_argmin.py b/tests/layer_tests/pytorch_tests/test_argmax_argmin.py index 80ed6fcb872b5f..80f035667565c3 100644 --- a/tests/layer_tests/pytorch_tests/test_argmax_argmin.py +++ b/tests/layer_tests/pytorch_tests/test_argmax_argmin.py @@ -73,7 +73,9 @@ def forward(self, x): @pytest.mark.parametrize("dtype", ["float32", "int32", "int64"]) @pytest.mark.nightly @pytest.mark.precommit - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + @pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), reason='Ticket - 122715') def test_argmin_argmax(self, axes, keep_dims, op_type, dtype, ie_device, precision, ir_version): self._test(*self.create_model(op_type, axes, keep_dims), diff --git a/tests/layer_tests/pytorch_tests/test_div.py b/tests/layer_tests/pytorch_tests/test_div.py index 564cb2915c8686..22243e1a591698 100644 --- a/tests/layer_tests/pytorch_tests/test_div.py +++ b/tests/layer_tests/pytorch_tests/test_div.py @@ -118,7 +118,9 @@ def forward3(self, lhs, rhs): ])) @pytest.mark.nightly @pytest.mark.precommit - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + @pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), reason='Ticket - 122715') def test_div_types(self, ie_device, precision, ir_version, lhs_type, lhs_shape, rhs_type, rhs_shape, rounding_mode): self.lhs_type = lhs_type diff --git a/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py b/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py index 26b7cdbd14812b..213a6e97ef78f8 100644 --- a/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py +++ b/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py @@ -76,7 +76,9 @@ def _prepare_input(self): ["need_weights", "average_attn_weights"], [[False, False], [True, False], [True, True]] ) - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + @pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), reason='Ticket - 122715') def test_native_multi_head_attention(self, ie_device, precision, ir_version, mask, need_weights, average_attn_weights): self._test(aten_native_multi_head_attention(mask, need_weights, average_attn_weights), diff --git a/tests/layer_tests/pytorch_tests/test_norm.py b/tests/layer_tests/pytorch_tests/test_norm.py index c884e6c17ff042..e3517bdf1ce874 100644 --- a/tests/layer_tests/pytorch_tests/test_norm.py +++ b/tests/layer_tests/pytorch_tests/test_norm.py @@ -263,7 +263,9 @@ def forward_out(self, x, y): @pytest.mark.parametrize("dtype", ["float32", "float64", None]) @pytest.mark.parametrize("out", [True, False]) @pytest.mark.parametrize("prim_dtype", [True, False]) - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', + @pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), reason='Ticket - 122715') def test_linalg_matrix_norm(self, p, dim, keepdim, dtype, out, prim_dtype, ie_device, precision, ir_version): self._test(*self.create_model(p, dim, keepdim, dtype, out, prim_dtype), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_ComplexFFT.py b/tests/layer_tests/tensorflow_tests/test_tf_ComplexFFT.py index 18d23b593abba1..5624d2c2984ad0 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_ComplexFFT.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_ComplexFFT.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -54,6 +56,10 @@ def create_complex_fft_net(self, input_shape, shift_roll, axis_roll, fft_op): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly + @pytest.mark.xfail(condition=platform.system() == 'Linux' and platform.machine() in ['arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'], + reason='Ticket - 126314') def test_complex_fft_basic(self, params, fft_op, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): diff --git a/tests/layer_tests/tensorflow_tests/test_tf_MaxPoolWithArgmax.py b/tests/layer_tests/tensorflow_tests/test_tf_MaxPoolWithArgmax.py index f08995f3c09d11..1805863b8c221b 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_MaxPoolWithArgmax.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_MaxPoolWithArgmax.py @@ -61,8 +61,10 @@ def create_max_pool_with_argmax_net(self, input_shape, ksize, strides, input_typ ]) @pytest.mark.precommit_tf_fe @pytest.mark.nightly - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', - reason='Ticket - 122716') + @pytest.mark.xfail(condition=platform.system() in ('Linux', 'Darwin') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), + reason='Ticket - 126314, 122716') def test_max_pool_with_argmax_basic(self, params, input_type, padding, targmax, include_batch_in_index, with_second_output, ie_device, precision, ir_version, temp_dir, diff --git a/tests/layer_tests/tensorflow_tests/test_tf_NormalizeL2.py b/tests/layer_tests/tensorflow_tests/test_tf_NormalizeL2.py index 5de76778d1d837..cfd06c7d3f32fe 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_NormalizeL2.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_NormalizeL2.py @@ -32,8 +32,10 @@ def create_normalize_l2_net(shape, axes): @pytest.mark.precommit @pytest.mark.precommit_tf_fe @pytest.mark.nightly - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', - reason='Ticket - 122716') + @pytest.mark.xfail(condition=platform.system() in ('Linux', 'Darwin') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), + reason='Ticket - 126314, 122716') def test_normalize_l2_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_normalize_l2_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py b/tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py index 73efaf490b23dd..737675de84dac8 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_TopKV2.py @@ -48,8 +48,10 @@ def create_topk_v2_net(self, input_shape, input_type, k, sorted, is_first_output @pytest.mark.parametrize("params", test_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', - reason='Ticket - 122716') + @pytest.mark.xfail(condition=platform.system() in ('Linux', 'Darwin') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), + reason='Ticket - 126314, 122716') def test_topk_v2_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_topk_v2_net(**params), diff --git a/tests/layer_tests/tensorflow_tests/test_tf_TruncateDiv.py b/tests/layer_tests/tensorflow_tests/test_tf_TruncateDiv.py index 18440dbcd7f44a..55859e62eca12d 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_TruncateDiv.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_TruncateDiv.py @@ -44,8 +44,10 @@ def create_truncate_div_net(self, input_shape, input_type): @pytest.mark.parametrize("params", test_data_basic) @pytest.mark.precommit_tf_fe @pytest.mark.nightly - @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', - reason='Ticket - 122716') + @pytest.mark.xfail(condition=platform.system() in ('Linux', 'Darwin') and platform.machine() in ('arm', 'armv7l', + 'aarch64', + 'arm64', 'ARM64'), + reason='Ticket - 126314, 122716') def test_truncate_div_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): self._test(*self.create_truncate_div_net(**params), diff --git a/tests/samples_tests/smoke_tests/test_speech_sample.py b/tests/samples_tests/smoke_tests/test_speech_sample.py index ff3649662d2207..5d67d2e868a2f9 100644 --- a/tests/samples_tests/smoke_tests/test_speech_sample.py +++ b/tests/samples_tests/smoke_tests/test_speech_sample.py @@ -12,6 +12,7 @@ """ import os import pytest +import platform import sys import logging as log from common.samples_common_test_class import SamplesCommonTestClass @@ -56,7 +57,8 @@ def setup_class(cls): super().setup_class() @pytest.mark.parametrize("param", test_data) - @pytest.mark.skipif(sys.platform == 'darwin', reason="GNA is not available on macOS") + @pytest.mark.skipif(condition=platform.system() == 'Darwin' or platform.machine() == 'aarch64', + reason="GNA is not available on macOS or aarch64") def test_speech_sample_nthreads(self, param): stdout = self._test(param).split('\n') @@ -65,7 +67,8 @@ def test_speech_sample_nthreads(self, param): assert avg_error <= self.threshold @pytest.mark.parametrize("param", new_format_test_data) - @pytest.mark.skipif(sys.platform == 'darwin', reason="GNA is not available on macOS") + @pytest.mark.skipif(condition=platform.system() == 'Darwin' or platform.machine() == 'aarch64', + reason="GNA is not available on macOS or aarch64") def test_speech_sample_new_format(self, param): stdout = self._test(param, complete_path=False).split('\n') From 725aae4dbd0d25c4d65b0b0679ebc3e42eef8189 Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Tue, 5 Dec 2023 10:28:17 +0100 Subject: [PATCH 12/20] partly reverted d6f7664 (#21454) --- .../functional_test_utils/layer_tests_summary/run_parallel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/test_utils/functional_test_utils/layer_tests_summary/run_parallel.py b/src/tests/test_utils/functional_test_utils/layer_tests_summary/run_parallel.py index 5916290b6abd52..42bde59030f9e2 100644 --- a/src/tests/test_utils/functional_test_utils/layer_tests_summary/run_parallel.py +++ b/src/tests/test_utils/functional_test_utils/layer_tests_summary/run_parallel.py @@ -873,7 +873,7 @@ def __save_log(logs_dir, dir, test_name): ) if os.path.isfile(interapted_log_path): test_cnt_real_saved_now += 1 - if self._is_save_cache and os.path.isfile(self._cache_path): + if self._is_save_cache: test_times.sort(reverse=True) with open(self._cache_path, "w", encoding=constants.ENCODING) as cache_file: cache_file.writelines( From c18041ab53cfb1569dae624735d25ee3a0b8ab72 Mon Sep 17 00:00:00 2001 From: Pawel Raasz Date: Tue, 5 Dec 2023 12:11:43 +0100 Subject: [PATCH 13/20] [core] Remove tensor conversion utils from new API (#21396) * Remove usage of util::wrap_tensor * Remove tensor conversion utils make it local in model to remove with legacy evaluate * Make only output tensor dynamic if Shape{0} * Evaluate fixes on HostTensor --------- Co-authored-by: Michal Lukaszewski --- src/core/dev_api/openvino/core/shape_util.hpp | 18 ------ src/core/dev_api/tensor_conversion_util.hpp | 54 ---------------- src/core/reference/src/op/function.cpp | 11 +--- src/core/src/bound_evaluate.cpp | 30 +++++---- src/core/src/model.cpp | 53 +++++++++++++--- src/core/src/node.cpp | 33 ++++++---- src/core/src/op/select.cpp | 9 +++ src/core/src/op/util/variable_value.cpp | 8 +-- src/core/src/runtime/itensor.cpp | 6 +- src/core/src/shape_util.cpp | 10 --- src/core/src/tensor_conversion_util.cpp | 62 ------------------- src/core/tests/tensor.cpp | 19 ------ src/plugins/intel_cpu/src/nodes/reference.cpp | 2 +- .../template/backend/int_executable.cpp | 10 +-- src/plugins/template/backend/ops/if.cpp | 11 +--- .../template/backend/ops/tensor_iterator.cpp | 1 - 16 files changed, 106 insertions(+), 231 deletions(-) delete mode 100644 src/core/dev_api/tensor_conversion_util.hpp delete mode 100644 src/core/src/tensor_conversion_util.cpp diff --git a/src/core/dev_api/openvino/core/shape_util.hpp b/src/core/dev_api/openvino/core/shape_util.hpp index 10acfcbc80f2fe..89688526d4f286 100644 --- a/src/core/dev_api/openvino/core/shape_util.hpp +++ b/src/core/dev_api/openvino/core/shape_util.hpp @@ -9,24 +9,6 @@ namespace ov { namespace util { -/** - * @brief Makes spacial version of 2D ov::Shape which is recognize as dynamic. - * - * This is special case used for tensor <-> host tensor conversion to indicate that tensor got dynamic shape. - * - * @return 2-D shape with {0, SIZE_MAX} - */ -OPENVINO_DEPRECATED("This function is deprecated and will be removed soon.") -OPENVINO_API Shape make_dynamic_shape(); - -/** - * @brief Check if Shape is marked as dynamic. - * - * @param s Shape for check. - * @return True if shape is dynamic otherwise false. - */ -OPENVINO_DEPRECATED("This function is deprecated and will be removed soon.") -OPENVINO_API bool is_dynamic_shape(const Shape& s); /** * @brief Creates reduced shape from input by removing dimensions. diff --git a/src/core/dev_api/tensor_conversion_util.hpp b/src/core/dev_api/tensor_conversion_util.hpp deleted file mode 100644 index 47a906ff9f0235..00000000000000 --- a/src/core/dev_api/tensor_conversion_util.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "ngraph/runtime/host_tensor.hpp" -#include "openvino/runtime/tensor.hpp" - -namespace ov { -namespace util { - -/** - * @brief Wrap host tensor into ov::Tensor. - * - * @param t Input tensor for conversion. - * @return ov::Tensor which points to host tensor data. Can return not allocated or special dynamic depends on input - * tensor state. - */ -OPENVINO_DEPRECATED("This function is deprecated and will be removed soon.") -OPENVINO_API Tensor wrap_tensor(const ngraph::HostTensorPtr& t); - -/** - * @brief Wrap node output into ov::Tensor. - * - * @param output Node output to make tensor. - * @return ov::Tensor from output properties. - */ -OPENVINO_DEPRECATED("This function is deprecated and will be removed soon.") -OPENVINO_API Tensor wrap_tensor(const Output& output); - -/** - * @brief Make vector of wrapped tensors. - * - * @param tensors Input vector of host tensor to convert. - * @return ov::TensorVectors, can contains not allocated or dynamic tensor depends on input tensor properties. - */ -OPENVINO_DEPRECATED("This function is deprecated and will be removed soon.") -OPENVINO_API TensorVector wrap_tensors(const std::vector& tensors); - -/** - * @brief Update output host tensors if they got dynamic shape before evaluation (not allocated). - * - * Other tensor not requires update as they are created from outputs and points to same data blob. - * - * @param output_values Temporary ov::Tensor vector created from outputs for evaluation - * @param outputs Output host tensors vector to update. - */ -OPENVINO_DEPRECATED("This function is deprecated and will be removed soon.") -OPENVINO_API void update_output_host_tensors(const std::vector& output_values, - const ov::TensorVector& outputs); - -} // namespace util -} // namespace ov diff --git a/src/core/reference/src/op/function.cpp b/src/core/reference/src/op/function.cpp index c70bf4020b17d0..37378d831f3ca7 100644 --- a/src/core/reference/src/op/function.cpp +++ b/src/core/reference/src/op/function.cpp @@ -12,14 +12,9 @@ namespace ov { namespace reference { void function(const std::shared_ptr& function, const ov::TensorVector& inputs, ov::TensorVector& outputs) { - const auto& results = function->get_results(); - outputs.reserve(results.size()); - for (size_t i = 0; i < results.size(); ++i) { - OPENVINO_SUPPRESS_DEPRECATED_START - auto shape = results[i]->get_output_partial_shape(0).is_static() ? results[i]->get_output_shape(0) - : ov::util::make_dynamic_shape(); - OPENVINO_SUPPRESS_DEPRECATED_END - outputs.push_back(ov::Tensor(results[i]->get_element_type(), shape)); + outputs.reserve(function->get_output_size()); + for (const auto& result : function->get_results()) { + outputs.emplace_back(result->output(0)); } function->evaluate(outputs, inputs); } diff --git a/src/core/src/bound_evaluate.cpp b/src/core/src/bound_evaluate.cpp index 1b1093b871c657..60d61126acc8f5 100644 --- a/src/core/src/bound_evaluate.cpp +++ b/src/core/src/bound_evaluate.cpp @@ -10,7 +10,6 @@ #include "openvino/core/shape_util.hpp" #include "openvino/op/util/symbolic_info.hpp" #include "openvino/opsets/opset10.hpp" -#include "tensor_conversion_util.hpp" #include "transformations/rt_info/decompression.hpp" #include "transformations/rt_info/is_shape_subgraph.hpp" @@ -70,6 +69,10 @@ bool are_equal(const ov::Tensor& lhs, const ov::Tensor& rhs) { return are_eq; } +bool is_type_allocable(const element::Type& type) { + return type != element::undefined && type.is_static(); +} + ov::Tensor evaluate_bound(const Output& output, bool is_upper, bool invalidate_all_unused_values = true) { if (is_upper && output.get_tensor().get_upper_value()) { return output.get_tensor().get_upper_value(); @@ -84,9 +87,11 @@ ov::Tensor evaluate_bound(const Output& output, bool is_upper, bool invali for (const auto& node : order) { ov::TensorVector outputs; for (const auto& out : node->outputs()) { - OPENVINO_SUPPRESS_DEPRECATED_START - outputs.push_back(util::wrap_tensor(out)); - OPENVINO_SUPPRESS_DEPRECATED_END + if (is_type_allocable(out.get_element_type())) { + outputs.emplace_back(out); + } else { + outputs.emplace_back(); + } } if (is_upper ? node->evaluate_upper(outputs) : node->evaluate_lower(outputs)) { @@ -312,10 +317,13 @@ std::pair ov::evaluate_both_bounds(const Output& o for (const auto& node : order) { ov::TensorVector outputs_lower, outputs_upper; for (const auto& out : node->outputs()) { - OPENVINO_SUPPRESS_DEPRECATED_START - outputs_lower.push_back(util::wrap_tensor(out)); - outputs_upper.push_back(util::wrap_tensor(out)); - OPENVINO_SUPPRESS_DEPRECATED_END + if (is_type_allocable(out.get_element_type())) { + outputs_lower.emplace_back(out); + outputs_upper.emplace_back(out); + } else { + outputs_lower.emplace_back(); + outputs_upper.emplace_back(); + } } if (!node->evaluate_lower(outputs_lower) || !node->evaluate_upper(outputs_upper)) { break; @@ -391,7 +399,7 @@ bool ov::interval_bound_evaluator(const Node* node, node->evaluate(lower_output_values, *input_variants.begin()); auto zero = op::v0::Constant::create(element::i64, {1}, {0}); - const auto zero_t = ov::Tensor(element::i64, Shape{1}); + const auto zero_t = ov::Tensor(element::i64, Shape{}); *zero_t.data() = 0; std::vector unsqueezed_output_variants; @@ -602,9 +610,7 @@ bool ov::default_label_evaluator(const Node* node, for (size_t i = 0; i < outputs_count; ++i) { const auto& partial_shape = node->get_output_partial_shape(i); // Set shape for static or special dynamic if partial shape is dynamic. - OPENVINO_SUPPRESS_DEPRECATED_START - auto shape = partial_shape.is_static() ? partial_shape.to_shape() : util::make_dynamic_shape(); - OPENVINO_SUPPRESS_DEPRECATED_END + const auto& shape = partial_shape.is_static() ? partial_shape.to_shape() : Shape{0}; outputs.emplace_back(element::from(), shape); } diff --git a/src/core/src/model.cpp b/src/core/src/model.cpp index b06bd5ece52933..c9ba2eb0416071 100644 --- a/src/core/src/model.cpp +++ b/src/core/src/model.cpp @@ -21,7 +21,6 @@ #include "openvino/op/util/variable_extension.hpp" #include "openvino/pass/manager.hpp" #include "shared_node_info.hpp" -#include "tensor_conversion_util.hpp" #include "transformations/smart_reshape/smart_reshape.hpp" using namespace std; @@ -487,24 +486,60 @@ int64_t ov::Model::get_result_index(const Output& value) const { return -1; } +OPENVINO_SUPPRESS_DEPRECATED_START +namespace { +ov::Tensor wrap_tensor(const ngraph::HostTensorPtr& t) { + const auto& et = t->get_element_type(); + const auto& p_shape = t->get_partial_shape(); + + if (et.is_dynamic() || et == ov::element::undefined) { + return {}; + } else if (p_shape.is_static()) { + return {et, p_shape.to_shape(), t->get_data_ptr()}; + } else { + return {et, ov::Shape{0}}; + } +} + +ov::TensorVector wrap_tensors(const std::vector& tensors) { + ov::TensorVector out; + out.reserve(tensors.size()); + for (const auto& ht : tensors) { + out.push_back(wrap_tensor(ht)); + } + return out; +} + +void update_output_host_tensors(const std::vector& output_values, + const ov::TensorVector& outputs) { + OPENVINO_ASSERT(output_values.size() == outputs.size()); + for (size_t i = 0; i < output_values.size(); ++i) { + auto& ht = output_values[i]; + auto& t = outputs[i]; + if (ht->get_partial_shape().is_dynamic()) { + ht->set_element_type(t.get_element_type()); + ht->set_shape(t.get_shape()); + std::memcpy(ht->get_data_ptr(), t.data(), t.get_byte_size()); + } + } +} +} // namespace + bool ov::Model::evaluate(const HostTensorVector& output_tensors, const HostTensorVector& input_tensors) const { ov::EvaluationContext evaluation_context; - OPENVINO_SUPPRESS_DEPRECATED_START return evaluate(output_tensors, input_tensors, evaluation_context); - OPENVINO_SUPPRESS_DEPRECATED_END } bool ov::Model::evaluate(const HostTensorVector& output_tensors, const HostTensorVector& input_tensors, EvaluationContext& evaluation_context) const { - OPENVINO_SUPPRESS_DEPRECATED_START - auto outputs = ov::util::wrap_tensors(output_tensors); - auto inputs = ov::util::wrap_tensors(input_tensors); + auto outputs = wrap_tensors(output_tensors); + auto inputs = wrap_tensors(input_tensors); bool sts = evaluate(outputs, inputs, evaluation_context); - ov::util::update_output_host_tensors(output_tensors, outputs); - OPENVINO_SUPPRESS_DEPRECATED_END + update_output_host_tensors(output_tensors, outputs); return sts; } +OPENVINO_SUPPRESS_DEPRECATED_END bool ov::Model::evaluate(ov::TensorVector& output_tensors, const ov::TensorVector& input_tensors) const { ov::EvaluationContext evaluation_context; @@ -550,7 +585,7 @@ bool ov::Model::evaluate(ov::TensorVector& output_tensors, for (const auto& v : node->outputs()) { auto it = output_tensor_map.find(v); if (it == output_tensor_map.end()) { - output_tensors.push_back(util::wrap_tensor(v)); + output_tensors.emplace_back(v); } else { output_tensors.push_back(it->second); } diff --git a/src/core/src/node.cpp b/src/core/src/node.cpp index e9a072d3cce0de..bbda98877044e4 100644 --- a/src/core/src/node.cpp +++ b/src/core/src/node.cpp @@ -19,7 +19,6 @@ #include "openvino/pass/pattern/matcher.hpp" #include "shape_validation.hpp" #include "shared_node_info.hpp" -#include "tensor_conversion_util.hpp" using namespace std; @@ -720,18 +719,27 @@ class DynamicTensor : public ngraph::runtime::HostTensor { inline ngraph::HostTensorPtr make_tmp_host_tensor(const ov::Tensor& t) { if (!t) { return std::make_shared(ov::element::dynamic); - } else if (ov::util::is_dynamic_shape(t.get_shape())) { + } else { + return std::make_shared(t.get_element_type(), t.get_shape(), t.data()); + } +} + +inline ngraph::HostTensorPtr make_tmp_out_host_tensor(const ov::Tensor& t) { + if (!t) { + return std::make_shared(ov::element::dynamic); + } else if (t.get_shape() == ov::Shape{0}) { return std::make_shared(t.get_element_type()); } else { return std::make_shared(t.get_element_type(), t.get_shape(), t.data()); } } -inline ngraph::HostTensorVector create_tmp_tensors(const ov::TensorVector& tensors) { +inline ngraph::HostTensorVector create_tmp_tensors(const ov::TensorVector& tensors, const bool is_output) { + const auto make_tmp_ht = is_output ? make_tmp_out_host_tensor : make_tmp_host_tensor; ngraph::HostTensorVector result; result.reserve(tensors.size()); for (const auto& tensor : tensors) { - result.push_back(make_tmp_host_tensor(tensor)); + result.push_back(make_tmp_ht(tensor)); } return result; } @@ -759,8 +767,8 @@ inline void update_output_tensors(ov::TensorVector& output_values, const ngraph: } // namespace bool ov::Node::evaluate(ov::TensorVector& output_values, const ov::TensorVector& input_values) const { - HostTensorVector output = create_tmp_tensors(output_values); - HostTensorVector input = create_tmp_tensors(input_values); + HostTensorVector output = create_tmp_tensors(output_values, true); + HostTensorVector input = create_tmp_tensors(input_values, false); bool sts = evaluate(output, input); if (sts) update_output_tensors(output_values, output); @@ -771,8 +779,8 @@ bool ov::Node::evaluate(ov::TensorVector& output_values, const ov::TensorVector& input_values, const ov::EvaluationContext& evaluationContext) const { // Call evaluate for old implementation with EvaluationContext - HostTensorVector output = create_tmp_tensors(output_values); - HostTensorVector input = create_tmp_tensors(input_values); + HostTensorVector output = create_tmp_tensors(output_values, true); + HostTensorVector input = create_tmp_tensors(input_values, false); bool sts = evaluate(output, input, evaluationContext); if (sts) update_output_tensors(output_values, output); @@ -826,9 +834,13 @@ bool ov::Node::constant_fold(OutputVector& output_values, const OutputVector& in } TensorVector output_tensors; - OPENVINO_SUPPRESS_DEPRECATED_START for (const auto& output : outputs()) { - output_tensors.push_back(ov::util::wrap_tensor(output)); + const auto& et = output.get_element_type(); + if (et != element::undefined && et.is_static()) { + output_tensors.emplace_back(output); + } else { + output_tensors.emplace_back(); + } } if (evaluate(output_tensors, input_tensors)) { @@ -838,7 +850,6 @@ bool ov::Node::constant_fold(OutputVector& output_values, const OutputVector& in } return true; } - OPENVINO_SUPPRESS_DEPRECATED_END return false; } diff --git a/src/core/src/op/select.cpp b/src/core/src/op/select.cpp index 719dd532f18ec3..eaad0378ac13a7 100644 --- a/src/core/src/op/select.cpp +++ b/src/core/src/op/select.cpp @@ -120,6 +120,15 @@ bool op::v1::Select::evaluate(const HostTensorVector& output_values, const HostT OPENVINO_ASSERT(validate_host_tensor_vector(output_values, 1)); OPENVINO_SUPPRESS_DEPRECATED_END const auto autob = get_auto_broadcast(); + + auto out_shape = shape_infer(this, + std::vector{input_values[0]->get_partial_shape(), + input_values[1]->get_partial_shape(), + input_values[2]->get_partial_shape()})[0] + .to_shape(); + + output_values[0]->set_shape(out_shape); + return detail::evaluate_select(output_values, input_values, autob, output_values[0]->get_element_type()); } diff --git a/src/core/src/op/util/variable_value.cpp b/src/core/src/op/util/variable_value.cpp index e1e434afc94b04..9de53857859f3b 100644 --- a/src/core/src/op/util/variable_value.cpp +++ b/src/core/src/op/util/variable_value.cpp @@ -35,13 +35,7 @@ class HostTensorWrapper : public ov::ITensor { HostTensorWrapper(const ngraph::HostTensorPtr& tensor) : tensor{tensor}, m_type(tensor->get_element_type()) { const auto& p_shape = tensor->get_partial_shape(); - if (p_shape.is_static()) { - m_shape = p_shape.to_shape(); - } else { - OPENVINO_SUPPRESS_DEPRECATED_START - m_shape = ov::util::make_dynamic_shape(); - OPENVINO_SUPPRESS_DEPRECATED_END - } + m_shape = p_shape.is_static() ? p_shape.to_shape() : ov::Shape{0}; update_strides(); } diff --git a/src/core/src/runtime/itensor.cpp b/src/core/src/runtime/itensor.cpp index 35483f88b718e1..5068d94952649f 100644 --- a/src/core/src/runtime/itensor.cpp +++ b/src/core/src/runtime/itensor.cpp @@ -65,10 +65,10 @@ void ITensor::copy_to(const std::shared_ptr& dst) const { " != dst: ", dst->get_element_type(), ")"); - OPENVINO_SUPPRESS_DEPRECATED_START - if (dst->get_shape() == ov::Shape{0} || ov::util::is_dynamic_shape(dst->get_shape())) + + if (dst->get_shape() == ov::Shape{0}) dst->set_shape(get_shape()); - OPENVINO_SUPPRESS_DEPRECATED_END + OPENVINO_ASSERT(shapes_equal(get_shape(), dst->get_shape()), "Tensor shapes are not equal. (src: ", get_shape(), diff --git a/src/core/src/shape_util.cpp b/src/core/src/shape_util.cpp index 72c72c39b68d4f..1d6b8e1c49d165 100644 --- a/src/core/src/shape_util.cpp +++ b/src/core/src/shape_util.cpp @@ -103,16 +103,6 @@ TContainer replace_container(const TContainer& input, const TAxes& axes) { } namespace util { -Shape make_dynamic_shape() { - return Shape{0, std::numeric_limits::max()}; -} - -bool is_dynamic_shape(const Shape& s) { - OPENVINO_SUPPRESS_DEPRECATED_START - static const auto dyn_shape = make_dynamic_shape(); - OPENVINO_SUPPRESS_DEPRECATED_END - return s == dyn_shape; -} Shape reduce(const Shape& input, const AxisSet& axes) { return ov::reduce_container(input, axes); diff --git a/src/core/src/tensor_conversion_util.cpp b/src/core/src/tensor_conversion_util.cpp deleted file mode 100644 index 4e0c40d3f21aa2..00000000000000 --- a/src/core/src/tensor_conversion_util.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "tensor_conversion_util.hpp" - -#include "openvino/core/shape_util.hpp" - -namespace ov { -namespace util { -OPENVINO_SUPPRESS_DEPRECATED_START -Tensor wrap_tensor(const ngraph::HostTensorPtr& t) { - const auto& et = t->get_element_type(); - const auto& p_shape = t->get_partial_shape(); - - if (et.is_dynamic() || et == element::undefined) { - return {}; - } else if (p_shape.is_static()) { - return {et, p_shape.to_shape(), t->get_data_ptr()}; - } else { - return {et, make_dynamic_shape()}; - } -} - -Tensor wrap_tensor(const Output& output) { - const auto& et = output.get_element_type(); - const auto& p_shape = output.get_partial_shape(); - - if (et.is_dynamic() || et == element::undefined) { - return {}; - } else if (p_shape.is_static()) { - return {et, p_shape.to_shape()}; - } else { - return {et, make_dynamic_shape()}; - } -} - -ov::TensorVector wrap_tensors(const std::vector& tensors) { - ov::TensorVector out; - out.reserve(tensors.size()); - for (const auto& ht : tensors) { - out.push_back(ov::util::wrap_tensor(ht)); - } - return out; -} - -void update_output_host_tensors(const std::vector& output_values, - const ov::TensorVector& outputs) { - OPENVINO_ASSERT(output_values.size() == outputs.size()); - for (size_t i = 0; i < output_values.size(); ++i) { - auto& ht = output_values[i]; - auto& t = outputs[i]; - if (ht->get_partial_shape().is_dynamic()) { - ht->set_element_type(t.get_element_type()); - ht->set_shape(t.get_shape()); - std::memcpy(ht->get_data_ptr(), t.data(), t.get_byte_size()); - } - } -} -OPENVINO_SUPPRESS_DEPRECATED_END -} // namespace util -} // namespace ov diff --git a/src/core/tests/tensor.cpp b/src/core/tests/tensor.cpp index 361e45e8a570ce..39b47ad2a86aee 100644 --- a/src/core/tests/tensor.cpp +++ b/src/core/tests/tensor.cpp @@ -14,7 +14,6 @@ #include "openvino/core/model.hpp" #include "openvino/op/parameter.hpp" #include "openvino/op/relu.hpp" -#include "tensor_conversion_util.hpp" using namespace std; using namespace ov; @@ -35,24 +34,6 @@ TEST(tensor, tensor_names) { ASSERT_EQ(f0->get_result()->input_value(0).get_tensor().get_names(), relu->get_output_tensor(0).get_names()); } -TEST(tensor, wrap_tensor_with_unspecified_type) { - auto param = std::make_shared(element::undefined, ov::PartialShape{}); - OPENVINO_SUPPRESS_DEPRECATED_START - auto tensor = ov::util::wrap_tensor(param->output(0)); - OPENVINO_SUPPRESS_DEPRECATED_END - // !tensor means that the tensor is not initialized - EXPECT_EQ(!tensor, true); -} - -TEST(tensor, wrap_tensor_with_unspecified_type_from_host_tensor) { - OPENVINO_SUPPRESS_DEPRECATED_START - auto host_tensor = std::make_shared(element::undefined, ov::PartialShape{}); - auto tensor = ov::util::wrap_tensor(host_tensor); - OPENVINO_SUPPRESS_DEPRECATED_END - // !tensor means that the tensor is not initialized - EXPECT_EQ(!tensor, true); -} - TEST(tensor, create_tensor_with_zero_dims_check_stride) { ov::Shape shape = {0, 0, 0, 0}; auto tensor = ov::Tensor(element::f32, shape); diff --git a/src/plugins/intel_cpu/src/nodes/reference.cpp b/src/plugins/intel_cpu/src/nodes/reference.cpp index b7e79de41fcd4a..b7774985dac231 100644 --- a/src/plugins/intel_cpu/src/nodes/reference.cpp +++ b/src/plugins/intel_cpu/src/nodes/reference.cpp @@ -72,7 +72,7 @@ void Reference::executeDynamicImpl(dnnl::stream strm) { if (mem_desc->isDefined()) { outputs.emplace_back(ovCoreNode->get_output_element_type(i), mem_desc->getShape().getStaticDims()); } else { - outputs.emplace_back(ovCoreNode->get_output_element_type(i), ov::util::make_dynamic_shape()); + outputs.emplace_back(ovCoreNode->get_output_element_type(i), ov::Shape{0}); } } } else { diff --git a/src/plugins/template/backend/int_executable.cpp b/src/plugins/template/backend/int_executable.cpp index 7bf130cad87b83..a8cada0e3041e8 100644 --- a/src/plugins/template/backend/int_executable.cpp +++ b/src/plugins/template/backend/int_executable.cpp @@ -123,19 +123,13 @@ bool ov::runtime::interpreter::INTExecutable::call(std::vector& outp std::vector op_outputs; for (size_t i = 0; i < op->get_output_size(); ++i) { auto tensor = op->output(i).get_tensor_ptr(); - ov::Tensor host_tensor; auto it = tensor_map.find(tensor); auto output = op->output(i); if (op::util::is_output(op) || it == tensor_map.end() || !it->second) { - OPENVINO_SUPPRESS_DEPRECATED_START - host_tensor = ov::Tensor( - output.get_element_type(), - output.get_partial_shape().is_dynamic() ? ov::util::make_dynamic_shape() : output.get_shape()); - OPENVINO_SUPPRESS_DEPRECATED_END + op_outputs.emplace_back(output); } else { - host_tensor = it->second; + op_outputs.push_back(it->second); } - op_outputs.push_back(host_tensor); } { diff --git a/src/plugins/template/backend/ops/if.cpp b/src/plugins/template/backend/ops/if.cpp index 2164d83bd58c04..874368d01ccfb6 100644 --- a/src/plugins/template/backend/ops/if.cpp +++ b/src/plugins/template/backend/ops/if.cpp @@ -103,14 +103,9 @@ void function(const std::shared_ptr& function, const ov::TensorVector " bytes"); } - const auto& results = function->get_results(); - outputs.reserve(results.size()); - for (size_t i = 0; i < results.size(); ++i) { - OPENVINO_SUPPRESS_DEPRECATED_START - ov::Shape res_shape = results[i]->get_output_partial_shape(0).is_static() ? results[i]->get_output_shape(0) - : ov::util::make_dynamic_shape(); - OPENVINO_SUPPRESS_DEPRECATED_END - outputs.push_back(ov::Tensor(results[i]->get_element_type(), res_shape)); + outputs.reserve(function->get_output_size()); + for (const auto& result : function->get_results()) { + outputs.emplace_back(result->output(0)); } call(outputs, inputs, function); } diff --git a/src/plugins/template/backend/ops/tensor_iterator.cpp b/src/plugins/template/backend/ops/tensor_iterator.cpp index d7398b5126fcb8..89dd7ce2ae96f4 100644 --- a/src/plugins/template/backend/ops/tensor_iterator.cpp +++ b/src/plugins/template/backend/ops/tensor_iterator.cpp @@ -6,7 +6,6 @@ #include "backend.hpp" #include "evaluate_node.hpp" -#include "tensor_conversion_util.hpp" namespace ti_v0 { ov::reference::custom_evaluate_function evaluate = From 791762fb19e840b29697f49c8481afd1e2f2ced3 Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Tue, 5 Dec 2023 12:47:35 +0100 Subject: [PATCH 14/20] Tests compilation fix (#21473) --- .../include/common_test_utils/node_builders/activation.hpp | 2 ++ .../include/common_test_utils/node_builders/augru_cell.hpp | 2 ++ .../common_test_utils/node_builders/binary_convolution.hpp | 2 ++ .../include/common_test_utils/node_builders/comparison.hpp | 2 ++ .../include/common_test_utils/node_builders/convolution.hpp | 2 ++ .../node_builders/convolution_backprop_data.hpp | 2 ++ .../include/common_test_utils/node_builders/dft.hpp | 2 ++ .../include/common_test_utils/node_builders/eltwise.hpp | 2 ++ .../node_builders/embedding_bag_offsets_sum.hpp | 2 ++ .../node_builders/embedding_bag_packed_sum.hpp | 2 ++ .../common_test_utils/node_builders/embedding_segments_sum.hpp | 2 ++ .../include/common_test_utils/node_builders/fully_connected.hpp | 2 ++ .../include/common_test_utils/node_builders/gather_nd.hpp | 2 ++ .../common_test_utils/node_builders/group_convolution.hpp | 2 ++ .../node_builders/group_convolution_backprop_data.hpp | 2 ++ .../include/common_test_utils/node_builders/gru_cell.hpp | 2 ++ .../include/common_test_utils/node_builders/logical.hpp | 2 ++ .../include/common_test_utils/node_builders/lstm_cell.hpp | 2 ++ .../include/common_test_utils/node_builders/rdft.hpp | 2 ++ .../include/common_test_utils/node_builders/reduce.hpp | 2 ++ .../include/common_test_utils/node_builders/rnn_cell.hpp | 2 ++ 21 files changed, 42 insertions(+) diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/activation.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/activation.hpp index 70e5fcce77cf7a..5a6b13d422bd81 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/activation.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/activation.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/augru_cell.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/augru_cell.hpp index 7d02653066c98c..4c35345db5178f 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/augru_cell.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/augru_cell.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/binary_convolution.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/binary_convolution.hpp index 3b769443056472..9cb3f8d56714cd 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/binary_convolution.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/binary_convolution.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/comparison.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/comparison.hpp index 3cf7095f161b9e..24e6abffae1131 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/comparison.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/comparison.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution.hpp index 9060fd132a8a39..34d29174bcca7f 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution_backprop_data.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution_backprop_data.hpp index c0ae90df18b286..4362ea90720fb9 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution_backprop_data.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/convolution_backprop_data.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/dft.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/dft.hpp index 85b7958d5051e6..c90259bbe2f800 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/dft.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/dft.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/eltwise.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/eltwise.hpp index 8b28f345b0d589..8e491be7144bc4 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/eltwise.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/eltwise.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_offsets_sum.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_offsets_sum.hpp index f05fba41f1b931..281022fd74fe04 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_offsets_sum.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_offsets_sum.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_packed_sum.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_packed_sum.hpp index 735027efb6875d..05ecb45b95a792 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_packed_sum.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_bag_packed_sum.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_segments_sum.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_segments_sum.hpp index 8c8aefd9dc7931..ad36485b0b306e 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_segments_sum.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/embedding_segments_sum.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/fully_connected.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/fully_connected.hpp index be4b0b7a993fee..59449b6a6d57c3 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/fully_connected.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/fully_connected.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/gather_nd.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/gather_nd.hpp index f264312dbd0a4f..ee4041eac628d9 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/gather_nd.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/gather_nd.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution.hpp index 347025f2addd01..5790a7769d7ec3 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution_backprop_data.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution_backprop_data.hpp index 14283a8a15511a..190e367b6f2a85 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution_backprop_data.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/group_convolution_backprop_data.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "openvino/core/node.hpp" namespace ov { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/gru_cell.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/gru_cell.hpp index 71eef86d4f57f9..3e2a06e6e47379 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/gru_cell.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/gru_cell.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/logical.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/logical.hpp index 8617c9ab4295dc..eb5d6684cb3297 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/logical.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/logical.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/lstm_cell.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/lstm_cell.hpp index 0aa1f4b29da218..058b92388b5bb4 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/lstm_cell.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/lstm_cell.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/rdft.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/rdft.hpp index fc416f00f8992e..425b6cb30bab8d 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/rdft.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/rdft.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/reduce.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/reduce.hpp index 171887dcbb1cff..06c062460c306a 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/reduce.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/reduce.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/rnn_cell.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/rnn_cell.hpp index b4943e50d8967d..463a4930f5c27f 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/rnn_cell.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/node_builders/rnn_cell.hpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // +#pragma once + #include "common_test_utils/test_enums.hpp" #include "openvino/core/node.hpp" From f80793e4209dfb72bc1a18aacc5925da05295506 Mon Sep 17 00:00:00 2001 From: Chenhu Wang Date: Tue, 5 Dec 2023 19:49:27 +0800 Subject: [PATCH 15/20] [SnippetS] Perf count nodes and emitters (#19493) --- .../snippets/include/snippets/generator.hpp | 2 +- .../include/snippets/lowered/linear_ir.hpp | 13 ++ .../lowered/pass/insert_perf_count.hpp | 33 +++++ .../include/snippets/op/perf_count.hpp | 93 ++++++++++++++ .../include/snippets/snippets_isa.hpp | 1 + .../include/snippets/snippets_isa_tbl.hpp | 3 + src/common/snippets/src/generator.cpp | 7 +- .../src/lowered/pass/insert_perf_count.cpp | 62 ++++++++++ src/common/snippets/src/op/perf_count.cpp | 115 ++++++++++++++++++ src/common/snippets/src/op/subgraph.cpp | 8 +- .../src/shape_inference/shape_inference.cpp | 2 + .../snippets/tests/src/lowering_utils.cpp | 2 + .../runtime/threading/thread_local.hpp | 14 +++ .../src/emitters/x64/cpu_generator.cpp | 16 ++- .../src/emitters/x64/jit_emitter.cpp | 68 +++++++++++ .../src/emitters/x64/jit_emitter.hpp | 9 ++ .../x64/jit_perf_count_chrono_emitters.cpp | 73 +++++++++++ .../x64/jit_perf_count_chrono_emitters.hpp | 40 ++++++ .../x64/jit_perf_count_rdtsc_emitters.cpp | 86 +++++++++++++ .../x64/jit_perf_count_rdtsc_emitters.hpp | 37 ++++++ .../emitters/x64/jit_snippets_emitters.cpp | 115 ++---------------- src/plugins/intel_cpu/src/extension.cpp | 5 + .../snippets/x64/op/perf_count_rdtsc.cpp | 32 +++++ .../snippets/x64/op/perf_count_rdtsc.hpp | 55 +++++++++ .../snippets/x64/shape_inference.cpp | 3 + 25 files changed, 781 insertions(+), 113 deletions(-) create mode 100644 src/common/snippets/include/snippets/lowered/pass/insert_perf_count.hpp create mode 100644 src/common/snippets/include/snippets/op/perf_count.hpp create mode 100644 src/common/snippets/src/lowered/pass/insert_perf_count.cpp create mode 100644 src/common/snippets/src/op/perf_count.cpp create mode 100644 src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_chrono_emitters.cpp create mode 100644 src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_chrono_emitters.hpp create mode 100644 src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_rdtsc_emitters.cpp create mode 100644 src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_rdtsc_emitters.hpp create mode 100644 src/plugins/intel_cpu/src/transformations/snippets/x64/op/perf_count_rdtsc.cpp create mode 100644 src/plugins/intel_cpu/src/transformations/snippets/x64/op/perf_count_rdtsc.hpp diff --git a/src/common/snippets/include/snippets/generator.hpp b/src/common/snippets/include/snippets/generator.hpp index 32b44b9e6abc81..1647ccf1e771a0 100644 --- a/src/common/snippets/include/snippets/generator.hpp +++ b/src/common/snippets/include/snippets/generator.hpp @@ -29,7 +29,7 @@ class Generator; class LoweringResult { friend class Generator; // Some emitters rely on other precompiled kernels. - // We need to keep the pointers to such emitters alive, so the kernels would still be accessible at runtime. + // We need to keep the pointers to such emitters alive, so the kernels or nodes would still be accessible at runtime. std::vector> m_saved_emitters{}; public: diff --git a/src/common/snippets/include/snippets/lowered/linear_ir.hpp b/src/common/snippets/include/snippets/lowered/linear_ir.hpp index 22ffc7ff36d324..55722b4c03d3b3 100644 --- a/src/common/snippets/include/snippets/lowered/linear_ir.hpp +++ b/src/common/snippets/include/snippets/lowered/linear_ir.hpp @@ -14,6 +14,18 @@ namespace ov { namespace snippets { namespace lowered { +// Snippets performance count mode +// Disabled - default, w/o perf count for snippets +// Chrono - perf count with chrono call. This is a universal method, and support multi-thread case to output perf count data for each thread. +// BackendSpecific - perf count provided by backend. This is for device specific requirment. +// For example, in sake of more light overhead and more accurate result, x86 CPU specific mode via read RDTSC register is implemented, +// which take ~50ns, while Chrono mode take 260ns for a pair of perf count start and perf count end execution, on ICX. This mode only support single thread. +enum PerfCountMode { + Disabled, + Chrono, + BackendSpecific, +}; + class Config { public: // True if the lowered Emitters need to be accessed during runtime. Normally they're destroyed after code emission. @@ -21,6 +33,7 @@ class Config { // True if we should check runtime info for nodes to call specific needed transformations bool m_need_fill_tail_register = false; size_t m_loop_depth = 1; + PerfCountMode perf_count_mode = PerfCountMode::Disabled; // Some Subgraphs doesn't support domain optimization due to operations' semantics bool m_enable_domain_optimization = false; // Minimal advised work amount for parallel execution. diff --git a/src/common/snippets/include/snippets/lowered/pass/insert_perf_count.hpp b/src/common/snippets/include/snippets/lowered/pass/insert_perf_count.hpp new file mode 100644 index 00000000000000..8478a0d931f182 --- /dev/null +++ b/src/common/snippets/include/snippets/lowered/pass/insert_perf_count.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "pass.hpp" + +#include "snippets/op/perf_count.hpp" + +namespace ov { +namespace snippets { +namespace lowered { +namespace pass { + +/** + * @interface InsertPerfCount + * @brief Insert PerfCountBegin node after last parameter and insert PerfCountEnd node before first result. + * This is a illustration transformation to enable perf count in snippets. + * Developers could modify this to insert perf count pairs around interested sequence of nodes. + * @ingroup snippets + */ +class InsertPerfCount: public Pass { +public: + OPENVINO_RTTI("InsertPerfCount", "Pass") + InsertPerfCount() = default; + bool run(LinearIR& linear_ir) override; +}; + +} // namespace pass +} // namespace lowered +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/include/snippets/op/perf_count.hpp b/src/common/snippets/include/snippets/op/perf_count.hpp new file mode 100644 index 00000000000000..be7eccfc5b44aa --- /dev/null +++ b/src/common/snippets/include/snippets/op/perf_count.hpp @@ -0,0 +1,93 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/op/op.hpp" +#include "openvino/runtime/threading/thread_local.hpp" + +namespace ov { +namespace snippets { +namespace op { + +/** + * @interface PerfCountBeginBase + * @brief Base class for PerfCountBegin and PerfCountRdtscBegin(cpu) + * @ingroup snippets + */ +class PerfCountBeginBase : public ov::op::Op { +public: + OPENVINO_OP("PerfCountBeginBase", "SnippetsOpset"); + PerfCountBeginBase(const std::vector>& args); + PerfCountBeginBase() = default; + + void validate_and_infer_types() override; + bool visit_attributes(AttributeVisitor& visitor) override; + +protected: + void validate_and_infer_types_except_PerfCountEnd(); +}; + +/** + * @interface PerfCountEndBase + * @brief Base class for PerfCountEnd and PerfCountRdtscEnd + * @ingroup snippets + */ +class PerfCountEndBase : public ov::op::Op { +public: + OPENVINO_OP("PerfCountEndBase", "SnippetsOpset"); + PerfCountEndBase(const std::vector>& args); + PerfCountEndBase() = default; + + void validate_and_infer_types() override; + bool visit_attributes(AttributeVisitor& visitor) override; +}; + +/** + * @interface PerfCountBegin + * @brief Performance count start time with chrono call + * @ingroup snippets + */ +class PerfCountBegin : public PerfCountBeginBase { +public: + OPENVINO_OP("PerfCountBegin", "SnippetsOpset", PerfCountBeginBase); + PerfCountBegin(); + + std::shared_ptr clone_with_new_inputs(const OutputVector& inputs) const override; + + void set_start_time(); + std::chrono::high_resolution_clock::time_point& get_start_time(); + +private: + ov::threading::ThreadLocal start_time_stamp; +}; + +/** + * @interface PerfCountEnd + * @brief Performance count end time and duration with chrono call + * @ingroup snippets + */ +class PerfCountEnd : public PerfCountEndBase { +public: + OPENVINO_OP("PerfCountEnd", "SnippetsOpset", PerfCountEndBase); + PerfCountEnd(const Output& pc_begin); + PerfCountEnd() = default; + ~PerfCountEnd() { + output_perf_count(); + } + void output_perf_count(); + std::shared_ptr clone_with_new_inputs(const OutputVector& inputs) const override; + + void init_pc_begin(); + void set_accumulated_time(); + +private: + ov::threading::ThreadLocal accumulation; + ov::threading::ThreadLocal iteration; + std::shared_ptr m_pc_begin = nullptr; +}; + +} // namespace op +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/include/snippets/snippets_isa.hpp b/src/common/snippets/include/snippets/snippets_isa.hpp index ba85ae68eeb634..b2c6d46b722b0b 100644 --- a/src/common/snippets/include/snippets/snippets_isa.hpp +++ b/src/common/snippets/include/snippets/snippets_isa.hpp @@ -25,6 +25,7 @@ #include "op/brgemm.hpp" #include "op/vector_buffer.hpp" #include "op/rank_normalization.hpp" +#include "op/perf_count.hpp" namespace ov { namespace snippets { diff --git a/src/common/snippets/include/snippets/snippets_isa_tbl.hpp b/src/common/snippets/include/snippets/snippets_isa_tbl.hpp index 351770bdab746f..163329d63948e6 100644 --- a/src/common/snippets/include/snippets/snippets_isa_tbl.hpp +++ b/src/common/snippets/include/snippets/snippets_isa_tbl.hpp @@ -24,6 +24,9 @@ OV_OP(Scalar, ov::snippets::op) OV_OP(Nop, ov::snippets::op) OV_OP(RankNormalization, ov::snippets::op) +OV_OP(PerfCountBegin, ov::snippets::op) +OV_OP(PerfCountEnd, ov::snippets::op) + // Layout-oblivious from opset1 // opset completeness diff --git a/src/common/snippets/src/generator.cpp b/src/common/snippets/src/generator.cpp index cede4c4a6e532c..0dacee4878d598 100644 --- a/src/common/snippets/src/generator.cpp +++ b/src/common/snippets/src/generator.cpp @@ -44,7 +44,8 @@ void Generator::generate(lowered::LinearIR& linear_ir, LoweringResult& result, c } OV_ITT_TASK_NEXT(GENERATE, "::GetSnippet") - // Note: some emitters use precompiled kernels. They need to be saved, so the kernels are accessible at runtime. + // 1. some emitters use precompiled kernels. They need to be saved, so the kernels are accessible at runtime. + // 2. perf count node as field of emitter should be alive at runtime. if (linear_ir.get_config().m_save_expressions) { for (const auto& expr : linear_ir) { const auto& emitter = expr->get_emitter(); @@ -66,7 +67,9 @@ Generator::opRegType Generator::get_op_reg_type(const std::shared_ptr& op) std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op) || - std::dynamic_pointer_cast(op)) + std::dynamic_pointer_cast(op) || + std::dynamic_pointer_cast(op) || + std::dynamic_pointer_cast(op)) return gpr2gpr; else if (std::dynamic_pointer_cast(op) || std::dynamic_pointer_cast(op)) diff --git a/src/common/snippets/src/lowered/pass/insert_perf_count.cpp b/src/common/snippets/src/lowered/pass/insert_perf_count.cpp new file mode 100644 index 00000000000000..2ed02c9010d063 --- /dev/null +++ b/src/common/snippets/src/lowered/pass/insert_perf_count.cpp @@ -0,0 +1,62 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/lowered/pass/insert_perf_count.hpp" +#include "snippets/lowered/linear_ir.hpp" +#include "snippets/snippets_isa.hpp" +#include "snippets/itt.hpp" + +namespace ov { +namespace snippets { +namespace lowered { +namespace pass { + +bool InsertPerfCount::run(LinearIR& linear_ir) { + OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::InsertPerfCount") + if (linear_ir.empty()) + return false; + + auto is_parameter = [](const std::shared_ptr& node) { + return ov::is_type(node); + }; + auto is_result = [](const std::shared_ptr& node) { + return ov::is_type(node); + }; + + // mark perf_count_begin and perf_count_end position + auto perf_count_begin_pos = linear_ir.cbegin(); + auto perf_count_end_pos = perf_count_begin_pos; + bool first_result_marked = false; + for (auto expr_it = linear_ir.cbegin(); expr_it != linear_ir.cend(); expr_it++) { + const auto expr = *expr_it; + const auto& node = expr->get_node(); + if (is_parameter(node)) + perf_count_begin_pos = expr_it; + + if (is_result(node) && !first_result_marked) { + perf_count_end_pos = expr_it; + first_result_marked = true; + } + } + + // insert perf_count_begin after last parameter + // linear_ir.insert has insert before behavior, need move to next. + perf_count_begin_pos = std::next(perf_count_begin_pos); + const auto& perf_count_begin = std::make_shared(); + const auto& perf_count_begin_expr = linear_ir.create_expression(perf_count_begin, std::vector{}); + linear_ir.insert(perf_count_begin_pos, perf_count_begin_expr); + + // insert perf_count_end before first result + const auto& perf_count_end = std::make_shared(perf_count_begin->output(0)); + perf_count_end->set_friendly_name("last_parameter_to_first_result"); + const auto& perf_count_end_expr = linear_ir.create_expression(perf_count_end, std::vector{}); + linear_ir.insert(perf_count_end_pos, perf_count_end_expr); + + return true; +} + +} // namespace pass +} // namespace lowered +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/src/op/perf_count.cpp b/src/common/snippets/src/op/perf_count.cpp new file mode 100644 index 00000000000000..66061753373e18 --- /dev/null +++ b/src/common/snippets/src/op/perf_count.cpp @@ -0,0 +1,115 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/op/perf_count.hpp" + +namespace ov { +namespace snippets { +namespace op { + +/////////////////PerfCountBeginBase///////////////// +PerfCountBeginBase::PerfCountBeginBase(const std::vector>& args) : Op() {} + +void PerfCountBeginBase::validate_and_infer_types() { + validate_and_infer_types_except_PerfCountEnd(); + OPENVINO_ASSERT(get_output_size() == 1, "PerfCountBegin must have only one output"); + const auto& last_output_inputs = get_output_target_inputs(0); + OPENVINO_ASSERT(last_output_inputs.size() == 1, "PerfCountBegin must have exactly one input attached to the last output"); + const auto& pc_end = ov::as_type_ptr(last_output_inputs.begin()->get_node()->shared_from_this()); + OPENVINO_ASSERT(pc_end != nullptr, "PerfCountBegin must have PerfCountEnd connected to its last output"); +} + +bool PerfCountBeginBase::visit_attributes(AttributeVisitor &visitor) { + return true; +} + +void PerfCountBeginBase::validate_and_infer_types_except_PerfCountEnd() { + NODE_VALIDATION_CHECK(this, get_input_size() == 0, "PerfCountBegin doesn't expect any inputs"); + set_output_type(0, element::f32, {}); +} + +//////////////////PerfCountEndBase///////////////// +PerfCountEndBase::PerfCountEndBase(const std::vector> &args) : Op(args) {} + +void PerfCountEndBase::validate_and_infer_types() { + NODE_VALIDATION_CHECK(this, get_input_size() == 1, "PerfCountEndBase must have one input"); + const auto& pc_begin = ov::as_type_ptr(get_input_node_shared_ptr(0)); + NODE_VALIDATION_CHECK(this, pc_begin != nullptr, "PerfCountEndBase must have PerfCountBeginBase as the last argument"); + set_output_type(0, element::f32, {}); +} + +bool PerfCountEndBase::visit_attributes(AttributeVisitor &visitor) { + return true; +} + +/////////////////PerfCountBegin///////////////// +PerfCountBegin::PerfCountBegin() : PerfCountBeginBase() { + validate_and_infer_types_except_PerfCountEnd(); +} + +std::shared_ptr PerfCountBegin::clone_with_new_inputs(const OutputVector& inputs) const { + return std::make_shared(); +} + +std::chrono::high_resolution_clock::time_point& PerfCountBegin::get_start_time() { + return start_time_stamp.local(); +} + +void PerfCountBegin::set_start_time() { + start_time_stamp.local() = std::chrono::high_resolution_clock::now(); +} + +//////////////////PerfCountEnd/////////////// +PerfCountEnd::PerfCountEnd(const Output& pc_begin) : PerfCountEndBase({pc_begin}), accumulation(0ul), iteration(0u) { + constructor_validate_and_infer_types(); + init_pc_begin(); +} + +std::shared_ptr PerfCountEnd::clone_with_new_inputs(const OutputVector& inputs) const { + return std::make_shared(inputs.at(0)); +} + +void PerfCountEnd::set_accumulated_time() { + auto current_time = std::chrono::high_resolution_clock::now(); + auto& start_time = m_pc_begin->get_start_time(); + accumulation.local() += std::chrono::duration_cast(current_time - start_time).count(); + iteration.local()++; +} + +void PerfCountEnd::init_pc_begin() { + m_pc_begin = ov::as_type_ptr(get_input_source_output(get_input_size() - 1).get_node_shared_ptr()); + NODE_VALIDATION_CHECK(this, m_pc_begin != nullptr, "PerfCountEnd last input is not connected to PerfCountBegin"); +} + +void PerfCountEnd::output_perf_count() { + OPENVINO_ASSERT(accumulation.size() == iteration.size(), "accumulation size should be the same as iteration size in perf_count_end node."); + auto iterator_iter = iteration.begin(); + auto iterator_acc = accumulation.begin(); + int t_num = 0; + uint64_t avg_max = 0; + std::cout << "Perf count data in perfCountEnd node with name " << get_friendly_name() << " is:"<< std::endl; + for (; iterator_iter != iteration.end(); ++iterator_iter, ++iterator_acc) { + const auto iter = *iterator_iter; + const auto acc = *iterator_acc; + uint64_t avg = iter == 0 ? 0 : acc / iter; + if (avg > avg_max) + avg_max = avg; + std::cout << "accumulated time:" << acc << "ns, iteration:" << iter << " avg time:" << avg << "ns"<< " on thread:" << t_num << std::endl; + t_num++; + } + + // max time of all threads: combine for reduce max + auto BinaryFunc = [](const uint64_t& a, const uint64_t& b) { + return a >= b ? a : b; + }; + // max accumulation + uint64_t acc_max = accumulation.combine(BinaryFunc); + std::cout << "max accumulated time:" << acc_max << "ns" << std::endl; + // max avg + std::cout << "max avg time:" << avg_max << "ns" << std::endl; +} + +} // namespace op +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/src/op/subgraph.cpp b/src/common/snippets/src/op/subgraph.cpp index 02e87459056d3b..adeed6e26b4473 100644 --- a/src/common/snippets/src/op/subgraph.cpp +++ b/src/common/snippets/src/op/subgraph.cpp @@ -42,6 +42,7 @@ #include "snippets/lowered/pass/validate_loops.hpp" #include "snippets/lowered/pass/insert_loops.hpp" #include "snippets/lowered/pass/optimize_domain.hpp" +#include "snippets/lowered/pass/insert_perf_count.hpp" #include "transformations/utils/utils.hpp" @@ -349,7 +350,8 @@ VectorDims Subgraph::infer_master_shape() { std::shared_ptr Subgraph::convert_body_to_linear_ir(const std::shared_ptr& shape_infer_factory) { lowered::Config lowering_config; - lowering_config.m_save_expressions = config.m_has_domain_sensitive_ops; + lowering_config.m_save_expressions = config.m_has_domain_sensitive_ops || + (lowering_config.perf_count_mode != lowered::PerfCountMode::Disabled); lowering_config.m_need_fill_tail_register = config.m_has_domain_sensitive_ops; lowering_config.m_loop_depth = tileRank; lowering_config.m_enable_domain_optimization = !config.m_has_domain_sensitive_ops; @@ -487,6 +489,10 @@ snippets::Schedule Subgraph::generate_from_linear_ir(const lowered::pass::PassPi auto linear_ir {*m_linear_ir->clone()}; LoweringResult lowering_result; control_flow_transformations(linear_ir, lowering_result, backend_passes_pre_common, backend_passes_post_common); + if (linear_ir.get_config().perf_count_mode == lowered::PerfCountMode::Chrono) { + lowered::pass::InsertPerfCount perf_count_pass; + perf_count_pass.run(linear_ir); + } m_generator->generate(linear_ir, lowering_result, compile_params); VectorDims parallel_exec_domain = linear_ir.get_master_shape(); diff --git a/src/common/snippets/src/shape_inference/shape_inference.cpp b/src/common/snippets/src/shape_inference/shape_inference.cpp index 0b9117d05d0477..f2c6be9ae0b49c 100644 --- a/src/common/snippets/src/shape_inference/shape_inference.cpp +++ b/src/common/snippets/src/shape_inference/shape_inference.cpp @@ -55,6 +55,8 @@ const IShapeInferSnippetsFactory::TRegistry IShapeInferSnippetsFactory::registry SHAPE_INFER_PREDEFINED(op::Scalar, SingleElementShapeInfer), SHAPE_INFER_PREDEFINED(op::VectorBuffer, SingleElementShapeInfer), SHAPE_INFER_PREDEFINED(op::LoopEnd, EmptyShapeInfer), + SHAPE_INFER_PREDEFINED(op::PerfCountBegin, EmptyShapeInfer), + SHAPE_INFER_PREDEFINED(op::PerfCountEnd, EmptyShapeInfer), SHAPE_INFER_PREDEFINED(op::Kernel, EmptyShapeInfer), SHAPE_INFER_PREDEFINED(op::Nop, EmptyShapeInfer), SHAPE_INFER_OP_SPECIFIC_EXTERNAL(opset1::Select, SelectShapeInfer), diff --git a/src/common/snippets/tests/src/lowering_utils.cpp b/src/common/snippets/tests/src/lowering_utils.cpp index 5d49d38a6af2e7..0fa490353e4efa 100644 --- a/src/common/snippets/tests/src/lowering_utils.cpp +++ b/src/common/snippets/tests/src/lowering_utils.cpp @@ -41,6 +41,8 @@ DummyTargetMachine::DummyTargetMachine(const std::vector& jitters[ov::snippets::op::Kernel::get_type_info_static()] = dummy_functor; jitters[ov::snippets::op::LoopBegin::get_type_info_static()] = dummy_functor; jitters[ov::snippets::op::LoopEnd::get_type_info_static()] = dummy_functor; + jitters[ov::snippets::op::PerfCountBegin::get_type_info_static()] = dummy_functor; + jitters[ov::snippets::op::PerfCountEnd::get_type_info_static()] = dummy_functor; jitters[ov::snippets::op::Brgemm::get_type_info_static()] = dummy_functor; jitters[ov::snippets::op::Buffer::get_type_info_static()] = dummy_functor; jitters[ov::snippets::op::VectorBuffer::get_type_info_static()] = dummy_functor; diff --git a/src/inference/dev_api/openvino/runtime/threading/thread_local.hpp b/src/inference/dev_api/openvino/runtime/threading/thread_local.hpp index 679d9518baa4ab..a92c312ee7273c 100644 --- a/src/inference/dev_api/openvino/runtime/threading/thread_local.hpp +++ b/src/inference/dev_api/openvino/runtime/threading/thread_local.hpp @@ -116,6 +116,20 @@ struct ThreadLocal { auto end() const -> Iterator const { return {_map.end()}; } + + // CombineFunc has signature T(T,T) or T(const T&, const T&) + template + T combine(CombineFunc f_combine) { + if (begin() != end()) { + auto ci = begin(); + T my_result = *ci; + while (++ci != end()) + my_result = f_combine(my_result, *ci); + return my_result; + } else { + return _create(); + } + } }; #endif diff --git a/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp b/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp index c1d3e9d1bd1cff..a765ac7c60dd91 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/cpu_generator.cpp @@ -14,12 +14,15 @@ #include "jit_dnnl_emitters.hpp" #include "jit_dnnl_ext_emitters.hpp" #include "jit_conversion_emitters.hpp" +#include "jit_perf_count_chrono_emitters.hpp" +#include "jit_perf_count_rdtsc_emitters.hpp" #include "transformations/snippets/x64/op/load_convert.hpp" #include "transformations/snippets/x64/op/store_convert.hpp" #include "transformations/snippets/x64/op/fused_mul_add.hpp" #include "transformations/snippets/x64/op/brgemm_copy_b.hpp" #include "transformations/snippets/x64/op/brgemm_cpu.hpp" +#include "transformations/snippets/x64/op/perf_count_rdtsc.hpp" #include "transformations/cpu_opset/common/op/swish_cpu.hpp" #include "transformations/snippets/x64/pass/lowered/fuse_load_store_and_convert.hpp" @@ -157,6 +160,11 @@ intel_cpu::CPUTargetMachine::CPUTargetMachine(dnnl::impl::cpu::x64::cpu_isa_t ho jitters[snippets::op::LoopEnd::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(LoopEndEmitter); jitters[intel_cpu::BrgemmCPU::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(BrgemmEmitter); jitters[intel_cpu::BrgemmCopyB::get_type_info_static()] = CREATE_SNIPPETS_EMITTER(BrgemmCopyBEmitter); + + jitters[snippets::op::PerfCountBegin::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_perf_count_chrono_start_emitter); + jitters[snippets::op::PerfCountEnd::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_perf_count_chrono_end_emitter); + jitters[ov::intel_cpu::PerfCountRdtscBegin::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_perf_count_rdtsc_start_emitter); + jitters[ov::intel_cpu::PerfCountRdtscEnd::get_type_info_static()] = CREATE_CPU_EMITTER(ov::intel_cpu::jit_perf_count_rdtsc_end_emitter); } size_t intel_cpu::CPUTargetMachine::get_lanes() const { @@ -224,6 +232,10 @@ snippets::Generator::opRegType intel_cpu::CPUGenerator::get_specific_op_reg_type } bool intel_cpu::CPUGenerator::uses_precompiled_kernel(const std::shared_ptr& e) const { return std::dynamic_pointer_cast(e) || - std::dynamic_pointer_cast(e); + std::dynamic_pointer_cast(e) || + std::dynamic_pointer_cast(e) || + std::dynamic_pointer_cast(e) || + std::dynamic_pointer_cast(e) || + std::dynamic_pointer_cast(e); } -} // namespace ov \ No newline at end of file +} // namespace ov diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.cpp index f9885daa0f6dc0..dbaafdde8124cc 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.cpp @@ -213,5 +213,73 @@ void jit_emitter::emit_code(const std::vector &in_idxs, const std::vecto emitter_postamble(); } +void jit_emitter::internal_call_preamble() const { + // gprs + Xbyak::Operand gprs_to_save[] = {h->r8, h->r9, h->r10, h->r11, h->r12, h->r13, h->r14, h->r15, + h->rax, h->rbx, h->rcx, h->rdx, h->rdi, h->rsi, h->rbp}; + size_t n_gprs_to_save = sizeof(gprs_to_save) / sizeof(gprs_to_save[0]); + + h->sub(h->rsp, n_gprs_to_save * gpr_size); + for (size_t i = 0; i < n_gprs_to_save; ++i) + h->mov(h->ptr[h->rsp + i * gpr_size], gprs_to_save[i]); + + // mask regs + // need preserve based on cpu capability, instead of host isa. + // in case there are possibilty that different isa emitters exist in one subgraph KernelEmitter from perf standpoint in the future. + // e.g. other emitters isa is avx512, while this emitter isa is avx2, and internal call is used. Internal call may use avx512 and spoil k-reg. + // do not care about platform w/ avx512_common but w/o avx512_core(knight landing), which is obsoleted. + if (dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core)) { + h->sub(h->rsp, k_mask_num * k_mask_size); + for (size_t i = 0; i < k_mask_num; ++i) { + h->kmovq(h->ptr[h->rsp + i * k_mask_size], Xbyak::Opmask(static_cast(i))); + } + } + + // vector regs + // 1. Caller obligation to save vector registers as callee may use them. + // 2. There is an implicit assumption that the host code uses the same + // `isa` as the injector. Once the assumption is wrong, `vecs_count` and + // `vlen` should be replaced with `host_isa::vlen` and + // `host_isa::vecs_count`. + h->sub(h->rsp, get_max_vecs_count() * get_vec_length()); + for (size_t i = 0; i < get_max_vecs_count(); ++i) { + push_vec(h->ptr[h->rsp + i * get_vec_length()], i); + } +} + +void jit_emitter::internal_call_postamble() const { + // restore vector registers + for (int i = static_cast(get_max_vecs_count()) - 1; i >= 0; --i) { + pop_vec(static_cast(i), h->ptr[h->rsp + i * get_vec_length()]); + } + h->add(h->rsp, (get_max_vecs_count()) * get_vec_length()); + + // restore k reg + if (dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core)) { + for (int i = k_mask_num - 1; i >= 0; --i) { + h->kmovq(Xbyak::Opmask(i), h->ptr[h->rsp + i * k_mask_size]); + } + h->add(h->rsp, k_mask_num * k_mask_size); + } + + // restore gpr registers + Xbyak::Operand gprs_to_save[] = {h->r8, h->r9, h->r10, h->r11, h->r12, h->r13, h->r14, h->r15, + h->rax, h->rbx, h->rcx, h->rdx, h->rdi, h->rsi, h->rbp}; + size_t n_gprs_to_save = sizeof(gprs_to_save) / sizeof(gprs_to_save[0]); + for (int i = n_gprs_to_save - 1; i >= 0; --i) + h->mov(gprs_to_save[i], h->ptr[h->rsp + i * gpr_size]); + h->add(h->rsp, n_gprs_to_save * gpr_size); +} + +void jit_emitter::internal_call_rsp_align() const { + h->mov(h->rbx, h->rsp); + h->and_(h->rbx, 0xf); + h->sub(h->rsp, h->rbx); +} + +void jit_emitter::internal_call_rsp_restore() const { + h->add(h->rsp, h->rbx); +} + } // namespace intel_cpu } // namespace ov diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.hpp b/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.hpp index c10adb19f9ee58..66f681265b9fd9 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.hpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_emitter.hpp @@ -106,6 +106,8 @@ class jit_emitter : public ov::snippets::Emitter { mutable std::vector aux_gpr_idxs; static constexpr int k_mask_size = 8; + static constexpr int k_mask_num = 8; + static constexpr int gpr_size = 8; Xbyak::Address table_val(std::string key, size_t key_off_val_shift = 0) const { auto off = table_off(key, key_off_val_shift); @@ -130,6 +132,13 @@ class jit_emitter : public ov::snippets::Emitter { } } + void internal_call_preamble() const; + void internal_call_postamble() const; + // align stack on 16-byte as ABI reqiures + // callee is responsible to save and restore rbx. rbx must not be changed after call callee. + void internal_call_rsp_align() const; + void internal_call_rsp_restore() const; + private: mutable std::vector preserved_vec_idxs; mutable std::vector preserved_gpr_idxs; diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_chrono_emitters.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_chrono_emitters.cpp new file mode 100644 index 00000000000000..a94535dfbcbd55 --- /dev/null +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_chrono_emitters.cpp @@ -0,0 +1,73 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "jit_emitter.hpp" +#include "jit_perf_count_chrono_emitters.hpp" +#include + +using namespace dnnl::impl; +using namespace dnnl::impl::utils; +using namespace dnnl::impl::cpu; +using namespace dnnl::impl::cpu::x64; +using namespace Xbyak; +using namespace Xbyak::util; + +namespace ov { +namespace intel_cpu { + +jit_perf_count_chrono_start_emitter::jit_perf_count_chrono_start_emitter(dnnl::impl::cpu::x64::jit_generator *host, dnnl::impl::cpu::x64::cpu_isa_t host_isa, + const std::shared_ptr& n) : jit_emitter(host, host_isa) { + m_start_node = ov::as_type_ptr(n); +} + +size_t jit_perf_count_chrono_start_emitter::get_inputs_num() const { + return 0; +} + +void jit_perf_count_chrono_start_emitter::set_start_time(snippets::op::PerfCountBegin* start_node) { + start_node->set_start_time(); +} + +void jit_perf_count_chrono_start_emitter::emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const { + internal_call_preamble(); + + const auto &set_start_time_overload = static_cast(set_start_time); + h->mov(h->rax, reinterpret_cast(set_start_time_overload)); + h->mov(abi_param1, reinterpret_cast(m_start_node.get())); + internal_call_rsp_align(); + h->call(h->rax); + internal_call_rsp_restore(); + + internal_call_postamble(); +} + +///////////////////jit_perf_count_chrono_end_emitter//////////////////////////////////// +jit_perf_count_chrono_end_emitter::jit_perf_count_chrono_end_emitter(dnnl::impl::cpu::x64::jit_generator *host, dnnl::impl::cpu::x64::cpu_isa_t host_isa, + const std::shared_ptr& n) : jit_emitter(host, host_isa) { + m_end_node = ov::as_type_ptr(n); +} + +size_t jit_perf_count_chrono_end_emitter::get_inputs_num() const { + return 0; +} + +void jit_perf_count_chrono_end_emitter::set_accumulated_time(snippets::op::PerfCountEnd* end_node) { + end_node->set_accumulated_time(); +} + +void jit_perf_count_chrono_end_emitter::emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const { + internal_call_preamble(); + + const auto &set_accumulated_time_overload = static_cast(set_accumulated_time); + h->mov(h->rax, reinterpret_cast(set_accumulated_time_overload)); + h->mov(abi_param1, reinterpret_cast(m_end_node.get())); + internal_call_rsp_align(); + h->call(h->rax); + internal_call_rsp_restore(); + + internal_call_postamble(); +} + +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_chrono_emitters.hpp b/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_chrono_emitters.hpp new file mode 100644 index 00000000000000..763ac995ffe3e3 --- /dev/null +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_chrono_emitters.hpp @@ -0,0 +1,40 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "jit_emitter.hpp" +#include + +#include "snippets/op/perf_count.hpp" + +namespace ov { +namespace intel_cpu { + +class jit_perf_count_chrono_start_emitter : public jit_emitter { +public: + jit_perf_count_chrono_start_emitter(dnnl::impl::cpu::x64::jit_generator *host, dnnl::impl::cpu::x64::cpu_isa_t host_isa, + const std::shared_ptr& n); + size_t get_inputs_num() const override; + +private: + void emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const override; + static void set_start_time(snippets::op::PerfCountBegin* start_node); + std::shared_ptr m_start_node = nullptr; +}; + +class jit_perf_count_chrono_end_emitter : public jit_emitter { +public: + jit_perf_count_chrono_end_emitter(dnnl::impl::cpu::x64::jit_generator *host, dnnl::impl::cpu::x64::cpu_isa_t host_isa, + const std::shared_ptr& n); + size_t get_inputs_num() const override; + +private: + void emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const override; + static void set_accumulated_time(snippets::op::PerfCountEnd* end_node); + std::shared_ptr m_end_node = nullptr; +}; + +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_rdtsc_emitters.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_rdtsc_emitters.cpp new file mode 100644 index 00000000000000..7f1ccda3aca62b --- /dev/null +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_rdtsc_emitters.cpp @@ -0,0 +1,86 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "jit_emitter.hpp" +#include "jit_perf_count_rdtsc_emitters.hpp" +#include + +using namespace dnnl::impl; +using namespace dnnl::impl::utils; +using namespace dnnl::impl::cpu; +using namespace dnnl::impl::cpu::x64; +using namespace Xbyak; +using namespace Xbyak::util; + +namespace ov { +namespace intel_cpu { + +jit_perf_count_rdtsc_start_emitter::jit_perf_count_rdtsc_start_emitter(dnnl::impl::cpu::x64::jit_generator *host, dnnl::impl::cpu::x64::cpu_isa_t host_isa, + const std::shared_ptr& n) : jit_emitter(host, host_isa) { + m_start_node = ov::as_type_ptr(n); +} + +size_t jit_perf_count_rdtsc_start_emitter::get_inputs_num() const { + return 0; +} + +void jit_perf_count_rdtsc_start_emitter::emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const { + h->push(h->rax); + h->push(h->rdx); + + // The EDX register is loaded with the high-order 32 bits of the MSR and the EAX register is loaded with the low-order 32 bits. + h->lfence(); + h->rdtsc(); + h->lfence(); + h->shl(h->rdx, 0x20); // shift to higher half of rdx 0x20(32) + h->or_(h->rdx, h->rax); // rdx has current tsc + + h->mov(h->rax, reinterpret_cast(&m_start_node->start_count)); + h->mov(qword[h->rax], h->rdx); + + h->pop(h->rdx); + h->pop(h->rax); +} + +///////////////////jit_perf_count_rdtsc_end_emitter//////////////////////////////////// +jit_perf_count_rdtsc_end_emitter::jit_perf_count_rdtsc_end_emitter(dnnl::impl::cpu::x64::jit_generator *host, dnnl::impl::cpu::x64::cpu_isa_t host_isa, + const std::shared_ptr& n) : jit_emitter(host, host_isa) { + m_end_node = ov::as_type_ptr(n); +} + +size_t jit_perf_count_rdtsc_end_emitter::get_inputs_num() const { + return 0; +} + +void jit_perf_count_rdtsc_end_emitter::emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const { + h->push(h->rax); + h->push(h->rdx); + + h->lfence(); + h->rdtsc(); + h->lfence(); + h->shl(h->rdx, 0x20); + h->or_(h->rdx, h->rax); // rdx has current tsc + + // tsc duration + h->mov(h->rax, reinterpret_cast(&m_end_node->get_pc_begin()->start_count)); + h->sub(h->rdx, qword[h->rax]); // rdx has tsc duration + + // accumulation = accumulation + tsc duration + h->mov(h->rax, reinterpret_cast(&m_end_node->accumulation)); + h->add(h->rdx, qword[h->rax]); + h->mov(qword[h->rax], h->rdx); + + // iteration++ + h->mov(h->rax, reinterpret_cast(&m_end_node->iteration)); + h->mov(h->rdx, qword[h->rax]); + h->add(h->rdx, 0x01); + h->mov(qword[h->rax], h->rdx); + + h->pop(h->rdx); + h->pop(h->rax); +} + +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_rdtsc_emitters.hpp b/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_rdtsc_emitters.hpp new file mode 100644 index 00000000000000..c6314adc72a084 --- /dev/null +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_perf_count_rdtsc_emitters.hpp @@ -0,0 +1,37 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "jit_emitter.hpp" +#include +#include "transformations/snippets/x64/op/perf_count_rdtsc.hpp" + +namespace ov { +namespace intel_cpu { + +class jit_perf_count_rdtsc_start_emitter : public jit_emitter { +public: + jit_perf_count_rdtsc_start_emitter(dnnl::impl::cpu::x64::jit_generator *host, dnnl::impl::cpu::x64::cpu_isa_t host_isa, + const std::shared_ptr& n); + size_t get_inputs_num() const override; + +private: + void emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const override; + std::shared_ptr m_start_node = nullptr; +}; + +class jit_perf_count_rdtsc_end_emitter : public jit_emitter { +public: + jit_perf_count_rdtsc_end_emitter(dnnl::impl::cpu::x64::jit_generator *host, dnnl::impl::cpu::x64::cpu_isa_t host_isa, + const std::shared_ptr& n); + size_t get_inputs_num() const override; + +private: + void emit_impl(const std::vector &in_idxs, const std::vector &out_idxs) const override; + std::shared_ptr m_end_node = nullptr; +}; + +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp index 40e49a7b158b6f..b87b265a03f562 100644 --- a/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp +++ b/src/plugins/intel_cpu/src/emitters/x64/jit_snippets_emitters.cpp @@ -26,10 +26,6 @@ using jit_generator = dnnl::impl::cpu::x64::jit_generator; using cpu_isa_t = dnnl::impl::cpu::x64::cpu_isa_t; using ExpressionPtr = ov::snippets::lowered::ExpressionPtr; -namespace { -constexpr size_t gpr_size = 8; -} // namespace - inline static void transform_idxs_to_regs(const std::vector& idxs, std::vector& regs) { regs.resize(idxs.size()); std::transform(idxs.begin(), idxs.end(), regs.begin(), [](size_t idx){return Reg64(static_cast(idx));}); @@ -1114,32 +1110,7 @@ void BrgemmEmitter::emit_brgemm_kernel_call(const brgemm_kernel_t *brg_kernel, c h->add(h->rsp, n_gprs_to_save * gpr_size); } - Xbyak::Operand gprs_to_save[] = {h->r8, h->r9, h->r10, h->r11, h->r12, h->r13, h->r14, h->r15, - h->rax, h->rcx, h->rdx, h->rdi, h->rsi, h->rbp, h->rbx}; - size_t n_gprs_to_save = sizeof(gprs_to_save) / sizeof(gprs_to_save[0]); - - h->sub(h->rsp, n_gprs_to_save * gpr_size); - for (size_t i = 0; i < n_gprs_to_save; ++i) - h->mov(h->ptr[h->rsp + i * gpr_size], gprs_to_save[i]); - - // caller obligation to save k-regs as callee may use them - size_t n_k_regs_to_save = 8; - h->sub(h->rsp, n_k_regs_to_save * k_mask_size); - for (size_t i = 0; i < n_k_regs_to_save; ++i) { - if (mayiuse(avx512_core)) - h->kmovq(h->ptr[h->rsp + i * k_mask_size], Opmask(static_cast(i))); - else - h->kmovw(h->ptr[h->rsp + i * k_mask_size], Opmask(static_cast(i))); - } - - // 1. Caller obligation to save vector registers as callee may use them. - // 2. There is an implicit assumption that the host code uses the same - // `isa` as the injector. Once the assumption is wrong, `vecs_count` and - // `vlen` should be replaced with `host_isa::vlen` and - // `host_isa::vecs_count`. - h->sub(h->rsp, get_max_vecs_count() * get_vec_length()); - for (size_t i = 0; i < get_max_vecs_count(); ++i) - h->uni_vmovups(h->ptr[h->rsp + i * get_vec_length()], Zmm(i)); + internal_call_preamble(); // save function address in gpr to pass in call instruction const auto& brgemm_kernel_overload = static_castmov(abi_param6, static_cast(m_with_comp)); #endif - // align stack on 16-byte as ABI requires - // note that RBX must not be changed by the callee - h->mov(h->rbx, h->rsp); - h->and_(h->rbx, 0xf); - h->sub(h->rsp, h->rbx); - + internal_call_rsp_align(); h->call(h->rbp); - - h->add(h->rsp, h->rbx); + internal_call_rsp_restore(); #ifdef _WIN32 h->add(h->rsp, num_args_passed_on_stack * gpr_size); #endif - // restore vector registers - for (int i = static_cast(get_max_vecs_count()) - 1; i >= 0; --i) { - h->uni_vmovups(Zmm(i), h->ptr[h->rsp + i * get_vec_length()]); - } - h->add(h->rsp, (get_max_vecs_count()) * get_vec_length()); - - // restore k registers - for (int i = n_k_regs_to_save - 1; i >= 0; --i) { - if (mayiuse(avx512_core)) - h->kmovq(Opmask(i), h->ptr[h->rsp + i * k_mask_size]); - else - h->kmovw(Opmask(i), h->ptr[h->rsp + i * k_mask_size]); - } - h->add(h->rsp, n_k_regs_to_save * k_mask_size); - // restore gpr registers - for (int i = n_gprs_to_save - 1; i >= 0; --i) - h->mov(gprs_to_save[i], h->ptr[h->rsp + i * gpr_size]); - h->add(h->rsp, n_gprs_to_save * gpr_size); + internal_call_postamble(); } void BrgemmEmitter::kernel_execute(const brgemm_kernel_t *brg_kernel, @@ -1358,32 +1306,7 @@ void BrgemmCopyBEmitter::emit_impl(const std::vector& in, void BrgemmCopyBEmitter::emit_kernel_call(const matmul::jit_brgemm_matmul_copy_b_t* kernel, Reg64 src, Reg64 dst, Reg64 comp, size_t N, size_t K, size_t offset_in, size_t offset_out, size_t offset_comp) const { - Xbyak::Operand gprs_to_save[] = {h->r8, h->r9, h->r10, h->r11, h->r12, h->r13, h->r14, h->r15, - h->rax, h->rcx, h->rdx, h->rdi, h->rsi, h->rbp, h->rbx}; - size_t n_gprs_to_save = sizeof(gprs_to_save) / sizeof(gprs_to_save[0]); - - h->sub(h->rsp, n_gprs_to_save * gpr_size); - for (size_t i = 0; i < n_gprs_to_save; ++i) - h->mov(h->ptr[h->rsp + i * gpr_size], gprs_to_save[i]); - - // caller obligation to save k-regs as callee may use them - size_t n_k_regs_to_save = 8; - h->sub(h->rsp, n_k_regs_to_save * k_mask_size); - for (size_t i = 0; i < n_k_regs_to_save; ++i) { - if (mayiuse(avx512_core)) - h->kmovq(h->ptr[h->rsp + i * k_mask_size], Opmask(static_cast(i))); - else - h->kmovw(h->ptr[h->rsp + i * k_mask_size], Opmask(static_cast(i))); - } - - // 1. Caller obligation to save vector registers as callee may use them. - // 2. There is an implicit assumption that the host code uses the same - // `isa` as the injector. Once the assumption is wrong, `vecs_count` and - // `vlen` should be replaced with `host_isa::vlen` and - // `host_isa::vecs_count`. - h->sub(h->rsp, get_max_vecs_count() * get_vec_length()); - for (size_t i = 0; i < get_max_vecs_count(); ++i) - h->uni_vmovups(h->ptr[h->rsp + i * get_vec_length()], Zmm(i)); + internal_call_preamble(); const auto data_ptr = [&](Xmm xmm, Xbyak::Reg64 reg, size_t bytes_offset) { h->uni_vmovq(reg, xmm); @@ -1437,38 +1360,16 @@ void BrgemmCopyBEmitter::emit_kernel_call(const matmul::jit_brgemm_matmul_copy_b h->mov(abi_param5, N); h->mov(abi_param6, K); #endif - // align stack on 16-byte as ABI requires - // note that RBX must not be changed by the callee - h->mov(h->rbx, h->rsp); - h->and_(h->rbx, 0xf); - h->sub(h->rsp, h->rbx); + internal_call_rsp_align(); h->call(h->rbp); - - h->add(h->rsp, h->rbx); + internal_call_rsp_restore(); #ifdef _WIN32 h->add(h->rsp, gpr_size * num_args_passed_on_stack); #endif - // restore vector registers - for (int i = static_cast(get_max_vecs_count()) - 1; i >= 0; --i) { - h->uni_vmovups(Zmm(i), h->ptr[h->rsp + i * get_vec_length()]); - } - h->add(h->rsp, (get_max_vecs_count()) * get_vec_length()); - - // restore k registers - for (int i = n_k_regs_to_save - 1; i >= 0; --i) { - if (mayiuse(avx512_core)) - h->kmovq(Opmask(i), h->ptr[h->rsp + i * k_mask_size]); - else - h->kmovw(Opmask(i), h->ptr[h->rsp + i * k_mask_size]); - } - h->add(h->rsp, n_k_regs_to_save * k_mask_size); - // restore gpr registers - for (int i = n_gprs_to_save - 1; i >= 0; --i) - h->mov(gprs_to_save[i], h->ptr[h->rsp + i * gpr_size]); - h->add(h->rsp, n_gprs_to_save * gpr_size); + internal_call_postamble(); } void BrgemmCopyBEmitter::execute(matmul::jit_brgemm_matmul_copy_b_t *kernel, const void *src, diff --git a/src/plugins/intel_cpu/src/extension.cpp b/src/plugins/intel_cpu/src/extension.cpp index 8110a4c2fff2ea..d9fe51c5151aa4 100644 --- a/src/plugins/intel_cpu/src/extension.cpp +++ b/src/plugins/intel_cpu/src/extension.cpp @@ -15,6 +15,7 @@ #include "transformations/snippets/x64/op/store_convert.hpp" #include "transformations/snippets/x64/op/brgemm_cpu.hpp" #include "transformations/snippets/x64/op/brgemm_copy_b.hpp" +#include "transformations/snippets/x64/op/perf_count_rdtsc.hpp" #include #include @@ -159,12 +160,16 @@ std::map Extension::getOpSets() { NGRAPH_OP(Subgraph, ov::snippets::op) NGRAPH_OP(VectorBuffer, ov::snippets::op) NGRAPH_OP(RankNormalization, ov::snippets::op) + NGRAPH_OP(PerfCountBegin, ov::snippets::op) + NGRAPH_OP(PerfCountEnd, ov::snippets::op) NGRAPH_OP_X64(LoadConvertSaturation, ov::intel_cpu) NGRAPH_OP_X64(LoadConvertTruncation, ov::intel_cpu) NGRAPH_OP_X64(StoreConvertSaturation, ov::intel_cpu) NGRAPH_OP_X64(StoreConvertTruncation, ov::intel_cpu) NGRAPH_OP_X64(BrgemmCPU, ov::intel_cpu) NGRAPH_OP_X64(BrgemmCopyB, ov::intel_cpu) + NGRAPH_OP_X64(PerfCountRdtscBegin, ov::intel_cpu) + NGRAPH_OP_X64(PerfCountRdtscEnd, ov::intel_cpu) #undef NGRAPH_OP return opset; diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/perf_count_rdtsc.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/perf_count_rdtsc.cpp new file mode 100644 index 00000000000000..a3343d5ab74e8c --- /dev/null +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/perf_count_rdtsc.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "perf_count_rdtsc.hpp" + +using namespace ov; +using namespace ov::intel_cpu; + +/////////////////////////PerfCountRdtscBegin////////////////////// +PerfCountRdtscBegin::PerfCountRdtscBegin() : PerfCountBeginBase() { + validate_and_infer_types_except_PerfCountEnd(); +} + +std::shared_ptr PerfCountRdtscBegin::clone_with_new_inputs(const OutputVector& inputs) const { + return std::make_shared(); +} + +/////////////////////////PerfCountRdtscEnd////////////////////// +PerfCountRdtscEnd::PerfCountRdtscEnd(const Output& pc_begin) : ov::snippets::op::PerfCountEndBase({pc_begin}), accumulation(0ul), iteration(0u) { + constructor_validate_and_infer_types(); +} + +std::shared_ptr PerfCountRdtscEnd::clone_with_new_inputs(const OutputVector& inputs) const { + return std::make_shared(inputs.at(0)); +} + +std::shared_ptr PerfCountRdtscEnd::get_pc_begin() { + const auto& pc_begin = ov::as_type_ptr(get_input_source_output(get_input_size() - 1).get_node_shared_ptr()); + OPENVINO_ASSERT(pc_begin != nullptr, "PerfCountRdtscEnd last input is not connected to PerfCountRdtscBegin"); + return pc_begin; +} diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/op/perf_count_rdtsc.hpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/perf_count_rdtsc.hpp new file mode 100644 index 00000000000000..91f8b82fed5055 --- /dev/null +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/op/perf_count_rdtsc.hpp @@ -0,0 +1,55 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/op/op.hpp" +#include "snippets/op/perf_count.hpp" + +using namespace ov::snippets::op; + +namespace ov { +namespace intel_cpu { + +/** + * @interface PerfCountRdtscBegin + * @brief Performance count start time via read rdtsc register + * @ingroup snippets + */ +class PerfCountRdtscBegin : public PerfCountBeginBase { +public: + OPENVINO_OP("PerfCountRdtscBegin", "SnippetsOpset", PerfCountBeginBase); + PerfCountRdtscBegin(); + std::shared_ptr clone_with_new_inputs(const OutputVector& inputs) const override; + + uint64_t start_count = 0ul; +}; + +/** + * @interface PerfCountRdtscEnd + * @brief Performance count end time and duration + * @ingroup snippets + */ +class PerfCountRdtscEnd : public PerfCountEndBase { +public: + OPENVINO_OP("PerfCountRdtscEnd", "SnippetsOpset", PerfCountEndBase); + PerfCountRdtscEnd(const Output& pc_begin); + PerfCountRdtscEnd() = default; + ~PerfCountRdtscEnd() { + uint64_t avg = iteration == 0 ? 0 : accumulation / iteration; + std::cout << "accumulation:" << accumulation << " iteration:" << iteration << " avg:" << avg << std::endl; + } + std::shared_ptr clone_with_new_inputs(const OutputVector& inputs) const override; + + std::shared_ptr get_pc_begin(); + // in each call, PerfCountRdtscBegin get start_count. + // in each call, PerfCountRdtscEnd get end_count, then total_duration += end_count - start_count, and iteration++. + // in destructor of PerfCountRdtscEnd, output the perf info + // accumulation is cycle count + uint64_t accumulation = 0ul; + uint32_t iteration = 0u; +}; + +} // namespace intel_cpu +} // namespace ov diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp index 6bb833262a516c..a9674cc00daa1f 100644 --- a/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp +++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/shape_inference.cpp @@ -9,6 +9,7 @@ #include "op/fused_mul_add.hpp" #include "op/load_convert.hpp" #include "op/store_convert.hpp" +#include "op/perf_count_rdtsc.hpp" #include "transformations/cpu_opset/common/op/swish_cpu.hpp" namespace ov { @@ -38,6 +39,8 @@ const CPUShapeInferSnippetsFactory::TRegistry CPUShapeInferSnippetsFactory::spec SHAPE_INFER_PREDEFINED(ov::intel_cpu::LoadConvertTruncation, PassThroughShapeInfer), SHAPE_INFER_PREDEFINED(ov::intel_cpu::StoreConvertSaturation, PassThroughShapeInfer), SHAPE_INFER_PREDEFINED(ov::intel_cpu::StoreConvertTruncation, PassThroughShapeInfer), + SHAPE_INFER_PREDEFINED(ov::intel_cpu::PerfCountRdtscBegin, EmptyShapeInfer), + SHAPE_INFER_PREDEFINED(ov::intel_cpu::PerfCountRdtscEnd, EmptyShapeInfer), SHAPE_INFER_OP_SPECIFIC_EXTERNAL(ov::intel_cpu::BrgemmCPU, BrgemmShapeInfer), // SHAPE_INFER_OP_SPECIFIC(ov::intel_cpu::BrgemmCopyB), From 65b8bdf892fd26ee956c568267ce967d4f5a475f Mon Sep 17 00:00:00 2001 From: River Li Date: Tue, 5 Dec 2023 22:18:16 +0800 Subject: [PATCH 16/20] [CPU Tests] migrate sub_graph test cases - part 2 (#21379) * [CPU Tests] migrate sub_graph test case - part 2 * remove unused header files --------- Co-authored-by: Vitaliy Urusovskij --- .../src/arm/convert_group_conv.cpp | 45 ++++---- .../src/arm/convert_group_conv1d.cpp | 47 +++----- .../src/arm/convert_reduce_multi_axis.cpp | 60 ++++------ .../subgraph_tests/src/eltwise_caching.cpp | 53 ++++----- .../subgraph_tests/src/eltwise_chain.cpp | 92 +++++++-------- .../subgraph_tests/src/rotary_pos_emb.cpp | 9 +- .../subgraph_tests/src/seq_native_order.cpp | 108 +++++++++--------- .../subgraph_tests/src/static_zero_dims.cpp | 31 +++-- 8 files changed, 212 insertions(+), 233 deletions(-) diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_group_conv.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_group_conv.cpp index 48aea1512428e5..2a631c344162f2 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_group_conv.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_group_conv.cpp @@ -2,28 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include -#include "common_test_utils/common_utils.hpp" -#include -#include "functional_test_utils/skip_tests_config.hpp" +#include "common_test_utils/node_builders/group_convolution.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" - -#include "test_utils/cpu_test_utils.hpp" -#include "test_utils/convolution_params.hpp" using namespace CPUTestUtils; -using namespace ov::test; -using namespace ngraph; -using namespace ngraph::helpers; -namespace CPUSubgraphTestsDefinitions { +namespace ov { +namespace test { typedef std::tuple groupConvLayerCPUTestParamsSet; @@ -60,15 +46,23 @@ class GroupConvToConvTransformationCPUTest: public testing::WithParamInterface(ngraph::element::f32, shape)); + inputParams.push_back(std::make_shared(ov::element::f32, shape)); } - conv = builder::makeGroupConvolution(inputParams[0], element::f32, kernelSize, strides, padBegin, padEnd, dilation, - paddingType, numOutChannels, numOfGroups); + conv = utils::make_group_convolution(inputParams[0], + element::f32, + kernelSize, + strides, + padBegin, + padEnd, + dilation, + paddingType, + numOutChannels, + numOfGroups); ResultVector results; - results.push_back(std::make_shared(conv)); + results.push_back(std::make_shared(conv)); - function = std::make_shared(results, inputParams, "groupConvolution"); + function = std::make_shared(results, inputParams, "groupConvolution"); } }; @@ -96,5 +90,6 @@ const auto groupConvTransformationParams = ::testing::Combine(::testing::ValuesI INSTANTIATE_TEST_SUITE_P(smoke_GroupConvToConvTransformationTest, GroupConvToConvTransformationCPUTest, groupConvTransformationParams, GroupConvToConvTransformationCPUTest::getTestCaseName); -} // namespace -} // namespace CPUSubgraphTestsDefinitions +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_group_conv1d.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_group_conv1d.cpp index 79a21d4c8bd854..9beb3be72f5882 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_group_conv1d.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_group_conv1d.cpp @@ -2,35 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include -#include "functional_test_utils/skip_tests_config.hpp" +#include "common_test_utils/node_builders/convolution.hpp" +#include "common_test_utils/node_builders/group_convolution.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" -#include "test_utils/cpu_test_utils.hpp" -#include "test_utils/convolution_params.hpp" - -using namespace InferenceEngine; using namespace CPUTestUtils; -using namespace ov::test; -using namespace ngraph; -using namespace ngraph::helpers; -namespace CPUSubgraphTestsDefinitions { +namespace ov { +namespace test { -typedef std::tuple conv1dConvertCPUTestParamsSet; +typedef std::tuple conv1dConvertCPUTestParamsSet; -class Conv1dConvertTransformationCPUTest: public testing::WithParamInterface, - virtual public SubgraphBaseTest, public CPUTestsBase { +class Conv1dConvertTransformationCPUTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest, + public CPUTestsBase { public: static std::string getTestCaseName(testing::TestParamInfo obj) { InputShape inputShapes; @@ -65,16 +53,16 @@ class Conv1dConvertTransformationCPUTest: public testing::WithParamInterface(ngraph::element::f32, shape)); + inputParams.push_back(std::make_shared(ov::element::f32, shape)); } switch (convType) { case nodeType::convolution : { - conv = builder::makeConvolution(inputParams[0], element::f32, kernelSize, strides, padBegin, padEnd, dilation, + conv = utils::make_convolution(inputParams[0], element::f32, kernelSize, strides, padBegin, padEnd, dilation, paddingType, numOutChannels); break; } case nodeType::groupConvolution : { - conv = builder::makeGroupConvolution(inputParams[0], element::f32, kernelSize, strides, padBegin, padEnd, dilation, + conv = utils::make_group_convolution(inputParams[0], element::f32, kernelSize, strides, padBegin, padEnd, dilation, paddingType, numOutChannels, numOfGroups); break; } @@ -84,9 +72,9 @@ class Conv1dConvertTransformationCPUTest: public testing::WithParamInterface(conv)); + results.push_back(std::make_shared(conv)); - function = std::make_shared(results, inputParams, "convolution"); + function = std::make_shared(results, inputParams, "convolution"); } }; @@ -132,5 +120,6 @@ const auto groupConvTransformationParams = ::testing::Combine(::testing::ValuesI INSTANTIATE_TEST_SUITE_P(smoke_GroupConvToConvTransformationTest, Conv1dConvertTransformationCPUTest, groupConvTransformationParams, Conv1dConvertTransformationCPUTest::getTestCaseName); -} // namespace -} // namespace CPUSubgraphTestsDefinitions +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_reduce_multi_axis.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_reduce_multi_axis.cpp index 3bb5a06c7d9f2c..2b837a4fd275c4 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_reduce_multi_axis.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/arm/convert_reduce_multi_axis.cpp @@ -2,35 +2,22 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include -#include "functional_test_utils/skip_tests_config.hpp" +#include "common_test_utils/node_builders/reduce.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" -#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" -#include "test_utils/cpu_test_utils.hpp" -#include "test_utils/convolution_params.hpp" - -using namespace InferenceEngine; using namespace CPUTestUtils; -using namespace ov::test; -using namespace ngraph; -using namespace ngraph::helpers; -namespace CPUSubgraphTestsDefinitions { +namespace ov { +namespace test { -typedef std::tuple< - std::vector, // Axis to reduce order - ngraph::helpers::ReductionType, // Reduce operation type - std::vector // Input shapes -> reduceConvertCPUTestParamsSet; +typedef std::tuple, // Axis to reduce order + ov::test::utils::ReductionType, // Reduce operation type + std::vector // Input shapes + > + reduceConvertCPUTestParamsSet; class reduceTransformationCPUTest: public testing::WithParamInterface, virtual public SubgraphBaseTest, public CPUTestsBase { @@ -38,7 +25,7 @@ class reduceTransformationCPUTest: public testing::WithParamInterface obj) { std::vector inputShapes; std::vector axes; - ReductionType reductionType; + utils::ReductionType reductionType; std::tie(axes, reductionType, inputShapes) = obj.param; std::ostringstream result; @@ -65,18 +52,18 @@ class reduceTransformationCPUTest: public testing::WithParamInterface(ngraph::element::f32, shape)); + params.push_back(std::make_shared(ov::element::f32, shape)); } std::vector shapeAxes; shapeAxes.push_back(axes.size()); - auto reductionAxesNode = std::dynamic_pointer_cast( - std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape(shapeAxes), axes)); + auto reductionAxesNode = std::dynamic_pointer_cast( + std::make_shared(ov::element::Type_t::i64, ov::Shape(shapeAxes), axes)); - const auto reduce = ngraph::builder::makeReduce(params[0], reductionAxesNode, keepDims, reductionType); + const auto reduce = utils::make_reduce(params[0], reductionAxesNode, keepDims, reductionType); function = makeNgraphFunction(ElementType::f32, params, reduce, "Reduce"); } private: - ngraph::helpers::ReductionType reductionType; + utils::ReductionType reductionType; }; TEST_P(reduceTransformationCPUTest, CompareWithRefs) { @@ -88,11 +75,11 @@ namespace { std::vector> inputShapes = { {{{}, {{2, 19, 2, 9}}}} }; -const std::vector reductionTypes = { - ReductionType::Min, - ReductionType::Max, - ReductionType::Sum, - ReductionType::Prod +const std::vector reductionTypes = { + utils::ReductionType::Min, + utils::ReductionType::Max, + utils::ReductionType::Sum, + utils::ReductionType::Prod }; const std::vector> axes = { {0, 1}, @@ -114,5 +101,6 @@ const auto reduceTransformationParams = ::testing::Combine(::testing::ValuesIn(a INSTANTIATE_TEST_SUITE_P(smoke_GroupConvToConvTransformationTest, reduceTransformationCPUTest, reduceTransformationParams, reduceTransformationCPUTest::getTestCaseName); -} // namespace -} // namespace CPUSubgraphTestsDefinitions +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/eltwise_caching.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/eltwise_caching.cpp index d5f5f3ead3cac9..487235fa8dd15b 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/eltwise_caching.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/eltwise_caching.cpp @@ -32,23 +32,23 @@ // |output| // -------- -#include -#include -#include -#include -#include -#include -#include #include "common_test_utils/common_utils.hpp" -#include -#include "functional_test_utils/skip_tests_config.hpp" +#include "common_test_utils/node_builders/eltwise.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" +#include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "test_utils/cpu_test_utils.hpp" +#include +#include +#include +#include + using namespace CPUTestUtils; -using ngraph::helpers::EltwiseTypes; -using namespace ov::test; -namespace CPUSubgraphTestsDefinitions { +namespace ov { +namespace test { +using namespace ov::test::utils; using InputShapesTuple = std::tuple< std::vector, // eltwise input shapes @@ -122,7 +122,7 @@ class EltwiseCacheTest : public testing::WithParamInterface& targetInputStaticShapes) override { + void generate_inputs(const std::vector& targetInputStaticShapes) override { inputs.clear(); const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { @@ -155,31 +155,31 @@ class EltwiseCacheTest : public testing::WithParamInterface> ngraphInputs; + ov::ParameterVector paramVec; + std::vector> inputNodes; for (size_t i = 0; i < inputDynamicShapes.size(); i++) { - ngraphParam.push_back(std::make_shared(inputPrecisions[i], inputDynamicShapes[i])); - ngraphInputs.push_back(ngraphParam.back()); + paramVec.push_back(std::make_shared(inputPrecisions[i], inputDynamicShapes[i])); + inputNodes.push_back(paramVec.back()); } - auto lastNode0 = ngraph::builder::makeEltwise(ngraphParam[0], ngraphParam[1], eltwiseOpTypes[0]); + auto lastNode0 = utils::makeEltwise(paramVec[0], paramVec[1], eltwiseOpTypes[0]); lastNode0->get_rt_info() = getCPUInfo(); - auto lastNode1 = ngraph::builder::makeEltwise(ngraphParam[2], ngraphParam[3], eltwiseOpTypes[1]); + auto lastNode1 = utils::makeEltwise(paramVec[2], paramVec[3], eltwiseOpTypes[1]); lastNode1->get_rt_info() = getCPUInfo(); if (withQuantization) { - lastNode0 = ngraph::builder::makeFakeQuantize(lastNode0, ::ngraph::element::Type(::ngraph::element::Type_t::f32), + lastNode0 = ngraph::builder::makeFakeQuantize(lastNode0, ov::element::Type(ov::element::Type_t::f32), 256, fqInputShapes[0]); - lastNode1 = ngraph::builder::makeFakeQuantize(lastNode1, ::ngraph::element::Type(::ngraph::element::Type_t::f32), + lastNode1 = ngraph::builder::makeFakeQuantize(lastNode1, ov::element::Type(ov::element::Type_t::f32), 256, fqInputShapes[1]); } if (needReshape) { - auto reshapeConstNode = ngraph::builder::makeConstant(::ngraph::element::Type(::ngraph::element::Type_t::i32), + auto reshapeConstNode = ngraph::builder::makeConstant(ov::element::Type(ov::element::Type_t::i32), {reshapeShape.size()}, reshapeShape); - lastNode1 = std::make_shared(lastNode1, reshapeConstNode, false); + lastNode1 = std::make_shared(lastNode1, reshapeConstNode, false); } auto concat = std::make_shared(ov::NodeVector{lastNode0, lastNode1}, 0); - function = std::make_shared(concat, ngraphParam, "eltwise_cache"); + function = std::make_shared(concat, paramVec, "eltwise_cache"); } }; @@ -1328,5 +1328,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_EltwiseCache_7D_dyn, EltwiseCacheTest, ::testing::Values(cpuParams_empty)), EltwiseCacheTest::getTestCaseName); -} // namespace -} // namespace CPUSubgraphTestsDefinitions +} // namespace +} // namespace test +} // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/eltwise_chain.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/eltwise_chain.cpp index ef20c4ffd0518d..b4bff5634bcac6 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/eltwise_chain.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/eltwise_chain.cpp @@ -6,35 +6,36 @@ #include #include #include -#include -#include -#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "ov_models/builders.hpp" #include "common_test_utils/common_utils.hpp" -#include -#include "functional_test_utils/skip_tests_config.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" #include "test_utils/cpu_test_utils.hpp" +#include "common_test_utils/node_builders/eltwise.hpp" using namespace CPUTestUtils; -using ngraph::helpers::EltwiseTypes; -using namespace ov::test; -namespace CPUSubgraphTestsDefinitions { -typedef std::tuple< - std::vector, // Input shapes - ngraph::helpers::InputLayerType, // Secondary input type - std::vector, // Input precisions - std::vector, // Eltwise operations - bool, // With quantization - std::string // Device name -> EltwiseChainTuple; +namespace ov { +namespace test { +using namespace ov::test::utils; + +typedef std::tuple, // Input shapes + InputLayerType, // Secondary input type + std::vector, // Input precisions + std::vector, // Eltwise operations + bool, // With quantization + std::string // Device name + > + EltwiseChainTuple; class EltwiseChainTest : public testing::WithParamInterface, virtual public SubgraphBaseTest { public: static std::string getTestCaseName(const testing::TestParamInfo &obj) { std::vector inputShapes; - ngraph::helpers::InputLayerType secondaryInputType; + InputLayerType secondaryInputType; std::vector inputPrecisions; std::vector eltwiseOpTypes; bool withQuantization; @@ -65,7 +66,7 @@ class EltwiseChainTest : public testing::WithParamInterface, return results.str(); } - void generate_inputs(const std::vector& targetInputStaticShapes) override { + void generate_inputs(const std::vector& targetInputStaticShapes) override { inputs.clear(); const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { @@ -81,7 +82,7 @@ class EltwiseChainTest : public testing::WithParamInterface, abs_threshold = 0.1f; std::vector inputShapes; - ngraph::helpers::InputLayerType secondaryInputType; + InputLayerType secondaryInputType; std::vector inputPrecisions; std::vector eltwiseOpTypes; bool withQuantization; @@ -89,27 +90,27 @@ class EltwiseChainTest : public testing::WithParamInterface, init_input_shapes(inputShapes); - ngraph::ParameterVector ngraphParam; - std::vector> ngraphInputs; + ov::ParameterVector paramVec; + std::vector> inputNodes; if (secondaryInputType == ngraph::helpers::InputLayerType::PARAMETER) { for (size_t i = 0; i < inputDynamicShapes.size(); i++) { - ngraphParam.push_back(std::make_shared(inputPrecisions[i], inputDynamicShapes[i])); - ngraphInputs.push_back(ngraphParam.back()); + paramVec.push_back(std::make_shared(inputPrecisions[i], inputDynamicShapes[i])); + inputNodes.push_back(paramVec.back()); } } else { - ngraphParam = ov::ParameterVector {std::make_shared(inputPrecisions[0], inputDynamicShapes.front())}; + paramVec = ov::ParameterVector {std::make_shared(inputPrecisions[0], inputDynamicShapes.front())}; for (size_t i = 1; i < inputPrecisions.size(); i++) { - std::vector ngraphInput1Data(ngraph::shape_size(targetStaticShapes[0][i])); - ngraphInputs.push_back(ngraph::builder::makeConstant(inputPrecisions[i], targetStaticShapes[0][i], - ngraphInput1Data, true)); + std::vector input1Data(ov::shape_size(targetStaticShapes[0][i])); + inputNodes.push_back( + ngraph::builder::makeConstant(inputPrecisions[i], targetStaticShapes[0][i], input1Data, true)); } } if (withQuantization) { - std::vector> eltwiseOps; - eltwiseOps.push_back(ngraph::builder::makeEltwise(ngraphParam[0], ngraphInputs[0], eltwiseOpTypes[0])); + std::vector> eltwiseOps; + eltwiseOps.push_back(makeEltwise(paramVec[0], inputNodes[0], eltwiseOpTypes[0])); for (size_t i = 1; i < eltwiseOpTypes.size() - 1; i++) { - eltwiseOps.push_back(ngraph::builder::makeEltwise(eltwiseOps[eltwiseOps.size() - 1], ngraphInputs[i], eltwiseOpTypes[i])); + eltwiseOps.push_back(makeEltwise(eltwiseOps[eltwiseOps.size() - 1], inputNodes[i], eltwiseOpTypes[i])); } std::vector constShape(targetStaticShapes[0][0].size(), 1); @@ -118,19 +119,19 @@ class EltwiseChainTest : public testing::WithParamInterface, ::ngraph::element::Type(::ngraph::element::Type_t::f32), 256, constShape); - eltwiseOps.push_back(ngraph::builder::makeEltwise(fq, ngraphInputs[eltwiseOpTypes.size() - 1], eltwiseOpTypes[eltwiseOpTypes.size() - 1])); + eltwiseOps.push_back(makeEltwise(fq, inputNodes[eltwiseOpTypes.size() - 1], eltwiseOpTypes[eltwiseOpTypes.size() - 1])); - ngraph::ResultVector results{std::make_shared(eltwiseOps[eltwiseOps.size() - 1])}; - function = std::make_shared(results, ngraphParam, "eltwise_chain_fq"); + ov::ResultVector results{std::make_shared(eltwiseOps[eltwiseOps.size() - 1])}; + function = std::make_shared(results, paramVec, "eltwise_chain_fq"); } else { - std::vector> eltwiseOps; - eltwiseOps.push_back(ngraph::builder::makeEltwise(ngraphParam[0], ngraphInputs[0], eltwiseOpTypes[0])); + std::vector> eltwiseOps; + eltwiseOps.push_back(makeEltwise(paramVec[0], inputNodes[0], eltwiseOpTypes[0])); for (size_t i = 1; i < eltwiseOpTypes.size(); i++) { - eltwiseOps.push_back(ngraph::builder::makeEltwise(eltwiseOps[eltwiseOps.size() - 1], ngraphInputs[i], eltwiseOpTypes[i])); + eltwiseOps.push_back(makeEltwise(eltwiseOps[eltwiseOps.size() - 1], inputNodes[i], eltwiseOpTypes[i])); } - ngraph::ResultVector results{std::make_shared(eltwiseOps[eltwiseOps.size() - 1])}; - function = std::make_shared(results, ngraphParam, "eltwise_chain"); + ov::ResultVector results{std::make_shared(eltwiseOps[eltwiseOps.size() - 1])}; + function = std::make_shared(results, paramVec, "eltwise_chain"); } } }; @@ -141,7 +142,7 @@ TEST_P(EltwiseChainTest, CompareWithRefs) { namespace { -std::vector> inputShapes = { +std::vector> inputShapes = { {{1, 1, 2, 3}, {1, 1, 2, 3}, {1, 1, 2, 3}, {1, 1, 2, 3}}, {{1, 48, 5, 6}, {1, 48, 1, 1}, {1, 48, 5, 6}, {1, 1, 5, 6}}, {{1, 72, 28, 28}, {1, 72, 1, 1}, {1, 72, 1, 1}, {1, 72, 1, 1}}, @@ -166,14 +167,14 @@ std::vector> eltwiseOps = { INSTANTIATE_TEST_SUITE_P(smoke_EltwiseChain, EltwiseChainTest, ::testing::Combine( ::testing::ValuesIn(static_shapes_to_test_representation(inputShapes)), - ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT), + ::testing::Values(InputLayerType::CONSTANT), ::testing::ValuesIn(inputPrecisions), ::testing::ValuesIn(eltwiseOps), ::testing::Values(false), ::testing::Values(ov::test::utils::DEVICE_CPU)), EltwiseChainTest::getTestCaseName); -std::vector> inputShapesFQ = { +std::vector> inputShapesFQ = { {{1, 2, 2, 3}, {1, 2, 2, 3}, {1, 2, 2, 3}, {1, 2, 2, 3}}, {{2, 33, 5, 5}, {2, 33, 5, 5}, {2, 33, 1, 5}, {2, 33, 5, 5}}, {{2, 33, 5, 17}, {2, 33, 5, 17}, {2, 33, 5, 17}, {2, 33, 5, 17}}, @@ -197,7 +198,7 @@ std::vector> inputPrecisionsFQ { INSTANTIATE_TEST_SUITE_P(smoke_EltwiseChainWithFQ, EltwiseChainTest, ::testing::Combine( ::testing::ValuesIn(static_shapes_to_test_representation(inputShapesFQ)), - ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT), + ::testing::Values(InputLayerType::CONSTANT), ::testing::ValuesIn(inputPrecisionsFQ), ::testing::ValuesIn(eltwiseOps), ::testing::Values(true), @@ -455,12 +456,13 @@ std::vector> inputShapes_dyn = { INSTANTIATE_TEST_SUITE_P(smoke_EltwiseChain_dyn, EltwiseChainTest, ::testing::Combine( ::testing::ValuesIn(inputShapes_dyn), - ::testing::Values(ngraph::helpers::InputLayerType::PARAMETER), + ::testing::Values(InputLayerType::PARAMETER), ::testing::ValuesIn(inputPrecisions), ::testing::ValuesIn(eltwiseOps), ::testing::Values(false), ::testing::Values(ov::test::utils::DEVICE_CPU)), EltwiseChainTest::getTestCaseName); -} // namespace -} // namespace CPUSubgraphTestsDefinitions +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/rotary_pos_emb.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/rotary_pos_emb.cpp index 28ed4371c6262d..c9b367599ab5b7 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/rotary_pos_emb.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/rotary_pos_emb.cpp @@ -22,9 +22,11 @@ using namespace CPUTestUtils; using namespace ov::gen_pattern; -using namespace ov::test; using namespace ov; +namespace ov { +namespace test { + static ov::OutputVector makeCosSinCache(int max_position_embeddings, int rotary_ndims) { std::vector lut_sin(max_position_embeddings * rotary_ndims, 0.0f); std::vector lut_cos(max_position_embeddings * rotary_ndims, 0.0f); @@ -129,8 +131,6 @@ static std::shared_ptr buildROPE_Llama2(const int batch, return std::make_shared(ov::NodeVector{add_Add}, ov::ParameterVector{input, pos_id_end, pos_ids}); } -namespace CPULayerTestsDefinitions { - class RoPECPUTestLlama2 : public SubgraphBaseTest { public: ov::Tensor create_i32_tensor(const ov::Shape& shape, int start, int step = 1) { @@ -328,4 +328,5 @@ TEST_F(RoPECPUTestChatGLM, smoke_CompareWithRefs) { CheckNumberOfNodesWithType(compiledModel, "RoPE", 1); } -} // namespace CPULayerTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/seq_native_order.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/seq_native_order.cpp index 5c8d1d8e2ddcf2..5c20ec3a6440cd 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/seq_native_order.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/seq_native_order.cpp @@ -2,16 +2,19 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "common_test_utils/node_builders/gru_cell.hpp" +#include "common_test_utils/node_builders/lstm_cell.hpp" +#include "common_test_utils/node_builders/rnn_cell.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" -#include "ov_models/builders.hpp" #include "test_utils/cpu_test_utils.hpp" #include "transformations/op_conversions/bidirectional_sequences_decomposition.hpp" #include "transformations/op_conversions/convert_sequences_to_tensor_iterator.hpp" using namespace CPUTestUtils; -using namespace ov::test; +using namespace ov::test::utils; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { enum class SEQ_TYPE { GRU, @@ -34,7 +37,7 @@ using SeqParams = std::tuple; // 'sequence_lengths' input type + InputLayerType>; // 'sequence_lengths' input type class SequenceCPUTest : public testing::WithParamInterface, virtual public ov::test::SubgraphBaseTest, public CPUTestsBase { public: @@ -47,7 +50,7 @@ class SequenceCPUTest : public testing::WithParamInterface, virtual p bool linearBeforeReset; ov::op::RecurrentSequenceDirection direction; ElementType netPrecision; - ngraph::helpers::InputLayerType seqInType; + InputLayerType seqInType; std::tie(seqType, hidden_size, input_size, inShapeParams, activations, clip, linearBeforeReset, direction, netPrecision, seqInType) = obj.param; @@ -141,7 +144,7 @@ class SequenceCPUTest : public testing::WithParamInterface, virtual p weightShape.push_back(B_shape); ov::PartialShape seq_len_shape(std::vector{bounds[batch_size_pos]}); - if (seqInType == ngraph::helpers::InputLayerType::PARAMETER) { + if (seqInType == InputLayerType::PARAMETER) { inputDynamicShapes.push_back(seq_len_shape); } else { OPENVINO_ASSERT(seq_len_shape.is_static()); @@ -160,7 +163,7 @@ class SequenceCPUTest : public testing::WithParamInterface, virtual p if (seqType == SEQ_TYPE::LSTM) { currTS.emplace_back(std::vector{bs, numDirections, hidden_size}); } - if (seqInType == ngraph::helpers::InputLayerType::PARAMETER) { + if (seqInType == InputLayerType::PARAMETER) { currTS.emplace_back(std::vector{bs}); } targetStaticShapes.push_back(currTS); @@ -168,7 +171,7 @@ class SequenceCPUTest : public testing::WithParamInterface, virtual p // funciton creation std::vector types(inputDynamicShapes.size(), netPrecision); - if (seqInType == ngraph::helpers::InputLayerType::PARAMETER) { + if (seqInType == InputLayerType::PARAMETER) { types.back() = ElementType::i64; } ov::ParameterVector params; @@ -190,45 +193,45 @@ class SequenceCPUTest : public testing::WithParamInterface, virtual p std::shared_ptr seq_node; if (seqType == SEQ_TYPE::GRU) { - seq_node = ngraph::builder::makeGRU(inputs, - weightShape, - hidden_size, - activations, - {}, - {}, - clip, - linearBeforeReset, - true, - direction, - (seqInType == ngraph::helpers::InputLayerType::CONSTANT ? - ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST : - ngraph::helpers::SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM)); + seq_node = utils::make_gru( + inputs, + weightShape, + hidden_size, + activations, + {}, + {}, + clip, + linearBeforeReset, + true, + direction, + (seqInType == InputLayerType::CONSTANT ? SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST + : SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM)); } else if (seqType == SEQ_TYPE::LSTM) { - seq_node = ngraph::builder::makeLSTM(inputs, - weightShape, - hidden_size, - activations, - {}, - {}, - clip, - true, - direction, - (seqInType == ngraph::helpers::InputLayerType::CONSTANT ? - ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST : - ngraph::helpers::SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM)); + seq_node = utils::make_lstm( + inputs, + weightShape, + hidden_size, + activations, + {}, + {}, + clip, + true, + direction, + (seqInType == InputLayerType::CONSTANT ? SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST + : SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM)); } else if (seqType == SEQ_TYPE::RNN) { - seq_node = ngraph::builder::makeRNN(inputs, - weightShape, - hidden_size, - activations, - {}, - {}, - clip, - true, - direction, - (seqInType == ngraph::helpers::InputLayerType::CONSTANT ? - ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST : - ngraph::helpers::SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM)); + seq_node = utils::make_rnn( + inputs, + weightShape, + hidden_size, + activations, + {}, + {}, + clip, + true, + direction, + (seqInType == InputLayerType::CONSTANT ? SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_CONST + : SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM)); } else { OPENVINO_THROW("Unsupported seq type"); } @@ -254,7 +257,7 @@ class SequenceCPUTest : public testing::WithParamInterface, virtual p const size_t batchSize = targetInputStaticShapes[0][1]; const int64_t maxSeqLen = targetInputStaticShapes[0][0]; - if (seqInType == ngraph::helpers::InputLayerType::PARAMETER) { + if (seqInType == InputLayerType::PARAMETER) { const auto& funcInputs = function->inputs(); const auto& seqLenInput = inputs.find(funcInputs[seqLengthInIdx].get_node_shared_ptr()); if (seqLenInput == inputs.end()) @@ -266,7 +269,7 @@ class SequenceCPUTest : public testing::WithParamInterface, virtual p } private: - ngraph::helpers::InputLayerType seqInType; + InputLayerType seqInType; size_t seqLengthInIdx = 2; }; @@ -326,7 +329,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_dynamic_lstm_rnn, SequenceCPUTest ::testing::ValuesIn(linearBeforeReset), ::testing::ValuesIn(direction), ::testing::ValuesIn(netPrecisions), - ::testing::Values(ngraph::helpers::InputLayerType::PARAMETER)), + ::testing::Values(InputLayerType::PARAMETER)), SequenceCPUTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_dynamic_gru, SequenceCPUTest, @@ -339,7 +342,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_dynamic_gru, SequenceCPUTest, ::testing::ValuesIn(linearBeforeReset), ::testing::ValuesIn(direction), ::testing::ValuesIn(netPrecisions), - ::testing::Values(ngraph::helpers::InputLayerType::PARAMETER)), + ::testing::Values(InputLayerType::PARAMETER)), SequenceCPUTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_static_gru, SequenceCPUTest, @@ -352,7 +355,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_static_gru, SequenceCPUTest, ::testing::ValuesIn(linearBeforeReset), ::testing::ValuesIn(direction), ::testing::ValuesIn(netPrecisions), - ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT)), + ::testing::Values(InputLayerType::CONSTANT)), SequenceCPUTest::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_static_rnn_lstm, SequenceCPUTest, @@ -365,7 +368,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_static_rnn_lstm, SequenceCPUTest, ::testing::ValuesIn(linearBeforeReset), ::testing::ValuesIn(direction), ::testing::ValuesIn(netPrecisions), - ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT)), + ::testing::Values(InputLayerType::CONSTANT)), SequenceCPUTest::getTestCaseName); -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/static_zero_dims.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/static_zero_dims.cpp index 1072890e51774b..4d304f5d19002d 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/static_zero_dims.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/static_zero_dims.cpp @@ -2,14 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "shared_test_classes/base/ov_subgraph.hpp" +#include "common_test_utils/ov_tensor_utils.hpp" #include "ov_models/builders.hpp" -#include -#include "functional_test_utils/skip_tests_config.hpp" - -using namespace ov::test; +#include "shared_test_classes/base/ov_subgraph.hpp" -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { class StaticZeroDims : public SubgraphBaseTest { protected: @@ -20,26 +18,26 @@ class StaticZeroDims : public SubgraphBaseTest { init_input_shapes({inputShapes}); - auto ngPrc = ngraph::element::f32; + auto ngPrc = ov::element::f32; ov::ParameterVector inputParams; for (auto&& shape : inputDynamicShapes) { inputParams.push_back(std::make_shared(ngPrc, shape)); } - auto splitAxisOp = std::make_shared(ngraph::element::i64, ngraph::Shape{}, std::vector{0}); + auto splitAxisOp = std::make_shared(ov::element::i64, ov::Shape{}, std::vector{0}); std::vector splitLenght = {1, 0, 6}; - auto splitLengthsOp = std::make_shared(ngraph::element::i32, ngraph::Shape{splitLenght.size()}, splitLenght); - auto varSplit = std::make_shared(inputParams[0], splitAxisOp, splitLengthsOp); + auto splitLengthsOp = std::make_shared(ov::element::i32, ov::Shape{splitLenght.size()}, splitLenght); + auto varSplit = std::make_shared(inputParams[0], splitAxisOp, splitLengthsOp); - auto relu1 = std::make_shared(varSplit->output(0)); + auto relu1 = std::make_shared(varSplit->output(0)); auto numInRoi = ngraph::builder::makeConstant(ngPrc, {0}, std::vector{}, false); auto expDet = std::make_shared(varSplit->output(1), numInRoi, 10); - auto relu2 = std::make_shared(expDet); + auto relu2 = std::make_shared(expDet); - auto relu3 = std::make_shared(varSplit->output(2)); + auto relu3 = std::make_shared(varSplit->output(2)); - ngraph::NodeVector results{relu1, relu2, relu3}; - function = std::make_shared(results, inputParams, "StaticZeroDims"); + ov::NodeVector results{relu1, relu2, relu3}; + function = std::make_shared(results, inputParams, "StaticZeroDims"); } void compare(const std::vector &expected, const std::vector &actual) override { @@ -59,4 +57,5 @@ TEST_F(StaticZeroDims, smoke_CompareWithRefs) { run(); } -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov From bd315f4b6aa29f06cc4e2075130a417686b1eb19 Mon Sep 17 00:00:00 2001 From: River Li Date: Tue, 5 Dec 2023 22:42:47 +0800 Subject: [PATCH 17/20] [CPU Tests] migrate matmul test cases to be api 2.0 (#21332) * [CPU Tests] migrate matmul test cases to be api 2.0 * Update * Handle convert2OutputVector inplace --------- Co-authored-by: Vitaliy Urusovskij --- .../skip_tests_config.cpp | 15 +- .../src/matmul_decompress_convert.cpp | 313 +++++++++--------- .../src/matmul_quantized_subgraph.cpp | 53 +-- .../src/matmul_strided_inputs_outputs.cpp | 52 +-- .../src/matmul_weights_decompression.cpp | 57 ++-- .../functional/test_utils/cpu_test_utils.hpp | 6 +- 6 files changed, 244 insertions(+), 252 deletions(-) diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp index 3fcbe9ab2a1ffc..6348e1afccfd40 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp @@ -3,14 +3,11 @@ // #include "functional_test_utils/skip_tests_config.hpp" - -#include +#include "openvino/runtime/system_conf.hpp" #include #include -#include "ie_parallel.hpp" - std::vector disabledTestPatterns() { std::vector retVector{ // TODO: Issue 31841 @@ -314,7 +311,7 @@ std::vector disabledTestPatterns() { retVector.emplace_back(R"(.*LoadNetworkCompiledKernelsCacheTest.*CanCreateCacheDirAndDumpBinariesUnicodePath.*)"); #endif - if (!InferenceEngine::with_cpu_x86_avx512_core()) { + if (!ov::with_cpu_x86_avx512_core()) { // on platforms which do not support bfloat16, we are disabling bf16 tests since there are no bf16 primitives, // tests are useless on such platforms retVector.emplace_back(R"(.*(BF|bf)16.*)"); @@ -325,7 +322,7 @@ std::vector disabledTestPatterns() { retVector.emplace_back(R"(.*Snippets.*(MatMul|Matmul).*)"); } #if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) - if (!InferenceEngine::with_cpu_x86_avx512_core_fp16()) { + if (!ov::with_cpu_x86_avx512_core_fp16()) { // Skip fp16 tests for paltforms that don't support fp16 precision retVector.emplace_back(R"(.*INFERENCE_PRECISION_HINT=(F|f)16.*)"); } @@ -339,7 +336,7 @@ std::vector disabledTestPatterns() { R"(.*EltwiseLayerCPUTest.*IS=\(\[1\.\.10\.2\.5\.6\]_\).*eltwiseOpType=SqDiff.*_configItem=INFERENCE_PRECISION_HINT=f16.*)"); # endif // OV_CPU_ARM_ENABLE_FP16 #endif - if (!InferenceEngine::with_cpu_x86_avx512_core_vnni() && !InferenceEngine::with_cpu_x86_avx512_core_amx_int8()) { + if (!ov::with_cpu_x86_avx512_core_vnni() && !ov::with_cpu_x86_avx512_core_amx_int8()) { // MatMul in Snippets uses BRGEMM that supports i8 only on platforms with VNNI or AMX instructions retVector.emplace_back(R"(.*Snippets.*MatMulFQ.*)"); retVector.emplace_back(R"(.*Snippets.*MatMul.*Quantized.*)"); @@ -347,11 +344,11 @@ std::vector disabledTestPatterns() { retVector.emplace_back(R"(.*Snippets.*MHAINT8.*)"); retVector.emplace_back(R"(.*Snippets.*MHAQuant.*)"); } - if (!InferenceEngine::with_cpu_x86_avx512_core_amx_int8()) + if (!ov::with_cpu_x86_avx512_core_amx_int8()) // TODO: Issue 92895 // on platforms which do not support AMX, we are disabling I8 input tests retVector.emplace_back(R"(smoke_LPT/FakeQuantizeWithNotOptimalTransformation.CompareWithRefImpl.*CPU.*i8.*)"); - if (!InferenceEngine::with_cpu_x86_avx512_core_amx_bf16() && !InferenceEngine::with_cpu_x86_bfloat16()) { + if (!ov::with_cpu_x86_avx512_core_amx_bf16() && !ov::with_cpu_x86_bfloat16()) { // ignored for not supported bf16 platforms retVector.emplace_back(R"(.*smoke_Snippets_EnforcePrecision_bf16.*)"); retVector.emplace_back(R"(.*smoke_Snippets_MHAWOTransposeEnforceBF16.*)"); diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_decompress_convert.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_decompress_convert.cpp index b0edba98c1dbff..55197fa04e63ca 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_decompress_convert.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_decompress_convert.cpp @@ -2,17 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "test_utils/fusing_test_utils.hpp" #include "ov_models/builders.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" +#include "test_utils/fusing_test_utils.hpp" #include "transformations/rt_info/decompression.hpp" -using namespace ngraph; -using namespace InferenceEngine; using namespace CPUTestUtils; -using namespace ov::test; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { /* This test checks MatMul weights constant folding on CPU plugin side and cover two optimizations: 1. Decompressing Convert FP16 -> FP32 CF (FuseFCAndConvertOnWeights in cpu graph optimizer) @@ -82,22 +80,21 @@ namespace SubgraphTestsDefinitions { -------- */ -using MatMulDecompressConvertParams = std::tuple< - std::vector, // input shapes - std::pair, // transposeA, transposeB - ElementType, // weights precision - std::map, // additional config - CPUSpecificParams ->; +using MatMulDecompressConvertParams = std::tuple, // input shapes + std::pair, // transposeA, transposeB + ElementType, // weights precision + ov::AnyMap, // additional config + CPUSpecificParams>; class MatMulDecompressConvertTest : public testing::WithParamInterface, - virtual public SubgraphBaseTest, public CPUTestsBase { + virtual public SubgraphBaseTest, + public CPUTestsBase { public: static std::string getTestCaseName(testing::TestParamInfo obj) { std::vector inputShapes; std::pair transpose; ElementType weiElemType; - std::map additionalConfig; + ov::AnyMap additionalConfig; CPUSpecificParams cpuParams; std::tie(inputShapes, transpose, weiElemType, additionalConfig, cpuParams) = obj.param; @@ -124,7 +121,7 @@ class MatMulDecompressConvertTest : public testing::WithParamInterface() << ":"; } result << ")"; @@ -134,14 +131,14 @@ class MatMulDecompressConvertTest : public testing::WithParamInterface - void transposeShape(T& shape) { + template + void transpose_shape(T& shape) { OPENVINO_ASSERT(shape.size() > 1); std::swap(*(shape.end() - 1), *(shape.end() - 2)); } - void CheckFCWeightsPrecision(ElementType expectedWeiElemType) const { - auto getExecValue = [](const ov::Node::RTMap& rtInfo, const std::string ¶mName) -> std::string { + void check_fc_weights_precision(ElementType expectedWeiElemType) const { + auto getExecValue = [](const ov::Node::RTMap& rtInfo, const std::string& paramName) -> std::string { auto it = rtInfo.find(paramName); OPENVINO_ASSERT(rtInfo.end() != it); return it->second.as(); @@ -149,10 +146,11 @@ class MatMulDecompressConvertTest : public testing::WithParamInterfaceget_ops()) { + for (const auto& fcNode : execFunction->get_ops()) { if (getExecValue(fcNode->get_rt_info(), ExecGraphInfoSerialization::LAYER_TYPE) == "FullyConnected") { - const auto &constNode = fcNode->get_input_node_shared_ptr(1); - element::Type expectedType(getExecValue(constNode->get_rt_info(), ExecGraphInfoSerialization::OUTPUT_PRECISIONS)); + const auto& constNode = fcNode->get_input_node_shared_ptr(1); + ov::element::Type expectedType( + getExecValue(constNode->get_rt_info(), ov::exec_model_info::OUTPUT_PRECISIONS)); ASSERT_EQ(expectedType, expectedWeiElemType); } } @@ -164,7 +162,7 @@ class MatMulDecompressConvertTest : public testing::WithParamInterface inputShapes; std::pair transpose; ElementType weiConstElemType; - std::map additionalConfig; + ov::AnyMap additionalConfig; CPUSpecificParams cpuParams; std::tie(inputShapes, transpose, weiConstElemType, additionalConfig, cpuParams) = this->GetParam(); @@ -175,19 +173,21 @@ class MatMulDecompressConvertTest : public testing::WithParamInterfacesecond.as() == ov::element::bf16) { convertOutType = inType = outType = netType = ElementType::bf16; weiConstElemType = (weiConstElemType != ElementType::f32) ? weiConstElemType : ElementType::bf16; } else { @@ -209,9 +210,10 @@ class MatMulDecompressConvertTest : public testing::WithParamInterface(inType, inShapeA)}; - std::shared_ptr inputB = builder::makeConstant(weiConstElemType, inShapeB.get_shape(), {}, true); + std::shared_ptr inputB = + ngraph::builder::makeConstant(weiConstElemType, inShapeB.get_shape(), {}, true); if (weiConstElemType == ElementType::f16) { - inputB = std::make_shared(inputB, convertOutType); + inputB = std::make_shared(inputB, convertOutType); mark_as_decompression(inputB); } expectedWeiConstElemType = weiConstElemType; @@ -221,13 +223,13 @@ class MatMulDecompressConvertTest : public testing::WithParamInterface> transposeParams = { const std::vector> inputShapes2D = { static_shapes_to_test_representation({{2, 3}, {3, 4}}), - { - {{-1, -1}, {{2, 3}, {5, 3}}}, - {{3, 4}, {{3, 4}, {3, 4}}} - }, + {{{-1, -1}, {{2, 3}, {5, 3}}}, {{3, 4}, {{3, 4}, {3, 4}}}}, }; const std::vector> inputShapes3D = { static_shapes_to_test_representation({{2, 2, 3}, {3, 4}}), static_shapes_to_test_representation({{2, 3}, {1, 3, 4}}), static_shapes_to_test_representation({{1, 2, 3}, {1, 3, 4}}), - { - {{-1, -1, -1}, {{2, 2, 3}, {3, 5, 3}}}, - {{3, 4}, {{3, 4}, {3, 4}}} - }, - { - {{-1, -1}, {{2, 3}, {5, 3}}}, - {{1, 3, 4}, {{1, 3, 4}, {1, 3, 4}}} - }, - { - {{-1, -1, -1}, {{1, 2, 3}, {1, 5, 3}}}, - {{1, 3, 4}, {{1, 3, 4}, {1, 3, 4}}} - }, + {{{-1, -1, -1}, {{2, 2, 3}, {3, 5, 3}}}, {{3, 4}, {{3, 4}, {3, 4}}}}, + {{{-1, -1}, {{2, 3}, {5, 3}}}, {{1, 3, 4}, {{1, 3, 4}, {1, 3, 4}}}}, + {{{-1, -1, -1}, {{1, 2, 3}, {1, 5, 3}}}, {{1, 3, 4}, {{1, 3, 4}, {1, 3, 4}}}}, }; -std::map emptyConfig = {/* empty config */}; +ov::AnyMap emptyConfig = {/* empty config */}; -std::vector> filterAdditionalConfig_BF16() { - std::vector> additionalConfig; - if (with_cpu_x86_avx512_core()) { - additionalConfig.push_back({{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}); +std::vector filter_additional_config_bf16() { + std::vector additionalConfig; + if (ov::with_cpu_x86_avx512_core()) { + additionalConfig.push_back({{ov::hint::inference_precision(ov::element::bf16)}}); } return additionalConfig; } -std::vector filterSpecificParams(bool trySetMlas) { +std::vector filter_specific_params(bool trySetMlas) { std::vector specificParams; if (trySetMlas) { #ifdef OV_CPU_WITH_MLAS @@ -295,9 +285,9 @@ std::vector filterSpecificParams(bool trySetMlas) { } // try set onednn jit params if we can't or shouldn't use mlas if (specificParams.empty()) { - if (with_cpu_x86_avx512_core()) { + if (ov::with_cpu_x86_avx512_core()) { specificParams.push_back(CPUSpecificParams{{}, {}, {"brgemm_avx512"}, "brgemm_avx512"}); - } else if (with_cpu_x86_avx2()) { + } else if (ov::with_cpu_x86_avx2()) { specificParams.push_back(CPUSpecificParams{{}, {}, {"brgemm_avx2"}, "brgemm_avx2"}); } } @@ -305,84 +295,84 @@ std::vector filterSpecificParams(bool trySetMlas) { return specificParams; } -std::vector filterSpecificParams_BF16() { +std::vector filter_specific_params_bf16() { std::vector specificParams; specificParams.push_back(CPUSpecificParams{{}, {}, {"jit_gemm"}, "jit_gemm"}); return specificParams; } - -const auto testParams2D_FP32_smoke = ::testing::Combine( - ::testing::ValuesIn(inputShapes2D), - ::testing::ValuesIn(transposeParams), - ::testing::Values(ElementType::f32), - ::testing::Values(emptyConfig), - ::testing::ValuesIn(filterSpecificParams(true))); - -INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP32, MatMulDecompressConvertTest, testParams2D_FP32_smoke, - MatMulDecompressConvertTest::getTestCaseName); - - -const auto testParams2D_FP16_smoke = ::testing::Combine( - ::testing::ValuesIn(inputShapes2D), - ::testing::ValuesIn(transposeParams), - ::testing::Values(ElementType::f16), - ::testing::Values(emptyConfig), - ::testing::ValuesIn(filterSpecificParams(false))); - -INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP16, MatMulDecompressConvertTest, testParams2D_FP16_smoke, - MatMulDecompressConvertTest::getTestCaseName); - - -const auto testParams2D_BF16_smoke = ::testing::Combine( - ::testing::ValuesIn(inputShapes2D), - ::testing::ValuesIn(transposeParams), - ::testing::Values(ElementType::f32, ElementType::f16), - ::testing::ValuesIn(filterAdditionalConfig_BF16()), - ::testing::ValuesIn(filterSpecificParams_BF16())); - -INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_BF16, MatMulDecompressConvertTest, testParams2D_BF16_smoke, - MatMulDecompressConvertTest::getTestCaseName); - - -const auto testParams3D_FP32_smoke = ::testing::Combine( - ::testing::ValuesIn(inputShapes3D), - ::testing::ValuesIn(transposeParams), - ::testing::Values(ElementType::f32), - ::testing::Values(emptyConfig), - ::testing::ValuesIn(filterSpecificParams(true))); - -INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_FP32, MatMulDecompressConvertTest, testParams3D_FP32_smoke, - MatMulDecompressConvertTest::getTestCaseName); - - -const auto testParams3D_FP16_smoke = ::testing::Combine( - ::testing::ValuesIn(inputShapes3D), - ::testing::ValuesIn(transposeParams), - ::testing::Values(ElementType::f16), - ::testing::Values(emptyConfig), - ::testing::ValuesIn(filterSpecificParams(false))); - -INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_FP16, MatMulDecompressConvertTest, testParams3D_FP16_smoke, - MatMulDecompressConvertTest::getTestCaseName); - - -const auto testParams3D_BF16_smoke = ::testing::Combine( - ::testing::ValuesIn(inputShapes3D), - ::testing::ValuesIn(transposeParams), - ::testing::Values(ElementType::f32, ElementType::f16), - ::testing::ValuesIn(filterAdditionalConfig_BF16()), - ::testing::ValuesIn(filterSpecificParams_BF16())); - -INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_BF16, MatMulDecompressConvertTest, testParams3D_BF16_smoke, - MatMulDecompressConvertTest::getTestCaseName); - -} // namespace +const auto testParams2D_FP32_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes2D), + ::testing::ValuesIn(transposeParams), + ::testing::Values(ElementType::f32), + ::testing::Values(emptyConfig), + ::testing::ValuesIn(filter_specific_params(true))); + +INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP32, + MatMulDecompressConvertTest, + testParams2D_FP32_smoke, + MatMulDecompressConvertTest::getTestCaseName); + +const auto testParams2D_FP16_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes2D), + ::testing::ValuesIn(transposeParams), + ::testing::Values(ElementType::f16), + ::testing::Values(emptyConfig), + ::testing::ValuesIn(filter_specific_params(false))); + +INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP16, + MatMulDecompressConvertTest, + testParams2D_FP16_smoke, + MatMulDecompressConvertTest::getTestCaseName); + +const auto testParams2D_BF16_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes2D), + ::testing::ValuesIn(transposeParams), + ::testing::Values(ElementType::f32, ElementType::f16), + ::testing::ValuesIn(filter_additional_config_bf16()), + ::testing::ValuesIn(filter_specific_params_bf16())); + +INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_BF16, + MatMulDecompressConvertTest, + testParams2D_BF16_smoke, + MatMulDecompressConvertTest::getTestCaseName); + +const auto testParams3D_FP32_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes3D), + ::testing::ValuesIn(transposeParams), + ::testing::Values(ElementType::f32), + ::testing::Values(emptyConfig), + ::testing::ValuesIn(filter_specific_params(true))); + +INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_FP32, + MatMulDecompressConvertTest, + testParams3D_FP32_smoke, + MatMulDecompressConvertTest::getTestCaseName); + +const auto testParams3D_FP16_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes3D), + ::testing::ValuesIn(transposeParams), + ::testing::Values(ElementType::f16), + ::testing::Values(emptyConfig), + ::testing::ValuesIn(filter_specific_params(false))); + +INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_FP16, + MatMulDecompressConvertTest, + testParams3D_FP16_smoke, + MatMulDecompressConvertTest::getTestCaseName); + +const auto testParams3D_BF16_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes3D), + ::testing::ValuesIn(transposeParams), + ::testing::Values(ElementType::f32, ElementType::f16), + ::testing::ValuesIn(filter_additional_config_bf16()), + ::testing::ValuesIn(filter_specific_params_bf16())); + +INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_BF16, + MatMulDecompressConvertTest, + testParams3D_BF16_smoke, + MatMulDecompressConvertTest::getTestCaseName); + +} // namespace /* In case of Convert has 2 or more consumers there is a problem with memory allocation in CPU plug-in (see Edge::init() method). Maybe we can just remove the check (edgePtr->getParent()->isConstant() && !edgePtr->getChild()->isConstant()) and everything will be OK, But this solution should be additionally checked. For now, for these cases we will not be - doing CF on the CPU side and it should be done on the ngraph side. + doing CF on the CPU side and it should be done on the graph side. * Graph before: ------------ ------------ ------------ @@ -422,13 +412,11 @@ INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_BF16, MatMulDecompressConvertTest, testPara |Output| -------- */ -using MatMulDecompressConvertParams2 = std::tuple< - std::vector, // input shapes - std::pair, // transposeA, transposeB - ElementType, // weights precision - std::map, // additional config - CPUSpecificParams ->; +using MatMulDecompressConvertParams2 = std::tuple, // input shapes + std::pair, // transposeA, transposeB + ElementType, // weights precision + ov::AnyMap, // additional property + CPUSpecificParams>; class MatMulDecompressConvertTest2 : public MatMulDecompressConvertTest { protected: @@ -438,7 +426,7 @@ class MatMulDecompressConvertTest2 : public MatMulDecompressConvertTest { std::vector inputShapes; std::pair transpose; ElementType weiConstElemType; - std::map additionalConfig; + ov::AnyMap additionalConfig; CPUSpecificParams cpuParams; std::tie(inputShapes, transpose, weiConstElemType, additionalConfig, cpuParams) = this->GetParam(); @@ -450,23 +438,25 @@ class MatMulDecompressConvertTest2 : public MatMulDecompressConvertTest { bool transpB = transpose.second; fullyConnectedCount = 2; - if (transpA) transposeCount += 2; - if (!transpB) transposeCount++; + if (transpA) + transposeCount += 2; + if (!transpB) + transposeCount++; if (transpA) { - transposeShape(inputDynamicShapes[0]); + transpose_shape(inputDynamicShapes[0]); for (auto& shapes : targetStaticShapes) { - transposeShape(shapes[0]); + transpose_shape(shapes[0]); } - transposeShape(inputDynamicShapes[1]); + transpose_shape(inputDynamicShapes[1]); for (auto& shapes : targetStaticShapes) { - transposeShape(shapes[1]); + transpose_shape(shapes[1]); } } if (transpB) { - transposeShape(inputDynamicShapes[2]); + transpose_shape(inputDynamicShapes[2]); for (auto& shapes : targetStaticShapes) { - transposeShape(shapes[2]); + transpose_shape(shapes[2]); } } @@ -478,7 +468,8 @@ class MatMulDecompressConvertTest2 : public MatMulDecompressConvertTest { ElementType netType = ElementType::f32; ElementType convertOutType = ElementType::f32; - if (additionalConfig[PluginConfigParams::KEY_ENFORCE_BF16] == PluginConfigParams::YES) { + auto it = additionalConfig.find(ov::hint::inference_precision.name()); + if (it != additionalConfig.end() && it->second.as() == ov::element::bf16) { convertOutType = inType = outType = netType = ElementType::bf16; weiConstElemType = (weiConstElemType != ElementType::f32) ? weiConstElemType : ElementType::bf16; } else { @@ -492,12 +483,13 @@ class MatMulDecompressConvertTest2 : public MatMulDecompressConvertTest { for (auto&& shape : {inShapeFC0, inShapeFC1}) { params.push_back(std::make_shared(inType, shape)); } - std::shared_ptr inputWeights = builder::makeConstant(weiConstElemType, inShapeWeights.get_shape(), {}, true); + std::shared_ptr inputWeights = + ngraph::builder::makeConstant(weiConstElemType, inShapeWeights.get_shape(), {}, true); if (weiConstElemType == ElementType::f16) { - inputWeights = std::make_shared(inputWeights, convertOutType); + inputWeights = std::make_shared(inputWeights, convertOutType); mark_as_decompression(inputWeights); } - // In this test, convert must be folded on the ngraph side, so the constant with fp32 precision is expected + // In this test, convert must be folded on the graph side, so the constant with fp32 precision is expected expectedWeiConstElemType = ElementType::f32; auto matMul0 = std::make_shared(params[0], inputWeights, transpA, transpB); @@ -512,21 +504,24 @@ class MatMulDecompressConvertTest2 : public MatMulDecompressConvertTest { TEST_P(MatMulDecompressConvertTest2, CompareWithRefs) { SKIP_IF_CURRENT_TEST_IS_DISABLED(); run(); - CheckExecutionGraph(); + check_execution_graph(); } namespace { -const auto testParams2D_FP16_2_smoke = ::testing::Combine( - ::testing::Values(static_shapes_to_test_representation({{2, 3}, {2, 3}, {3, 4}})), - ::testing::Values(std::pair{false, true}), - ::testing::Values(ElementType::f16), - ::testing::Values(emptyConfig), - ::testing::ValuesIn(filterSpecificParams(true))); +const auto testParams2D_FP16_2_smoke = + ::testing::Combine(::testing::Values(static_shapes_to_test_representation({{2, 3}, {2, 3}, {3, 4}})), + ::testing::Values(std::pair{false, true}), + ::testing::Values(ElementType::f16), + ::testing::Values(emptyConfig), + ::testing::ValuesIn(filter_specific_params(true))); -INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP16_2, MatMulDecompressConvertTest2, testParams2D_FP16_2_smoke, - MatMulDecompressConvertTest2::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP16_2, + MatMulDecompressConvertTest2, + testParams2D_FP16_2_smoke, + MatMulDecompressConvertTest2::getTestCaseName); -} // namespace +} // namespace -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_quantized_subgraph.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_quantized_subgraph.cpp index 2a04bdf843a72a..c5e2a9ec08d903 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_quantized_subgraph.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_quantized_subgraph.cpp @@ -6,18 +6,18 @@ #include "test_utils/fusing_test_utils.hpp" #include "ov_models/builders.hpp" #include "common_test_utils/common_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include #include -using namespace ngraph; -using namespace InferenceEngine; using namespace CPUTestUtils; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { using ElementType = ov::element::Type_t; -using MatmulBrgemmInt8TestParams = std::tuplef32 // (u8/s8 + s8)->u8/s8 class MatmulBrgemmInt8Test : public testing::WithParamInterface, public CpuTestWithFusing, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public ov::test::SubgraphBaseStaticTest { public: static std::string getTestCaseName(testing::TestParamInfo obj) { - SizeVector supportedInputShapes; + ov::Shape supportedInputShapes; bool isFC; ElementType inType; ElementType outType; @@ -41,7 +41,7 @@ class MatmulBrgemmInt8Test : public testing::WithParamInterfaceGetParam(); std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; - const auto ngPrec = element::f32; + const auto ngPrec = ov::element::f32; ov::ParameterVector inputParams {std::make_shared(ngPrec, ov::Shape(inShapes))}; - std::shared_ptr fq1; - std::shared_ptr matMul; - std::shared_ptr nodeBeforeConv; + std::shared_ptr fq1; + std::shared_ptr matMul; + std::shared_ptr nodeBeforeConv; selectedType = makeSelectedTypeStr(selectedType, ElementType::i8); if (inType == ElementType::u8) fq1 = ngraph::builder::makeFakeQuantize(inputParams[0], ngPrec, 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f}); @@ -74,15 +74,15 @@ class MatmulBrgemmInt8Test : public testing::WithParamInterface{0.0f}, true); auto fq2 = ngraph::builder::makeFakeQuantize(weightsNode, ngPrec, 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); - auto fc = std::make_shared(fq1, fq2, false, false); + auto fc = std::make_shared(fq1, fq2, false, false); fc->get_rt_info() = getCPUInfo(); fc->set_friendly_name(nameMatmul); auto biasWeightsNode = ngraph::builder::makeConstant(ngPrec, {}, std::vector{0.0f}, true); - matMul = std::make_shared(fc, biasWeightsNode); + matMul = std::make_shared(fc, biasWeightsNode); } else { auto fq2 = ngraph::builder::makeFakeQuantize(inputParams[0], ngPrec, 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); matMul = std::make_shared(fq1, fq2, false, true); @@ -98,7 +98,7 @@ class MatmulBrgemmInt8Test : public testing::WithParamInterfacefq->matmul can cover x8*s8->x8 case auto filterWeightsShape = matMul->get_output_shape(0); - auto filterWeightsNode = ngraph::builder::makeConstant(element::f32, filterWeightsShape, std::vector{}, true); + auto filterWeightsNode = ngraph::builder::makeConstant(ov::element::f32, filterWeightsShape, std::vector{}, true); auto fq3 = ngraph::builder::makeFakeQuantize(filterWeightsNode, ngPrec, 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f}); // only matmul avx2 support s8*s8 input auto matMul2 = std::make_shared(nodeBeforeConv, fq3, false, false); @@ -106,7 +106,7 @@ class MatmulBrgemmInt8Test : public testing::WithParamInterface function, const std::string& nodeName) { + void check_node(std::shared_ptr function, const std::string& nodeName) { ASSERT_NE(nullptr, function); for (const auto &node : function->get_ops()) { const auto & rtInfo = node->get_rt_info(); @@ -127,18 +127,17 @@ class MatmulBrgemmInt8Test : public testing::WithParamInterface supportedInputShapes = { +const std::vector supportedInputShapes = { {16, 32}, {17, 15}, }; @@ -148,7 +147,8 @@ const std::vectormatmulSpecificFilterParams = { {{}, {}, {"jit_gemm"}, "jit_gemm"} }; -INSTANTIATE_TEST_SUITE_P(smoke_matmulBrgemmInt8, MatmulBrgemmInt8Test, +INSTANTIATE_TEST_SUITE_P(smoke_matmulBrgemmInt8, + MatmulBrgemmInt8Test, ::testing::Combine(::testing::ValuesIn(supportedInputShapes), ::testing::ValuesIn({true, false}), ::testing::ValuesIn({ElementType::u8, ElementType::i8}), @@ -156,6 +156,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_matmulBrgemmInt8, MatmulBrgemmInt8Test, ::testing::ValuesIn(matmulSpecificFilterParams)), MatmulBrgemmInt8Test::getTestCaseName); -} // namespace +} // namespace -} // namespace SubgraphTestsDefinitions +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_strided_inputs_outputs.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_strided_inputs_outputs.cpp index 4bf666a1600bd0..ced1ce82c8b7b6 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_strided_inputs_outputs.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/matmul_strided_inputs_outputs.cpp @@ -2,59 +2,62 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "test_utils/cpu_test_utils.hpp" #include "ov_models/builders.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "test_utils/cpu_test_utils.hpp" -using namespace ngraph; -using namespace InferenceEngine; using namespace CPUTestUtils; -namespace SubgraphTestsDefinitions { +namespace ov { +namespace test { -using MatmulStridedInputsOutputsTestParams = Precision; +using MatmulStridedInputsOutputsTestParams = ov::element::Type; class MatmulStridedInputsOutputsTest : public testing::WithParamInterface, public CPUTestsBase, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public SubgraphBaseStaticTest { public: static std::string getTestCaseName(testing::TestParamInfo obj) { - Precision netPrecision; + ov::element::Type netPrecision; netPrecision = obj.param; std::ostringstream result; - result << "netPRC=" << netPrecision.name() << "_"; + result << "netPRC=" << netPrecision.to_string() << "_"; return result.str(); } protected: void SetUp() override { - targetDevice = ov::test::utils::DEVICE_CPU; - Precision netPrecision; - netPrecision = this->GetParam(); - const auto ngPrec = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + targetDevice = utils::DEVICE_CPU; + const auto ngPrec = this->GetParam(); - SizeVector splitShape{1, 2, 1, 16}; + ov::Shape splitShape{1, 2, 1, 16}; ov::ParameterVector splitInputParams {std::make_shared(ngPrec, ov::Shape(splitShape))}; auto split_axis_op = std::make_shared(ov::element::Type_t::i64, ov::Shape{}, std::vector{1}); auto split = std::make_shared(splitInputParams[0], split_axis_op, 2); std::vector concatShapes{{1, 1, 8, 8}, {1, 1, 8, 8}}; - ov::ParameterVector concatInputParams {std::make_shared(ngPrec, concatShapes[0]), - std::make_shared(ngPrec, concatShapes[1])}; - const auto concatOutputNodes = helpers::convert2OutputVector(helpers::castOps2Nodes(concatInputParams)); + ov::ParameterVector concatInputParams{std::make_shared(ngPrec, concatShapes[0]), + std::make_shared(ngPrec, concatShapes[1])}; + ov::OutputVector concatOutputNodes; + for (auto&& node : concatInputParams) { + for (auto&& param : node->outputs()) + concatOutputNodes.push_back(param); + } + const auto concat = std::make_shared(concatOutputNodes, 2); const auto matMul1 = std::make_shared(split->output(0), concat, false, false); - SizeVector matmulShape{1, 1, 16, 8}; + ov::Shape matmulShape{1, 1, 16, 8}; ov::ParameterVector matmulInputParams {std::make_shared(ngPrec, ov::Shape(matmulShape))}; const auto matMul2 = std::make_shared(split->output(1), matmulInputParams[0], false, false); const auto concatMatMuls = std::make_shared(ov::NodeVector{matMul1, matMul2}, 2 /* 3rd axis */); - ngraph::ParameterVector inputParams = {splitInputParams[0], concatInputParams[0], concatInputParams[1], matmulInputParams[0]}; + ov::ParameterVector inputParams = {splitInputParams[0], concatInputParams[0], concatInputParams[1], matmulInputParams[0]}; function = makeNgraphFunction(ngPrec, inputParams, concatMatMuls, "MatmulStridedInputsOutputs"); } }; @@ -84,16 +87,17 @@ class MatmulStridedInputsOutputsTest : public testing::WithParamInterface, // additional config + ov::AnyMap, // additional config fusingSpecificParams, bool>; // should use decompression implementation @@ -73,7 +71,7 @@ class MatmulWeightsDecompression : public testing::WithParamInterface additional_config; + ov::AnyMap additional_config; fusingSpecificParams fusing_params; bool should_fuse; @@ -99,7 +97,7 @@ class MatmulWeightsDecompression : public testing::WithParamInterface() << ":"; } result << ")"; result << CpuTestWithFusing::getTestCaseName(fusing_params); @@ -145,7 +143,7 @@ class MatmulWeightsDecompression : public testing::WithParamInterface(weights_precision, transformed_weights_shape, {}, true, 7); weights->set_friendly_name("Compressed_weights"); - auto weights_convert = std::make_shared(weights, decompression_precision); + auto weights_convert = std::make_shared(weights, decompression_precision); std::shared_ptr mul_parent = weights_convert; auto output_channels = *weights_shape.rbegin(); @@ -166,7 +164,7 @@ class MatmulWeightsDecompression : public testing::WithParamInterface(weights_precision, scaleshift_const_shape, {}, true, 7); - std::shared_ptr shift_convert = std::make_shared(shift_const, decompression_precision); + std::shared_ptr shift_convert = std::make_shared(shift_const, decompression_precision); if (reshape_on_decompression_constant) { auto shift_reshape_const = ov::opset10::Constant::create(ov::element::i32, {scaleshift_target_shape.size()}, scaleshift_target_shape); auto shift_reshape = std::make_shared(shift_convert, shift_reshape_const, false); @@ -234,7 +232,7 @@ class MatmulWeightsDecompression : public testing::WithParamInterface additional_config; + ov::AnyMap additional_config; fusingSpecificParams fusing_params; bool should_fuse; @@ -252,7 +250,7 @@ class MatmulWeightsDecompression : public testing::WithParamInterface(test_param); @@ -290,19 +288,19 @@ class MatmulWeightsDecompression : public testing::WithParamInterface> filterAdditionalConfigBasic() { - std::vector> additional_config = {CPUTestUtils::cpuEmptyPluginConfig}; +std::vector filter_additional_config_basic() { + std::vector additional_config = {CPUTestUtils::empty_plugin_config}; return additional_config; } -std::vector> filterAdditionalConfigAMX() { - std::vector> additional_config = {}; - if (with_cpu_x86_avx512_core_amx()) - additional_config.push_back({{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}}); +std::vector filter_additional_config_amx() { + std::vector additional_config = {}; + if (ov::with_cpu_x86_avx512_core_amx()) + additional_config.push_back({{ov::hint::inference_precision(ov::element::bf16)}}); return additional_config; } @@ -331,11 +329,7 @@ const std::vector input_shapes_amx = { {{{}, {{11, 339, 577}}}, {577, 335}}, {{{}, {{1, 1, 256}}}, {256, 128}, 64ul}, }; -const std::vector fusing_params { - emptyFusingSpec, - fusingBias, - fusingFakeQuantizePerTensorRelu -}; +const std::vector fusing_params{emptyFusingSpec, fusingBias, fusingFakeQuantizePerTensorRelu}; INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_basic, MatmulWeightsDecompression, @@ -345,7 +339,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_basic, ::testing::Values(true), ::testing::Values(true), ::testing::Values(true), - ::testing::ValuesIn(filterAdditionalConfigBasic()), + ::testing::ValuesIn(filter_additional_config_basic()), ::testing::ValuesIn(fusing_params), ::testing::Values(true)), MatmulWeightsDecompression::getTestCaseName); @@ -358,7 +352,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_amx, ::testing::Values(true), ::testing::Values(true), ::testing::Values(true), - ::testing::ValuesIn(filterAdditionalConfigAMX()), + ::testing::ValuesIn(filter_additional_config_amx()), ::testing::ValuesIn(fusing_params), ::testing::Values(true)), MatmulWeightsDecompression::getTestCaseName); @@ -387,7 +381,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_basic, ::testing::ValuesIn(transpose_weights), ::testing::ValuesIn(add_decompression_sub), ::testing::ValuesIn(reshape_on_decompression), - ::testing::ValuesIn(filterAdditionalConfigBasic()), + ::testing::ValuesIn(filter_additional_config_basic()), ::testing::Values(emptyFusingSpec), ::testing::Values(true)), MatmulWeightsDecompression::getTestCaseName); @@ -400,9 +394,10 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_amx, ::testing::ValuesIn(transpose_weights), ::testing::ValuesIn(add_decompression_sub), ::testing::ValuesIn(reshape_on_decompression), - ::testing::ValuesIn(filterAdditionalConfigAMX()), + ::testing::ValuesIn(filter_additional_config_amx()), ::testing::Values(emptyFusingSpec), ::testing::Values(true)), MatmulWeightsDecompression::getTestCaseName); -} // namespace -} // namespace SubgraphTestsDefinitions +} // namespace +} // namespace test +} // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp b/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp index 99299059e28197..a17f0e13303aa4 100644 --- a/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp +++ b/src/plugins/intel_cpu/tests/functional/test_utils/cpu_test_utils.hpp @@ -155,9 +155,9 @@ class CPUTestsBase { * @param lastNode The last node of the initial graph. * @return The last node of the modified graph. */ - virtual std::shared_ptr modifyGraph(const ov::element::Type &ngPrc, - ov::ParameterVector ¶ms, - const std::shared_ptr &lastNode); + virtual std::shared_ptr modifyGraph(const ov::element::Type& ngPrc, + ov::ParameterVector& params, + const std::shared_ptr& lastNode); virtual bool primTypeCheck(std::string primType) const; From ea1ffbaf7f6eb9f343837ac7a6dc3e4774f4cd71 Mon Sep 17 00:00:00 2001 From: Fang Xu Date: Wed, 6 Dec 2023 02:52:15 +0800 Subject: [PATCH 18/20] [CPU] Output correct streams and threads number (#21421) --- src/plugins/intel_cpu/src/config.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/plugins/intel_cpu/src/config.cpp b/src/plugins/intel_cpu/src/config.cpp index df2304c50e8583..53b2779936b7b3 100644 --- a/src/plugins/intel_cpu/src/config.cpp +++ b/src/plugins/intel_cpu/src/config.cpp @@ -378,8 +378,6 @@ void Config::updateProperties() { _config.insert({ov::device::id.name(), device_id}); - _config.insert({ov::num_streams.name(), std::to_string(streamExecutorConfig._streams)}); - _config.insert({ov::inference_num_threads.name(), std::to_string(streamExecutorConfig._threads)}); _config.insert({ov::hint::performance_mode.name(), ov::util::to_string(hintPerfMode)}); _config.insert({ov::hint::num_requests.name(), std::to_string(hintNumRequests)}); From 052021648132eae40f2a9a4e3a87640424989501 Mon Sep 17 00:00:00 2001 From: Wanglei Shen Date: Wed, 6 Dec 2023 11:53:58 +0800 Subject: [PATCH 19/20] fix streams calculation issue for latency mode with big threads input (#21437) * fix streams calculation issue for latency mode with big threads input * update for typo * update for typo * add test cases * update for comments --- .../intel_cpu/src/cpu_streams_calculation.cpp | 113 ++++++------- .../streams_info/streams_info_table_test.cpp | 148 ++++++++++++++++-- 2 files changed, 185 insertions(+), 76 deletions(-) diff --git a/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp b/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp index 0d22db1546118e..ea8ba981dc1992 100644 --- a/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp +++ b/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp @@ -146,68 +146,62 @@ std::vector> get_streams_info_table(const int input_streams, } if (((input_streams_changed == false) && - (input_perf_hint == ov::util::to_string(ov::hint::PerformanceMode::LATENCY)) && - ((latencyThreadingMode == Config::LatencyThreadingMode::PER_PLATFORM) || (proc_type_table.size() == 1))) || + (input_perf_hint == ov::util::to_string(ov::hint::PerformanceMode::LATENCY))) || ((input_streams_changed == true) && (input_streams == 1))) { - n_streams = 1; - if ((proc_type_table.size() == 1) && (input_threads == 0) && (model_prefer_threads > 0)) { - stream_info[NUMBER_OF_STREAMS] = n_streams; - if ((model_prefer_threads == proc_type_table[0][MAIN_CORE_PROC]) && - (proc_type_table[0][MAIN_CORE_PROC] > 0)) { - stream_info[PROC_TYPE] = MAIN_CORE_PROC; - n_threads_per_stream = proc_type_table[0][MAIN_CORE_PROC] + proc_type_table[0][HYPER_THREADING_PROC]; - stream_info[THREADS_PER_STREAM] = n_threads_per_stream; - update_ids_method(proc_type_table[0]); - } else if (proc_type_table[0][MAIN_CORE_PROC] == 0) { - stream_info[PROC_TYPE] = EFFICIENT_CORE_PROC; - n_threads_per_stream = proc_type_table[0][EFFICIENT_CORE_PROC]; - stream_info[THREADS_PER_STREAM] = n_threads_per_stream; - update_ids_method(proc_type_table[0]); + if (input_threads > 0) { + n_streams = 1; + n_threads_per_stream = std::min(input_threads, proc_type_table[0][ALL_PROC]); + if (proc_type_table.size() == 1) { + if ((n_threads_per_stream > proc_type_table[0][MAIN_CORE_PROC]) && + (proc_type_table[0][MAIN_CORE_PROC] > 0)) { + stream_info[PROC_TYPE] = ALL_PROC; + } + } + } else if (((input_streams_changed == false) && + (latencyThreadingMode == Config::LatencyThreadingMode::PER_PLATFORM)) || + (proc_type_table.size() == 1) || ((input_streams_changed == true) && (input_streams == 1))) { + n_streams = 1; + if ((proc_type_table.size() == 1) && (model_prefer_threads > 0)) { + stream_info[NUMBER_OF_STREAMS] = n_streams; + if ((model_prefer_threads == proc_type_table[0][MAIN_CORE_PROC]) && + (proc_type_table[0][MAIN_CORE_PROC] > 0)) { + stream_info[PROC_TYPE] = MAIN_CORE_PROC; + n_threads_per_stream = + proc_type_table[0][MAIN_CORE_PROC] + proc_type_table[0][HYPER_THREADING_PROC]; + stream_info[THREADS_PER_STREAM] = n_threads_per_stream; + update_ids_method(proc_type_table[0]); + } else if (proc_type_table[0][MAIN_CORE_PROC] == 0) { + stream_info[PROC_TYPE] = EFFICIENT_CORE_PROC; + n_threads_per_stream = proc_type_table[0][EFFICIENT_CORE_PROC]; + stream_info[THREADS_PER_STREAM] = n_threads_per_stream; + update_ids_method(proc_type_table[0]); + } else { + stream_info[PROC_TYPE] = ALL_PROC; + n_threads_per_stream = proc_type_table[0][ALL_PROC]; + } } else { - stream_info[PROC_TYPE] = ALL_PROC; n_threads_per_stream = proc_type_table[0][ALL_PROC]; } - } else { - n_threads_per_stream = input_threads > 0 ? std::min(input_threads, proc_type_table[0][ALL_PROC]) - : proc_type_table[0][ALL_PROC]; - if ((proc_type_table.size() == 1) && (n_threads_per_stream > proc_type_table[0][MAIN_CORE_PROC]) && - (proc_type_table[0][MAIN_CORE_PROC] > 0)) { - stream_info[PROC_TYPE] = ALL_PROC; + } else if ((input_streams_changed == false) && + (latencyThreadingMode == Config::LatencyThreadingMode::PER_SOCKET)) { + for (auto& row : proc_socket_table) { + n_threads_per_stream = std::max(n_threads_per_stream, row[ALL_PROC]); } - } - } else if ((input_streams_changed == false) && - (input_perf_hint == ov::util::to_string(ov::hint::PerformanceMode::LATENCY)) && - (latencyThreadingMode == Config::LatencyThreadingMode::PER_SOCKET)) { - for (auto& row : proc_socket_table) { - n_threads_per_stream = std::max(n_threads_per_stream, row[ALL_PROC]); - } - n_threads_per_stream = input_threads > 0 ? std::min(input_threads, n_threads_per_stream) : n_threads_per_stream; - for (auto& row : proc_socket_table) { - if (n_threads_per_stream <= row[ALL_PROC]) { - n_streams++; + for (auto& row : proc_socket_table) { + if (n_threads_per_stream <= row[ALL_PROC]) { + n_streams++; + } } - } - n_streams = input_threads > 0 ? static_cast(input_threads / n_threads_per_stream) : n_streams; - n_streams = input_infer_requests > 0 ? std::min(input_infer_requests, n_streams) : n_streams; - } else if ((input_streams_changed == false) && - (input_perf_hint == ov::util::to_string(ov::hint::PerformanceMode::LATENCY)) && - (latencyThreadingMode == Config::LatencyThreadingMode::PER_NUMA_NODE)) { - if (proc_type_table.size() == 1) { - n_streams = 1; - n_threads_per_stream = input_threads > 0 ? std::min(input_threads, proc_type_table[0][ALL_PROC]) - : proc_type_table[0][ALL_PROC]; + n_streams = input_infer_requests > 0 ? std::min(input_infer_requests, n_streams) : n_streams; } else { for (size_t i = 1; i < proc_type_table.size(); i++) { n_threads_per_stream = std::max(n_threads_per_stream, proc_type_table[i][ALL_PROC]); } - n_threads_per_stream = - input_threads > 0 ? std::min(input_threads, n_threads_per_stream) : n_threads_per_stream; for (size_t i = 1; i < proc_type_table.size(); i++) { if (n_threads_per_stream <= proc_type_table[i][ALL_PROC]) { n_streams++; } } - n_streams = input_threads > 0 ? static_cast(input_threads / n_threads_per_stream) : n_streams; n_streams = input_infer_requests > 0 ? std::min(input_infer_requests, n_streams) : n_streams; } } else { @@ -305,35 +299,20 @@ std::vector> get_streams_info_table(const int input_streams, } } - if (total_streams == n_streams) { + if ((total_streams == n_streams) && (input_threads == 0)) { if (proc_type_table.size() == 1) { if (proc_type_table[0][ALL_PROC] >= stream_info[THREADS_PER_STREAM]) { update_mix_stream_info(proc_type_table[0], proc_type_table); n_streams--; } } else { - for (size_t n_node = 1; (n_node < proc_type_table.size()) && (n_streams > 0); n_node++) { - if (proc_type_table[n_node][ALL_PROC] >= stream_info[THREADS_PER_STREAM]) { - update_mix_stream_info(proc_type_table[n_node], proc_type_table); + for (size_t n_node = 0; (n_node < proc_socket_table.size()) && (n_streams > 0); n_node++) { + if (proc_socket_table[n_node][ALL_PROC] >= stream_info[THREADS_PER_STREAM]) { + update_mix_stream_info(proc_socket_table[n_node], proc_type_table); n_streams--; } } } - for (size_t n_node = 0; (n_node < proc_socket_table.size()) && (n_streams > 0); n_node++) { - if (proc_socket_table[n_node][ALL_PROC] >= stream_info[THREADS_PER_STREAM]) { - update_mix_stream_info(proc_socket_table[n_node], proc_type_table); - n_streams--; - } - } - } - - if (total_streams == n_streams) { - for (size_t n_node = 0; (n_node < proc_socket_table.size()) && (n_streams > 0); n_node++) { - if (proc_socket_table[n_node][ALL_PROC] >= stream_info[THREADS_PER_STREAM]) { - update_mix_stream_info(proc_socket_table[n_node], proc_type_table); - n_streams--; - } - } } if (total_streams == n_streams) { @@ -389,7 +368,7 @@ std::vector> get_streams_info_table(const int input_streams, } } else { if (stream_info[PROC_TYPE] == ALL_PROC) { - update_mix_stream_info(proc_socket_table[0], proc_type_table); + update_mix_stream_info(proc_type_table[0], proc_type_table); } else if (stream_info[PROC_TYPE] == MAIN_CORE_PROC) { if (stream_info[THREADS_PER_STREAM] == proc_socket_table[0][MAIN_CORE_PROC]) { streams_info_table.push_back(stream_info); diff --git a/src/plugins/intel_cpu/tests/unit/streams_info/streams_info_table_test.cpp b/src/plugins/intel_cpu/tests/unit/streams_info/streams_info_table_test.cpp index 61efd3ec2e1b10..3b68ef44d693fc 100644 --- a/src/plugins/intel_cpu/tests/unit/streams_info/streams_info_table_test.cpp +++ b/src/plugins/intel_cpu/tests/unit/streams_info/streams_info_table_test.cpp @@ -222,6 +222,43 @@ StreamsCalculationTestCase _2sockets_104cores_latency_socket_7 = { {0, MAIN_CORE_PROC, 26, 2, 1}, {0, MAIN_CORE_PROC, 26, 3, 1}}, }; +StreamsCalculationTestCase _2sockets_104cores_latency_socket_8 = { + 1, + false, + 208, + 0, + 0, + "LATENCY", + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{208, 104, 0, 104, -1, -1}, {104, 52, 0, 52, 0, 0}, {104, 52, 0, 52, 1, 1}}, + {{1, ALL_PROC, 208, -1, -1}, + {0, MAIN_CORE_PROC, 52, 0, 0}, + {0, MAIN_CORE_PROC, 52, 1, 1}, + {0, HYPER_THREADING_PROC, 52, 0, 0}, + {0, HYPER_THREADING_PROC, 52, 1, 1}}, +}; +StreamsCalculationTestCase _2sockets_104cores_latency_socket_9 = { + 1, + false, + 104, + 0, + 0, + "LATENCY", + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{208, 104, 0, 104, -1, -1}, {104, 52, 0, 52, 0, 0}, {104, 52, 0, 52, 1, 1}}, + {{1, ALL_PROC, 104, -1, -1}, {0, MAIN_CORE_PROC, 52, 0, 0}, {0, MAIN_CORE_PROC, 52, 1, 1}}, +}; +StreamsCalculationTestCase _2sockets_104cores_latency_socket_10 = { + 1, + false, + 52, + 0, + 0, + "LATENCY", + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{208, 104, 0, 104, -1, -1}, {104, 52, 0, 52, 0, 0}, {104, 52, 0, 52, 1, 1}}, + {{1, MAIN_CORE_PROC, 52, 0, 0}}, +}; StreamsCalculationTestCase _2sockets_104cores_latency_node_1 = { 1, false, @@ -262,17 +299,17 @@ StreamsCalculationTestCase _2sockets_104cores_latency_node_3 = { {52, 26, 0, 26, 1, 0}, {52, 26, 0, 26, 2, 1}, {52, 26, 0, 26, 3, 1}}, - {{1, ALL_PROC, 52, 0, 0}, + {{1, ALL_PROC, 52, -1, 0}, {0, MAIN_CORE_PROC, 26, 0, 0}, - {0, HYPER_THREADING_PROC, 26, 0, 0}, - {1, ALL_PROC, 52, 1, 0}, {0, MAIN_CORE_PROC, 26, 1, 0}, - {0, HYPER_THREADING_PROC, 26, 1, 0}, - {1, ALL_PROC, 52, 2, 1}, + {1, ALL_PROC, 52, -1, 1}, {0, MAIN_CORE_PROC, 26, 2, 1}, - {0, HYPER_THREADING_PROC, 26, 2, 1}, - {1, ALL_PROC, 52, 3, 1}, {0, MAIN_CORE_PROC, 26, 3, 1}, + {1, ALL_PROC, 52, -1, 0}, + {0, HYPER_THREADING_PROC, 26, 0, 0}, + {0, HYPER_THREADING_PROC, 26, 1, 0}, + {1, ALL_PROC, 52, -1, 1}, + {0, HYPER_THREADING_PROC, 26, 2, 1}, {0, HYPER_THREADING_PROC, 26, 3, 1}}, }; StreamsCalculationTestCase _2sockets_104cores_latency_node_4 = { @@ -304,6 +341,43 @@ StreamsCalculationTestCase _2sockets_104cores_latency_node_5 = { {0, MAIN_CORE_PROC, 26, 2, 1}, {0, MAIN_CORE_PROC, 26, 3, 1}}, }; +StreamsCalculationTestCase _2sockets_104cores_latency_node_6 = { + 1, + false, + 104, + 0, + 0, + "LATENCY", + ov::intel_cpu::Config::LatencyThreadingMode::PER_NUMA_NODE, + {{104, 104, 0, 0, -1, -1}, {26, 26, 0, 0, 0, 0}, {26, 26, 0, 0, 1, 0}, {26, 26, 0, 0, 2, 1}, {26, 26, 0, 0, 3, 1}}, + {{1, ALL_PROC, 104, -1, -1}, + {0, MAIN_CORE_PROC, 26, 0, 0}, + {0, MAIN_CORE_PROC, 26, 1, 0}, + {0, MAIN_CORE_PROC, 26, 2, 1}, + {0, MAIN_CORE_PROC, 26, 3, 1}}, +}; +StreamsCalculationTestCase _2sockets_104cores_latency_node_7 = { + 1, + false, + 52, + 0, + 0, + "LATENCY", + ov::intel_cpu::Config::LatencyThreadingMode::PER_NUMA_NODE, + {{104, 104, 0, 0, -1, -1}, {26, 26, 0, 0, 0, 0}, {26, 26, 0, 0, 1, 0}, {26, 26, 0, 0, 2, 1}, {26, 26, 0, 0, 3, 1}}, + {{1, ALL_PROC, 52, -1, -1}, {0, MAIN_CORE_PROC, 26, 0, 0}, {0, MAIN_CORE_PROC, 26, 1, 0}}, +}; +StreamsCalculationTestCase _2sockets_104cores_latency_node_8 = { + 1, + false, + 26, + 0, + 0, + "LATENCY", + ov::intel_cpu::Config::LatencyThreadingMode::PER_NUMA_NODE, + {{104, 104, 0, 0, -1, -1}, {26, 26, 0, 0, 0, 0}, {26, 26, 0, 0, 1, 0}, {26, 26, 0, 0, 2, 1}, {26, 26, 0, 0, 3, 1}}, + {{1, MAIN_CORE_PROC, 26, 0, 0}}, +}; StreamsCalculationTestCase _2sockets_104cores_latency_1 = { 1, false, @@ -705,7 +779,17 @@ StreamsCalculationTestCase _2sockets_48cores_latency_1 = { {{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}}, {{1, ALL_PROC, 48, -1, -1}, {0, MAIN_CORE_PROC, 24, 0, 0}, {0, MAIN_CORE_PROC, 24, 1, 1}}, }; - +StreamsCalculationTestCase _2sockets_48cores_latency_2 = { + 1, + false, + 96, + 0, + 0, + "LATENCY", + ov::intel_cpu::Config::LatencyThreadingMode::PER_SOCKET, + {{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}}, + {{1, ALL_PROC, 48, -1, -1}, {0, MAIN_CORE_PROC, 24, 0, 0}, {0, MAIN_CORE_PROC, 24, 1, 1}}, +}; StreamsCalculationTestCase _2sockets_48cores_tput_1 = { 1, false, @@ -754,6 +838,18 @@ StreamsCalculationTestCase _2sockets_48cores_tput_4 = { {{2, MAIN_CORE_PROC, 10, 0, 0}}, }; +StreamsCalculationTestCase _2sockets_20cores_tput_1 = { + 1, + false, + 0, + 0, + 0, + "THROUGHPUT", + ov::intel_cpu::Config::LatencyThreadingMode::PER_PLATFORM, + {{20, 20, 0, 0, -1, -1}, {10, 10, 0, 0, 0, 0}, {10, 10, 0, 0, 1, 1}}, + {{2, MAIN_CORE_PROC, 5, 0, 0}, {2, MAIN_CORE_PROC, 5, 1, 1}}, +}; + StreamsCalculationTestCase _1sockets_14cores_latency_1 = { 1, false, @@ -1747,6 +1843,30 @@ StreamsCalculationTestCase _1sockets_mock_tput_1 = { {{6, MAIN_CORE_PROC, 1, 0, 0}, {3, EFFICIENT_CORE_PROC, 2, 0, 0}, {3, HYPER_THREADING_PROC, 1, 0, 0}}, }; +StreamsCalculationTestCase _1sockets_mock_tput_2 = { + 1, + false, + 0, + 0, + 0, + "THROUGHPUT", + ov::intel_cpu::Config::LatencyThreadingMode::PER_PLATFORM, + {{27, 27, 0, 0, -1, -1}, {19, 19, 0, 0, 0, 0}, {8, 8, 0, 0, 1, 1}}, + {{4, MAIN_CORE_PROC, 4, 0, 0}, {2, MAIN_CORE_PROC, 4, 1, 1}}, +}; + +StreamsCalculationTestCase _1sockets_mock_tput_3 = { + 1, + false, + 0, + 0, + 0, + "THROUGHPUT", + ov::intel_cpu::Config::LatencyThreadingMode::PER_PLATFORM, + {{19, 19, 0, 0, -1, -1}, {11, 11, 0, 0, 0, 0}, {8, 8, 0, 0, 1, 1}}, + {{5, MAIN_CORE_PROC, 2, 0, 0}, {4, MAIN_CORE_PROC, 2, 1, 1}}, +}; + TEST_P(StreamsCalculationTests, StreamsCalculation) {} INSTANTIATE_TEST_SUITE_P(StreamsInfoTable, @@ -1762,11 +1882,17 @@ INSTANTIATE_TEST_SUITE_P(StreamsInfoTable, _2sockets_104cores_latency_socket_5, _2sockets_104cores_latency_socket_6, _2sockets_104cores_latency_socket_7, + _2sockets_104cores_latency_socket_8, + _2sockets_104cores_latency_socket_9, + _2sockets_104cores_latency_socket_10, _2sockets_104cores_latency_node_1, _2sockets_104cores_latency_node_2, _2sockets_104cores_latency_node_3, _2sockets_104cores_latency_node_4, _2sockets_104cores_latency_node_5, + _2sockets_104cores_latency_node_6, + _2sockets_104cores_latency_node_7, + _2sockets_104cores_latency_node_8, _2sockets_104cores_latency_1, _2sockets_104cores_latency_2, _2sockets_104cores_latency_3, @@ -1796,10 +1922,12 @@ INSTANTIATE_TEST_SUITE_P(StreamsInfoTable, _2sockets_104cores_tput_19, _2sockets_104cores_tput_20, _2sockets_48cores_latency_1, + _2sockets_48cores_latency_2, _2sockets_48cores_tput_1, _2sockets_48cores_tput_2, _2sockets_48cores_tput_3, _2sockets_48cores_tput_4, + _2sockets_20cores_tput_1, _1sockets_14cores_latency_1, _1sockets_14cores_latency_2, _1sockets_14cores_latency_3, @@ -1879,6 +2007,8 @@ INSTANTIATE_TEST_SUITE_P(StreamsInfoTable, _1sockets_ecores_tput_3, _1sockets_ecores_tput_4, _1sockets_ecores_tput_5, - _1sockets_mock_tput_1)); + _1sockets_mock_tput_1, + _1sockets_mock_tput_2, + _1sockets_mock_tput_3)); } // namespace \ No newline at end of file From d217847714587cd388b3910ee74be889ace410b0 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 6 Dec 2023 10:21:30 +0400 Subject: [PATCH 20/20] Allow to load extension by relative path in frontends, node factory (#21486) --- .../dev_api/openvino/core/so_extension.hpp | 14 ++++++++++++- src/inference/src/core.cpp | 20 ++----------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/core/dev_api/openvino/core/so_extension.hpp b/src/core/dev_api/openvino/core/so_extension.hpp index 98fb1e9f67a65a..cbba0d29c68d37 100644 --- a/src/core/dev_api/openvino/core/so_extension.hpp +++ b/src/core/dev_api/openvino/core/so_extension.hpp @@ -28,8 +28,20 @@ class OPENVINO_API SOExtension : public Extension { std::shared_ptr m_so; }; +inline std::string resolve_extension_path(const std::string& path) { + std::string retvalue; + try { + const std::string absolute_path = ov::util::get_absolute_file_path(path); + retvalue = ov::util::file_exists(absolute_path) ? absolute_path : path; + } catch (const std::runtime_error&) { + retvalue = path; + } + return retvalue; +} + inline std::vector load_extensions(const std::string& path) { - auto so = ov::util::load_shared_object(path.c_str()); + const std::string resolved_path = resolve_extension_path(path); + auto so = ov::util::load_shared_object(resolved_path.c_str()); using CreateFunction = void(std::vector&); std::vector extensions; reinterpret_cast(ov::util::get_symbol(so, "create_extensions"))(extensions); diff --git a/src/inference/src/core.cpp b/src/inference/src/core.cpp index fd05fbaec54a78..9ee07f6246afe5 100644 --- a/src/inference/src/core.cpp +++ b/src/inference/src/core.cpp @@ -13,20 +13,6 @@ #include "openvino/runtime/iremote_context.hpp" #include "openvino/util/file_util.hpp" -namespace { -std::string resolve_extension_path(const std::string& path) { - std::string retvalue; - try { - const std::string absolute_path = ov::util::get_absolute_file_path(path); - retvalue = ov::util::file_exists(absolute_path) ? absolute_path : path; - } catch (const std::runtime_error&) { - retvalue = path; - } - return retvalue; -} - -} // namespace - namespace ov { std::string find_plugins_xml(const std::string& xml_file) { @@ -166,8 +152,7 @@ void Core::add_extension(const InferenceEngine::IExtensionPtr& extension) { void Core::add_extension(const std::string& library_path) { try { - const std::string path = resolve_extension_path(library_path); - add_extension(ov::detail::load_extensions(path)); + add_extension(ov::detail::load_extensions(library_path)); } catch (const std::runtime_error&) { try { // Try to load legacy extension @@ -186,8 +171,7 @@ void Core::add_extension(const std::string& library_path) { #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT void Core::add_extension(const std::wstring& library_path) { try { - const std::string path = resolve_extension_path(ov::util::wstring_to_string(library_path)); - add_extension(ov::detail::load_extensions(ov::util::string_to_wstring(path))); + add_extension(ov::detail::load_extensions(library_path)); } catch (const std::runtime_error&) { try { // Try to load legacy extension