From 28a5bf7b0417653b46751838c8cc92e53b4daed0 Mon Sep 17 00:00:00 2001 From: Chenhu Wang Date: Fri, 25 Aug 2023 01:31:42 +0800 Subject: [PATCH] [CPU][Snippets] Dynamism via recompilation and cache (#15430) --- .../snippets/include/snippets/op/subgraph.hpp | 3 + .../snippets/include/snippets/pass/hash.hpp | 39 + src/common/snippets/src/op/subgraph.cpp | 49 +- .../snippets/src/pass/collapse_subgraph.cpp | 5 +- src/common/snippets/src/pass/hash.cpp | 411 ++++++++++ src/plugins/intel_cpu/src/nodes/subgraph.cpp | 721 ++++++++++-------- src/plugins/intel_cpu/src/nodes/subgraph.h | 133 ++-- .../src/shape_inference/custom/subgraph.hpp | 73 +- .../transformation_pipeline.cpp | 16 +- .../skip_tests_config.cpp | 2 +- .../shared_tests_instances/snippets/add.cpp | 86 ++- .../snippets/check_broadcast.cpp | 59 +- .../snippets/codegen_gelu.cpp | 43 +- .../snippets/convert.cpp | 46 +- .../snippets/eltwise_two_results.cpp | 17 +- .../snippets/max_num_params_eltwise.cpp | 17 +- .../precision_propagation_convertion.cpp | 7 +- .../snippets/select.cpp | 56 +- .../snippets/softmax.cpp | 70 +- .../snippets/three_inputs_eltwise.cpp | 18 +- .../snippets/two_inputs_and_outputs.cpp | 38 +- .../single_layer_tests/classes/eltwise.cpp | 20 +- .../single_layer_tests/classes/eltwise.hpp | 5 +- .../instances/common/eltwise.cpp | 36 +- .../instances/x64/eltwise.cpp | 72 +- .../functional/single_layer_tests/select.cpp | 2 +- .../subgraph_tests/src/conv_sum_broadcast.cpp | 6 + .../functional/subgraph_tests/src/ngram.cpp | 6 + .../plugin/shared/include/snippets/add.hpp | 24 +- .../include/snippets/check_broadcast.hpp | 2 +- .../shared/include/snippets/codegen_gelu.hpp | 17 +- .../shared/include/snippets/convert.hpp | 2 +- .../include/snippets/eltwise_two_results.hpp | 4 +- .../snippets/max_num_params_eltwise.hpp | 2 +- .../precision_propagation_convertion.hpp | 2 +- .../plugin/shared/include/snippets/select.hpp | 15 +- .../shared/include/snippets/softmax.hpp | 4 +- .../include/snippets/three_inputs_eltwise.hpp | 15 +- .../snippets/two_inputs_and_outputs.hpp | 2 +- .../plugin/shared/src/snippets/add.cpp | 94 ++- .../shared/src/snippets/check_broadcast.cpp | 25 +- .../shared/src/snippets/codegen_gelu.cpp | 57 +- .../plugin/shared/src/snippets/convert.cpp | 93 ++- .../src/snippets/eltwise_two_results.cpp | 26 +- .../src/snippets/max_num_params_eltwise.cpp | 27 +- .../precision_propagation_convertion.cpp | 22 +- .../plugin/shared/src/snippets/select.cpp | 69 +- .../plugin/shared/src/snippets/softmax.cpp | 34 +- .../src/snippets/three_inputs_eltwise.cpp | 31 +- .../src/snippets/two_inputs_and_outputs.cpp | 32 +- .../include/subgraph_simple.hpp | 13 +- .../src/subgraph_simple.cpp | 11 +- 52 files changed, 1932 insertions(+), 747 deletions(-) create mode 100644 src/common/snippets/include/snippets/pass/hash.hpp create mode 100644 src/common/snippets/src/pass/hash.cpp diff --git a/src/common/snippets/include/snippets/op/subgraph.hpp b/src/common/snippets/include/snippets/op/subgraph.hpp index 5c329502cb3..9e56e25fc46 100644 --- a/src/common/snippets/include/snippets/op/subgraph.hpp +++ b/src/common/snippets/include/snippets/op/subgraph.hpp @@ -116,6 +116,7 @@ public: const void* compile_params = nullptr); snippets::Schedule generate(const void* compile_params = nullptr); ov::PartialShape canonicalize(const BlockedShapeVector& output_shapes, const BlockedShapeVector& input_shapes); + ov::PartialShape canonicalized_body_shape_infer(const BlockedShapeVector& input_shapes); std::vector reshape_body(const std::vector& input_shapes); std::vector reshape_body(const std::vector& input_shapes); @@ -161,6 +162,8 @@ private: ov::PartialShape master_shape; size_t tileRank = 0; // set by plugin to specify the number of dimensions processed in a single kernel call + size_t maxInputRank = 0; + std::vector appendOnesForCanonical; /** * @interface SubgraphConfig diff --git a/src/common/snippets/include/snippets/pass/hash.hpp b/src/common/snippets/include/snippets/pass/hash.hpp new file mode 100644 index 00000000000..8d0689c7376 --- /dev/null +++ b/src/common/snippets/include/snippets/pass/hash.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "openvino/core/model.hpp" +#include + +namespace ov { +namespace snippets { +namespace pass { + +/** + * @brief Hash transformation calculates hash value for snippets. Don't care about names as no difference from execution perspective + */ +class Hash : public ov::pass::ModelPass { +public: + OPENVINO_RTTI("HashPass", "0"); + + bool run_on_model(const std::shared_ptr& f) override; + + /** + * @brief Hash pass constructor + * + * @param output_hash_value Reference to output value. By applying hash pass on function, resulting hash value + * will be set to this variable + */ + Hash(uint64_t& output_hash_value); + +private: + uint64_t& m_hash; +}; + +} // namespace pass +} // namespace snippets +} // namespace ov diff --git a/src/common/snippets/src/op/subgraph.cpp b/src/common/snippets/src/op/subgraph.cpp index a1eead792fc..a71ea3b9b82 100644 --- a/src/common/snippets/src/op/subgraph.cpp +++ b/src/common/snippets/src/op/subgraph.cpp @@ -325,7 +325,8 @@ ov::PartialShape snippets::op::Subgraph::canonicalize(const BlockedShapeVector& PartialShape baseShape; AxisVector baseOrder; std::tie(baseShape, baseOrder, std::ignore) = getMaxRankBlockedShape(inputShapes); - const auto baseRank = baseShape.size(); + maxInputRank = baseShape.size(); + appendOnesForCanonical.resize(inputShapes.size(), 0); const bool baseIsBlocked = baseOrder.size() != std::set(baseOrder.begin(), baseOrder.end()).size(); for (size_t i = 0; i < inputShapes.size(); i++) { const auto& blockedShape = inputShapes[i]; @@ -334,14 +335,16 @@ ov::PartialShape snippets::op::Subgraph::canonicalize(const BlockedShapeVector& element::Type inType; std::tie(inShape, inOrder, inType) = blockedShape; const auto inRank = inShape.size(); - NODE_VALIDATION_CHECK(this, inRank <= baseRank, "Input rank can't be larger than output rank in snippets."); - if (inRank < baseRank) { - PartialShape newShape(ov::Shape(baseRank, 1)); + NODE_VALIDATION_CHECK(this, inRank <= maxInputRank, "Input rank can't be larger than output rank in snippets."); + if (inRank < maxInputRank) { + appendOnesForCanonical[i] = maxInputRank - inRank; + PartialShape newShape(ov::Shape(maxInputRank, 1)); // todo: more complicated logics is needed if we want to merge smth else than blocked and planar if (baseIsBlocked) { const bool inIsNotBlocked = inOrder.size() == std::set(inOrder.begin(), inOrder.end()).size(); NODE_VALIDATION_CHECK(this, inIsNotBlocked, "Snippets don't support conversion between blocked layouts of different ranks"); inShape.insert(inShape.end(), ov::Dimension(1)); + appendOnesForCanonical[i]--; } NODE_VALIDATION_CHECK(this, PartialShape::broadcast_merge_into(newShape, inShape, ov::op::AutoBroadcastType::NUMPY), "Failed to broadcast_merge inputs in snippets canonicalization"); @@ -364,6 +367,7 @@ ov::PartialShape snippets::op::Subgraph::canonicalize(const BlockedShapeVector& body_ptr()->replace_parameter(i, std::make_shared(paramType, inShape)); } body_ptr()->validate_nodes_and_infer_types(); + auto skipStartEndOnes = [](const PartialShape& shape) { auto begin = shape.begin(); auto end = shape.end(); @@ -415,6 +419,43 @@ ov::PartialShape snippets::op::Subgraph::canonicalize(const BlockedShapeVector& return master_shape; } +ov::PartialShape snippets::op::Subgraph::canonicalized_body_shape_infer(const BlockedShapeVector& inputShapes) { + std::vector normInputShapes; + for (size_t i = 0; i < inputShapes.size(); i++) { + PartialShape inShape = std::get<0>(inputShapes[i]); + const auto inRank = inShape.size(); + if (inRank < maxInputRank) { + PartialShape newShape(ov::Shape(maxInputRank, 1)); + for (size_t ir = 0; ir < inRank; ir++) { + newShape[appendOnesForCanonical[i] + ir] = inShape[ir]; + } + normInputShapes.push_back(newShape.get_shape()); + } else { + normInputShapes.push_back(inShape.get_shape()); + } + } + reshape_body(normInputShapes); + + const auto& body_results = body_ptr()->get_results(); + PartialShape outPShape = body_results[0]->get_input_partial_shape(0); + const auto& result_parent = body_results[0]->get_input_node_shared_ptr(0); + if (body_results.size() == 1 && + ov::is_type(result_parent) && + ov::is_type(result_parent->get_input_node_shared_ptr(0))) { + outPShape = result_parent->get_input_partial_shape(0); + } else { + for (size_t i = 0; i < body_results.size(); i++) { + auto shape_i = body_results[i]->get_input_partial_shape(0); + bool compatibleWithOtherOutputs = PartialShape::broadcast_merge_into(outPShape, shape_i, + ::ov::op::AutoBroadcastType::NUMPY); + NODE_VALIDATION_CHECK(this, compatibleWithOtherOutputs, + "Snippets output shapes must be numpy broadcastable"); + } + } + master_shape = outPShape; + return master_shape; +} + bool snippets::op::Subgraph::check_broadcast(const std::shared_ptr& node) noexcept { const auto elementwise = std::dynamic_pointer_cast(node); return diff --git a/src/common/snippets/src/pass/collapse_subgraph.cpp b/src/common/snippets/src/pass/collapse_subgraph.cpp index 8c5f526929e..f14418f0f83 100644 --- a/src/common/snippets/src/pass/collapse_subgraph.cpp +++ b/src/common/snippets/src/pass/collapse_subgraph.cpp @@ -188,11 +188,10 @@ auto has_supported_in_out(const std::shared_ptr &n) -> bool { auto supported = [&n](descriptor::Tensor& t) -> bool { // Todo: int32 isn't supported in general because i32 emitters are required for bit-exact i32 calculations in some cases // So i32 is supported exclusively for transposes and broadcast - return t.get_partial_shape().is_static() && - (TokenizeSnippets::supported_element_types.count(t.get_element_type()) != 0 || + return TokenizeSnippets::supported_element_types.count(t.get_element_type()) != 0 || (t.get_element_type() == ov::element::i32 && (ov::is_type(n) || - ov::is_type(n)))); + ov::is_type(n))); }; const auto& inputs = n->inputs(); const auto& outputs = n->outputs(); diff --git a/src/common/snippets/src/pass/hash.cpp b/src/common/snippets/src/pass/hash.cpp new file mode 100644 index 00000000000..8d509b56886 --- /dev/null +++ b/src/common/snippets/src/pass/hash.cpp @@ -0,0 +1,411 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "snippets/pass/hash.hpp" + +#include +#include +#include +#include +#include + +#include "ngraph/ops.hpp" +#include "ngraph/opsets/opset.hpp" +#include "openvino/core/except.hpp" +#include "openvino/core/meta_data.hpp" +#include "openvino/core/model.hpp" +#include "openvino/op/util/framework_node.hpp" +#include "openvino/opsets/opset1.hpp" +#include "transformations/rt_info/primitives_priority_attribute.hpp" + +namespace ov { +namespace snippets { +namespace pass { + +OPENVINO_SUPPRESS_DEPRECATED_START +// helper +namespace { +template +std::string join(const Container& c, const char* glue = ", ") { + std::stringstream oss; + const char* s = ""; + for (const auto& v : c) { + oss << s << v; + s = glue; + } + return oss.str(); +} + +struct Edge { + int from_layer = 0; + int from_port = 0; + int to_layer = 0; + int to_port = 0; +}; + +enum class AttrType {layers, layer, id, type, data, rt_info, attribute, name, version, input, port, precision, dimension, output, value, + edges, edge, from_layer, from_port, to_layer, to_port, constant, size}; + +template ::value , int>::type = 0> +static uint64_t hash_combine(uint64_t seed, const T &v) { + // Hash combine formula from boost + return seed ^= std::hash {}(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +} + +template ::value , int>::type = 0> +static uint64_t hash_combine(uint64_t seed, const T &v) { + using underlying_t = typename std::underlying_type::type; + return hash_combine(seed, static_cast(v)); +} + +namespace rt_info { + +// some node attr is not type of ov::RuntimeAttribute, need dedicate visitor. +const std::vector list_of_names{ + "PrimitivesPriority", + "alt_width", +}; + +class NodeAuxRTInfoHasher { +public: + explicit NodeAuxRTInfoHasher(uint64_t& hash) : m_hash(hash) {} + + void serialize(const ov::Node::RTMap& rt_info) { + for (const auto& rt_info_name : list_of_names) { + const auto& found_rt_info = rt_info.find(rt_info_name); + if (found_rt_info != rt_info.end()) { + std::stringstream strm; + found_rt_info->second.print(strm); + m_hash = hash_combine(m_hash, rt_info_name); + m_hash = hash_combine(m_hash, strm.str()); + } + } + } + +private: + uint64_t& m_hash; +}; + +class RTInfoHasher : public ov::AttributeVisitor { + uint64_t& m_rt_hash; + +public: + RTInfoHasher(uint64_t& rt_hash) : m_rt_hash(rt_hash) {} + + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + if (auto a = ov::as_type>>(&adapter)) { + const auto& value = join(a->get()); + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), value); + } else { + OPENVINO_THROW("Unsupported attribute type for snippets hash generation: ", name); + } + } + + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), adapter.get()); + } + + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), adapter.get()); + } + + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), adapter.get()); + } + + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), adapter.get()); + } + + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + const auto& value = join(adapter.get()); + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), value); + } + + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + const auto& value = join(adapter.get()); + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), value); + } + + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + const auto& value = join(adapter.get()); + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), value); + } + + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + const auto& value = join(adapter.get()); + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), value); + } + + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + const auto& value = join(adapter.get()); + m_rt_hash = hash_combine(hash_combine(m_rt_hash, name), value); + } + + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + OPENVINO_THROW("Model type is unsupported for snippets rt info hash generation"); + } +}; + +} // namespace rt_info + +void ovfunction_2_hash(uint64_t& hash, const ov::Model& model); + +OPENVINO_SUPPRESS_DEPRECATED_START +class SnippetsHasher : public ov::AttributeVisitor { + uint64_t& m_hash; + const std::string& m_node_type_name; + + template + std::string create_attribute_list(ov::ValueAccessor>& adapter) { + return join(adapter.get()); + } + +public: + SnippetsHasher(uint64_t& hash, + const std::string& node_type_name) + : m_hash(hash), + m_node_type_name(node_type_name) {} + + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + if (const auto& a = ov::as_type>>(&adapter)) { + m_hash = hash_combine(hash_combine(m_hash, name), a->get()->get_info().variable_id); + } else if (const auto& a = + ov::as_type>>(&adapter)) { + if (name == "value" && m_node_type_name == "Constant") { + m_hash = hash_combine(m_hash, AttrType::constant); + const int64_t size = a->get()->size(); + m_hash = hash_combine(hash_combine(m_hash, AttrType::size), size); + auto data = static_cast(a->get()->get_ptr()); + for (int64_t i = 0; i < size; i++) { + m_hash = hash_combine(m_hash, data[i]); + } + } + } else if (const auto& a = ov::as_type>(&adapter)) { + const auto& attrs = a->get(); + // Update node attributes in data field + for (const auto& attr : attrs) { + m_hash = hash_combine(hash_combine(m_hash, attr.first), attr.second); + } + } else if (const auto& a = ov::as_type>(&adapter)) { + const auto& attrs = a->get(); + m_hash = hash_combine(hash_combine(m_hash, name), join(attrs)); + } else if (const auto& a = ov::as_type>(&adapter)) { + const auto& attrs = a->get(); + auto shape_str = attrs.to_string(); + m_hash = hash_combine(hash_combine(m_hash, name), shape_str); + } else if (const auto& a = ov::as_type>(&adapter)) { + const auto& attrs = a->get(); + std::stringstream dim_str_stream; + dim_str_stream << attrs; + auto dim_str = dim_str_stream.str(); + m_hash = hash_combine(hash_combine(m_hash, name), dim_str); + } else { + OPENVINO_THROW("Unsupported attribute type for snippets hash generation: ", name); + } + } + + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), adapter.get()); + } + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), adapter.get()); + } + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), static_cast(adapter.get())); + } + void on_adapter(const std::string& name, ov::ValueAccessor& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), adapter.get()); + } + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), create_attribute_list(adapter)); + } + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), create_attribute_list(adapter)); + } + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), create_attribute_list(adapter)); + } + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), create_attribute_list(adapter)); + } + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + m_hash = hash_combine(hash_combine(m_hash, name), create_attribute_list(adapter)); + } + void on_adapter(const std::string& name, ov::ValueAccessor>& adapter) override { + ovfunction_2_hash(m_hash, *adapter.get()); + } +}; +OPENVINO_SUPPRESS_DEPRECATED_END + +std::unordered_map create_layer_ids(const ov::Model& model) { + std::unordered_map layer_ids; + int id = 0; + for (const auto& node : model.get_ordered_ops()) { + layer_ids[node.get()] = id++; + } + return layer_ids; +} + +std::vector create_edge_mapping(const std::unordered_map& layer_ids, + const ov::Model& model) { + std::vector edges; + for (const auto& node : model.get_ordered_ops()) { + if (ov::op::util::is_parameter(node)) { + continue; + } + + for (const auto& i : node->inputs()) { + auto source_output = i.get_source_output(); + auto source_node = source_output.get_node(); + auto current_node = i.get_node(); + + if (layer_ids.find(source_node) == layer_ids.end() || layer_ids.find(current_node) == layer_ids.end()) { + OPENVINO_THROW("Failed creat edge map in snippets hash generation"); + } + + Edge e{}; + e.from_layer = layer_ids.find(source_node)->second; + e.from_port = static_cast(source_node->get_input_size() + source_output.get_index()); + e.to_layer = layer_ids.find(current_node)->second; + e.to_port = static_cast(i.get_index()); + edges.push_back(e); + } + } + std::sort(begin(edges), end(edges), [](const Edge& a, const Edge& b) -> bool { + return a.from_layer < b.from_layer; + }); + return edges; +} + +void hash_rt_info(uint64_t& hash, const std::string& name, const ov::Any& data) { + if (data.is>()) { + std::shared_ptr meta = data.as>(); + ov::AnyMap& map = *meta; + for (const auto& it : map) { + hash_rt_info(hash, it.first, it.second); + } + } else if (data.is()) { + const ov::AnyMap& any_map = data.as(); + for (const auto& it : any_map) { + hash_rt_info(hash, it.first, it.second); + } + } else { + std::string value = data.as(); + hash = hash_combine(hash_combine(hash, AttrType::value), value); + } +} + +void ovfunction_2_hash(uint64_t& hash, + const ov::Model& model) { + hash = hash_combine(hash, AttrType::layers); + + const std::unordered_map layer_ids = create_layer_ids(model); + std::unordered_set unique_names; + + auto sorted_ops = model.get_ordered_ops(); + + for (const auto& n : sorted_ops) { + ov::Node* node = n.get(); + const std::string& node_type_name{node->get_type_name()}; + + if (layer_ids.find(node) == layer_ids.end()) + OPENVINO_THROW("Failed to find layer's id in snippets hash generation."); + // + hash = hash_combine(hash, AttrType::layer); + hash = hash_combine(hash_combine(hash, AttrType::id), layer_ids.find(node)->second); + hash = hash_combine(hash_combine(hash, AttrType::type), node_type_name); + + // general attributes + hash = hash_combine(hash, AttrType::data); + auto append_runtime_info = [&](uint64_t& hash, ov::RTMap& attributes) { + hash = hash_combine(hash, AttrType::rt_info); + for (auto& item : attributes) { + if (item.second.is()) { + auto& rt_attribute = item.second.as(); + const auto& type_info = rt_attribute.get_type_info(); + if (!strcmp(type_info.name, "fused_names")) { + continue; + } + hash = hash_combine(hash, AttrType::attribute); + hash = hash_combine(hash_combine(hash, AttrType::name), type_info.name); + hash = hash_combine(hash_combine(hash, AttrType::version), type_info.get_version()); + + rt_info::RTInfoHasher rt_info_visitor(hash); + rt_attribute.visit_attributes(rt_info_visitor); + } + } + }; + + append_runtime_info(hash, node->get_rt_info()); + + int port_id = 0; + // + if (node->get_input_size() > 0) { + hash = hash_combine(hash, AttrType::input); + for (auto& i : node->inputs()) { + hash = hash_combine(hash, AttrType::port); + hash = hash_combine(hash_combine(hash, AttrType::id), port_id++); + hash = hash_combine(hash_combine(hash, AttrType::precision), i.get_element_type().hash()); + hash = hash_combine(hash_combine(hash, AttrType::dimension), i.get_partial_shape().to_string()); + append_runtime_info(hash, i.get_rt_info()); + } + } + // + if ((node->get_output_size() > 0) && !ov::op::util::is_output(node)) { + hash = hash_combine(hash, AttrType::output); + for (auto& o : node->outputs()) { + hash = hash_combine(hash, AttrType::port); + hash = hash_combine(hash_combine(hash, AttrType::id), port_id++); + hash = hash_combine(hash_combine(hash, AttrType::precision), o.get_element_type().hash()); + hash = hash_combine(hash_combine(hash, AttrType::dimension), o.get_partial_shape().to_string()); + append_runtime_info(hash, o.get_rt_info()); + } + } + + // fill general attributes + { + SnippetsHasher visitor(hash, node_type_name); + if (!node->visit_attributes(visitor)) { + OPENVINO_THROW("Visitor API is not supported in " + node_type_name + " in snippets hash generation"); + } + } + rt_info::NodeAuxRTInfoHasher{hash}.serialize(node->get_rt_info()); + } + // + const std::vector edge_mapping = create_edge_mapping(layer_ids, model); + hash = hash_combine(hash, AttrType::edges); + for (auto& e : edge_mapping) { + hash = hash_combine(hash, AttrType::edge); + hash = hash_combine(hash_combine(hash, AttrType::from_layer), e.from_layer); + hash = hash_combine(hash_combine(hash, AttrType::from_port), e.from_port); + hash = hash_combine(hash_combine(hash, AttrType::to_layer), e.to_layer); + hash = hash_combine(hash_combine(hash, AttrType::to_port), e.to_port); + } + + // Serialize rt info + hash = hash_combine(hash, AttrType::rt_info); + for (const auto& it : model.get_rt_info()) { + hash_rt_info(hash, it.first, it.second); + } +} + +} // namespace + +bool Hash::run_on_model(const std::shared_ptr& f) { + uint64_t seed = 0; + std::string name = "net"; + SnippetsHasher visitor(seed, name); + std::shared_ptr m(f); // for complilation error, on_attribute don't accept f + visitor.on_attribute(name, m); + m_hash = seed; + // Return false because we didn't change OpenVINO Model + return false; +} + +Hash::Hash(uint64_t& output_hash_value) : m_hash(output_hash_value) {} + +} // namespace pass +} // namespace snippets +} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.cpp b/src/plugins/intel_cpu/src/nodes/subgraph.cpp index ace2064e6b4..a7ee33dfda4 100644 --- a/src/plugins/intel_cpu/src/nodes/subgraph.cpp +++ b/src/plugins/intel_cpu/src/nodes/subgraph.cpp @@ -34,6 +34,8 @@ #include "transformations/cpu_opset/common/pass/convert_to_swish_cpu.hpp" #include "transformations/defs.hpp" #include "shape_inference/custom/subgraph.hpp" +#include +#include "snippets/pass/hash.hpp" using namespace InferenceEngine; using namespace dnnl::impl::utils; @@ -44,35 +46,138 @@ using namespace Xbyak; namespace ov { namespace intel_cpu { namespace node { +namespace { + +struct SnippetKey { + Snippet::SnippetAttrs attrs; + + size_t hash() const; + bool operator==(const SnippetKey& rhs) const; +}; + +size_t SnippetKey::hash() const { + using namespace dnnl::impl; + using namespace dnnl::impl::primitive_hashing; + + size_t seed = 0; + for (const auto& blockedDim : attrs.inMemBlockedDims) + seed = get_vector_hash(seed, blockedDim); + for (const auto& order : attrs.inMemOrders) + seed = get_vector_hash(seed, order); + for (const auto& prec : attrs.inMemPrecs) + seed = hash_combine(seed, prec.getPrecVal()); + + for (const auto& blockedDim : attrs.outMemBlockedDims) + seed = get_vector_hash(seed, blockedDim); + for (const auto& order : attrs.outMemOrders) + seed = get_vector_hash(seed, order); + for (const auto& prec : attrs.outMemPrecs) + seed = hash_combine(seed, prec.getPrecVal()); + + seed = hash_combine(seed, attrs.bodyHash); + + return seed; +} + +bool SnippetKey::operator==(const SnippetKey& rhs) const { + if (attrs.bodyHash != rhs.attrs.bodyHash) + return false; + if (attrs.inMemBlockedDims.size() != rhs.attrs.inMemBlockedDims.size() || + attrs.inMemOrders.size() != rhs.attrs.inMemOrders.size() || + attrs.inMemPrecs.size() != rhs.attrs.inMemPrecs.size()) + return false; + if (attrs.outMemBlockedDims.size() != rhs.attrs.outMemBlockedDims.size() || + attrs.outMemOrders.size() != rhs.attrs.outMemOrders.size() || + attrs.outMemPrecs.size() != rhs.attrs.outMemPrecs.size()) + return false; + + for (size_t i = 0; i < attrs.inMemBlockedDims.size(); i++) { + if (!(attrs.inMemBlockedDims[i] == rhs.attrs.inMemBlockedDims[i])) + return false; + } + for (size_t i = 0; i < attrs.outMemBlockedDims.size(); i++) { + if (!(attrs.outMemBlockedDims[i] == rhs.attrs.outMemBlockedDims[i])) + return false; + } + for (size_t i = 0; i < attrs.inMemOrders.size(); i++) { + if (!(attrs.inMemOrders[i] == rhs.attrs.inMemOrders[i])) + return false; + } + for (size_t i = 0; i < attrs.outMemOrders.size(); i++) { + if (!(attrs.outMemOrders[i] == rhs.attrs.outMemOrders[i])) + return false; + } + for (size_t i = 0; i < attrs.inMemPrecs.size(); i++) { + if (!(attrs.inMemPrecs[i] == rhs.attrs.inMemPrecs[i])) + return false; + } + for (size_t i = 0; i < attrs.outMemPrecs.size(); i++) { + if (!(attrs.outMemPrecs[i] == rhs.attrs.outMemPrecs[i])) + return false; + } + + return true; +} + +snippets::op::Subgraph::BlockedShapeVector getBlockedShapes(const std::vector>& memBlockedDims, + const std::vector>& memOrders, const std::vector& memPrecs) { + size_t numShapes = memBlockedDims.size(); + if (memOrders.size() != numShapes || memPrecs.size() != numShapes) + IE_THROW(Unexpected) << "Number of shapes is mismacthed for dimensions, orders and precisions"; + snippets::op::Subgraph::BlockedShapeVector blockedShapes(numShapes); + for (size_t i = 0; i < numShapes; i++) { + size_t dimSize = memBlockedDims[i].size(); + std::vector dims(dimSize); + for (size_t j = 0; j < dimSize; j++) { + dims[j] = memBlockedDims[i][j]; + } + ov::PartialShape shape(dims); + ov::AxisVector order(memOrders[i]); + ov::element::Type precision = InferenceEngine::details::convertPrecision(memPrecs[i]); + + blockedShapes[i] = snippets::op::Subgraph::BlockedShape{shape, order, precision}; + } + + return blockedShapes; +} +} // namespace Snippet::Snippet(const std::shared_ptr& op, const GraphContext::CPtr context) - : Node(op, context, SnippetShapeInferFactory(this)) { + : Node(op, context, SnippetShapeInferFactory(op)) { host_isa = dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core) ? dnnl::impl::cpu::x64::avx512_core : dnnl::impl::cpu::x64::avx2; original_snippet = ov::as_type_ptr(op); if (!original_snippet) { IE_THROW(NotImplemented) << "Node is not an instance of snippets::op::Subgraph"; } + init_body_hash(); + is_dynamic = isDynamicNgraphNode(op); } -void Snippet::copy_snippet() { +void Snippet::copy_snippet() const { ov::OutputVector subgraph_node_inputs; for (const auto &input : original_snippet->input_values()) { auto new_input = std::make_shared(input.get_element_type(), input.get_partial_shape()); subgraph_node_inputs.push_back(new_input); } std::shared_ptr new_body = original_snippet->body_ptr()->clone(); - snippet = std::make_shared(subgraph_node_inputs, new_body); - ov::copy_runtime_info(original_snippet, snippet); - snippet->set_friendly_name(original_snippet->get_friendly_name()); + snippetAttrs.snippet = std::make_shared(subgraph_node_inputs, new_body); + ov::copy_runtime_info(original_snippet, snippetAttrs.snippet); + snippetAttrs.snippet->set_friendly_name(original_snippet->get_friendly_name()); #if defined(OPENVINO_ARCH_X86_64) - snippet->set_generator(std::make_shared(host_isa)); - isa_num_lanes = snippet->get_generator()->get_target_machine()->get_lanes(); + snippetAttrs.snippet->set_generator(std::make_shared(host_isa)); #else IE_THROW(NotImplemented) << "CPU plugin: code-generation is not supported on non-x64 platforms"; #endif // OPENVINO_ARCH_X86_64 } +void Snippet::init_body_hash() { + uint64_t seed = 0; + ov::snippets::pass::Hash hash_function(seed); + hash_function.run_on_model(original_snippet->body_ptr()); + snippetAttrs.bodyHash = seed; +} + void Snippet::initSupportedPrimitiveDescriptors() { copy_snippet(); if (!supportedPrimitiveDescriptors.empty()) @@ -90,12 +195,12 @@ void Snippet::initSupportedPrimitiveDescriptors() { const size_t ndims = outputShapes[0].getRank(); // Domain sensitive operations support only Planar layout - const bool isOnlyPlanarApplicable = snippet->has_domain_sensitive_ops(); + const bool isOnlyPlanarApplicable = snippetAttrs.snippet->has_domain_sensitive_ops(); const bool isChannelsFirstApplicable = dnnl::impl::utils::one_of(ndims, 1u, 2u, 3u, 4u, 5u) && dimRanksAreEqual && !isOnlyPlanarApplicable; // Todo: Snippets currently don't support per-channel broadcasting of Blocked descriptors because // canonicalization can't distinguish between and cases. // See snippets::op::Subgraph::canonicalize for details. - bool isBlockedApplicable = dnnl::impl::utils::one_of(ndims, 4u, 5u) && dimRanksAreEqual && !isOnlyPlanarApplicable; + bool isBlockedApplicable = dnnl::impl::utils::one_of(ndims, 3u, 4u, 5u) && dimRanksAreEqual && !isOnlyPlanarApplicable; for (const auto& inShape : inputShapes) { if (isDynamic && inShape.getRank() != 1) @@ -153,7 +258,7 @@ void Snippet::initSupportedPrimitiveDescriptors() { const auto originalInputPrecision = getOriginalInputPrecisionAtPort(i); const auto precision = ((originalInputPrecision == InferenceEngine::Precision::FP32) && context->getConfig().inferencePrecision == ov::element::bf16 && - snippet->has_domain_sensitive_ops()) ? + snippetAttrs.snippet->has_domain_sensitive_ops()) ? static_cast(InferenceEngine::Precision::BF16) : originalInputPrecision; if (supportedPrecisions.count(precision) == 0) @@ -208,6 +313,33 @@ void Snippet::initSupportedPrimitiveDescriptors() { void Snippet::selectOptimalPrimitiveDescriptor() { selectPreferPrimitiveDescriptor(getImplPriority(), true); } + +void Snippet::initOptimalPrimitiveDescriptor() { + Node::initOptimalPrimitiveDescriptor(); + // memory order and precision is determined now, there is no need to prepare for each dynamic shapes. + const auto config = getSelectedPrimitiveDescriptor()->getConfig(); + inputNum = config.inConfs.size(); + snippetAttrs.inMemPrecs.resize(inputNum); + snippetAttrs.inMemOrders.resize(inputNum); + for (size_t i = 0; i < inputNum; i++) { + const auto& memDesc = config.inConfs[i].getMemDesc(); + snippetAttrs.inMemPrecs[i] = memDesc->getPrecision(); + snippetAttrs.inMemOrders[i] = memDesc->as()->getOrder(); + } + outputNum = config.outConfs.size(); + snippetAttrs.outMemPrecs.resize(outputNum); + snippetAttrs.outMemOrders.resize(outputNum); + for (size_t i = 0; i < outputNum; i++) { + snippetAttrs.outMemPrecs[i] = config.outConfs[i].getMemDesc()->getPrecision(); + snippetAttrs.outMemOrders[i] = config.outConfs[i].getMemDesc()->as()->getOrder(); + } + // reserve fixed size. + snippetAttrs.inMemBlockedDims.resize(inputNum); + snippetAttrs.outMemBlockedDims.resize(outputNum); + srcMemPtrs.resize(inputNum); + dstMemPtrs.resize(outputNum); +} + InferenceEngine::Precision Snippet::getRuntimePrecision() const { std::vector inputPrecisions; for (size_t i = 0; i < getParentEdges().size(); i++) { @@ -220,7 +352,280 @@ InferenceEngine::Precision Snippet::getRuntimePrecision() const { return getMaxPrecision(inputPrecisions); } -bool Snippet::optimizeExecDomain(std::vector& inputShapes, std::vector& outputShapes, +void Snippet::prepareParams() { + for (size_t i = 0; i < inputNum; i++) + snippetAttrs.inMemBlockedDims[i] = getParentEdgesAtPort(i)[0]->getMemory().getDescWithType()->getBlockDims(); + for (size_t i = 0; i < outputNum; i++) + snippetAttrs.outMemBlockedDims[i] = getChildEdgesAtPort(i)[0]->getMemory().getDescWithType()->getBlockDims(); + + SnippetKey key = {snippetAttrs}; + + auto builder = [this](const SnippetKey& key) -> std::shared_ptr { + std::shared_ptr executor = std::make_shared(key.attrs, is_canonicalized, + is_dynamic, context->getConfig().inferencePrecision == ov::element::bf16); + is_canonicalized = true; + return executor; + }; + + auto cache = context->getParamsCache(); + auto result = cache->getOrCreate(key, builder); + execPtr = result.first; + if (!execPtr) { + IE_THROW() << "Executor is not created for node " << getName() << "."; + } +} + +bool Snippet::needPrepareParams() const { + auto jit_executor = dynamic_cast(execPtr.get()); + return inputShapesModified() || (jit_executor && !jit_executor->schedule_created()); +} + +bool Snippet::canBeInPlace() const { + if (isDynamic || getParentEdgesAtPort(0)[0]->getParent()->getType() == Type::Input) { + return false; + } + if (getChildEdges().size() != 1) { + return false; + } + + for (auto& parentEdge : getParentEdges()) { + auto parent = parentEdge.lock()->getParent(); + if (parent->getChildEdges().size() != 1) + return false; + + // WA to prevent memory corruption caused by inplace feature + if (parent->getType() == Type::Concatenation) { + for (auto& parentParentEdge : parent->getParentEdges()) { + auto parentParent = parentParentEdge.lock()->getParent(); + if (parentParent->getChildEdges().size() != 1) + return false; + } + } + } + return getInputShapeAtPort(0) == getOutputShapeAtPort(0); +} + +bool Snippet::created() const { + return getType() == Type::Subgraph; +} + +void Snippet::execute(dnnl::stream strm) { + if (!execPtr) { + IE_THROW() << "Can't execute Subgraph node. Primitive didn't created"; + } + for (size_t i = 0; i < inputNum; i++) + srcMemPtrs[i] = getParentEdgeAt(i)->getMemoryPtr(); + for (size_t i = 0; i < outputNum; i++) + dstMemPtrs[i] = getChildEdgeAt(i)->getMemoryPtr(); + + execPtr->exec(srcMemPtrs, dstMemPtrs); +} + +void Snippet::executeDynamicImpl(dnnl::stream strm) { + execute(strm); +} + +void Snippet::SnippetJitExecutor::exec(const std::vector& inMemPtrs, const std::vector& outMemPtrs) { + if (schedule.ptr == nullptr) { + IE_THROW() << "Snippet can't use Optimized implementation and can't fallback to reference"; + } + auto initStartMemoryOffsets = [this, &inMemPtrs, &outMemPtrs]() { + for (size_t i = 0; i < numInput; i++) { + start_offset_in[i] = inMemPtrs[i]->getDescWithType()->getOffsetPadding() * dataSize[i]; + } + for (size_t i = 0; i < numOutput; i++) { + start_offset_out[i] = outMemPtrs[i]->getDescWithType()->getOffsetPadding() * dataSize[i + numInput]; + } + }; + // initialize start offsets to src and dst memory + // Needs to be done for every set of infer, as data memory ptrs could've updated + initStartMemoryOffsets(); + + if (tensorRank == rank6D) { + schedule_6d(inMemPtrs, outMemPtrs); + } else { + schedule_nt(inMemPtrs, outMemPtrs); + } +} + +void Snippet::SnippetJitExecutor::update_ptrs(jit_snippets_call_args& call_args, + const std::vector& inMemPtrs, const std::vector& outMemPtrs) { + for (size_t i = 0; i < inMemPtrs.size(); i++) + call_args.src_ptrs[i] = reinterpret_cast(inMemPtrs[i]->getData()) + start_offset_in[i]; + + for (size_t i = 0; i < outMemPtrs.size(); i++) + call_args.dst_ptrs[i] = reinterpret_cast(outMemPtrs[i]->getData()) + start_offset_out[i]; + + if (buffer_scratchpad_size > 0) { + call_args.buffer_scratchpad_ptr = + reinterpret_cast(buffer_scratchpad.data()) + parallel_get_thread_num() * buffer_scratchpad_size; + } +} + +void Snippet::SnippetJitExecutor::schedule_6d(const std::vector& inMemPtrs, const std::vector& outMemPtrs) { + const auto& dom = exec_domain; + // < N, C, H, W > < 1, 1, N, C*H*W> + parallel_for5d(dom[0], dom[1], dom[2], dom[3], dom[4], + [&](int64_t d0, int64_t d1, int64_t d2, int64_t d3, int64_t d4) { + int64_t indexes[] = {d0, d1, d2, d3, d4}; + jit_snippets_call_args call_args; + update_ptrs(call_args, inMemPtrs, outMemPtrs); + + schedule.get_callable()(indexes, &call_args); + }); +} + +void Snippet::SnippetJitExecutor::schedule_nt(const std::vector& inMemPtrs, const std::vector& outMemPtrs) { + const auto& work_size = exec_domain; + parallel_nt(0, [&](const int ithr, const int nthr) { + jit_snippets_call_args call_args; + update_ptrs(call_args, inMemPtrs, outMemPtrs); + + size_t start = 0, end = 0; + splitter(harnessWorkAmount, nthr, ithr, start, end); + + std::vector indexes(work_size.size() - 1, 0); + for (size_t iwork = start; iwork < end; ++iwork) { + size_t tmp = iwork; + for (ptrdiff_t j = work_size.size() - 2; j >= 0; j--) { + indexes[j] = tmp % work_size[j]; + tmp /= work_size[j]; + } + + schedule.get_callable()(indexes.data(), &call_args); + } + }); +} + +Snippet::SnippetExecutor::SnippetExecutor(const SnippetAttrs& attrs, bool is_canonicalized, bool is_dynamic, bool enforceBF16) + : snippetAttrs(attrs), is_canonicalized(is_canonicalized), is_dynamic(is_dynamic), enforceBF16(enforceBF16) {} + +Snippet::SnippetJitExecutor::SnippetJitExecutor(const SnippetAttrs& attrs, bool is_canonicalized, bool is_dynamic, bool enforceBF16) : + SnippetExecutor(attrs, is_canonicalized, is_dynamic, enforceBF16) { + numInput = snippetAttrs.inMemBlockedDims.size(); + numOutput = snippetAttrs.outMemBlockedDims.size(); + start_offset_in.resize(numInput); + start_offset_out.resize(numOutput); + auto local_copy = [this]() { + ov::OutputVector subgraph_node_inputs; + for (size_t i = 0; i < numInput; i++) { + const auto paramShape = snippetAttrs.snippet->body_ptr()->get_parameters()[i]->get_shape(); + const auto paramType = snippetAttrs.snippet->body_ptr()->get_parameters()[i]->get_element_type(); + auto new_input = std::make_shared(paramType, paramShape); + subgraph_node_inputs.push_back(new_input); + } + std::shared_ptr new_body = snippetAttrs.snippet->body_ptr()->clone(); + + snippet_for_generation = std::make_shared(subgraph_node_inputs, new_body); + ov::copy_runtime_info(snippetAttrs.snippet, snippet_for_generation); + snippet_for_generation->set_friendly_name(snippetAttrs.snippet->get_friendly_name()); + auto host_isa = dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core) ? + dnnl::impl::cpu::x64::avx512_core : dnnl::impl::cpu::x64::avx2; + snippet_for_generation->set_generator(std::make_shared(host_isa)); + }; + + // is_canonicalized is ture means just reshape canonicalized graph with new input shapes, and get updated master shape, + // false means canonicalization, determine master_shape on snippetAttrs.snippet. + ov::PartialShape canonicalShape = canonicalizeBody(is_canonicalized); + + if (is_dynamic) { + // we need a local snippets for generation, which will be adjusted based on input shapes possibily. + // The adjustment may be not compatible with new input shape in dynamic node, such as broadcastMove inserted. + local_copy(); + } else { + snippet_for_generation = snippetAttrs.snippet; + } + + // initialize by maximum output dimension. Dimensions of outputs should be broadcastable + tensorRank = std::max(static_cast(rank6D), canonicalShape.size()); + auto initDataSizes = [this]() { + dataSize.resize(numInput + numOutput); + for (size_t i = 0; i < numInput; i++) + dataSize[i] = snippetAttrs.inMemPrecs[i].size(); + for (size_t i = 0; i < numOutput; i++) + dataSize[i + numInput] = snippetAttrs.outMemPrecs[i].size(); + }; + initDataSizes(); + + if (canonicalShape.is_dynamic()) + IE_THROW() << "Snippets: Canonicalization returned dynamic shape in static pipeline"; + masterShape = canonicalShape.get_shape(); + const auto &body = snippet_for_generation->body_ptr(); + normInputShapes.clear(); + for (const auto& p : body->get_parameters()) + normInputShapes.emplace_back(p->get_output_shape(0)); + normOutputShapes.clear(); + for (const auto& r : body->get_results()) + normOutputShapes.emplace_back(r->get_input_shape(0)); + + // prepare + masterShape = getNormalizedDimsBySize(masterShape, tensorRank); + std::vector original_input_shape_ranks; + for (auto& pshape : normInputShapes) { + original_input_shape_ranks.push_back(pshape.size()); + pshape = getNormalizedDimsBySize(pshape, tensorRank); + } + for (auto& pshape : normOutputShapes) + pshape = getNormalizedDimsBySize(pshape, tensorRank); + + tileRank = 1; + bool dims_collapsed = false; + fullWorkAmount = std::accumulate(masterShape.begin(), masterShape.end(), 1, std::multiplies()); + if (snippet_for_generation->has_domain_sensitive_ops()) { + tileRank = 2; + } else { + dims_collapsed = optimizeExecDomain(normInputShapes, normOutputShapes, masterShape, tileRank); + } + exec_domain = masterShape; + + std::vector scheduler_work_amounts; + // rename schedulerWorkAmount to harnessWorkAmount? + harnessWorkAmount = fullWorkAmount; + const auto rank = exec_domain.size(); + for (auto i = rank - tileRank; i < rank; i++) { + auto& dim = exec_domain[i]; + harnessWorkAmount /= dim; + scheduler_work_amounts.push_back(dim); + dim = 1; + } + + if (dims_collapsed) { + std::vector new_shapes; + for (size_t i = 0; i < normInputShapes.size(); i++) { + const auto norm_shape = normInputShapes[i]; + size_t ndims_to_skip = norm_shape.size() - original_input_shape_ranks[i]; + new_shapes.emplace_back(norm_shape.begin() + ndims_to_skip, norm_shape.end()); + } + snippet_for_generation->reshape_body(new_shapes); + } + snippet_for_generation->set_master_shape(ov::PartialShape(masterShape)); + snippet_for_generation->set_tile_rank(tileRank); + + // generate + jit_snippets_compile_args jcp; + jcp.master_shape = masterShape; + jcp.tile_rank = tileRank; + generate(&jcp); + buffer_scratchpad_size = snippet_for_generation->get_buffer_scratchpad_size(); + buffer_scratchpad.resize(buffer_scratchpad_size * parallel_get_max_threads(), 0); +} + +ov::PartialShape Snippet::SnippetJitExecutor::canonicalizeBody(bool reshape) { + ov::snippets::op::Subgraph::BlockedShapeVector input_blocked_shapes = getBlockedShapes( + snippetAttrs.inMemBlockedDims, snippetAttrs.inMemOrders, snippetAttrs.inMemPrecs); + if (reshape) { + const auto& canonicalShape = snippetAttrs.snippet->canonicalized_body_shape_infer(input_blocked_shapes); + return canonicalShape; + } else { + ov::snippets::op::Subgraph::BlockedShapeVector output_blocked_shapes = getBlockedShapes( + snippetAttrs.outMemBlockedDims, snippetAttrs.outMemOrders, snippetAttrs.outMemPrecs); + + const auto& canonicalShape = snippetAttrs.snippet->canonicalize(output_blocked_shapes, input_blocked_shapes); + return canonicalShape; + } +} + +bool Snippet::SnippetJitExecutor::optimizeExecDomain(std::vector& inputShapes, std::vector& outputShapes, VectorDims &domain, size_t& TileRank) const { const size_t minimalConcurrency = parallel_get_max_threads(); const size_t minimalJitWorkAmount = 256; @@ -287,240 +692,11 @@ bool Snippet::optimizeExecDomain(std::vector& inputShapes, std::vect }; return findDimsToCollapse(); } -ov::PartialShape Snippet::canonicalizeBody() { - auto edgeToBlockedShape = [](const EdgePtr& edge) { - const auto blockedDesc = edge->getMemory().getDescWithType(); - std::vector dims; - // if blockDim == Shape::UNDEFINED_DIM, then it's a dynamic dimension, and we need to recreate a proper dynamic Dim - for (const auto& d : blockedDesc->getBlockDims()) - dims.emplace_back(d == Shape::UNDEFINED_DIM ? -1 : d); - ov::PartialShape shape(dims); - ov::AxisVector blocking(blockedDesc->getOrder()); - ov::element::Type precision = InferenceEngine::details::convertPrecision(blockedDesc->getPrecision()); - return snippets::op::Subgraph::BlockedShape{shape, blocking, precision}; - }; - inputShapeIsBlocked.resize(inputShapes.size(), false); - masterShapeIsBlocked = false; - snippets::op::Subgraph::BlockedShapeVector input_blocked_shapes; - for (size_t i = 0; i < inputShapes.size(); i++) { - auto blockedShape = edgeToBlockedShape(getParentEdgesAtPort(i)[0]); - inputShapeIsBlocked[i] = std::get<0>(blockedShape).size() != std::get<1>(blockedShape).size(); - masterShapeIsBlocked = masterShapeIsBlocked || inputShapeIsBlocked[i]; - input_blocked_shapes.push_back(blockedShape); - } - outputShapeIsBlocked.resize(outputShapes.size(), false); - ov::snippets::op::Subgraph::BlockedShapeVector output_blocked_shapes; - for (size_t i = 0; i < outputShapes.size(); i++) { - auto blockedShape = edgeToBlockedShape(getChildEdgesAtPort(i)[0]); - outputShapeIsBlocked[i] = std::get<0>(blockedShape).size() != std::get<1>(blockedShape).size(); - output_blocked_shapes.push_back(blockedShape); - } - - const auto& canonicalShape = snippet->canonicalize(output_blocked_shapes, input_blocked_shapes); - return canonicalShape; -} -void Snippet::createPrimitive() { - // determine canonicalize, determine master_shape and prepend up to 6D - // NB! normInputShapes are updated, so body reshape might be needed - const auto& canonicalShape = canonicalizeBody(); - // initialize by maximum output dimension. Dimensions of outputs should be broadcastable - tensorRank = std::max(static_cast(rank6D), canonicalShape.size()); - - const auto config = getSelectedPrimitiveDescriptor()->getConfig(); - auto initDataSizes = [this, config]() { - const size_t numInputs = inputShapes.size(); - const size_t numOutputs = outputShapes.size(); - dataSize.resize(numInputs + numOutputs); - for (size_t i = 0; i < numInputs; i++) - dataSize[i] = config.inConfs[i].getMemDesc()->getPrecision().size(); - for (size_t i = 0; i < numOutputs; i++) - dataSize[i + numInputs] = config.outConfs[i].getMemDesc()->getPrecision().size(); - }; - initDataSizes(); - - jit_snippets_compile_args jcp; - if (canonicalShape.is_dynamic()) - IE_THROW() << "Snippets: Canonicalization returned dynamic shape in static pipeline"; - masterShape = canonicalShape.get_shape(); - const auto &body = snippet->body_ptr(); - for (const auto& p : body->get_parameters()) - normInputShapes.emplace_back(p->get_output_shape(0)); - for (const auto& r : body->get_results()) - normOutputShapes.emplace_back(r->get_input_shape(0)); - - prepareParams(); - jcp.master_shape = masterShape; - jcp.tile_rank = tileRank; - generate(&jcp); - buffer_scratchpad_size = snippet->get_buffer_scratchpad_size(); - buffer_scratchpad.resize(buffer_scratchpad_size * parallel_get_max_threads(), 0); -} - -std::vector Snippet::shapeInfer() { - // todo: it's very strange that we don't have broadcast_merge_into for cpu shapes - auto broadcast_merge = [](VectorDims& dst, const VectorDims& src){ - // Ranks are both static. - auto dst_rank = dst.size(); - auto src_rank = src.size(); - const auto new_rank = std::max(dst_rank, src_rank); - dst.insert(dst.begin(), new_rank - dst_rank, 1); - std::vector dims(new_rank); - bool success = true; - for (size_t i = 0; i < new_rank; i++) { - auto dsti = i < (new_rank - dst_rank) ? 1 : dst[i - (new_rank - dst_rank)]; - auto srci = i < (new_rank - src_rank) ? 1 : src[i - (new_rank - src_rank)]; - if (dsti != srci && srci != Shape::UNDEFINED_DIM) { - if (dsti == 1 || dsti == Shape::UNDEFINED_DIM) { - dsti = srci; - } else { - success = false; - } - } - } - return success; - }; - for (size_t i = 0; i < getParentEdges().size(); i++) { - VectorDims inDims {getParentEdgesAtPort(i)[0]->getMemory().getShape().getDims()}; - if (masterShapeIsBlocked && !inputShapeIsBlocked[i]) - inDims.insert(inDims.end(), 1); - // todo: this is a simple master_shape inference for shape-agnostic operations, - // we'll need to account for body operations semantics in the future - if (i == 0) - masterShape = inDims; - else - broadcast_merge(masterShape, inDims); - normInputShapes[i] = std::move(inDims); - } - if (std::any_of(masterShape.begin(), masterShape.end(), [](const Dim& d){ return d == Shape::UNDEFINED_DIM;})) { - std::ostringstream errorMessage; - errorMessage << "Can't compute static master shape for Snippet node with name: " << getName(); - errorMessage << ". Input shapes = ( "; - for (size_t i = 0; i < getParentEdges().size(); i++) { - errorMessage << i << " port = " << getParentEdgesAtPort(i)[0]->getMemory().getShape().toString() << ", "; - } - errorMessage << "). Master shape = ( " << Shape(masterShape).toString() << " )"; - IE_THROW() << errorMessage.str(); - } - - if (normOutputShapes.size() == 1) { - normOutputShapes[0] = masterShape; - return {masterShape}; - } - std::vector outputDims; - std::vector new_shapes; - for (const auto& s : normInputShapes) - new_shapes.emplace_back(s); - const auto& outputShapes = snippet->reshape_body(new_shapes); - for (size_t i = 0; i < outputShapes.size(); i++) - normOutputShapes[i] = outputShapes[i]; - return normOutputShapes; -} - -void Snippet::prepareParams() { - masterShape = getNormalizedDimsBySize(masterShape, tensorRank); - std::vector original_input_shape_ranks; - for (auto& pshape : normInputShapes) { - original_input_shape_ranks.push_back(pshape.size()); - pshape = getNormalizedDimsBySize(pshape, tensorRank); - } - for (auto& pshape : normOutputShapes) - pshape = getNormalizedDimsBySize(pshape, tensorRank); - - tileRank = 1; - bool dims_collapsed = false; - fullWorkAmount = std::accumulate(masterShape.begin(), masterShape.end(), 1, std::multiplies()); - if (snippet->has_domain_sensitive_ops()) { - tileRank = 2; - } else { - dims_collapsed = optimizeExecDomain(normInputShapes, normOutputShapes, masterShape, tileRank); - } - exec_domain = masterShape; - - auto initStartMemoryOffsets = [this]() { - const auto config = getSelectedPrimitiveDescriptor()->getConfig(); - const size_t numInputs = inputShapes.size(); - start_offset_in.resize(numInputs); - srcMemPtrs.resize(numInputs); - for (size_t i = 0; i < numInputs; i++) { - const auto memPtr = getParentEdgeAt(i)->getMemoryPtr(); - srcMemPtrs[i] = memPtr; - start_offset_in[i] = memPtr->getDescWithType()->getOffsetPadding() * dataSize[i]; - } - const size_t numOutputs = outputShapes.size(); - start_offset_out.resize(numOutputs); - dstMemPtrs.resize(numOutputs); - for (size_t i = 0; i < numOutputs; i++) { - const auto memPtr = getChildEdgeAt(i)->getMemoryPtr(); - dstMemPtrs[i] = memPtr; - start_offset_out[i] = memPtr->getDescWithType()->getOffsetPadding() * dataSize[i + numInputs]; - } - }; - // initialize start offsets to src and dst memory - // Needs to be done for every set of input shapes sce memory ptrs could've updated - initStartMemoryOffsets(); - std::vector scheduler_work_amounts; - // rename schedulerWorkAmount to harnessWorkAmount? - harnessWorkAmount = fullWorkAmount; - const auto rank = exec_domain.size(); - for (auto i = rank - tileRank; i < rank; i++) { - auto& dim = exec_domain[i]; - harnessWorkAmount /= dim; - scheduler_work_amounts.push_back(dim); - dim = 1; - } - - if (dims_collapsed) { - std::vector new_shapes; - for (size_t i = 0; i < normInputShapes.size(); i++) { - const auto norm_shape = normInputShapes[i]; - size_t ndims_to_skip = norm_shape.size() - original_input_shape_ranks[i]; - new_shapes.emplace_back(norm_shape.begin() + ndims_to_skip, norm_shape.end()); - } - snippet->reshape_body(new_shapes); - } - - snippet->set_master_shape(ov::PartialShape(masterShape)); - snippet->set_tile_rank(tileRank); -} - -bool Snippet::needPrepareParams() const { - return inputShapesModified() || !schedule.ptr; -} - -bool Snippet::canBeInPlace() const { - if (isDynamic || getParentEdgesAtPort(0)[0]->getParent()->getType() == Type::Input) { - return false; - } - if (getChildEdges().size() != 1) { - return false; - } - - for (auto& parentEdge : getParentEdges()) { - auto parent = parentEdge.lock()->getParent(); - if (parent->getChildEdges().size() != 1) - return false; - - // WA to prevent memory corruption caused by inplace feature - if (parent->getType() == Type::Concatenation) { - for (auto& parentParentEdge : parent->getParentEdges()) { - auto parentParent = parentParentEdge.lock()->getParent(); - if (parentParent->getChildEdges().size() != 1) - return false; - } - } - } - return getInputShapeAtPort(0) == getOutputShapeAtPort(0); -} - -bool Snippet::created() const { - return getType() == Type::Subgraph; -} - -void Snippet::generate(const jit_snippets_compile_args* jcp) { +void Snippet::SnippetJitExecutor::generate(const jit_snippets_compile_args* jcp) { ov::pass::Manager pre_dialect; pre_dialect.register_pass(); - if (context->getConfig().inferencePrecision == ov::element::bf16 && snippet->has_domain_sensitive_ops()) { + if (enforceBF16 && snippet_for_generation->has_domain_sensitive_ops()) { // enforce BF16 precisions to supported operations // MatMul has to be decomposed to Brgemm operations before enforcement // Note, MatMul decomposition will be ran later again for case if BF16 enforcement is not happened @@ -542,7 +718,7 @@ void Snippet::generate(const jit_snippets_compile_args* jcp) { ov::snippets::lowered::pass::PassPipeline control_flow_pipeline; CPU_REGISTER_PASS_X64(control_flow_pipeline, ov::intel_cpu::pass::FuseLoadStoreConvert); - schedule = snippet->generate( + schedule = snippet_for_generation->generate( pre_dialect, post_dialect, post_precision, @@ -551,63 +727,8 @@ void Snippet::generate(const jit_snippets_compile_args* jcp) { reinterpret_cast(jcp)); } -void Snippet::update_ptrs(jit_snippets_call_args& call_args) { - for (size_t i = 0; i < srcMemPtrs.size(); i++) - call_args.src_ptrs[i] = reinterpret_cast(srcMemPtrs[i]->getData()) + start_offset_in[i]; - - for (size_t i = 0; i < dstMemPtrs.size(); i++) - call_args.dst_ptrs[i] = reinterpret_cast(dstMemPtrs[i]->getData()) + start_offset_out[i]; - - if (buffer_scratchpad_size > 0) { - call_args.buffer_scratchpad_ptr = - reinterpret_cast(buffer_scratchpad.data()) + parallel_get_thread_num() * buffer_scratchpad_size; - } -} - -void Snippet::execute(dnnl::stream strm) { - if (schedule.ptr == nullptr) { - IE_THROW() << "Snippet can't use Optimized implementation and can't fallback to reference"; - } - if (tensorRank == rank6D) { - schedule_6d(); - } else { - schedule_nt(); - } -} - -void Snippet::schedule_6d() { - const auto& dom = exec_domain; - // < N, C, H, W > < 1, 1, N, C*H*W> - parallel_for5d(dom[0], dom[1], dom[2], dom[3], dom[4], - [&](int64_t d0, int64_t d1, int64_t d2, int64_t d3, int64_t d4) { - int64_t indexes[] = {d0, d1, d2, d3, d4}; - jit_snippets_call_args call_args; - update_ptrs(call_args); - - schedule.get_callable()(indexes, &call_args); - }); -} - -void Snippet::schedule_nt() { - const auto& work_size = exec_domain; - parallel_nt(0, [&](const int ithr, const int nthr) { - jit_snippets_call_args call_args; - update_ptrs(call_args); - - size_t start = 0, end = 0; - splitter(harnessWorkAmount, nthr, ithr, start, end); - - std::vector indexes(work_size.size() - 1, 0); - for (size_t iwork = start; iwork < end; ++iwork) { - size_t tmp = iwork; - for (ptrdiff_t j = work_size.size() - 2; j >= 0; j--) { - indexes[j] = tmp % work_size[j]; - tmp /= work_size[j]; - } - - schedule.get_callable()(indexes.data(), &call_args); - } - }); +bool Snippet::SnippetJitExecutor::schedule_created() { + return schedule.ptr != nullptr; } } // namespace node diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.h b/src/plugins/intel_cpu/src/nodes/subgraph.h index 435b709b492..7d4947cea97 100644 --- a/src/plugins/intel_cpu/src/nodes/subgraph.h +++ b/src/plugins/intel_cpu/src/nodes/subgraph.h @@ -30,6 +30,7 @@ public: void getSupportedDescriptors() override {}; void initSupportedPrimitiveDescriptors() override; void selectOptimalPrimitiveDescriptor() override; + void initOptimalPrimitiveDescriptor() override; InferenceEngine::Precision getRuntimePrecision() const override; // to avoid collisions in throughput mode with copy of TypeRelaxed nodes @@ -37,9 +38,7 @@ public: void setSharedMutex(const std::shared_ptr& mutex); // Here we convert to canonical for & jit everything - void createPrimitive() override; void prepareParams() override; - std::vector shapeInfer(); bool needPrepareParams() const override; bool canBeInPlace() const override; @@ -47,6 +46,19 @@ public: // if generator is set, it would execute generated code otherwise it would fallback to nGraph reference void execute(dnnl::stream strm) override; + void executeDynamicImpl(dnnl::stream strm) override; + + struct SnippetAttrs { + // Local copy of subgraph node for canonization & code generation + std::shared_ptr snippet; + uint64_t bodyHash; + std::vector> inMemBlockedDims; + std::vector> inMemOrders; + std::vector inMemPrecs; + std::vector> outMemBlockedDims; + std::vector> outMemOrders; + std::vector outMemPrecs; + }; private: static const size_t rank6D {6}; @@ -55,61 +67,96 @@ private: // Create a deep local copy of the input snippet to perform canonicalization & code generation // TODO: Probably better to implement a proper copy constructor - // NOTE: Before call mutex should be initialized - void copy_snippet(); + void copy_snippet() const; + void init_body_hash(); - ov::PartialShape canonicalizeBody(); - // returns true if exec domain was modified - bool optimizeExecDomain(std::vector&, std::vector&, VectorDims&, size_t&) const; - - void generate(const jit_snippets_compile_args*); - inline void update_ptrs(jit_snippets_call_args&); - // Evaluates generated snippet using parallel backend - void schedule_6d(); - void schedule_nt(); + size_t inputNum = 0; + size_t outputNum = 0; // Original subgraph node std::shared_ptr original_snippet; - // Local copy of subgraph node for canonization & code generation - std::shared_ptr snippet; - - // Holds generated snippet with information about how to schedule it - snippets::Schedule schedule; + mutable std::shared_ptr local_snippet; // Holds ISA version used is codeGeneration target dnnl::impl::cpu::x64::cpu_isa_t host_isa; - size_t isa_num_lanes = 0; // number of elements that fit in vector size - - // Holds index of output used as in execution domain - // it should be compatible with a schedule's work size - std::vector exec_domain = {}; - - /// scheduling info - size_t tensorRank = 0; - size_t tileRank = 1; - size_t fullWorkAmount = 0; - size_t harnessWorkAmount = 0; - const size_t maxTileRank = 2; std::vector srcMemPtrs = {}; std::vector dstMemPtrs = {}; - std::vector dataSize = {}; - // this is needed for fast shape inference of blocking-invariant prepended shapes - std::vector inputShapeIsBlocked = {}; // we need this info to shape-infer mixed layouts - std::vector outputShapeIsBlocked = {}; // we need this info to shape-infer mixed layouts - bool masterShapeIsBlocked = false; + mutable SnippetAttrs snippetAttrs; + mutable bool is_canonicalized = false; + bool is_dynamic = false; - VectorDims masterShape = {}; - std::vector normInputShapes = {}; - std::vector normOutputShapes = {}; + class SnippetExecutor { + public: + SnippetExecutor(const SnippetAttrs& attrs, bool is_canonicalized, bool is_dynamic, bool enforceBF16); + virtual void exec(const std::vector& inMemPtrs, const std::vector& outMemPtrs) = 0; + virtual ~SnippetExecutor() = default; - std::vector start_offset_in = {}; - std::vector start_offset_out = {}; + protected: + SnippetAttrs snippetAttrs; + bool is_canonicalized = false; + bool is_dynamic = false; + bool enforceBF16 = false; + }; - // Buffer scratchpad - std::vector buffer_scratchpad = {}; - size_t buffer_scratchpad_size = 0; + std::shared_ptr execPtr = nullptr; + + class SnippetJitExecutor : public SnippetExecutor { + public: + SnippetJitExecutor(const SnippetAttrs& attrs, bool is_canonicalized, bool is_dynamic, bool enforceBF16); + void exec(const std::vector& inMemPtrs, const std::vector& outMemPtrs) override; + + bool schedule_created(); + + private: + static const size_t rank6D {6}; + + typedef void (*kernel)(const void *, const void *); + + size_t numInput = 0; + size_t numOutput = 0; + + ov::PartialShape canonicalizeBody(bool reshape); + // returns true if exec domain was modified + bool optimizeExecDomain(std::vector&, std::vector&, VectorDims&, size_t&) const; + + void generate(const jit_snippets_compile_args*); + inline void update_ptrs(jit_snippets_call_args&, const std::vector& inMemPtrs, const std::vector& outMemPtrs); + // Evaluates generated snippet using parallel backend + void schedule_6d(const std::vector& inMemPtrs, const std::vector& outMemPtrs); + void schedule_nt(const std::vector& inMemPtrs, const std::vector& outMemPtrs); + + std::shared_ptr snippet_for_generation; + + // Holds generated snippet with information about how to schedule it + snippets::Schedule schedule; + + // Holds index of output used as in execution domain + // it should be compatible with a schedule's work size + std::vector exec_domain = {}; + + /// scheduling info + size_t tensorRank = 0; + size_t tileRank = 1; + size_t fullWorkAmount = 0; + size_t harnessWorkAmount = 0; + const size_t maxTileRank = 2; + + std::vector dataSize = {}; + + // master shape is mutable since we need to modify it inside const shapeInfer method + mutable VectorDims masterShape = {}; + mutable std::vector normInputShapes = {}; + mutable std::vector normOutputShapes = {}; + + std::vector start_offset_in = {}; + std::vector start_offset_out = {}; + + // Buffer scratchpad + std::vector buffer_scratchpad = {}; + size_t buffer_scratchpad_size = 0; + }; }; } // namespace node diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/subgraph.hpp b/src/plugins/intel_cpu/src/shape_inference/custom/subgraph.hpp index ef750e0f9a9..7c1bad348eb 100644 --- a/src/plugins/intel_cpu/src/shape_inference/custom/subgraph.hpp +++ b/src/plugins/intel_cpu/src/shape_inference/custom/subgraph.hpp @@ -10,15 +10,69 @@ namespace ov { namespace intel_cpu { namespace node { using Result = IShapeInfer::Result; -/* This class implementation is a temporal WA - TODO: revise the implementation to remove the node reference*/ class SnippetShapeInfer : public ShapeInferEmptyPads { public: - SnippetShapeInfer(Snippet* node) : m_node(node) {} + SnippetShapeInfer(std::shared_ptr body) : m_body(body) {} Result infer( const std::vector>& input_shapes, const std::unordered_map& data_dependency) override { - return {m_node->shapeInfer(), ShapeInferStatus::success}; + auto broadcast_merge = [](VectorDims& dst, const VectorDims& src) { + // Ranks are both static. + auto dst_rank = dst.size(); + auto src_rank = src.size(); + const auto new_rank = std::max(dst_rank, src_rank); + dst.insert(dst.begin(), new_rank - dst_rank, 1); + for (size_t i = 0; i < new_rank; i++) { + auto srci = i < (new_rank - src_rank) ? 1 : src[i - (new_rank - src_rank)]; + if (dst[i] != srci && srci != Shape::UNDEFINED_DIM) { + if (dst[i] == 1 || dst[i] == Shape::UNDEFINED_DIM) { + dst[i] = srci; + } else { + if (srci != 1) { + IE_THROW() << "Got imcompatible input shapes in snippets shape infer"; + } + } + } + } + }; + + const size_t out_size = m_body->get_output_size(); + if (out_size == 1) { + VectorDims masterShape; + for (size_t i = 0; i < input_shapes.size(); i++) { + if (i == 0) + masterShape = input_shapes[i]; + else + broadcast_merge(masterShape, input_shapes[i]); + } + size_t output_rank = m_body->get_output_partial_shape(0).rank().get_length(); + if (output_rank > masterShape.size()) { + masterShape.insert(masterShape.begin(), output_rank - masterShape.size(), 1); + } + return {{masterShape}, ShapeInferStatus::success}; + } else { + std::vector outputDims; + std::vector new_shapes; + for (const auto& s : input_shapes) + new_shapes.emplace_back(s); + auto& params = m_body->get_parameters(); + if (params.size() != input_shapes.size()) { + IE_THROW() << "Got invalid number of input shapes to reshape subgraph body"; + } + for (size_t i = 0; i < params.size(); ++i) { + params[i]->set_partial_shape(new_shapes[i]); + } + m_body->validate_nodes_and_infer_types(); + for (const auto& res : m_body->get_results()) { + auto& pshape = res->get_input_partial_shape(0); + if (!pshape.is_static()) { + IE_THROW() << "Subgraph inferred dynamic output shape during reshape with static inputs"; + } + outputDims.emplace_back(pshape.get_shape()); + } + + return {outputDims, ShapeInferStatus::success}; + } } port_mask_t get_port_mask() const override { @@ -26,18 +80,21 @@ public: } private: - Snippet* m_node; + std::shared_ptr m_body; }; class SnippetShapeInferFactory : public ShapeInferFactory { public: - SnippetShapeInferFactory(Snippet* node) : m_node(node) {} + SnippetShapeInferFactory(const std::shared_ptr& op) { + auto subgraph = ov::as_type_ptr(op); + snippet_body = subgraph->body_ptr()->clone(); + } ShapeInferPtr makeShapeInfer() const override { - return std::make_shared(m_node); + return std::make_shared(snippet_body); } private: - Snippet* m_node; + std::shared_ptr snippet_body = nullptr; }; } // namespace node } // namespace intel_cpu diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp index ae0e82a1c37..45576cf7194 100644 --- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp +++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp @@ -667,10 +667,14 @@ void Transformations::MainSnippets(void) { }, snippets::pass::ExtractReshapesFromMHA); CPU_SET_CALLBACK_X64(snippetsManager, [](const std::shared_ptr& n) -> bool { + if (n->is_dynamic()) + return true; // CPU Plugin support Swish in Subgraph via conversion to SwichCPU which assumes second input to be constant const bool is_unsupported_swish = ov::is_type(n) && n->inputs().size() > 1 && !ov::is_type(n->get_input_node_shared_ptr(1)); + if (is_unsupported_swish) + return true; // todo: general tokenization flow is not currently supported for these operations. // they can be tokenized only as a part of complex patterns const bool is_disabled_tokenization = (ov::is_type(n) || @@ -679,6 +683,8 @@ void Transformations::MainSnippets(void) { ov::is_type(n) || ov::is_type(n) || ov::is_type(n)); + if (is_disabled_tokenization) + return true; const auto& inputs = n->inputs(); // todo: clarify whether we can evaluate snippets on const paths const bool has_only_const_inputs = std::all_of(inputs.begin(), inputs.end(), @@ -686,6 +692,8 @@ void Transformations::MainSnippets(void) { return ov::is_type( in.get_source_output().get_node_shared_ptr()); }); + if (has_only_const_inputs) + return true; // todo: clarify whether we can evaluate snippets on inputs with larger ranks auto rank_is_too_large = [](const ov::descriptor::Tensor& t) { // callback is called has_supported_in_out(), so it's safe to assume that the shapes are static @@ -695,13 +703,17 @@ void Transformations::MainSnippets(void) { [&](const ov::Input& in) { return rank_is_too_large(in.get_tensor()); }); + if (bad_input_rank) + return true; const auto& outputs = n->outputs(); const bool bad_output_rank = std::any_of(outputs.begin(), outputs.end(), [&](const ov::Output& out) { return rank_is_too_large(out.get_tensor()); }); - return has_only_const_inputs || bad_input_rank || bad_output_rank || is_unsupported_swish || - is_disabled_tokenization; + if (bad_output_rank) + return true; + + return false; }, snippets::pass::TokenizeSnippets); } 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 00a0da81efc..a691d342fb6 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 @@ -180,7 +180,7 @@ std::vector disabledTestPatterns() { // Issue: 111412 R"(.*smoke_Proposal_(Static|Dynamic)_Test_Case1/ProposalLayerCPUTest.*)", // Issue: 111418 - R"(.*smoke_Snippets_ConvertStub/ConvertStub\.CompareWithRefImpl/IS=.*_OT=\(bf16\)_#N=2_#S=2_targetDevice=CPU.*)", + R"(.*smoke_Snippets_ConvertStub/ConvertStub\.CompareWithRefImpl/IS.*_OT=\(bf16\)_#N=2_#S=2_targetDevice=CPU.*)", // Issue: 111944 R"(.*smoke_DefConvLayoutTest6.*)", // Issue: 106939 diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/add.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/add.cpp index 6330bfef11a..45aaf9f4eea 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/add.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/add.cpp @@ -11,11 +11,17 @@ namespace snippets { namespace { - -namespace snippets_static_1 { +// ===================================Add=========================================================// // These inputs are needed to test static Loop optimizations (emit the whole tile, body with increments, set WA etc) -std::vector inShapesStatic1{{1, 16, 29, 1}, {1, 16, 29, 7}, {1, 16, 29, 8}, {1, 16, 29, 15}, {1, 16, 29, 16}, {1, 16, 29, 31}}; -std::vector inShapesStatic2{{1, 16, 29, 1}, {1, 16, 1, 1}, {1, 1, 1, 1}}; +std::vector inShapesStatic1{{{}, {{1, 16, 29, 1}}}, + {{}, {{1, 16, 29, 7}}}, + {{}, {{1, 16, 29, 8}}}, + {{}, {{1, 16, 29, 15}}}, + {{}, {{1, 16, 29, 16}}}, + {{}, {{1, 16, 29, 31}}}}; +std::vector inShapesStatic2{{{}, {{1, 16, 29, 1}}}, + {{}, {{1, 16, 1, 1}}}, + {{}, {{1, 1, 1, 1}}}}; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, Add, ::testing::Combine( @@ -26,41 +32,79 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, Add, ::testing::Values(1), // Subgraph is created, since the inputs are followed by converts ::testing::Values(ov::test::utils::DEVICE_CPU)), Add::getTestCaseName); + +// DS +std::vector inShapesDynamic1{ + { + {{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic()}, + {{1, 3, 1, 10}, {1, 3, 10, 10}, {1, 3, 1, 10}}}, + } +}; +std::vector inShapesDynamic2{ + { + {{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic()}, + {{1, 3, 10, 1}, {1, 3, 1, 1}, {1, 3, 10, 1}}}, + } +}; +INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise_Add, Add, + ::testing::Combine( + ::testing::ValuesIn(inShapesDynamic1), + ::testing::ValuesIn(inShapesDynamic2), + ::testing::Values(ov::element::f32), + ::testing::Values(1), + ::testing::Values(1), // Subgraph is created, since the inputs are followed by converts + ::testing::Values(ov::test::utils::DEVICE_CPU)), + Add::getTestCaseName); + +// ===================================AddPair=========================================================// // test cross-tile (vector vs scalar) optimizations in the absence of vector tile -std::vector> inShapesStatic{ - {{1, 128, 1, 1}, {1, 128, 1, 1}}, - {{1, 128, 1, 9}, {1, 128, 1, 9}}, - {{1, 128, 1, 16}, {1, 128, 1, 16}}, - {{1, 128, 1, 17}, {1, 128, 1, 17}}, - {{1, 128, 1, 29}, {1, 128, 1, 29}}, - {{1, 128, 1, 33}, {1, 128, 1, 33}}, - {{1, 128, 9, 30}, {1, 128, 1, 30}}, - {{1, 128, 9, 1}, {1, 128, 1, 30}}, - {{1, 128, 9, 16}, {1, 128, 9, 1}}, +std::vector> inShapesAddPair { + {{{}, {{1, 128, 1, 1}}}, {{}, {{1, 128, 1, 1}}}}, + {{{}, {{1, 128, 1, 9}}}, {{}, {{1, 128, 1, 9}}}}, + {{{}, {{1, 128, 1, 16}}}, {{}, {{1, 128, 1, 16}}}}, + {{{}, {{1, 128, 1, 17}}}, {{}, {{1, 128, 1, 17}}}}, + {{{}, {{1, 128, 1, 29}}}, {{}, {{1, 128, 1, 29}}}}, + {{{}, {{1, 128, 1, 33}}}, {{}, {{1, 128, 1, 33}}}}, + {{{}, {{1, 128, 9, 30}}}, {{}, {{1, 128, 1, 30}}}}, + {{{}, {{1, 128, 9, 1}}}, {{}, {{1, 128, 1, 30}}}}, + {{{}, {{1, 128, 9, 16}}}, {{}, {{1, 128, 9, 1}}}}, + // DS + {{{1, -1, {1, 10}, {1, 33}}, {{1, 128, 1, 1}, {1, 128, 1, 9}, {1, 128, 1, 17}, {1, 128, 1, 29}, {1, 128, 9, 1}, {1, 128, 1, 1}}}, + {{{1, 1}, {128, 128}, {1, 10}, {1, 33}}, {{1, 128, 1, 1}, {1, 128, 1, 9}, {1, 128, 1, 17}, {1, 128, 1, 29}, {1, 128, 1, 30}, {1, 128, 1, 1}}}}, + {{{1, -1, 1, {1, 32}}, {{1, 16, 1, 32}, {1, 16, 1, 32}, {1, 16, 1, 32}, {1, 16, 1, 32}}}, + {{1, -1, 1, {1, 32}}, {{1, 16, 1, 32}, {1, 16, 1, 32}, {1, 16, 1, 32}, {1, 16, 1, 32}}}}, }; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, AddPair, ::testing::Combine( - ::testing::ValuesIn(inShapesStatic), + ::testing::ValuesIn(inShapesAddPair), ::testing::Values(ov::element::f32), ::testing::Values(1), ::testing::Values(1), // Subgraph is created, since the inputs are followed by converts ::testing::Values(ov::test::utils::DEVICE_CPU)), AddPair::getTestCaseName); -} // namespace snippets_static_1 +// ===================================AddConst, AddRollConst=========================================================// +std::vector inShapesAddConst{{{}, {{1, 2, 3, 32}}}, + {{}, {{1, 3, 17, 33}}}, + {{-1, -1, -1, -1}, {{1, 3, 17, 33}, {1, 2, 1, 65}, {1, 3, 17, 33}}}, + {{1, {1, 10}, {1, 8}, {1, 4}}, {{1, 2, 8, 4}, {1, 8, 1, 1}, {1, 2, 8, 4}}}}; +std::vector inShapesConstAddConst{{1, 1, 1, 1}}; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, AddConst, ::testing::Combine( - ::testing::Values(ov::Shape {1, 42, 16, 64}), + ::testing::ValuesIn(inShapesAddConst), + ::testing::ValuesIn(inShapesConstAddConst), ::testing::Values(ov::element::f32), ::testing::Values(1), // Add ::testing::Values(1), // Subgraph is created, since the inputs are followed by converts ::testing::Values(ov::test::utils::DEVICE_CPU)), AddConst::getTestCaseName); +// ===================================AddRollConst=========================================================// INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, AddRollConst, ::testing::Combine( - ::testing::Values(ov::Shape {1, 42, 16, 64}), + ::testing::ValuesIn(inShapesAddConst), + ::testing::ValuesIn(inShapesConstAddConst), ::testing::Values(ov::element::f32), ::testing::Values(2), // Add + roll after inputs ::testing::Values(1), // Subgraph is created, since the inputs are followed by converts @@ -69,13 +113,15 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, AddRollConst, INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise_BF16, AddRollConst, ::testing::Combine( - ::testing::Values(ov::Shape {1, 2, 3, 32}), + ::testing::ValuesIn(inShapesAddConst), + ::testing::ValuesIn(inShapesConstAddConst), ::testing::Values(ov::element::bf16), ::testing::Values(3), // Add + reorder + roll after inputs ::testing::Values(1), // Subgraph is created, since the inputs are followed by converts ::testing::Values(ov::test::utils::DEVICE_CPU)), AddRollConst::getTestCaseName); -} // namespace + +} // namespace } // namespace snippets } // namespace test } // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/check_broadcast.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/check_broadcast.cpp index 477d256e57f..8ecd904021c 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/check_broadcast.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/check_broadcast.cpp @@ -21,13 +21,26 @@ const std::vector input_types = { const std::vector test_cases = { // broadcast is neccessary { - {{1, 3, 4, 4}, {4, 4}}, + {{{}, {{1, 3, 4, 4}}}, {{}, {{4, 4}}}}, ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::PDPD, -1), 1, 0 }, { - {{1, 3, 4, 4}, {4, 4}}, + {{{}, {{1, 3, 4, 4}}}, {{}, {{4, 4}}}}, + ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::PDPD, 2), + 1, + 0 + }, + // DS + { + {{{1, 3, -1, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}, {{-1, {1, 4}}, {{4, 4}, {1, 3}, {4, 4}}}}, + ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::PDPD, -1), + 1, + 0 + }, + { + {{{1, 3, -1, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}, {{-1, {1, 4}}, {{4, 4}, {1, 3}, {4, 4}}}}, ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::PDPD, 2), 1, 0 @@ -35,13 +48,26 @@ const std::vector test_cases = { // broadcast is not neccessary { - {{1, 3, 4, 4}, {1, 3, 4, 4}}, + {{{}, {{1, 3, 4, 4}}}, {{}, {{1, 3, 4, 4}}}}, ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::PDPD, -1), 1, 1 }, { - {{1, 3, 4, 4}, {1, 3, 4, 4}}, + {{{}, {{1, 3, 4, 4}}}, {{}, {{1, 3, 4, 4}}}}, + ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::PDPD, 0), + 1, + 1 + }, + // DS + { + {{{1, 3, -1, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}, {{-1, 3, {1, 4}, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}}, + ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::PDPD, -1), + 1, + 1 + }, + { + {{{1, 3, -1, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}, {{-1, 3, {1, 4}, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}}, ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::PDPD, 0), 1, 1 @@ -49,19 +75,38 @@ const std::vector test_cases = { // any other PDPD { - {{1, 3, 4, 4}, {4, 4}}, + {{{}, {{1, 3, 4, 4}}}, {{}, {{4, 4}}}}, ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY, -1), 1, 1 }, { - {{1, 3, 4, 4}, {4, 4}}, + {{{}, {{1, 3, 4, 4}}}, {{}, {{4, 4}}}}, ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY, 0), 1, 1 }, { - {{1, 3, 4, 4}, {4, 4}}, + {{{}, {{1, 3, 4, 4}}}, {{}, {{4, 4}}}}, + ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY, 2), + 1, + 1 + }, + // DS + { + {{{1, 3, -1, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}, {{-1, {1, 4}}, {{4, 4}, {1, 3}, { 4, 4}}}}, + ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY, -1), + 1, + 1 + }, + { + {{{1, 3, -1, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}, {{-1, {1, 4}}, {{4, 4}, {1, 3}, {4, 4}}}}, + ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY, 0), + 1, + 1 + }, + { + {{{1, 3, -1, {1, 4}}, {{1, 3, 4, 4}, {1, 3, 1, 3}, {1, 3, 4, 4}}}, {{-1, {1, 4}}, {{4, 4}, {1, 3}, {4, 4}}}}, ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY, 2), 1, 1 diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/codegen_gelu.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/codegen_gelu.cpp index f20ca746753..62e9a37bd4f 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/codegen_gelu.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/codegen_gelu.cpp @@ -13,15 +13,42 @@ namespace ov { namespace test { namespace snippets { namespace { +std::vector inShapes0{ + {{}, {{1, 38, 130}}}, + {{}, {{1, 1, 130}}}, +}; +std::vector inShapes1{ + {{}, {{1, 38, 130}}}, + {{}, {{1, 38, 1}}}, +}; - INSTANTIATE_TEST_SUITE_P(NoReshape, CodegenGelu, - ::testing::Combine( - ::testing::Values(ov::element::f32), - ::testing::Values(ov::Shape {1, 384, 4096}), - ::testing::Values(true, false), - ::testing::Values(ov::test::utils::DEVICE_CPU)), - CodegenGelu::getTestCaseName); -} // namespace +INSTANTIATE_TEST_SUITE_P(NoReshapeAndReshape, CodegenGelu, + ::testing::Combine( + ::testing::Values(ov::element::f32), + ::testing::ValuesIn(inShapes0), + ::testing::ValuesIn(inShapes1), + ::testing::Values(true, false), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + CodegenGelu::getTestCaseName); + +// DS +std::vector inShapesDynamic0{ + {{-1, -1, -1}, {{1, 12, 128}, {1, 12, 1}, {1, 12, 128}}}, +}; +std::vector inShapesDynamic1{ + {{-1, -1, -1}, {{1, 12, 128}, {1, 1, 128}, {1, 12, 128}}}, +}; + +INSTANTIATE_TEST_SUITE_P(NoReshapeAndReshapeDynamic, CodegenGelu, + ::testing::Combine( + ::testing::Values(ov::element::f32), + ::testing::ValuesIn(inShapesDynamic0), + ::testing::ValuesIn(inShapesDynamic1), + ::testing::Values(true, false), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + CodegenGelu::getTestCaseName); + +} // namespace } // namespace snippets } // namespace test } // namespace ov diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/convert.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/convert.cpp index ddf5be3369c..dff3f158599 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/convert.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/convert.cpp @@ -30,10 +30,14 @@ const std::vector, std::vector> inputShapes_Convert = { - { ov::PartialShape{2, 16} }, - { ov::PartialShape{5, 5} }, - { ov::PartialShape{2, 12, 1} } +const std::vector> inputShapes_Convert = { + { {{}, {{2, 16}}} }, + { {{}, {{5, 5}}} }, + { {{}, {{2, 12, 1}}} }, + // DS(dynamic shape) + { {{-1, -1}, {{2, 16}, {2, 8}, {2, 16}}} }, + { {{{1, 5}, 5}, {{5, 5}, {1, 5}, {5, 5}}} }, + { {{{1, 10}, {4, 12}, {1, 2}}, {{2, 12, 1}, {4, 4, 2}, {2, 12, 1}}} } }; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Convert, Convert, @@ -57,10 +61,14 @@ const std::vector, std::vector> inputShapes_ConvertInput = { - { ov::PartialShape{2, 16}, ov::PartialShape{1, 16} }, - { ov::PartialShape{5, 18}, ov::PartialShape{5, 1} }, - { ov::PartialShape{3, 1}, ov::PartialShape{3, 21} } +const std::vector> inputShapes_ConvertInput = { + { {{}, {{2, 16}}}, {{}, {{1, 16}}} }, + { {{}, {{5, 18}}}, {{}, {{5, 1}}} }, + { {{}, {{3, 1}}}, {{}, {{3, 21}}} }, + // DS + { {{-1, -1}, {{2, 16}, {1, 16}, {2, 16}}}, {{-1, -1}, {{1, 16}, {2, 16}, {1, 16}}} }, + { {{5, -1}, {{5, 18}, {5, 1}, {5, 18}}}, {{-1, 1}, {{5, 1}, {1, 1}, {5, 1}}} }, + { {{{1, 4}, {1, 8}}, {{3, 1}, {4, 8}, {3, 1}}}, {{{1, 4}, {8, 21}}, {{3, 21}, {1, 8}, {3, 21}}} } }; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_ConvertInput, ConvertInput, @@ -94,10 +102,12 @@ const std::vector, std::vector> inputShapes_ConvertPartialInputsAndResults = { - { ov::PartialShape{2, 16}, ov::PartialShape{1, 16}, ov::PartialShape{1, 1} }, - { ov::PartialShape{5, 18}, ov::PartialShape{5, 1}, ov::PartialShape{1, 18} }, - { ov::PartialShape{3, 1}, ov::PartialShape{3, 21}, ov::PartialShape{3, 1} } +const std::vector> inputShapes_ConvertPartialInputsAndResults = { + { {{}, {{2, 16}}}, {{}, {{1, 16}}}, {{}, {{1, 1}}} }, + { {{}, {{5, 18}}}, {{}, {{5, 1}}}, {{}, {{1, 18}}} }, + { {{}, {{3, 1}}}, {{}, {{3, 21}}}, {{}, {{3, 1}}} }, + // DS + { {{-1, -1}, {{3, 1}, {2, 4}, {3, 1}}}, {{{1, 3}, -1}, {{3, 21}, {2, 1}, {3, 21}}}, {{{1, 3}, {1, 2}}, {{3, 1}, {1, 1}, {3, 1}}} }, }; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_ConvertPartialInputsAndResults, ConvertPartialInputsAndResults, @@ -115,9 +125,15 @@ const std::vector, std::vector> inputShapes_ConvertManyOnInputs = { + { {{}, {{5, 5, 5, 5}}} }, + // DS + { {{-1, -1, -1, -1}, {{5, 5, 5, 5}, {3, 3, 3, 3}, {5, 5, 5, 5}}} } +}; + INSTANTIATE_TEST_SUITE_P(smoke_Snippets_ConvertManyOnInputs, ConvertManyOnInputs, ::testing::Combine( - ::testing::Values(std::vector{{5, 5, 5, 5}}), + ::testing::ValuesIn(inputShapes_ConvertManyOnInputs), ::testing::ValuesIn(types_ConvertMany), ::testing::Values(1), ::testing::Values(1), @@ -126,7 +142,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_ConvertManyOnInputs, ConvertManyOnInputs INSTANTIATE_TEST_SUITE_P(smoke_Snippets_ConvertManyOnOutputs, ConvertManyOnOutputs, ::testing::Combine( - ::testing::Values(std::vector{{5, 5, 5, 5}}), + ::testing::ValuesIn(inputShapes_ConvertManyOnInputs), ::testing::ValuesIn(types_ConvertMany), ::testing::Values(1), ::testing::Values(1), @@ -140,7 +156,7 @@ const std::vector, std::vector{{5, 5, 5, 5}}), + ::testing::ValuesIn(inputShapes_ConvertManyOnInputs), ::testing::ValuesIn(types_ConvertManyIO), ::testing::Values(1), ::testing::Values(1), diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/eltwise_two_results.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/eltwise_two_results.cpp index 9756b297efa..b43a17d5b45 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/eltwise_two_results.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/eltwise_two_results.cpp @@ -10,16 +10,25 @@ namespace test { namespace snippets { namespace { -INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, EltwiseTwoResults, +INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise_TwoResults, EltwiseTwoResults, ::testing::Combine( - ::testing::Values(ov::Shape {1, 64, 10, 10}), - ::testing::Values(ov::Shape {1, 64, 10, 1}), + ::testing::Values(InputShape {{}, {{1, 64, 10, 10}}}), + ::testing::Values(InputShape {{}, {{1, 64, 10, 1}}}), ::testing::Values(2), ::testing::Values(2), ::testing::Values(ov::test::utils::DEVICE_CPU)), EltwiseTwoResults::getTestCaseName); -} // namespace +INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise_TwoResults_Dynamic, EltwiseTwoResults, + ::testing::Combine( + ::testing::Values(InputShape {{-1, -1, -1, -1}, {{1, 64, 10, 10}, {2, 8, 2, 1}, {1, 64, 10, 10}}}), + ::testing::Values(InputShape {{{1, 2}, {1, 64}, {1, 10}, 1}, {{1, 64, 10, 1}, {2, 1, 1, 1}, {1, 64, 10, 1}}}), + ::testing::Values(2), + ::testing::Values(2), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + EltwiseTwoResults::getTestCaseName); + +} // namespace } // namespace snippets } // namespace test } // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/max_num_params_eltwise.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/max_num_params_eltwise.cpp index 1d36ad40650..ae9dec5eadc 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/max_num_params_eltwise.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/max_num_params_eltwise.cpp @@ -10,8 +10,19 @@ namespace test { namespace snippets { namespace { // Note that we need these shapes to cover all cases of code emission (none/one/multiple of scalar/vector tiles) -std::vector input_shapes {{1, 64, 10, 10}, {1, 1, 17, 37}, {1, 1, 1, 1}, {1, 1, 1, 7}, - {1, 1, 1, 128}, {1, 1, 1, 14}, {1, 1, 1, 16}, {1, 1, 1, 30}}; +std::vector input_shapes {{{}, {{1, 64, 10, 10}}}, + {{}, {{1, 1, 17, 37}}}, + {{}, {{1, 1, 1, 1}}}, + {{}, {{1, 1, 1, 7}}}, + {{}, {{1, 1, 1, 128}}}, + {{}, {{1, 1, 1, 14}}}, + {{}, {{1, 1, 1, 16}}}, + {{}, {{1, 1, 1, 30}}}, + // DS + {{-1, -1, -1, -1}, {{1, 64, 10, 10}, {1, 1, 17, 37}, {1, 64, 10, 10}}}, + {{1, {1, 64}, {10, 20}, -1}, {{1, 64, 10, 10}, {1, 1, 17, 37}, {1, 64, 10, 10}}}, + {{1, 1, 1, {1, 128}}, {{1, 1, 1, 1}, {1, 1, 1, 7}, {1, 1, 1, 128}, {1, 1, 1, 14}, {1, 1, 1, 16}, {1, 1, 1, 1}}}}; + INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, MaxNumParamsEltwise, ::testing::Combine( ::testing::ValuesIn(input_shapes), @@ -20,7 +31,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, MaxNumParamsEltwise, ::testing::Values(ov::test::utils::DEVICE_CPU)), MaxNumParamsEltwise::getTestCaseName); -} // namespace +} // namespace } // namespace snippets } // namespace test } // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/precision_propagation_convertion.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/precision_propagation_convertion.cpp index e4d57c96740..2bd4c7ddbdf 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/precision_propagation_convertion.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/precision_propagation_convertion.cpp @@ -13,8 +13,11 @@ namespace snippets { namespace { -const std::vector> input_shapes = { - {{ 1, 3, 16, 16 }, { 1, 1, 1, 16 }}, +const std::vector> input_shapes = { + { {{}, {{1, 3, 16, 16}}}, {{}, {{1, 1, 1, 16}}} }, + // DS + { {{-1, -1, -1, -1}, {{1, 3, 16, 16}, {1, 1, 1, 16}, {1, 3, 16, 16}}}, {{-1, -1, -1, -1}, {{1, 3, 16, 16}, {1, 1, 1, 16}, {1, 3, 16, 16}}} }, + { {{1, 16, -1, {1, 16}}, {{1, 16, 32, 1}, {1, 16, 1, 16}, {1, 16, 32, 1}}}, {{1, 1, -1, {1, 20}}, {{1, 1, 1, 16}, {1, 1, 8, 16}, {1, 1, 1, 16}}} } }; const std::vector> fake_quantize_intervals = { diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/select.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/select.cpp index 27720f39b40..9bf27c6be07 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/select.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/select.cpp @@ -12,31 +12,71 @@ namespace snippets { namespace { +//============================Select=======================================// +std::vector inShapes_a{{{}, {{1, 5, 5, 35}}}}; +std::vector inShapes_b{{{}, {{1}}}}; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Select, Select, ::testing::Combine( - ::testing::ValuesIn({ov::Shape{1, 5, 5, 35}, }), - ::testing::ValuesIn({ov::Shape{1, 5, 5, 35}, }), - ::testing::ValuesIn({ov::Shape{1}}), + ::testing::ValuesIn(inShapes_a), + ::testing::ValuesIn(inShapes_a), + ::testing::ValuesIn(inShapes_b), ::testing::ValuesIn({ov::element::f32, ov::element::i8}), ::testing::Values(1), ::testing::Values(1), ::testing::Values(ov::test::utils::DEVICE_CPU)), Select::getTestCaseName); +// DS +std::vector inShapesDynamic_a{{{1, {1, 5}, -1, 35}, {{1, 5, 5, 35}, {1, 1, 1, 35}, {1, 5, 5, 35}}}}; +std::vector inShapesDynamic_b{{{-1}, {{1}, {1}, {1}}}}; +INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Select_Dynamic, Select, + ::testing::Combine( + ::testing::ValuesIn(inShapesDynamic_a), + ::testing::ValuesIn(inShapesDynamic_a), + ::testing::ValuesIn(inShapesDynamic_b), + ::testing::ValuesIn({ov::element::f32, ov::element::i8}), + ::testing::Values(1), + ::testing::Values(1), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + Select::getTestCaseName); + +//============================BroadcastSelect=======================================// +std::vector inShapes0{{{}, {{1, 8, 2, 1}}}, {{}, {{1, 1, 1, 1}}}}; +std::vector inShapes1{{{}, {{1, 8, 2, 10}}}, {{}, {{1, 8, 2, 1}}}}; +std::vector inShapes2{{{}, {{1, 8, 2, 10}}}, {{}, {{1, 1, 1, 1}}}}; +std::vector inShapes3{{1, 8, 2, 1}, {1, 8, 2, 10}}; + INSTANTIATE_TEST_SUITE_P(smoke_Snippets_BroadcastSelect, BroadcastSelect, ::testing::Combine( - ::testing::ValuesIn({Shape{1, 8, 2, 1}, Shape{1, 1, 1, 1}}), - ::testing::ValuesIn({Shape{1, 8, 2, 10}, Shape{1, 8, 2, 1}}), - ::testing::ValuesIn({Shape{1, 8, 2, 10}, Shape{1, 1, 1, 1}}), - ::testing::ValuesIn({Shape{1, 8, 2, 1}, Shape{1, 8, 2, 10}}), + ::testing::ValuesIn(inShapes0), + ::testing::ValuesIn(inShapes1), + ::testing::ValuesIn(inShapes2), + ::testing::ValuesIn(inShapes3), ::testing::ValuesIn({ov::element::f32, ov::element::i8}), ::testing::Values(1), ::testing::Values(1), ::testing::Values(ov::test::utils::DEVICE_CPU)), BroadcastSelect::getTestCaseName); +// DS +std::vector inShapes0_d{{{-1, -1, -1, -1}, {{1, 8, 2, 1}, {1, 1, 1, 1}, {1, 8, 2, 1}}}}; +std::vector inShapes1_d{{{1, -1, -1, -1}, {{1, 8, 2, 10}, {1, 8, 2, 10}, {1, 8, 2, 10}}}}; +std::vector inShapes2_d{{{1, {1, 8}, {1, 2}, {1, 10}}, {{1, 8, 2, 10}, {1, 1, 2, 1}, {1, 8, 2, 10}}}}; +std::vector inShapes3_d{{1, 8, 2, 1}, {1, 8, 2, 10}}; -} // namespace +INSTANTIATE_TEST_SUITE_P(smoke_Snippets_BroadcastSelect_Dynamic, BroadcastSelect, + ::testing::Combine( + ::testing::ValuesIn(inShapes0_d), + ::testing::ValuesIn(inShapes1_d), + ::testing::ValuesIn(inShapes2_d), + ::testing::ValuesIn(inShapes3_d), + ::testing::ValuesIn({ov::element::f32, ov::element::i8}), + ::testing::Values(1), + ::testing::Values(1), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + BroadcastSelect::getTestCaseName); + +} // namespace } // namespace snippets } // namespace test } // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/softmax.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/softmax.cpp index 2dfcead2727..11a959b0a70 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/softmax.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/softmax.cpp @@ -12,31 +12,34 @@ namespace snippets { namespace { -const std::vector inputShape = { - ov::Shape{1, 16}, - ov::Shape{1, 32}, - ov::Shape{1, 1}, - ov::Shape{1, 9}, - ov::Shape{1, 17}, - ov::Shape{1, 19}, - ov::Shape{1, 49}, - ov::Shape{1, 50}, - ov::Shape{5, 16}, - ov::Shape{5, 32}, - ov::Shape{5, 1}, - ov::Shape{5, 9}, - ov::Shape{5, 17}, - ov::Shape{5, 19}, - ov::Shape{5, 49}, - ov::Shape{5, 50}, - ov::Shape{1, 3, 128, 128}, - ov::Shape{1, 3, 128, 129}, - ov::Shape{1, 3, 128, 130}, - ov::Shape{1, 3, 128, 1}, - ov::Shape{1, 3, 128, 9}, - ov::Shape{1, 3, 128, 16}, - ov::Shape{1, 3, 128, 17}, - ov::Shape{1, 3, 128, 20}, +const std::vector inputShape = { + {{}, {{1, 16}}}, + {{}, {{1, 32}}}, + {{}, {{1, 1}}}, + {{}, {{1, 9}}}, + {{}, {{1, 17}}}, + {{}, {{1, 19}}}, + {{}, {{1, 49}}}, + {{}, {{1, 50}}}, + {{}, {{5, 16}}}, + {{}, {{5, 32}}}, + {{}, {{5, 1}}}, + {{}, {{5, 9}}}, + {{}, {{5, 17}}}, + {{}, {{5, 19}}}, + {{}, {{5, 49}}}, + {{}, {{5, 50}}}, + {{}, {{1, 3, 128, 128}}}, + {{}, {{1, 3, 128, 129}}}, + {{}, {{1, 3, 128, 130}}}, + {{}, {{1, 3, 128, 1}}}, + {{}, {{1, 3, 128, 9}}}, + {{}, {{1, 3, 128, 16}}}, + {{}, {{1, 3, 128, 17}}}, + {{}, {{1, 3, 128, 20}}}, + // DS + {{-1, -1}, {{1, 16}, {1, 32}, {1, 1}, {1, 9}, {1, 17}, {1, 19}, {1, 49}, {1, 50}, {5, 16}, {1, 16}, {1, 9}}}, + {{-1, -1, -1, -1}, {{1, 3, 128, 128}, {1, 3, 128, 129}, {1, 3, 128, 130}, {1, 3, 128, 1}, {1, 3, 128, 16}, {1, 3, 128, 1}}} }; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Softmax, Softmax, @@ -48,13 +51,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Softmax, Softmax, ::testing::Values(ov::test::utils::DEVICE_CPU)), Softmax::getTestCaseName); -const std::vector> inputShapesPair = { - std::pair{ov::Shape{1, 5, 16, 35}, ov::Shape{1, 5, 16, 35}}, - std::pair{ov::Shape{1, 5, 16, 1}, ov::Shape{1, 5, 16, 35}}, - std::pair{ov::Shape{1, 5, 16, 35}, ov::Shape{1, 5, 1, 1}}, - std::pair{ov::Shape{1, 5, 16, 1}, ov::Shape{1, 5, 16, 1}}, - std::pair{ov::Shape{1, 5, 16, 35}, ov::Shape{1, 5, 1, 35}}, - std::pair{ov::Shape{1, 5, 1, 35}, ov::Shape{1, 5, 1, 35}}, +const std::vector> inputShapesPair = { + {{{}, {{1, 5, 16, 35}}}, {{}, {{1, 5, 16, 35}}}}, + {{{}, {{1, 5, 16, 1}}}, {{}, {{1, 5, 16, 35}}}}, + {{{}, {{1, 5, 16, 35}}}, {{}, {{1, 5, 1, 1}}}}, + {{{}, {{1, 5, 16, 1}}}, {{}, {{1, 5, 16, 1}}}}, + {{{}, {{1, 5, 16, 35}}}, {{}, {{1, 5, 1, 35}}}}, + {{{}, {{1, 5, 1, 35}}}, {{}, {{1, 5, 1, 35}}}}, + // DS + {{{-1, -1, -1, -1}, {{1, 5, 16, 35}, {1, 5, 16, 1}, {1, 5, 16, 35}}}, {{-1, -1, -1, -1}, {{1, 5, 16, 35}, {1, 5, 16, 35}, {1, 5, 16, 35}}}}, + {{{-1, {1, 8}, {1, 16}, {1, 16}}, {{1, 3, 1, 8}, {1, 8, 16, 16}, {1, 3, 1, 8}}}, {{-1, {1, 8}, -1, {1, 8}}, {{1, 3, 2, 8}, {2, 1, 1, 1}, {1, 3, 2, 8}}}} }; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_AddSoftmax, AddSoftmax, diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/three_inputs_eltwise.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/three_inputs_eltwise.cpp index 38feacd6101..6026263ca95 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/three_inputs_eltwise.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/three_inputs_eltwise.cpp @@ -12,15 +12,25 @@ namespace { INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, ThreeInputsEltwise, ::testing::Combine( - ::testing::Values(ov::Shape {1, 64, 10, 10}), - ::testing::Values(ov::Shape {1, 64, 10, 1}), - ::testing::Values(ov::Shape {1, 1, 1, 10}), + ::testing::Values(InputShape {{}, {{1, 64, 10, 10}}}), + ::testing::Values(InputShape {{}, {{1, 64, 10, 1}}}), + ::testing::Values(InputShape {{}, {{1, 1, 1, 10}}}), ::testing::Values(1), // eltwises fuse only for non-broadcasted shapes ::testing::Values(1), ::testing::Values(ov::test::utils::DEVICE_CPU)), ThreeInputsEltwise::getTestCaseName); -} // namespace +// DS +INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise_Dynamic, ThreeInputsEltwise, + ::testing::Combine( + ::testing::Values(InputShape {{-1, -1, -1, -1}, {{1, 64, 10, 10}, {2, 3, 1, 8}, {1, 64, 10, 10}}}), + ::testing::Values(InputShape {{1, -1, {1, 10}, 1}, {{1, 64, 10, 1}, {1, 3, 2, 1}, {1, 64, 10, 1}}}), + ::testing::Values(InputShape {{1, 1, 1, {1, 10}}, {{1, 1, 1, 10}, {1, 1, 1, 8}, {1, 1, 1, 10}}}), + ::testing::Values(1), // eltwises fuse only for non-broadcasted shapes + ::testing::Values(1), + ::testing::Values(ov::test::utils::DEVICE_CPU)), + ThreeInputsEltwise::getTestCaseName); +} // namespace } // namespace snippets } // namespace test } // namespace ov \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/two_inputs_and_outputs.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/two_inputs_and_outputs.cpp index 71dc5fa71ee..ea94a878950 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/two_inputs_and_outputs.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/two_inputs_and_outputs.cpp @@ -10,24 +10,32 @@ namespace test { namespace snippets { namespace { -const std::vector> input_shapes = { - { {5, 5, 256, 1}, {5, 5, 256, 1} }, - { {5, 5, 16, 35}, {5, 5, 16, 35} }, - { {5, 5, 256, 1}, {5, 5, 256, 35} }, - { {5, 5, 256, 1}, {5, 5, 1, 1} }, +const std::vector> input_shapes = { + { {{}, {{5, 5, 256, 1}}}, {{}, {{5, 5, 256, 1}}} }, + { {{}, {{5, 5, 16, 35}}}, {{}, {{5, 5, 16, 35}}} }, + { {{}, {{5, 5, 256, 1}}}, {{}, {{5, 5, 256, 35}}} }, + { {{}, {{5, 5, 256, 1}}}, {{}, {{5, 5, 1, 1}}} }, - { {5, 5, 16, 35}, {5, 5, 1, 1} }, - { {5, 5, 16, 35}, {5, 5, 16, 1} }, - { {5, 5, 5, 35}, {5, 5, 1, 35} }, - { {5, 5, 16, 1}, {5, 5, 1, 35} }, + { {{}, {{5, 5, 16, 35}}}, {{}, {{5, 5, 1, 1}}} }, + { {{}, {{5, 5, 16, 35}}}, {{}, {{5, 5, 16, 1}}} }, + { {{}, {{5, 5, 5, 35}}}, {{}, {{5, 5, 1, 35}}} }, + { {{}, {{5, 5, 16, 1}}}, {{}, {{5, 5, 1, 35}}} }, - { {5, 5, 35, 16}, {5, 5, 35, 16} }, - { {5, 5, 35, 16}, {5, 5, 1, 16} }, + { {{}, {{5, 5, 35, 16}}}, {{}, {{5, 5, 35, 16}}} }, + { {{}, {{5, 5, 35, 16}}}, {{}, {{5, 5, 1, 16}}} }, - { {5, 5, 35, 17}, {5, 5, 35, 17} }, - { {5, 5, 35, 17}, {5, 5, 1, 17} }, - { {5, 5, 35, 18}, {5, 5, 35, 18} }, - { {5, 5, 35, 18}, {5, 5, 1, 18} }, + { {{}, {{5, 5, 35, 17}}}, {{}, {{5, 5, 35, 17}}} }, + { {{}, {{5, 5, 35, 17}}}, {{}, {{5, 5, 1, 17}}} }, + { {{}, {{5, 5, 35, 18}}}, {{}, {{5, 5, 35, 18}}} }, + { {{}, {{5, 5, 35, 18}}}, {{}, {{5, 5, 1, 18}}} }, + + // DS + { {{-1, -1, -1, -1}, {{5, 5, 256, 1}, {3, 3, 8, 15}, {5, 5, 256, 1}}}, + {{-1, -1, -1, -1}, {{5, 5, 256, 1}, {1, 1, 8, 1}, {5, 5, 256, 1}}} }, + { {{{1, 5}, {2, 6}, {3, 7}, {4, 8}}, {{1, 2, 3, 4}, {5, 6, 7, 8}, {1, 2, 3, 4}}}, + {{1, 1, 1, -1}, {{1, 1, 1, 4}, {1, 1, 1, 8}, {1, 1, 1, 4}}} }, + { {{1, -1, {1, 10}, {4, 12}}, {{1, 5, 3, 4}, {1, 10, 8, 12}, {1, 5, 3, 4}}}, + {{1, 1, -1, {1, 12}}, {{1, 1, 3, 1}, {1, 1, 8, 12}, {1, 1, 3, 1}}} } }; INSTANTIATE_TEST_SUITE_P(smoke_Snippets_Eltwise, TwoInputsAndOutputs, diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/eltwise.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/eltwise.cpp index f7d4845a989..3595284e847 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/eltwise.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/eltwise.cpp @@ -7,6 +7,7 @@ #include "openvino/core/type/element_type.hpp" #include "openvino/runtime/properties.hpp" #include "test_utils/cpu_test_utils.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" using namespace InferenceEngine; using namespace CPUTestUtils; @@ -19,13 +20,15 @@ std::string EltwiseLayerCPUTest::getTestCaseName(testing::TestParamInfo( basicParamsSet, 0)); result << CPUTestsBase::getTestCaseName(cpuParams); result << CpuTestWithFusing::getTestCaseName(fusingParams); + result << "_enforceSnippets=" << enforceSnippets; return result.str(); } @@ -78,7 +81,8 @@ void EltwiseLayerCPUTest::SetUp() { subgraph::EltwiseTestParams basicParamsSet; CPUSpecificParams cpuParams; fusingSpecificParams fusingParams; - std::tie(basicParamsSet, cpuParams, fusingParams) = this->GetParam(); + bool enforceSnippets; + std::tie(basicParamsSet, cpuParams, fusingParams, enforceSnippets) = this->GetParam(); std::vector shapes; ElementType netType; ngraph::helpers::InputLayerType secondaryInputType; @@ -126,6 +130,13 @@ void EltwiseLayerCPUTest::SetUp() { } #endif + if (enforceSnippets) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } else { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::DISABLE}); + } ov::ParameterVector parameters{std::make_shared(netType, inputDynamicShapes.front())}; std::shared_ptr secondaryInput; if (secondaryInputType == ngraph::helpers::InputLayerType::PARAMETER) { @@ -426,5 +437,10 @@ const std::vector& cpuParams_5D_1D_constant() { return cpuParams_5D_1D_constant; } +const std::vector& enforceSnippets() { + static const std::vector enforceSnippets = { false, true }; + return enforceSnippets; +} + } // namespace Eltwise } // namespace CPULayerTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/eltwise.hpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/eltwise.hpp index 59cb82ba593..3b17539e611 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/eltwise.hpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/classes/eltwise.hpp @@ -20,7 +20,8 @@ namespace CPULayerTestsDefinitions { typedef std::tuple< subgraph::EltwiseTestParams, CPUSpecificParams, - fusingSpecificParams> EltwiseLayerCPUTestParamsSet; + fusingSpecificParams, + bool> EltwiseLayerCPUTestParamsSet; class EltwiseLayerCPUTest : public testing::WithParamInterface, virtual public SubgraphBaseTest, public CPUTestUtils::CpuTestWithFusing { @@ -67,5 +68,7 @@ const std::vector& cpuParams_5D_1D_parameter(); const std::vector& eltwiseOpTypesI32(); +const std::vector& enforceSnippets(); + } // namespace Eltwise } // namespace CPULayerTestsDefinitions diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/eltwise.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/eltwise.cpp index c6a05e524c7..bf61d07e289 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/eltwise.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/common/eltwise.cpp @@ -27,7 +27,8 @@ const auto params_4D = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_MemOrder, EltwiseLayerCPUTest, params_4D, EltwiseLayerCPUTest::getTestCaseName); @@ -43,7 +44,8 @@ const auto params_4D_emptyCPUSpec = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::Values(emptyCPUSpec), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_emptyCPUSpec, EltwiseLayerCPUTest, params_4D_emptyCPUSpec, EltwiseLayerCPUTest::getTestCaseName); @@ -59,7 +61,8 @@ const auto params_5D = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_MemOrder, EltwiseLayerCPUTest, params_5D, EltwiseLayerCPUTest::getTestCaseName); @@ -75,7 +78,8 @@ const auto params_5D_emptyCPUSpec = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::Values(emptyCPUSpec), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D, EltwiseLayerCPUTest, params_5D_emptyCPUSpec, EltwiseLayerCPUTest::getTestCaseName); @@ -91,7 +95,8 @@ const auto params_4D_1D_constant_mode = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_1D_Constant_mode())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_1D_Constant, EltwiseLayerCPUTest, params_4D_1D_constant_mode, EltwiseLayerCPUTest::getTestCaseName); @@ -107,7 +112,8 @@ const auto params_4D_1D_parameter_mode = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_1D_Parameter_mode())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_1D_Parameter, EltwiseLayerCPUTest, params_4D_1D_parameter_mode, EltwiseLayerCPUTest::getTestCaseName); @@ -123,7 +129,8 @@ const auto params_5D_1D_constant = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_1D_constant())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_1D_Constant, EltwiseLayerCPUTest, params_5D_1D_constant, EltwiseLayerCPUTest::getTestCaseName); @@ -139,7 +146,8 @@ const auto params_5D_1D_parameter = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_1D_parameter())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_1D_Parameter, EltwiseLayerCPUTest, params_5D_1D_parameter, EltwiseLayerCPUTest::getTestCaseName); @@ -155,7 +163,8 @@ const auto params_4D_dyn_const = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_MemOrder_dyn_const, EltwiseLayerCPUTest, params_4D_dyn_const, EltwiseLayerCPUTest::getTestCaseName); @@ -171,7 +180,8 @@ const auto params_4D_dyn_param = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_MemOrder_dyn_param, EltwiseLayerCPUTest, params_4D_dyn_param, EltwiseLayerCPUTest::getTestCaseName); @@ -187,7 +197,8 @@ const auto params_5D_dyn_const = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_MemOrder_dyn_const, EltwiseLayerCPUTest, params_5D_dyn_const, EltwiseLayerCPUTest::getTestCaseName); @@ -203,7 +214,8 @@ const auto params_5D_dyn_param = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::Values(false)); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_MemOrder_dyn_param, EltwiseLayerCPUTest, params_5D_dyn_param, EltwiseLayerCPUTest::getTestCaseName); diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/eltwise.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/eltwise.cpp index 7e988d59dc1..47a4dd77b2d 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/eltwise.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/instances/x64/eltwise.cpp @@ -167,7 +167,8 @@ const auto params_4D_Blocked_Blocked = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Blocked_Blocked())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_MemOrder_Blocked_Blocked, EltwiseLayerCPUTest, params_4D_Blocked_Blocked, EltwiseLayerCPUTest::getTestCaseName); @@ -184,7 +185,8 @@ const auto params_4D_fusing = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D())), - ::testing::ValuesIn(fusingParamsSet_x64)); + ::testing::ValuesIn(fusingParamsSet_x64), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Fusing, EltwiseLayerCPUTest, params_4D_fusing, EltwiseLayerCPUTest::getTestCaseName); @@ -200,7 +202,8 @@ const auto params_4D_fusing_blocked_blocked = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Blocked_Blocked())), - ::testing::ValuesIn(fusingParamsSet_x64)); + ::testing::ValuesIn(fusingParamsSet_x64), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Fusing_Blocked_Blocked, EltwiseLayerCPUTest, params_4D_fusing_blocked_blocked, EltwiseLayerCPUTest::getTestCaseName); @@ -217,7 +220,8 @@ const auto params_4D_blocked_blocked_fusing = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Blocked_Blocked())), - ::testing::ValuesIn(fusingParamsSet_x64)); + ::testing::ValuesIn(fusingParamsSet_x64), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Blocked_Blocked_Fusing, EltwiseLayerCPUTest, params_4D_blocked_blocked_fusing, EltwiseLayerCPUTest::getTestCaseName); @@ -234,7 +238,8 @@ const auto params_4D_emptyCPUSpec = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::Values(emptyCPUSpec), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_emptyCPUSpec_x64, EltwiseLayerCPUTest, params_4D_emptyCPUSpec, EltwiseLayerCPUTest::getTestCaseName); @@ -250,7 +255,8 @@ const auto params_5D_Blocked_Blocked = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_Blocked_Blocked())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_MemOrder_Blocked_Blocked, EltwiseLayerCPUTest, params_5D_Blocked_Blocked, EltwiseLayerCPUTest::getTestCaseName); @@ -271,7 +277,8 @@ const auto params_5D_emptyCPUSpec_I32 = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::Values(emptyCPUSpec), - ::testing::ValuesIn(fusingParamsSet_I32)); + ::testing::ValuesIn(fusingParamsSet_I32), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_I32, EltwiseLayerCPUTest, params_5D_emptyCPUSpec_I32, EltwiseLayerCPUTest::getTestCaseName); @@ -287,7 +294,8 @@ const auto params_4D_Blocked_Planar = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Blocked_Planar())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Blocked_Planar, EltwiseLayerCPUTest, params_4D_Blocked_Planar, EltwiseLayerCPUTest::getTestCaseName); @@ -303,7 +311,8 @@ const auto params_4D_Planar_Blocked = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Planar_Blocked())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Planar_Blocked, EltwiseLayerCPUTest, params_4D_Planar_Blocked, EltwiseLayerCPUTest::getTestCaseName); @@ -319,7 +328,8 @@ const auto params_5D_Blocked_Planar = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_Blocked_Planar())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_Blocked_Planar, EltwiseLayerCPUTest, params_5D_Blocked_Planar, EltwiseLayerCPUTest::getTestCaseName); @@ -335,7 +345,8 @@ const auto params_5D_Planar_Blocked = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_Planar_Blocked())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_Planar_Blocked_x64, EltwiseLayerCPUTest, params_5D_Planar_Blocked, EltwiseLayerCPUTest::getTestCaseName); @@ -351,7 +362,8 @@ const auto params_4D_1D_constant_mode = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_1D_Constant_mode_x64())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_1D_Constant_x64, EltwiseLayerCPUTest, params_4D_1D_constant_mode, EltwiseLayerCPUTest::getTestCaseName); @@ -367,7 +379,8 @@ const auto params_4D_1D_parameter_mode = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_1D_Parameter_mode())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_1D_Parameter_x64, EltwiseLayerCPUTest, params_4D_1D_parameter_mode, EltwiseLayerCPUTest::getTestCaseName); @@ -383,7 +396,8 @@ const auto params_5D_1D_constant = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_1D_constant())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_1D_Constant_x64, EltwiseLayerCPUTest, params_5D_1D_constant, EltwiseLayerCPUTest::getTestCaseName); @@ -399,7 +413,8 @@ const auto params_5D_1D_parameter = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_1D_parameter())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_1D_Parameter_x64, EltwiseLayerCPUTest, params_5D_1D_parameter, EltwiseLayerCPUTest::getTestCaseName); @@ -417,7 +432,8 @@ const auto params_4D_dyn_const = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_MemOrder_dyn_const_x64, EltwiseLayerCPUTest, params_4D_dyn_const, EltwiseLayerCPUTest::getTestCaseName); @@ -433,7 +449,8 @@ const auto params_4D_blocked_blocked_dyn_const = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Blocked_Blocked())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Blocked_Blocked_MemOrder_dyn_const_x64, EltwiseLayerCPUTest, params_4D_blocked_blocked_dyn_const, EltwiseLayerCPUTest::getTestCaseName); @@ -450,7 +467,8 @@ const auto params_4D_dyn_param = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_MemOrder_dyn_param_x64, EltwiseLayerCPUTest, params_4D_dyn_param, EltwiseLayerCPUTest::getTestCaseName); @@ -466,7 +484,8 @@ const auto params_4D_blocked_blocked_dyn_param = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Blocked_Blocked())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_Blocked_Blocked_MemOrder_dyn_param_x64, EltwiseLayerCPUTest, params_4D_blocked_blocked_dyn_param, EltwiseLayerCPUTest::getTestCaseName); @@ -483,7 +502,8 @@ const auto params_4D_dyn_param_fusing = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D())), - ::testing::ValuesIn(fusingParamsSet_x64)); + ::testing::ValuesIn(fusingParamsSet_x64), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_dyn_param_fusing, EltwiseLayerCPUTest, params_4D_dyn_param_fusing, EltwiseLayerCPUTest::getTestCaseName); @@ -499,7 +519,8 @@ const auto params_4D_dyn_param_fusing_Blocked_Blocked = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Blocked_Blocked())), - ::testing::ValuesIn(fusingParamsSet_x64)); + ::testing::ValuesIn(fusingParamsSet_x64), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_dyn_param_fusing_Blocked_Blocked, EltwiseLayerCPUTest, params_4D_dyn_param_fusing_Blocked_Blocked, EltwiseLayerCPUTest::getTestCaseName); @@ -516,7 +537,8 @@ const auto params_4D_blocked_blocked_dyn_param_fusing = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D_Blocked_Blocked())), - ::testing::ValuesIn(fusingParamsSet_x64)); + ::testing::ValuesIn(fusingParamsSet_x64), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_4D_blocked_blocked_dyn_param_fusing, EltwiseLayerCPUTest, params_4D_blocked_blocked_dyn_param_fusing, EltwiseLayerCPUTest::getTestCaseName); @@ -535,7 +557,8 @@ const auto params_5D_dyn_const_Blocked_Blocked = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_Blocked_Blocked())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_MemOrder_dyn_const_Blocked_Blocked, EltwiseLayerCPUTest, params_5D_dyn_const_Blocked_Blocked, EltwiseLayerCPUTest::getTestCaseName); @@ -552,7 +575,8 @@ const auto params_5D_dyn_param_Blocked_Blocked = ::testing::Combine( ::testing::Values(ov::test::utils::DEVICE_CPU), ::testing::ValuesIn(additional_config())), ::testing::ValuesIn(filterCPUSpecificParams(cpuParams_5D_Blocked_Blocked())), - ::testing::Values(emptyFusingSpec)); + ::testing::Values(emptyFusingSpec), + ::testing::ValuesIn(enforceSnippets())); INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_5D_MemOrder_dyn_param_Blocked_Blocked, EltwiseLayerCPUTest, params_5D_dyn_param_Blocked_Blocked, EltwiseLayerCPUTest::getTestCaseName); diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/select.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/select.cpp index eda55181ff6..ec1c3289a6c 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/select.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/select.cpp @@ -86,7 +86,7 @@ protected: TEST_P(SelectLayerCPUTest, CompareWithRefs) { run(); - CheckPluginRelatedResults(compiledModel, "Eltwise"); + CheckPluginRelatedResults(compiledModel, std::set{"Eltwise", "Subgraph"}); } const std::vector precisions = { diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/conv_sum_broadcast.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/conv_sum_broadcast.cpp index c33cd1aa784..8dde75cd890 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/conv_sum_broadcast.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/conv_sum_broadcast.cpp @@ -8,6 +8,7 @@ #include "shared_test_classes/base/ov_subgraph.hpp" #include "ngraph_functions/utils/ngraph_helpers.hpp" #include "ngraph_functions/builders.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" using namespace CPUTestUtils; using namespace InferenceEngine; @@ -127,6 +128,11 @@ public: function = makeNgraphFunction(getNetType(), inputParams, sum, "ConvolutionSumBroadcast"); targetDevice = ov::test::utils::DEVICE_CPU; + + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::DISABLE}); + } } protected: 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 898be51eb21..4d8fe623c4e 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 @@ -13,6 +13,7 @@ #include #include "test_utils/cpu_test_utils.hpp" #include +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" using namespace CPUTestUtils; using namespace ov::test; @@ -205,6 +206,11 @@ protected: std::tie(inputShapes, data_et, idces_et, k) = this->GetParam(); 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}); + } } }; diff --git a/src/tests/functional/plugin/shared/include/snippets/add.hpp b/src/tests/functional/plugin/shared/include/snippets/add.hpp index 1895d204df6..399c6c3bc8b 100644 --- a/src/tests/functional/plugin/shared/include/snippets/add.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/add.hpp @@ -11,8 +11,8 @@ namespace test { namespace snippets { typedef std::tuple< - ov::Shape, // Input 0 Shape - ov::Shape, // Input 1 Shape + InputShape, // Input 0 Shape + InputShape, // Input 1 Shape ov::element::Type, // Element type size_t, // Expected num nodes size_t, // Expected num subgraphs @@ -20,21 +20,22 @@ typedef std::tuple< > AddParams; typedef std::tuple< - std::vector, // Input 0, Input 1 Shape - ov::element::Type, // Element type - size_t, // Expected num nodes - size_t, // Expected num subgraphs - std::string // Target Device -> AddParamsPair; - -typedef std::tuple< - ov::Shape, // Input 0 Shape + InputShape, // Input 0 Shape + PartialShape, // const shape ov::element::Type, // Element type size_t, // Expected num nodes size_t, // Expected num subgraphs std::string // Target Device > AddConstParams; +typedef std::tuple< + std::vector, // Input 0, Input 1 Shape + ov::element::Type, // Element type + size_t, // Expected num nodes + size_t, // Expected num subgraphs + std::string // Target Device +> AddParamsPair; + class Add : public testing::WithParamInterface, virtual public ov::test::SnippetsTestsCommon { public: @@ -57,7 +58,6 @@ protected: void SetUp() override; }; -// repack AddPair input shapes into shape vector to cover some cases easier class AddPair : public testing::WithParamInterface, virtual public ov::test::SnippetsTestsCommon { public: diff --git a/src/tests/functional/plugin/shared/include/snippets/check_broadcast.hpp b/src/tests/functional/plugin/shared/include/snippets/check_broadcast.hpp index 1c33792cd32..20009c40114 100644 --- a/src/tests/functional/plugin/shared/include/snippets/check_broadcast.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/check_broadcast.hpp @@ -12,7 +12,7 @@ namespace snippets { class CheckBroadcastTestCaseParams { public: - std::pair input_shapes; + std::pair input_shapes; ov::op::AutoBroadcastSpec broadcast; size_t num_nodes; size_t num_subgraphs; diff --git a/src/tests/functional/plugin/shared/include/snippets/codegen_gelu.hpp b/src/tests/functional/plugin/shared/include/snippets/codegen_gelu.hpp index fb672b16a44..e3e50a14ba8 100644 --- a/src/tests/functional/plugin/shared/include/snippets/codegen_gelu.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/codegen_gelu.hpp @@ -4,15 +4,7 @@ #pragma once -#include -#include -#include -#include - -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "ngraph_functions/utils/ngraph_helpers.hpp" -#include "ngraph_functions/builders.hpp" -// todo: Rewrite this test using Snippets test infrastructure. See add_convert or conv_eltwise for example +#include "shared_test_classes/base/snippets_test_utils.hpp" namespace ov { namespace test { @@ -20,13 +12,14 @@ namespace snippets { typedef std::tuple< ov::element::Type_t, // Network Precision - ov::Shape, // Input Shape, + InputShape, // Input1 Shape, + InputShape, // Input2 Shape, bool, - std::string // Target Device + std::string // Target Device > CodegenGeluParams; class CodegenGelu : public testing::WithParamInterface, -virtual public LayerTestsUtils::LayerTestsCommon { + virtual public ov::test::SnippetsTestsCommon { public: static std::string getTestCaseName(testing::TestParamInfo obj); diff --git a/src/tests/functional/plugin/shared/include/snippets/convert.hpp b/src/tests/functional/plugin/shared/include/snippets/convert.hpp index fe534480fc4..8e3871a77ea 100644 --- a/src/tests/functional/plugin/shared/include/snippets/convert.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/convert.hpp @@ -11,7 +11,7 @@ namespace test { namespace snippets { typedef std::tuple< - std::vector, // InputShapes + std::vector, // InputShapes std::pair, std::vector>, // Input and Output data types for Converts size_t, // Expected num nodes size_t, // Expected num subgraphs diff --git a/src/tests/functional/plugin/shared/include/snippets/eltwise_two_results.hpp b/src/tests/functional/plugin/shared/include/snippets/eltwise_two_results.hpp index 59d3e17e5ac..17a598a3ee9 100644 --- a/src/tests/functional/plugin/shared/include/snippets/eltwise_two_results.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/eltwise_two_results.hpp @@ -11,8 +11,8 @@ namespace test { namespace snippets { typedef std::tuple< - ov::Shape, // Input 0 Shape - ov::Shape, // Input 1 Shape + InputShape, // Input 0 Shape + InputShape, // Input 1 Shape size_t, // Expected num nodes size_t, // Expected num subgraphs std::string // Target Device diff --git a/src/tests/functional/plugin/shared/include/snippets/max_num_params_eltwise.hpp b/src/tests/functional/plugin/shared/include/snippets/max_num_params_eltwise.hpp index 70803a346fa..beaa33127d9 100644 --- a/src/tests/functional/plugin/shared/include/snippets/max_num_params_eltwise.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/max_num_params_eltwise.hpp @@ -11,7 +11,7 @@ namespace test { namespace snippets { typedef std::tuple< - ov::Shape, // Input Shape All shapes are replicated + InputShape, // Input Shape All shapes are replicated size_t, // Expected num nodes size_t, // Expected num subgraphs std::string // Target Device diff --git a/src/tests/functional/plugin/shared/include/snippets/precision_propagation_convertion.hpp b/src/tests/functional/plugin/shared/include/snippets/precision_propagation_convertion.hpp index 3ab24d7cf29..759b89fbd46 100644 --- a/src/tests/functional/plugin/shared/include/snippets/precision_propagation_convertion.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/precision_propagation_convertion.hpp @@ -11,7 +11,7 @@ namespace test { namespace snippets { typedef std::tuple< - std::vector, // Input shapes + std::vector, // Input shapes std::vector, // FakeQuantize intervals size_t, // Expected num nodes size_t, // Expected num subgraphs diff --git a/src/tests/functional/plugin/shared/include/snippets/select.hpp b/src/tests/functional/plugin/shared/include/snippets/select.hpp index e8e15ab97e4..35efecdf90a 100644 --- a/src/tests/functional/plugin/shared/include/snippets/select.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/select.hpp @@ -11,9 +11,9 @@ namespace test { namespace snippets { typedef std::tuple< - ov::Shape, // Input 0 Shape - ov::Shape, // Input 1 Shape - ov::Shape, // Input 2 Shape + InputShape, // Input 0 Shape + InputShape, // Input 1 Shape + InputShape, // Input 2 Shape ov::element::Type, // Element type size_t, // Expected num nodes size_t, // Expected num subgraphs @@ -21,10 +21,10 @@ typedef std::tuple< > SelectParams; typedef std::tuple< - ov::Shape, // Input 0 Shape - ov::Shape, // Input 1 Shape - ov::Shape, // Input 2 Shape - ov::Shape, // Input 3 Shape + InputShape, // Input 0 Shape + InputShape, // Input 1 Shape + InputShape, // Input 2 Shape + ov::PartialShape, // Input 3 Shape ov::element::Type, // Element type size_t, // Expected num nodes size_t, // Expected num subgraphs @@ -53,7 +53,6 @@ protected: void generate_inputs(const std::vector& targetInputStaticShapes) override; }; - } // namespace snippets } // namespace test } // namespace ov diff --git a/src/tests/functional/plugin/shared/include/snippets/softmax.hpp b/src/tests/functional/plugin/shared/include/snippets/softmax.hpp index ca3f77e4319..79a7ddcffde 100644 --- a/src/tests/functional/plugin/shared/include/snippets/softmax.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/softmax.hpp @@ -11,7 +11,7 @@ namespace test { namespace snippets { typedef std::tuple< - ov::Shape, // Input 0 Shape + InputShape, // Input 0 Shape int, // Axis size_t, // Expected num nodes size_t, // Expected num subgraphs @@ -19,7 +19,7 @@ typedef std::tuple< > SoftmaxParams; typedef std::tuple< - std::pair, // Input Shapes + std::pair,// Input Shapes int, // Axis size_t, // Expected num nodes size_t, // Expected num subgraphs diff --git a/src/tests/functional/plugin/shared/include/snippets/three_inputs_eltwise.hpp b/src/tests/functional/plugin/shared/include/snippets/three_inputs_eltwise.hpp index ce1fd7a8b5b..68aff359bac 100644 --- a/src/tests/functional/plugin/shared/include/snippets/three_inputs_eltwise.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/three_inputs_eltwise.hpp @@ -11,23 +11,14 @@ namespace test { namespace snippets { typedef std::tuple< - ov::Shape, // Input 0 Shape - ov::Shape, // Input 1 Shape - ov::Shape, // Input 2 Shape + InputShape, // Input 0 Shape + InputShape, // Input 1 Shape + InputShape, // Input 2 Shape size_t, // Expected num nodes size_t, // Expected num subgraphs std::string // Target Device > ThreeInputsEltwiseParams; -typedef std::tuple< - InputShape, // Input 0 Shape - InputShape, // Input 1 Shape - InputShape, // Input 2 Shape - size_t, // Expected num nodes - size_t, // Expected num subgraphs - std::string // Target Device - > ThreeInputsEltwiseDynamicParams; - class ThreeInputsEltwise : public testing::WithParamInterface, virtual public ov::test::SnippetsTestsCommon { public: diff --git a/src/tests/functional/plugin/shared/include/snippets/two_inputs_and_outputs.hpp b/src/tests/functional/plugin/shared/include/snippets/two_inputs_and_outputs.hpp index ccf908cbfc8..00d0a78f527 100644 --- a/src/tests/functional/plugin/shared/include/snippets/two_inputs_and_outputs.hpp +++ b/src/tests/functional/plugin/shared/include/snippets/two_inputs_and_outputs.hpp @@ -11,7 +11,7 @@ namespace test { namespace snippets { typedef std::tuple< - std::vector, // Input Shape All shapes + std::vector, // Input Shape All shapes size_t, // Expected num nodes size_t, // Expected num subgraphs std::string // Target Device diff --git a/src/tests/functional/plugin/shared/src/snippets/add.cpp b/src/tests/functional/plugin/shared/src/snippets/add.cpp index 1b47c780ef4..e6ad44fb9e9 100644 --- a/src/tests/functional/plugin/shared/src/snippets/add.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/add.cpp @@ -7,21 +7,30 @@ #include "subgraph_simple.hpp" #include "ngraph_functions/builders.hpp" #include "functional_test_utils/skip_tests_config.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" namespace ov { namespace test { namespace snippets { std::string Add::getTestCaseName(testing::TestParamInfo obj) { - ov::Shape inputShapes0, inputShapes1, newInputShapes; + ov::test::InputShape inputShapes0, inputShapes1; ov::element::Type type; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes0, inputShapes1, type, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes0) << "_"; - result << "IS[1]=" << ov::test::utils::vec2str(inputShapes1) << "_"; + result << "IS[0]=" << ov::test::utils::partialShape2str({inputShapes0.first}) << "_"; + result << "TS[0]="; + for (const auto& shape : inputShapes0.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[1]=" << ov::test::utils::partialShape2str({inputShapes1.first}) << "_"; + result << "TS[1]="; + for (const auto& shape : inputShapes1.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } result << "T=" << type << "_"; result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; @@ -30,25 +39,34 @@ std::string Add::getTestCaseName(testing::TestParamInfoGetParam(); - init_input_shapes({{{}, {inputShape0, }}, {{}, {inputShape1, }}}); - - auto f = ov::test::snippets::AddFunction({inputShape0, inputShape1}); + init_input_shapes({inputShape0, inputShape1}); + auto f = ov::test::snippets::AddFunction(inputDynamicShapes); function = f.getOriginal(); setInferenceType(type); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } std::string AddConst::getTestCaseName(testing::TestParamInfo obj) { - ov::Shape inputShapes, newInputShapes; + InputShape inputShapes; + PartialShape constShape; ov::element::Type type; std::string targetDevice; size_t num_nodes, num_subgraphs; - std::tie(inputShapes, type, num_nodes, num_subgraphs, targetDevice) = obj.param; + std::tie(inputShapes, constShape, type, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes) << "_"; + result << "IS[0]=" << ov::test::utils::partialShape2str({inputShapes.first}) << "_"; + result << "TS[0]="; + for (const auto& shape : inputShapes.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS_ConstShape=" << ov::test::utils::partialShape2str({constShape}) << "_"; result << "T=" << type << "_"; result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; @@ -57,29 +75,37 @@ std::string AddConst::getTestCaseName(testing::TestParamInfoGetParam(); - init_input_shapes({{{}, {inputShape, }}}); - - auto f = ov::test::snippets::AddConstFunction({inputShape}); + std::tie(inputShape, constShape, type, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); + init_input_shapes({{inputShape}}); + auto f = ov::test::snippets::AddConstFunction({inputDynamicShapes}, constShape); function = f.getOriginal(); setInferenceType(type); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } void AddRollConst::SetUp() { - ov::Shape inputShape; + InputShape inputShape; + PartialShape constShape; ov::element::Type type; - std::tie(inputShape, type, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes({{{}, {inputShape, }}}); - - auto f = ov::test::snippets::AddRollConstFunction({inputShape}); + std::tie(inputShape, constShape, type, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); + init_input_shapes({inputShape}); + auto f = ov::test::snippets::AddRollConstFunction({inputDynamicShapes}, constShape); function = f.getOriginal(); setInferenceType(type); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } std::string AddPair::getTestCaseName(testing::TestParamInfo obj) { - std::vector input_shapes; + std::vector input_shapes; ov::element::Type type; std::string targetDevice; size_t num_nodes, num_subgraphs; @@ -87,8 +113,16 @@ std::string AddPair::getTestCaseName(testing::TestParamInfo input_shapes; + std::vector input_shapes; ov::element::Type type; std::tie(input_shapes, type, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - std::vector is; - for (const auto& s : input_shapes) { - is.emplace_back(InputShape {{}, {s, }}); - } - init_input_shapes(is); - auto f = ov::test::snippets::AddFunction({input_shapes[0], input_shapes[1]}); + init_input_shapes(input_shapes); + auto f = ov::test::snippets::AddFunction(inputDynamicShapes); function = f.getOriginal(); setInferenceType(type); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } TEST_P(Add, CompareWithRefImpl) { diff --git a/src/tests/functional/plugin/shared/src/snippets/check_broadcast.cpp b/src/tests/functional/plugin/shared/src/snippets/check_broadcast.cpp index 4734e397942..2c0a5bc9e9d 100644 --- a/src/tests/functional/plugin/shared/src/snippets/check_broadcast.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/check_broadcast.cpp @@ -7,6 +7,7 @@ #include "common_test_utils/common_utils.hpp" #include "subgraph_converts.hpp" #include "common_test_utils/ov_tensor_utils.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" namespace ov { namespace test { @@ -49,8 +50,16 @@ std::string CheckBroadcast::getTestCaseName(testing::TestParamInfo -#include -#include -#include - -#include - -#include "common_test_utils/common_utils.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "shared_test_classes/base/layer_test_utils.hpp" -#include "functional_test_utils/blob_utils.hpp" - -#include "ngraph_functions/pass/convert_prc.hpp" - -#include "snippets/codegen_gelu.hpp" - #include -#include +#include "common_test_utils/common_utils.hpp" +#include "snippets/codegen_gelu.hpp" +#include "subgraph_simple.hpp" +#include "ngraph_functions/builders.hpp" +#include "functional_test_utils/skip_tests_config.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" -#include -#include -// todo: Rewrite this test using Snippets test infrastructure. See add_convert or conv_eltwise for example namespace ov { namespace test { namespace snippets { std::string CodegenGelu::getTestCaseName(testing::TestParamInfo obj) { ov::element::Type_t netPrecision; - ov::Shape inputShapes0, newInputShapes; + InputShape inputShapes0, inputShapes1; bool useSubgraph; std::string targetDevice; - std::tie(netPrecision, inputShapes0, useSubgraph, targetDevice) = obj.param; + std::tie(netPrecision, inputShapes0, inputShapes1, useSubgraph, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes0) << "_"; + result << "IS[0]=" << ov::test::utils::partialShape2str({inputShapes0.first}) << "_"; + result << "TS[0]="; + for (const auto& shape : inputShapes0.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[1]=" << ov::test::utils::partialShape2str({inputShapes1.first}) << "_"; + result << "TS[1]="; + for (const auto& shape : inputShapes1.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } result << "netPRC=" << netPrecision << "_"; result << "overSnippet=" << (useSubgraph ? "yes" : "no") << "_"; result << "targetDevice=" << targetDevice; @@ -46,13 +41,15 @@ namespace snippets { // Gelu from bert-large-uncased-whole-word-masking-squad-fp32-onnx-0001 void CodegenGelu::SetUp() { - ov::Shape inputShape0; + InputShape inputShape0, inputShapes1; ov::element::Type_t netPrecision; bool useSubgraph; - std::tie(netPrecision, inputShape0, useSubgraph, targetDevice) = this->GetParam(); + std::tie(netPrecision, inputShape0, inputShapes1, useSubgraph, targetDevice) = this->GetParam(); - auto input0 = std::make_shared(netPrecision, ngraph::Shape{inputShape0}); - auto input1 = std::make_shared(netPrecision, ngraph::Shape{inputShape0}); + init_input_shapes({inputShape0, inputShapes1}); + + auto input0 = std::make_shared(netPrecision, inputDynamicShapes[0]); + auto input1 = std::make_shared(netPrecision, inputDynamicShapes[1]); auto add = std::make_shared(input0, input1); auto gelu = std::make_shared(add); @@ -67,10 +64,14 @@ namespace snippets { ov::pass::InitNodeInfo().run_on_model(function); ngraph::pass::ConstantFolding().run_on_model(function); } + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } TEST_P(CodegenGelu, CompareWithRefImpl) { - Run(); + run(); }; diff --git a/src/tests/functional/plugin/shared/src/snippets/convert.cpp b/src/tests/functional/plugin/shared/src/snippets/convert.cpp index 32f749a9567..af37875d50f 100644 --- a/src/tests/functional/plugin/shared/src/snippets/convert.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/convert.cpp @@ -6,22 +6,27 @@ #include "snippets/convert.hpp" #include "subgraph_converts.hpp" #include "common_test_utils/ov_tensor_utils.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" namespace ov { namespace test { namespace snippets { std::string Convert::getTestCaseName(testing::TestParamInfo obj) { - std::vector inputShape; + std::vector inputShape; std::pair, std::vector> types; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShape, types, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS="; - for (const auto& sh : inputShape) - result << ov::test::utils::vec2str(sh.get_shape()) << "_"; + for (size_t i = 0; i < inputShape.size(); ++i) { + result << "IS[" << i << "]=" << ov::test::utils::partialShape2str({inputShape[i].first}) << "_"; + result << "TS[" << i << "]="; + for (const auto& shape : inputShape[i].second) { + result << ov::test::utils::vec2str(shape) << "_"; + } + } result << "IT=" << ov::test::utils::vec2str(types.first) << "_"; result << "OT=" << ov::test::utils::vec2str(types.second) << "_"; result << "#N=" << num_nodes << "_"; @@ -31,13 +36,17 @@ std::string Convert::getTestCaseName(testing::TestParamInfo inputShape; + std::vector inputShape; std::pair, std::vector> types; std::tie(inputShape, types, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); - auto f = ov::test::snippets::ConvertFunction(inputShape, types.first[0], types.second[0]); + init_input_shapes(inputShape); + auto f = ov::test::snippets::ConvertFunction(inputDynamicShapes, types.first[0], types.second[0]); function = f.getOriginal(); output_type = types.second.front(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } parameters Convert::generate_params_random() const { @@ -84,12 +93,16 @@ void Convert::generate_inputs(const std::vector& targetInputStaticSha } void ConvertInput::SetUp() { - std::vector inputShape; + std::vector inputShape; std::pair, std::vector> types; std::tie(inputShape, types, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); - auto f = ov::test::snippets::ConvertInputFunction(inputShape, types.first[0], types.second[0]); + init_input_shapes(inputShape); + auto f = ov::test::snippets::ConvertInputFunction(inputDynamicShapes, types.first[0], types.second[0]); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } parameters ConvertInput::generate_params_random() const { @@ -123,65 +136,89 @@ parameters ConvertInput::generate_params_random() const { } void ConvertOutput::SetUp() { - std::vector inputShape; + std::vector inputShape; std::pair, std::vector> types; std::tie(inputShape, types, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); + init_input_shapes(inputShape); - auto f = ov::test::snippets::ConvertOutputFunction(inputShape, types.first[0], types.second[0]); + auto f = ov::test::snippets::ConvertOutputFunction(inputDynamicShapes, types.first[0], types.second[0]); function = f.getOriginal(); output_type = types.second.front(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } void ConvertStub::SetUp() { - std::vector inputShape; + std::vector inputShape; std::pair, std::vector> types; std::tie(inputShape, types, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); + init_input_shapes(inputShape); - auto f = ov::test::snippets::ConvertStubFunction(inputShape, types.first[0], types.second[0]); + auto f = ov::test::snippets::ConvertStubFunction(inputDynamicShapes, types.first[0], types.second[0]); function = f.getOriginal(); output_type = types.second.front(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } void ConvertPartialInputsAndResults::SetUp() { - std::vector inputShape; + std::vector inputShape; std::pair, std::vector> types; std::tie(inputShape, types, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); + init_input_shapes(inputShape); - auto f = ov::test::snippets::ConvertPartialInputsAndResultsFunction(inputShape, types.first, types.second); + auto f = ov::test::snippets::ConvertPartialInputsAndResultsFunction(inputDynamicShapes, types.first, types.second); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } void ConvertManyOnInputs::SetUp() { - std::vector inputShape; + std::vector inputShape; std::pair, std::vector> types; std::tie(inputShape, types, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); + init_input_shapes(inputShape); - auto f = ov::test::snippets::ConvertManyOnInputsFunction(inputShape, types.first); + auto f = ov::test::snippets::ConvertManyOnInputsFunction(inputDynamicShapes, types.first); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } void ConvertManyOnOutputs::SetUp() { - std::vector inputShape; + std::vector inputShape; std::pair, std::vector> types; std::tie(inputShape, types, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); + init_input_shapes(inputShape); - auto f = ov::test::snippets::ConvertManyOnOutputsFunction(inputShape, types.first); + auto f = ov::test::snippets::ConvertManyOnOutputsFunction(inputDynamicShapes, types.first); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } void ConvertManyOnInputOutput::SetUp() { - std::vector inputShape; + std::vector inputShape; std::pair, std::vector> types; std::tie(inputShape, types, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); + init_input_shapes(inputShape); - auto f = ov::test::snippets::ConvertManyOnInputOutputFunction(inputShape, types.first, types.second); + auto f = ov::test::snippets::ConvertManyOnInputOutputFunction(inputDynamicShapes, types.first, types.second); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } TEST_P(Convert, CompareWithRefImpl) { diff --git a/src/tests/functional/plugin/shared/src/snippets/eltwise_two_results.cpp b/src/tests/functional/plugin/shared/src/snippets/eltwise_two_results.cpp index 3522f235400..110ebd12588 100644 --- a/src/tests/functional/plugin/shared/src/snippets/eltwise_two_results.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/eltwise_two_results.cpp @@ -5,20 +5,30 @@ #include "common_test_utils/common_utils.hpp" #include "snippets/eltwise_two_results.hpp" #include "subgraph_simple.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" namespace ov { namespace test { namespace snippets { std::string EltwiseTwoResults::getTestCaseName(testing::TestParamInfo obj) { - ov::Shape inputShapes0, inputShapes1; + InputShape inputShapes0, inputShapes1; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes0, inputShapes1, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes0) << "_"; - result << "IS[1]=" << ov::test::utils::vec2str(inputShapes1) << "_"; + result << "IS=" << ov::test::utils::partialShape2str({inputShapes0.first}) << "_" + << ov::test::utils::partialShape2str({inputShapes1.first}) << "_"; + + result << "TS[0]="; + for (const auto& item : inputShapes0.second) { + result << ov::test::utils::vec2str(item) << "_"; + } + result << "TS[1]="; + for (const auto& item : inputShapes1.second) { + result << ov::test::utils::vec2str(item) << "_"; + } result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; result << "targetDevice=" << targetDevice; @@ -26,12 +36,16 @@ std::string EltwiseTwoResults::getTestCaseName(testing::TestParamInfoGetParam(); - init_input_shapes({{{}, {inputShape0, }}, {{}, {inputShape1, }}}); + init_input_shapes({inputShape0, inputShape1}); - auto f = ov::test::snippets::EltwiseTwoResultsFunction({inputShape0, inputShape1}); + auto f = ov::test::snippets::EltwiseTwoResultsFunction({inputDynamicShapes[0], inputDynamicShapes[1]}); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } TEST_P(EltwiseTwoResults, CompareWithRefImpl) { diff --git a/src/tests/functional/plugin/shared/src/snippets/max_num_params_eltwise.cpp b/src/tests/functional/plugin/shared/src/snippets/max_num_params_eltwise.cpp index 0bf3b54f7fc..c176b5d236c 100644 --- a/src/tests/functional/plugin/shared/src/snippets/max_num_params_eltwise.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/max_num_params_eltwise.cpp @@ -5,19 +5,25 @@ #include "common_test_utils/common_utils.hpp" #include "snippets/max_num_params_eltwise.hpp" #include "subgraph_simple.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" namespace ov { namespace test { namespace snippets { std::string MaxNumParamsEltwise::getTestCaseName(testing::TestParamInfo obj) { - ov::Shape inputShapes; + ov::test::InputShape inputShapes; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes) << "_"; + result << "IS[0]=" << ov::test::utils::partialShape2str({inputShapes.first}) << "_"; + result << "TS[0]="; + for (const auto& item : inputShapes.second) { + result << ov::test::utils::vec2str(item) << "_"; + } + result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; result << "targetDevice=" << targetDevice; @@ -25,18 +31,17 @@ std::string MaxNumParamsEltwise::getTestCaseName(testing::TestParamInfoGetParam(); - std::vector expandedShapes(10, inputShape); - std::vector input_shapes; - for (const auto& s : expandedShapes) { - input_shapes.emplace_back(InputShape {{}, {s.get_shape(), }}); - } + std::vector expandedShapes(10, inputShape); + init_input_shapes(expandedShapes); - init_input_shapes(input_shapes); - - auto f = ov::test::snippets::EltwiseMaxNumParamsFunction(expandedShapes); + auto f = ov::test::snippets::EltwiseMaxNumParamsFunction(inputDynamicShapes); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } TEST_P(MaxNumParamsEltwise, CompareWithRefImpl) { diff --git a/src/tests/functional/plugin/shared/src/snippets/precision_propagation_convertion.cpp b/src/tests/functional/plugin/shared/src/snippets/precision_propagation_convertion.cpp index 570fa4b44da..67a91386cf3 100644 --- a/src/tests/functional/plugin/shared/src/snippets/precision_propagation_convertion.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/precision_propagation_convertion.cpp @@ -6,21 +6,27 @@ #include "common_test_utils/common_utils.hpp" #include "precision_propagation_convertion_function.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" namespace ov { namespace test { namespace snippets { std::string PrecisionPropagationConvertion::getTestCaseName(testing::TestParamInfo obj) { - std::vector input_shapes; + std::vector input_shapes; std::vector fake_quantize_intervals; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(input_shapes, fake_quantize_intervals, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - for (size_t i = 0; i < input_shapes.size(); ++i) - result << "IS[" << i << "]=" << input_shapes[i] << "_"; + for (size_t i = 0; i < input_shapes.size(); ++i) { + result << "IS[" << i << "]=" << ov::test::utils::partialShape2str({input_shapes[i].first}) << "_"; + result << "TS[" << i << "}="; + for (const auto& shape : input_shapes[i].second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + } for (size_t i = 0; i < fake_quantize_intervals.size(); ++i) result << "FQ[" << i << "]=" << fake_quantize_intervals[i] << "_"; result << "#N=" << num_nodes << "_"; @@ -30,12 +36,16 @@ std::string PrecisionPropagationConvertion::getTestCaseName(testing::TestParamIn } void PrecisionPropagationConvertion::SetUp() { - std::vector input_shapes; + std::vector input_shapes; std::vector fake_quantize_intervals; std::tie(input_shapes, fake_quantize_intervals, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(input_shapes)); + init_input_shapes(input_shapes); - function = PrecisionPropagationConvertionFunction(input_shapes, ov::element::f32, fake_quantize_intervals).getOriginal(); + function = PrecisionPropagationConvertionFunction(inputDynamicShapes, ov::element::f32, fake_quantize_intervals).getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } TEST_P(PrecisionPropagationConvertion, CompareWithRefImpl) { diff --git a/src/tests/functional/plugin/shared/src/snippets/select.cpp b/src/tests/functional/plugin/shared/src/snippets/select.cpp index 1f101e15165..37911036a85 100644 --- a/src/tests/functional/plugin/shared/src/snippets/select.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/select.cpp @@ -13,11 +13,12 @@ namespace test { namespace snippets { namespace { -void generate_data(std::map, ov::Tensor>& data_inputs, const std::vector>& model_inputs) { +void generate_data(std::map, ov::Tensor>& data_inputs, const std::vector>& model_inputs, + const std::vector& targetInputStaticShapes) { data_inputs.clear(); - auto tensor_bool = ov::test::utils::create_and_fill_tensor(model_inputs[0].get_element_type(), model_inputs[0].get_shape(), 3, -1, 2); - auto tensor0 = ov::test::utils::create_and_fill_tensor(model_inputs[1].get_element_type(), model_inputs[1].get_shape(), 10, -10, 2); - auto tensor1 = ov::test::utils::create_and_fill_tensor(model_inputs[2].get_element_type(), model_inputs[2].get_shape(), 10, 0, 2); + auto tensor_bool = ov::test::utils::create_and_fill_tensor(model_inputs[0].get_element_type(), targetInputStaticShapes[0], 3, -1, 2); + auto tensor0 = ov::test::utils::create_and_fill_tensor(model_inputs[1].get_element_type(), targetInputStaticShapes[1], 10, -10, 2); + auto tensor1 = ov::test::utils::create_and_fill_tensor(model_inputs[2].get_element_type(), targetInputStaticShapes[2], 10, 0, 2); data_inputs.insert({model_inputs[0].get_node_shared_ptr(), tensor_bool}); data_inputs.insert({model_inputs[1].get_node_shared_ptr(), tensor0}); data_inputs.insert({model_inputs[2].get_node_shared_ptr(), tensor1}); @@ -25,16 +26,28 @@ void generate_data(std::map, ov::Tensor>& data_inputs, } // namespace std::string Select::getTestCaseName(testing::TestParamInfo obj) { - ov::Shape inputShapes0, inputShapes1, inputShapes2; + InputShape inputShapes0, inputShapes1, inputShapes2; ov::element::Type type; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes0, inputShapes1, inputShapes2, type, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes0) << "_"; - result << "IS[1]=" << ov::test::utils::vec2str(inputShapes1) << "_"; - result << "IS[2]=" << ov::test::utils::vec2str(inputShapes2) << "_"; + result << "IS[0]=" << ov::test::utils::partialShape2str({inputShapes0.first}) << "_"; + result << "TS[0]="; + for (const auto& shape : inputShapes0.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[1]=" << ov::test::utils::partialShape2str({inputShapes1.first}) << "_"; + result << "TS[1]="; + for (const auto& shape : inputShapes1.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[2]=" << ov::test::utils::partialShape2str({inputShapes2.first}) << "_"; + result << "TS[2]="; + for (const auto& shape : inputShapes2.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } result << "T=" << type << "_"; result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; @@ -43,12 +56,12 @@ std::string Select::getTestCaseName(testing::TestParamInfoGetParam(); - init_input_shapes(static_shapes_to_test_representation({inputShape0, inputShape1, inputShape2})); + init_input_shapes({{inputShape0}, {inputShape1}, {inputShape2}}); - auto f = ov::test::snippets::SelectFunction({inputShape0, inputShape1, inputShape2}); + auto f = ov::test::snippets::SelectFunction(inputDynamicShapes); function = f.getOriginal(); if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { @@ -58,21 +71,34 @@ void Select::SetUp() { } void Select::generate_inputs(const std::vector& targetInputStaticShapes) { - generate_data(inputs, function->inputs()); + generate_data(inputs, function->inputs(), targetInputStaticShapes); } std::string BroadcastSelect::getTestCaseName(testing::TestParamInfo obj) { - ov::Shape inputShapes0, inputShapes1, inputShapes2, broadcastShape; + InputShape inputShapes0, inputShapes1, inputShapes2; + ov::PartialShape broadcastShape; ov::element::Type type; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes0, inputShapes1, inputShapes2, broadcastShape, type, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes0) << "_"; - result << "IS[1]=" << ov::test::utils::vec2str(inputShapes1) << "_"; - result << "IS[2]=" << ov::test::utils::vec2str(inputShapes2) << "_"; - result << "BS=" << ov::test::utils::vec2str(broadcastShape) << "_"; + result << "IS[0]=" << ov::test::utils::partialShape2str({inputShapes0.first}) << "_"; + result << "TS[0]="; + for (const auto& shape : inputShapes0.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[1]=" << ov::test::utils::partialShape2str({inputShapes1.first}) << "_"; + result << "TS[1]="; + for (const auto& shape : inputShapes1.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[2]=" << ov::test::utils::partialShape2str({inputShapes2.first}) << "_"; + result << "TS[2]="; + for (const auto& shape : inputShapes2.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS_Broadcast=" << ov::test::utils::partialShape2str({broadcastShape}) << "_"; result << "T=" << type << "_"; result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; @@ -81,12 +107,13 @@ std::string BroadcastSelect::getTestCaseName(testing::TestParamInfoGetParam(); - init_input_shapes(static_shapes_to_test_representation({inputShape0, inputShape1, inputShape2})); + init_input_shapes({inputShape0, inputShape1, inputShape2}); - auto f = ov::test::snippets::BroadcastSelectFunction({inputShape0, inputShape1, inputShape2}, broadcastShape); + auto f = ov::test::snippets::BroadcastSelectFunction({inputDynamicShapes[0], inputDynamicShapes[1], inputDynamicShapes[2]}, broadcastShape); function = f.getOriginal(); if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { @@ -96,7 +123,7 @@ void BroadcastSelect::SetUp() { } void BroadcastSelect::generate_inputs(const std::vector& targetInputStaticShapes) { - generate_data(inputs, function->inputs()); + generate_data(inputs, function->inputs(), targetInputStaticShapes); } TEST_P(Select, CompareWithRefImpl) { diff --git a/src/tests/functional/plugin/shared/src/snippets/softmax.cpp b/src/tests/functional/plugin/shared/src/snippets/softmax.cpp index f639d172c6d..0a611cdf882 100644 --- a/src/tests/functional/plugin/shared/src/snippets/softmax.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/softmax.cpp @@ -14,14 +14,18 @@ namespace test { namespace snippets { std::string Softmax::getTestCaseName(testing::TestParamInfo obj) { - ov::Shape inputShapes; + InputShape inputShapes; int axis; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes, axis, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS=" << ov::test::utils::vec2str(inputShapes) << "_"; + result << "IS=" << ov::test::utils::partialShape2str({inputShapes.first}) << "_"; + result << "TS="; + for (const auto& shape : inputShapes.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } result << "Axis=" << axis << "_"; result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; @@ -30,12 +34,12 @@ std::string Softmax::getTestCaseName(testing::TestParamInfoGetParam(); - init_input_shapes({{{}, {inputShape, }}}); + init_input_shapes({inputShape}); - auto f = ov::test::snippets::SoftmaxFunction({inputShape}, axis); + auto f = ov::test::snippets::SoftmaxFunction(inputDynamicShapes, axis); function = f.getOriginal(); if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { @@ -45,15 +49,23 @@ void Softmax::SetUp() { } std::string AddSoftmax::getTestCaseName(testing::TestParamInfo obj) { - std::pair inputShapes; + std::pair inputShapes; int axis; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes, axis, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes.first) << "_"; - result << "IS[1]=" << ov::test::utils::vec2str(inputShapes.second) << "_"; + result << "IS[0]=" << ov::test::utils::partialShape2str({inputShapes.first.first}) << "_"; + result << "TS[0]="; + for (const auto& shape : inputShapes.first.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[1]=" << ov::test::utils::partialShape2str({inputShapes.second.first}) << "_"; + result << "TS[1]="; + for (const auto& shape : inputShapes.second.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } result << "Axis=" << axis << "_"; result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; @@ -62,12 +74,12 @@ std::string AddSoftmax::getTestCaseName(testing::TestParamInfo inputShapes; + std::pair inputShapes; int axis; std::tie(inputShapes, axis, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes({{{}, {inputShapes.first, }}, {{}, {inputShapes.second, }}}); + init_input_shapes({inputShapes.first, inputShapes.second}); - auto f = ov::test::snippets::AddSoftmaxFunction({inputShapes.first, inputShapes.second}, axis); + auto f = ov::test::snippets::AddSoftmaxFunction(inputDynamicShapes, axis); function = f.getOriginal(); if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { diff --git a/src/tests/functional/plugin/shared/src/snippets/three_inputs_eltwise.cpp b/src/tests/functional/plugin/shared/src/snippets/three_inputs_eltwise.cpp index 5dc13add6d3..cbf377c0b5f 100644 --- a/src/tests/functional/plugin/shared/src/snippets/three_inputs_eltwise.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/three_inputs_eltwise.cpp @@ -6,22 +6,35 @@ #include "snippets/three_inputs_eltwise.hpp" #include "subgraph_simple.hpp" #include "functional_test_utils/skip_tests_config.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" namespace ov { namespace test { namespace snippets { std::string ThreeInputsEltwise::getTestCaseName(testing::TestParamInfo obj) { - ov::Shape inputShapes0, inputShapes1, inputShapes2; + InputShape inputShapes0, inputShapes1, inputShapes2; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes0, inputShapes1, inputShapes2, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - result << "IS[0]=" << ov::test::utils::vec2str(inputShapes0) << "_"; - result << "IS[1]=" << ov::test::utils::vec2str(inputShapes1) << "_"; - result << "IS[2]=" << ov::test::utils::vec2str(inputShapes2) << "_"; + result << "IS[0]=" << ov::test::utils::partialShape2str({inputShapes0.first}) << "_"; + result << "TS[0]="; + for (const auto& shape : inputShapes0.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[1]=" << ov::test::utils::partialShape2str({inputShapes1.first}) << "_"; + result << "TS[1]="; + for (const auto& shape : inputShapes1.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + result << "IS[2]=" << ov::test::utils::partialShape2str({inputShapes2.first}) << "_"; + result << "TS[2]="; + for (const auto& shape : inputShapes2.second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; result << "targetDevice=" << targetDevice; @@ -29,13 +42,17 @@ std::string ThreeInputsEltwise::getTestCaseName(testing::TestParamInfoGetParam(); - init_input_shapes({{{}, {inputShape0, }}, {{}, {inputShape1, }}, {{}, {inputShape2, }}}); + init_input_shapes({inputShape0, inputShape1, inputShape2}); - auto f = ov::test::snippets::EltwiseThreeInputsFunction({inputShape0, inputShape1, inputShape2}); + auto f = ov::test::snippets::EltwiseThreeInputsFunction(inputDynamicShapes); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } TEST_P(ThreeInputsEltwise, CompareWithRefImpl) { diff --git a/src/tests/functional/plugin/shared/src/snippets/two_inputs_and_outputs.cpp b/src/tests/functional/plugin/shared/src/snippets/two_inputs_and_outputs.cpp index d4121e07924..019a4d6efb9 100644 --- a/src/tests/functional/plugin/shared/src/snippets/two_inputs_and_outputs.cpp +++ b/src/tests/functional/plugin/shared/src/snippets/two_inputs_and_outputs.cpp @@ -5,20 +5,26 @@ #include "common_test_utils/common_utils.hpp" #include "snippets/two_inputs_and_outputs.hpp" #include "subgraph_simple.hpp" +#include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" namespace ov { namespace test { namespace snippets { std::string TwoInputsAndOutputs::getTestCaseName(testing::TestParamInfo obj) { - std::vector inputShapes; + std::vector inputShapes; std::string targetDevice; size_t num_nodes, num_subgraphs; std::tie(inputShapes, num_nodes, num_subgraphs, targetDevice) = obj.param; std::ostringstream result; - for (auto i = 0; i < inputShapes.size(); i++) - result << "IS[" << i << "]=" << ov::test::utils::vec2str(inputShapes[i].get_shape()) << "_"; + for (size_t i = 0; i < inputShapes.size(); ++i) { + result << "IS[" << i << "]=" << ov::test::utils::partialShape2str({inputShapes[i].first}) << "_"; + result << "TS[" << i << "]="; + for (const auto& shape : inputShapes[i].second) { + result << "(" << ov::test::utils::vec2str(shape) << ")_"; + } + } result << "#N=" << num_nodes << "_"; result << "#S=" << num_subgraphs << "_"; result << "targetDevice=" << targetDevice; @@ -26,19 +32,27 @@ std::string TwoInputsAndOutputs::getTestCaseName(testing::TestParamInfo inputShape; + std::vector inputShape; std::tie(inputShape, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); - auto f = ov::test::snippets::TwoInputsAndOutputsFunction(inputShape); + init_input_shapes(inputShape); + auto f = ov::test::snippets::TwoInputsAndOutputsFunction(inputDynamicShapes); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } void TwoInputsAndOutputsWithReversedOutputs::SetUp() { - std::vector inputShape; + std::vector inputShape; std::tie(inputShape, ref_num_nodes, ref_num_subgraphs, targetDevice) = this->GetParam(); - init_input_shapes(static_partial_shapes_to_test_representation(inputShape)); - auto f = ov::test::snippets::TwoInputsAndOutputsWithReversedOutputsFunction(inputShape); + init_input_shapes(inputShape); + auto f = ov::test::snippets::TwoInputsAndOutputsWithReversedOutputsFunction(inputDynamicShapes); function = f.getOriginal(); + if (!configuration.count(InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE)) { + configuration.insert({InferenceEngine::PluginConfigInternalParams::KEY_SNIPPETS_MODE, + InferenceEngine::PluginConfigInternalParams::IGNORE_CALLBACK}); + } } TEST_P(TwoInputsAndOutputs, CompareWithRefImpl) { diff --git a/src/tests/ngraph_helpers/snippets_ngraph_functions/include/subgraph_simple.hpp b/src/tests/ngraph_helpers/snippets_ngraph_functions/include/subgraph_simple.hpp index 47842b5cfe4..2d189952a3e 100644 --- a/src/tests/ngraph_helpers/snippets_ngraph_functions/include/subgraph_simple.hpp +++ b/src/tests/ngraph_helpers/snippets_ngraph_functions/include/subgraph_simple.hpp @@ -36,12 +36,14 @@ protected: // todo: remove Sinh once "no subgraph after input" limitation is relaxed class AddConstFunction : public SnippetsFunctionBase { public: - explicit AddConstFunction(const std::vector& inputShapes) : SnippetsFunctionBase(inputShapes) { + explicit AddConstFunction(const std::vector& inputShapes, const PartialShape& constShape) : + SnippetsFunctionBase(inputShapes), m_const_shape(constShape) { NGRAPH_CHECK(input_shapes.size() == 1, "Got invalid number of input shapes"); - NGRAPH_CHECK(input_shapes[0].is_static(), "This test supports only static shapes"); + NGRAPH_CHECK(m_const_shape.is_static(), "Const shape must be static shape"); } protected: std::shared_ptr initOriginal() const override; + PartialShape m_const_shape; // std::shared_ptr initReference() const override; }; // Function is to check for different model precision @@ -52,11 +54,12 @@ protected: // Add // Result // The function is needed to check different input element types (model precision change) -class AddRollConstFunction : public SnippetsFunctionBase { +class AddRollConstFunction : public AddConstFunction { public: - explicit AddRollConstFunction(const std::vector& inputShapes) : SnippetsFunctionBase(inputShapes) { + explicit AddRollConstFunction(const std::vector& inputShapes, const PartialShape& constShape) : + AddConstFunction(inputShapes, constShape) { NGRAPH_CHECK(input_shapes.size() == 1, "Got invalid number of input shapes"); - NGRAPH_CHECK(input_shapes[0].is_static(), "Only static shapes are supported"); + NGRAPH_CHECK(m_const_shape[0].is_static(), "Const shape must be static shape"); } protected: std::shared_ptr initOriginal() const override; diff --git a/src/tests/ngraph_helpers/snippets_ngraph_functions/src/subgraph_simple.cpp b/src/tests/ngraph_helpers/snippets_ngraph_functions/src/subgraph_simple.cpp index d2e67ad3930..fe427408bd4 100644 --- a/src/tests/ngraph_helpers/snippets_ngraph_functions/src/subgraph_simple.cpp +++ b/src/tests/ngraph_helpers/snippets_ngraph_functions/src/subgraph_simple.cpp @@ -28,16 +28,15 @@ std::shared_ptr AddFunction::initReference() const { } std::shared_ptr AddConstFunction::initOriginal() const { auto data0 = std::make_shared(precision, input_shapes[0]); - const std::vector const_values = ov::test::utils::generate_float_numbers(shape_size(input_shapes[0].get_shape()), -10., 10.); - auto const_data1 = std::make_shared(precision, input_shapes[0].get_shape(), const_values); + const std::vector const_values = ov::test::utils::generate_float_numbers(shape_size(m_const_shape.get_shape()), -10., 10.); + auto const_data1 = std::make_shared(precision, m_const_shape.get_shape(), const_values); auto add = std::make_shared(data0, const_data1); return std::make_shared(NodeVector{add}, ParameterVector{data0}); } std::shared_ptr AddRollConstFunction::initOriginal() const { - const auto input_shape = input_shapes[0].get_shape(); - auto data0 = std::make_shared(precision, input_shape); - const std::vector const_values = ov::test::utils::generate_float_numbers(shape_size(input_shape), -10., 10.); - auto const_data1 = std::make_shared(precision, input_shape, const_values); + auto data0 = std::make_shared(precision, input_shapes[0]); + const std::vector const_values = ov::test::utils::generate_float_numbers(shape_size(m_const_shape.get_shape()), -10., 10.); + auto const_data1 = std::make_shared(precision, m_const_shape.get_shape(), const_values); auto shift = std::make_shared(ov::element::i32, ov::Shape{1}, std::vector{1}); auto axes = std::make_shared(ov::element::i32, ov::Shape{1}, std::vector{0}); auto roll0 = std::make_shared(data0, shift, axes);