From 5e81b116705eed8a17a18dbcb6bebb47de848c40 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Fri, 12 Jan 2024 01:05:33 +0400 Subject: [PATCH] Refactor shared beh tests to API 2.0 --- .../behavior/plugin/hetero_synthetic.cpp | 17 +- .../skip_tests_config.cpp | 2 - .../compiled_model/compiled_model_base.hpp | 13 + .../ov_executable_network/exec_graph_info.hpp | 31 ++ .../behavior/ov_plugin/core_integration.hpp | 12 + .../behavior/ov_plugin/core_threading.hpp | 10 + .../behavior/ov_plugin/hetero_synthetic.hpp | 64 +++ .../ov_executable_network/exec_graph_info.cpp | 431 ++++++++++++++++++ .../behavior/ov_infer_request/io_tensor.cpp | 23 + .../behavior/ov_plugin/hetero_synthetic.cpp | 196 ++++++++ 10 files changed, 789 insertions(+), 10 deletions(-) create mode 100644 src/tests/functional/plugin/shared/include/behavior/ov_plugin/hetero_synthetic.hpp create mode 100644 src/tests/functional/plugin/shared/src/behavior/ov_plugin/hetero_synthetic.cpp diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/plugin/hetero_synthetic.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/plugin/hetero_synthetic.cpp index e767a26ca072ba..c72285d1e5a2f6 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/plugin/hetero_synthetic.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/plugin/hetero_synthetic.cpp @@ -4,7 +4,7 @@ #include -#include "behavior/plugin/hetero_synthetic.hpp" +#include "behavior/ov_plugin/hetero_synthetic.hpp" #include "ov_models/builders.hpp" #include "ov_models/subgraph_builders.hpp" @@ -12,22 +12,23 @@ extern const char * cpu_plugin_file_name; namespace { -using namespace HeteroTests; +using ov::test::behavior::OVHeteroSyntheticTest; +using ov::test::behavior::PluginParameter; // this tests load plugin by library name: this is not available during static linkage #ifndef OPENVINO_STATIC_LIBRARY -INSTANTIATE_TEST_SUITE_P(smoke_SingleMajorNode, HeteroSyntheticTest, +INSTANTIATE_TEST_SUITE_P(smoke_SingleMajorNode, OVHeteroSyntheticTest, ::testing::Combine( ::testing::Values(std::vector{{"CPU0", cpu_plugin_file_name}, {"CPU1", cpu_plugin_file_name}}), - ::testing::ValuesIn(HeteroTests::HeteroSyntheticTest::_singleMajorNodeFunctions)), - HeteroSyntheticTest::getTestCaseName); + ::testing::ValuesIn(OVHeteroSyntheticTest::_singleMajorNodeFunctions)), + OVHeteroSyntheticTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(nightly_RandomMajorNodes, HeteroSyntheticTest, +INSTANTIATE_TEST_SUITE_P(nightly_RandomMajorNodes, OVHeteroSyntheticTest, ::testing::Combine( ::testing::Values(std::vector{{"CPU0", cpu_plugin_file_name}, {"CPU1", cpu_plugin_file_name}}), - ::testing::ValuesIn(HeteroTests::HeteroSyntheticTest::_randomMajorNodeFunctions)), - HeteroSyntheticTest::getTestCaseName); + ::testing::ValuesIn(OVHeteroSyntheticTest::_randomMajorNodeFunctions)), + OVHeteroSyntheticTest::getTestCaseName); #endif // !OPENVINO_STATIC_LIBRARY diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp index 524c8fdee99e27..70d0ee093e2b26 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp @@ -62,8 +62,6 @@ std::vector disabledTestPatterns() { R"(.*KernelCachingSupportCase.*CanCreateCacheDirAndDumpBinariesUnicodePath.*)", #endif R"(.*CachingSupportCase.*GPU.*CompileModelCacheTestBase.*CompareWithRefImpl.*)", - // Looks like the test is targeting CPU plugin and doesn't respect that execution graph may vary from plugin to plugin - R"(.*ExecGraphSerializationTest.*)", // unsupported metrics R"(.*nightly_HeteroAutoBatchOVGetMetricPropsTest.*OVGetMetricPropsTest.*(FULL_DEVICE_NAME_with_DEVICE_ID|AVAILABLE_DEVICES|DEVICE_UUID|OPTIMIZATION_CAPABILITIES|MAX_BATCH_SIZE|DEVICE_GOPS|DEVICE_TYPE|RANGE_FOR_ASYNC_INFER_REQUESTS|RANGE_FOR_STREAMS).*)", // Issue: 111437 diff --git a/src/tests/functional/plugin/shared/include/behavior/compiled_model/compiled_model_base.hpp b/src/tests/functional/plugin/shared/include/behavior/compiled_model/compiled_model_base.hpp index 6692159f296e29..bfbd7437668efb 100644 --- a/src/tests/functional/plugin/shared/include/behavior/compiled_model/compiled_model_base.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/compiled_model/compiled_model_base.hpp @@ -454,6 +454,19 @@ TEST_P(OVCompiledModelBaseTestOptional, CheckExecGraphInfoAfterExecution) { } } +TEST_P(OVCompiledModelBaseTest, CheckExecGraphInfoSerialization) { + auto filePrefix = ov::test::utils::generateTestFilePrefix(); + std::string out_xml_path = filePrefix + ".xml"; + std::string out_bin_path = filePrefix + ".bin"; + + std::shared_ptr runtime_model; + + auto compiled_model = core->compile_model(function, target_device, configuration); + ASSERT_NO_THROW(runtime_model = compiled_model.get_runtime_model()); + ASSERT_NO_THROW(ov::serialize(runtime_model, out_xml_path, out_bin_path)); + ov::test::utils::removeIRFiles(out_xml_path, out_bin_path); +} + TEST_P(OVCompiledModelBaseTest, getInputFromFunctionWithSingleInput) { ov::CompiledModel execNet; diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_executable_network/exec_graph_info.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_executable_network/exec_graph_info.hpp index 4ebcfb1c34beb3..a0e360c596922c 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_executable_network/exec_graph_info.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_executable_network/exec_graph_info.hpp @@ -8,6 +8,7 @@ #include "exec_graph_info.hpp" #include "base/ov_behavior_test_utils.hpp" #include "shared_test_classes/base/ov_subgraph.hpp" +#include "pugixml.hpp" namespace ov { namespace test { @@ -45,6 +46,36 @@ class OVExecGraphUniqueNodeNames : public testing::WithParamInterface fnPtr; }; +class OVExecGraphSerializationTest : public testing::WithParamInterface, + public OVCompiledNetworkTestBase { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + void SetUp() override; + void TearDown() override; + +private: + // walker traverse (DFS) xml document and store layer & data nodes in + // vector which is later used for comparison + struct exec_graph_walker : pugi::xml_tree_walker { + std::vector nodes; + bool for_each(pugi::xml_node &node) override; + }; + + // compare_docs() helper + std::pair compare_nodes(const pugi::xml_node &node1, + const pugi::xml_node &node2); + +protected: + // checks if two exec graph xml's are equivalent: + // - the same count of and nodes + // - the same count of attributes of each node + // - the same name of each attribute (value is not checked, since it can differ + // beetween different devices) + std::pair compare_docs(const pugi::xml_document &doc1, + const pugi::xml_document &doc2); + + std::string m_out_xml_path, m_out_bin_path; +}; } // namespace behavior } // namespace test } // namespace ov diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp index 5f77a7f28d0edc..bc6df2494a9012 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp @@ -518,6 +518,18 @@ TEST_P(OVClassBasicTestP, SetConfigAllNoThrow) { OV_ASSERT_NO_THROW(ie.get_versions(target_device)); } +TEST_P(OVClassBasicTestP, SetGetConfigForTbbTerminateThrows) { + ov::Core ie = createCoreWithTemplate(); + bool value = false; + ASSERT_NO_THROW(ie.set_property({ov::force_tbb_terminate(true)})); + ASSERT_NO_THROW(value = ie.get_property(target_device, ov::force_tbb_terminate)); + ASSERT_TRUE(value); + + ASSERT_NO_THROW(ie.set_property({{ov::force_tbb_terminate(false)}})); + ASSERT_NO_THROW(value = ie.get_property(target_device, ov::force_tbb_terminate)); + ASSERT_FALSE(value); +} + TEST(OVClassBasicTest, smoke_SetConfigHeteroThrows) { ov::Core ie = createCoreWithTemplate(); OV_ASSERT_NO_THROW(ie.set_property(ov::test::utils::DEVICE_HETERO, ov::enable_profiling(true))); diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_threading.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_threading.hpp index bc9d8e9ace2249..56c4e0f9e6230d 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_threading.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_threading.hpp @@ -334,6 +334,16 @@ TEST_P(CoreThreadingTest, smoke_GetVersions) { }); } +// tested function: get_property, UnregisterPlugin +TEST_P(CoreThreadingTest, smoke_GetMetric) { + ov::Core core; + + runParallel([&] () { + core.get_property(target_device, ov::internal::supported_properties); + safePluginUnload(core, target_device); + }); +} + // tested function: set_property for already created plugins TEST_P(CoreThreadingTest, smoke_SetProperty_PluginExists) { ov::Core core; diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/hetero_synthetic.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/hetero_synthetic.hpp new file mode 100644 index 00000000000000..53eac08ca97ded --- /dev/null +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/hetero_synthetic.hpp @@ -0,0 +1,64 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" +#include "ov_models/utils/ov_helpers.hpp" + +namespace ov { +namespace test { +namespace behavior { + +struct PluginParameter { + std::string _name; + std::string _location; +}; + +struct FunctionParameter { + std::unordered_set _majorPluginNodeIds; + std::shared_ptr _function; + bool _dynamic_batch; + uint32_t _seed; +}; + +using OVHeteroSyntheticTestParameters = std::tuple< + std::vector, + FunctionParameter +>; + +class OVHeteroSyntheticTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseStaticTest { +protected: + enum {Plugin, Function}; + + ~OVHeteroSyntheticTest() override = default; + void SetUp() override; + void TearDown() override; + + std::string SetUpAffinity(); + + std::vector _registredPlugins; + +public: + static std::string getTestCaseName(const ::testing::TestParamInfo& obj); + + static std::vector singleMajorNodeFunctions( + const std::vector()>>& builders, bool dynamic_batch = false); + + static std::vector randomMajorNodeFunctions( + const std::vector()>>& builders, bool dynamic_batch = false, uint32_t seed = 0); + + static std::vector _singleMajorNodeFunctions; + static std::vector _randomMajorNodeFunctions; +}; + +} // namespace behavior +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_executable_network/exec_graph_info.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_executable_network/exec_graph_info.cpp index 1e1b93baf5d50d..4c4a6e94d5140e 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_executable_network/exec_graph_info.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_executable_network/exec_graph_info.cpp @@ -353,6 +353,437 @@ TEST_P(OVExecGraphUniqueNodeNames, CheckUniqueNodeNames) { } }; + + + +const char serialize_test_model[] = R"V0G0N( + + + + + + + + 1 + + + + + + + + 1 + + + + + + + 1 + + + 1 + + + + + 1 + + + + + + + 1 + + + 1 + + + + + 1 + + + + + + + 1 + + + 1 + + + + + 1 + + + + + + + + 1 + + + + + + + 1 + + + 1 + + + + + 1 + + + + + + + 1 + + + 1 + + + + + 1 + + + + + + + 1 + + + + + + + + + + + + + + + + + + +)V0G0N"; + +const char expected_serialized_model[] = R"V0G0N( + + + + + + + + 1 + + + + + + + + 1 + + + + + + + + 1 + + + + + + + + 1 + + + 1 + + + + + 1 + + + + + + + + 1 + + + 1 + + + 1 + + + 1 + + + + + 1 + + + + + + + + 1 + + + 1 + + + + + 1 + + + + + + + + 1 + + + + + + + + + + + + + + + + +)V0G0N"; + +const char expected_serialized_model_cpu[] = R"V0G0N( + + + + + + + + 1 + + + + + + + + 1 + + + + + + + + 1 + + + + + + + + 1 + + + 1 + + + 1 + + + 1 + + + + + 1 + + + + + + + + 1 + + + + + + + + + + + + + +)V0G0N"; + + +std::string OVExecGraphSerializationTest::getTestCaseName(testing::TestParamInfo obj) { + std::ostringstream result; + std::string target_device = obj.param; + std::replace(target_device.begin(), target_device.end(), ':', '.'); + result << "TargetDevice=" << target_device; + return result.str(); +} + +void OVExecGraphSerializationTest::SetUp() { + target_device = this->GetParam(); + SKIP_IF_CURRENT_TEST_IS_DISABLED() + APIBaseTest::SetUp(); + + const std::string XML_EXT = ".xml"; + const std::string BIN_EXT = ".bin"; + + std::string filePrefix = ov::test::utils::generateTestFilePrefix(); + + m_out_xml_path = filePrefix + XML_EXT; + m_out_bin_path = filePrefix + BIN_EXT; +} + +void OVExecGraphSerializationTest::TearDown() { + APIBaseTest::TearDown(); + ov::test::utils::removeIRFiles(m_out_xml_path, m_out_bin_path); +} + +bool OVExecGraphSerializationTest::exec_graph_walker::for_each(pugi::xml_node &node) { + std::string node_name{node.name()}; + if (node_name == "layer" || node_name == "data") { + nodes.push_back(node); + } + return true; // continue traversal +} + +std::pair OVExecGraphSerializationTest::compare_nodes(const pugi::xml_node &node1, + const pugi::xml_node &node2) { + // node names must be the same + const std::string node1_name{node1.name()}; + const std::string node2_name{node2.name()}; + if (node1_name != node2_name) { + return {false, "Node name is different: " + node1_name + " != " + node2_name}; + } + + // node attribute count must be the same + const auto attr1 = node1.attributes(); + const auto attr2 = node2.attributes(); + const auto attr1_size = std::distance(attr1.begin(), attr1.end()); + const auto attr2_size = std::distance(attr2.begin(), attr2.end()); + if (attr1_size != attr2_size) { + return {false, "Attribute count is different in <" + node1_name + "> :" + + std::to_string(attr1_size) + " != " + + std::to_string(attr2_size)}; + } + + // every node attribute name must be the same + auto a1 = attr1.begin(); + auto a2 = attr2.begin(); + for (int j = 0; j < attr1_size; ++j, ++a1, ++a2) { + const std::string a1_name{a1->name()}; + const std::string a2_name{a2->name()}; + const std::string a1_value{a1->value()}; + const std::string a2_value{a2->value()}; + if (a1_name != a2_name || (a1_name == "type" && a1_value != a2_value)) { + // TODO: Remove temporary w/a later + if (a1_value == "Output" && a2_value == "Result") { + continue; + } + return {false, "Attributes are different in <" + node1_name + "> : " + + a1_name + "=" + a1_value + " != " + a2_name + + "=" + a2_value}; + } + } + return {true, ""}; +} + +std::pair OVExecGraphSerializationTest::compare_docs(const pugi::xml_document &doc1, + const pugi::xml_document &doc2) { + // traverse document and prepare vector of & nodes to compare + exec_graph_walker walker1, walker2; + doc1.child("net").child("layers").traverse(walker1); + doc2.child("net").child("layers").traverse(walker2); + + // nodes count must be the same + const auto &nodes1 = walker1.nodes; + const auto &nodes2 = walker2.nodes; + if (nodes1.size() != nodes2.size()) { + return {false, "Node count differ: " + std::to_string(nodes1.size()) + + " != " + std::to_string(nodes2.size())}; + } + + // every node must be equivalent + for (int i = 0; i < nodes1.size(); i++) { + const auto res = compare_nodes(nodes1[i], nodes2[i]); + if (res.first == false) { + return res; + } + } + return {true, ""}; +} + +TEST_P(OVExecGraphSerializationTest, ExecutionGraph) { + auto core = utils::PluginCache::get().core(); + auto model = core->read_model(serialize_test_model); + auto compiled_model = core->compile_model(model, target_device); + auto runtime_model = compiled_model.get_runtime_model(); + + ov::serialize(runtime_model, m_out_xml_path, m_out_bin_path); + + pugi::xml_document expected; + pugi::xml_document result; + if (target_device == "CPU" || target_device == "AUTO:CPU" || target_device == "MULTI:CPU") { + ASSERT_TRUE(expected.load_string(expected_serialized_model_cpu)); + } else { + ASSERT_TRUE(expected.load_string(expected_serialized_model)); + } + ASSERT_TRUE(result.load_file(m_out_xml_path.c_str())); + + bool status; + std::string message; + std::tie(status, message) = this->compare_docs(expected, result); + + ASSERT_TRUE(status) << message; +} + } // namespace behavior } // namespace test } // namespace ov diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/io_tensor.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/io_tensor.cpp index c1bfefc2eb2e43..a6e24feebd50a7 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/io_tensor.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/io_tensor.cpp @@ -86,6 +86,29 @@ TEST_P(OVInferRequestIOTensorTest, canSetAndGetOutput) { ASSERT_EQ(output.get_shape(), actual_tensor.get_shape()); } + +TEST_P(OVInferRequestIOTensorTest, getAfterSetInputDoNotChangeInput) { + auto tensor = utils::create_and_fill_tensor(input.get_element_type(), input.get_shape()); + OV_ASSERT_NO_THROW(req.set_tensor(input, tensor)); + ov::Tensor actual_tensor; + ASSERT_NO_THROW(actual_tensor = req.get_tensor(input)); + + ASSERT_EQ(tensor.data(), actual_tensor.data()); + ASSERT_EQ(tensor.get_shape(), actual_tensor.get_shape()); + ASSERT_EQ(tensor.get_element_type(), actual_tensor.get_element_type()); +} + +TEST_P(OVInferRequestIOTensorTest, getAfterSetOutputDoNotChangeOutput) { + auto tensor = utils::create_and_fill_tensor(output.get_element_type(), output.get_shape()); + OV_ASSERT_NO_THROW(req.set_tensor(output, tensor)); + ov::Tensor actual_tensor; + ASSERT_NO_THROW(actual_tensor = req.get_tensor(output)); + + ASSERT_EQ(tensor.data(), actual_tensor.data()); + ASSERT_EQ(tensor.get_shape(), actual_tensor.get_shape()); + ASSERT_EQ(tensor.get_element_type(), actual_tensor.get_element_type()); +} + TEST_P(OVInferRequestIOTensorTest, failToSetTensorWithIncorrectName) { auto tensor = utils::create_and_fill_tensor(input.get_element_type(), input.get_shape()); ASSERT_THROW(req.set_tensor("incorrect_input", tensor), ov::Exception); diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/hetero_synthetic.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/hetero_synthetic.cpp new file mode 100644 index 00000000000000..125735eb476fd1 --- /dev/null +++ b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/hetero_synthetic.cpp @@ -0,0 +1,196 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "behavior/ov_plugin/hetero_synthetic.hpp" + +#include + +#include "common_test_utils/subgraph_builders/split_conv_concat.hpp" +#include "common_test_utils/subgraph_builders/split_multi_conv_concat.hpp" +#include "common_test_utils/subgraph_builders/nested_branch_conv_concat.hpp" +#include "common_test_utils/subgraph_builders/nested_split_conv_concat.hpp" +#include "functional_test_utils/ov_plugin_cache.hpp" +#include "common_test_utils/file_utils.hpp" +#include "openvino/op/util/op_types.hpp" + +namespace ov { +namespace test { +namespace behavior { + +static std::vector()>> builders = { + [] {return ov::test::utils::make_split_multi_conv_concat();}, + [] {return ov::test::utils::make_nested_split_conv_concat();}, + [] {return ov::test::utils::make_cplit_conv_concat_nested_in_branch();}, + [] {return ov::test::utils::make_cplit_conv_concat_nested_in_branch_nested_out();}, + [] {return ov::test::utils::make_nested_branch_conv_concat();}, +}; + +std::string OVHeteroSyntheticTest::getTestCaseName(const ::testing::TestParamInfo& obj) { + std::vector pluginParameters; + FunctionParameter functionParamter; + std::tie(pluginParameters, functionParamter) = obj.param; + std::string name = "function=" + functionParamter._function->get_friendly_name(); + name += "_layers="; + std::size_t num = functionParamter._majorPluginNodeIds.size() - 1; + for (auto&& id : functionParamter._majorPluginNodeIds) { + name += id + ((num !=0) ? "," : ""); + num--; + } + name += "_targetDevice=HETERO:"; + num = pluginParameters.size() - 1; + for (auto&& pluginParameter : pluginParameters) { + name += pluginParameter._name + ((num !=0) ? "," : ""); + num--; + } + return name; +} + +void OVHeteroSyntheticTest::SetUp() { + auto& param = GetParam(); + targetDevice = "HETERO:"; + int num = std::get(param).size() - 1; + + auto core = ov::test::utils::PluginCache::get().core(); + for (auto&& pluginParameter : std::get(param)) { + bool registred = true; + try { + if (pluginParameter._location == "openvino_template_plugin") { + core->register_plugin(ov::util::make_plugin_library_name( + ov::test::utils::getExecutableDirectory(), pluginParameter._location + OV_BUILD_POSTFIX), pluginParameter._name); + } else { + core->register_plugin(pluginParameter._location + OV_BUILD_POSTFIX, pluginParameter._name); + } + } catch (ov::Exception& ex) { + if (std::string{ex.what()}.find("Device with \"" + pluginParameter._name + + "\" is already registered in the OpenVINO Runtime") + == std::string::npos) { + throw ex; + } else { + registred = false; + } + } + if (registred) { + _registredPlugins.push_back(pluginParameter._name); + } + targetDevice += pluginParameter._name; + targetDevice += ((num !=0) ? "," : ""); + --num; + } + function = std::get(param)._function; + if (std::get(param)._dynamic_batch) { + for (auto&& input : function->inputs()) { + auto shape = input.get_partial_shape(); + shape[0] = ov::Dimension(1, 16); + } + } +} + +void OVHeteroSyntheticTest::TearDown() { + auto core = ov::test::utils::PluginCache::get().core(); + for (auto&& pluginName : _registredPlugins) { + core->unload_plugin(pluginName); + } +} + +std::string OVHeteroSyntheticTest::SetUpAffinity() { + auto& param = GetParam(); + std::string affinities; + auto& pluginParameters = std::get(param); + affinities += "\n{\n"; + for (auto&& node : std::get(param)._function->get_ordered_ops()) { + std::string affinity; + auto get_affinity = [&](const std::string& name) { + if (std::get(param)._majorPluginNodeIds.end() != + std::get(param)._majorPluginNodeIds.find(name)) { + return pluginParameters.at(0)._name; + } else { + return pluginParameters.at(1)._name; + } + }; + if (ov::op::util::is_constant(node) || ov::op::util::is_output(node) || ov::op::util::is_parameter(node)) { + auto& node_with_affinity_name = + ov::op::util::is_output(node) + ? node->input_value(0).get_node()->get_friendly_name() + : node->output(0).get_target_inputs().begin()->get_node()->get_friendly_name(); + affinity = get_affinity(node_with_affinity_name); + } else { + affinity = get_affinity(node->get_friendly_name()); + } + node->get_rt_info()["affinity"] = affinity; + affinities += "\t{\"" + node->get_friendly_name() + "\",\t\t\"" + affinity + "\"}\n"; + } + affinities += "}"; + affinities += "\nseed = " + std::to_string(std::get(param)._seed); + return affinities; +} + +TEST_P(OVHeteroSyntheticTest, someLayersToMajorPluginOthersToFallback) { + auto affinities = SetUpAffinity(); + SCOPED_TRACE(affinities); + run(); +} + +std::vector OVHeteroSyntheticTest::singleMajorNodeFunctions( + const std::vector()>>& builders, + bool dynamic_batch) { + std::vector result; + for (auto&& builder : builders) { + auto function = builder(); + for (auto&& node : function->get_ordered_ops()) { + if (!ov::op::util::is_constant(node) && + !(ov::op::util::is_parameter(node)) && + !(ov::op::util::is_output(node))) { + result.push_back(FunctionParameter{{node->get_friendly_name()}, function, dynamic_batch, 0}); + } + } + } + return result; +} + + +std::vector OVHeteroSyntheticTest::randomMajorNodeFunctions( + const std::vector()>>& builders, + bool dynamic_batch, + uint32_t seed) { + std::vector results; + for (auto p = 0.2; p < 1.; p+=0.2) { + while (seed == 0) { + seed = std::random_device {}(); + } + std::mt19937 e{seed}; + std::bernoulli_distribution d{p}; + for (auto&& builder : builders) { + auto function = builder(); + auto ordered_ops = function->get_ordered_ops(); + for (std::size_t i = 0; i < ordered_ops.size(); ++i) { + std::unordered_set majorPluginNodeIds; + for (auto&& node : ordered_ops) { + if (!(ov::op::util::is_constant(node)) && + !(ov::op::util::is_parameter(node)) && + !(ov::op::util::is_output(node)) && d(e)) { + majorPluginNodeIds.emplace(node->get_friendly_name()); + } + } + if (std::any_of(std::begin(results), std::end(results), [&] (const FunctionParameter& param) { + return majorPluginNodeIds == param._majorPluginNodeIds; + })) { + continue; + } + results.push_back(FunctionParameter{majorPluginNodeIds, function, dynamic_batch, seed}); + } + } + } + return results; +} + + +std::vector OVHeteroSyntheticTest::_singleMajorNodeFunctions + = OVHeteroSyntheticTest::singleMajorNodeFunctions(builders); + +std::vector OVHeteroSyntheticTest::_randomMajorNodeFunctions + = OVHeteroSyntheticTest::randomMajorNodeFunctions(builders); + +} // namespace behavior +} // namespace test +} // namespace ov