diff --git a/docs/template_plugin/tests/functional/shared_tests_instances/behavior/ov_exec_network.cpp b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/ov_exec_network.cpp new file mode 100644 index 00000000000..e87a2ead8f3 --- /dev/null +++ b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/ov_exec_network.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "behavior/ov_exec_network.hpp" + +#include "ie_plugin_config.hpp" + +using namespace ov::test; +namespace { +const std::vector netPrecisions = { + ov::element::i8, + ov::element::i16, + ov::element::i32, + ov::element::i64, + ov::element::u8, + ov::element::u16, + ov::element::u32, + ov::element::u64, + ov::element::f16, + ov::element::f32, + }; + +const std::vector> configs = { + {}, +}; +const std::vector> multiConfigs = { + {{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_TEMPLATE}}}; + +INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, + OVExecNetwork, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_TEMPLATE), + ::testing::ValuesIn(configs)), + OVExecNetwork::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests, + OVExecNetwork, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_MULTI), + ::testing::ValuesIn(multiConfigs)), + OVExecNetwork::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, + OVExecNetwork, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(multiConfigs)), + OVExecNetwork::getTestCaseName); +} // namespace diff --git a/inference-engine/src/inference_engine/src/ie_core.cpp b/inference-engine/src/inference_engine/src/ie_core.cpp index 8bc2b23b998..4dfc8f85de1 100644 --- a/inference-engine/src/inference_engine/src/ie_core.cpp +++ b/inference-engine/src/inference_engine/src/ie_core.cpp @@ -42,6 +42,8 @@ using namespace std::placeholders; namespace ov { namespace runtime { +namespace { + template struct Parsed { std::string _deviceName; @@ -118,6 +120,13 @@ ie::Parameter copyParameterValue(const ie::Parameter& value) { return std::move(value); } +ie::CNNNetwork toCNN(const std::shared_ptr& model) { + return ie::CNNNetwork( + std::make_shared(std::const_pointer_cast(model), + std::vector{}, + true)); +} + template void allowNotImplemented(F&& f) { try { @@ -126,6 +135,8 @@ void allowNotImplemented(F&& f) { } } +} // namespace + class CoreImpl : public ie::ICore, public std::enable_shared_from_this { mutable std::map plugins; @@ -180,6 +191,8 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this pluginRegistry; mutable std::mutex pluginsMutex; // to lock parallel access to pluginRegistry and plugins + const bool newAPI; + bool DeviceSupportsImportExport(const std::string& deviceName) const override { auto parsed = parseDeviceNameIntoConfig(deviceName); auto plugin = GetCPPPluginByName(parsed._deviceName); @@ -345,7 +358,7 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this( + cnnNet.getFunction(), + std::vector{}, + newAPI)); } ie::CNNNetwork ReadNetwork(const std::string& model, const ie::Blob::CPtr& weights) const override { OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::IE_RT, "CoreImpl::ReadNetwork from memory"); - return ie::details::ReadNetwork(model, weights, extensions); + auto cnnNet = InferenceEngine::details::ReadNetwork(model, weights, extensions); + OPENVINO_ASSERT(cnnNet.getFunction() || !newAPI, "Cannot read IR v7 from OpenVINO 2.0 API"); + if (!newAPI) + return cnnNet; + + return InferenceEngine::CNNNetwork(std::make_shared( + cnnNet.getFunction(), + std::vector{}, + newAPI)); } // TODO: In future this method can be added to ICore interface @@ -980,7 +1009,10 @@ std::vector DeviceIDParser::getMultiDevices(std::string devicesList return deviceNames; } -class Core::Impl : public ov::runtime::CoreImpl {}; +class Core::Impl : public ov::runtime::CoreImpl { +public: + Impl() : ov::runtime::CoreImpl(false) {} +}; Core::Core(const std::string& xmlConfigFile) { _impl = std::make_shared(); @@ -1244,7 +1276,10 @@ namespace runtime { OPENVINO_ASSERT(false, "Unexpected exception"); \ } -class Core::Impl : public CoreImpl {}; +class Core::Impl : public CoreImpl { +public: + Impl() : ov::runtime::CoreImpl(true) {} +}; Core::Core(const std::string& xmlConfigFile) { _impl = std::make_shared(); @@ -1278,17 +1313,6 @@ std::shared_ptr Core::read_model(const std::string& model, con OV_CORE_CALL_STATEMENT(return _impl->ReadNetwork(model, weights).getFunction();); } -namespace { - -ie::CNNNetwork toCNN(const std::shared_ptr& model) { - return ie::CNNNetwork( - std::make_shared(std::const_pointer_cast(model), - std::vector{}, - true)); -} - -} // namespace - ExecutableNetwork Core::compile_model(const std::shared_ptr& model, const std::string& deviceName, const ConfigMap& config) { @@ -1303,7 +1327,6 @@ ExecutableNetwork Core::compile_model(const std::string& modelPath, const std::string& deviceName, const ConfigMap& config) { OV_CORE_CALL_STATEMENT({ - // TODO: need to pass newAPI flag to preserve conversions of precisions auto exec = _impl->LoadNetwork(modelPath, deviceName, config); return {exec.operator const InferenceEngine::details::SharedObjectLoader&().get(), exec.operator std::shared_ptr&()}; diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_exec_network.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_exec_network.cpp new file mode 100644 index 00000000000..8a046af3a3c --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_exec_network.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "behavior/ov_exec_network.hpp" + +#include "ie_plugin_config.hpp" + +using namespace ov::test; +namespace { +const std::vector netPrecisions = { + ov::element::i8, + ov::element::i16, + ov::element::i32, + ov::element::i64, + ov::element::u8, + ov::element::u16, + ov::element::u32, + ov::element::u64, + ov::element::f16, + ov::element::f32, +}; + +const std::vector> configs = { + {}, +}; +const std::vector> multiConfigs = { + {{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_CPU}}}; + +INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests, + OVExecNetwork, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::ValuesIn(configs)), + OVExecNetwork::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests, + OVExecNetwork, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_MULTI), + ::testing::ValuesIn(multiConfigs)), + OVExecNetwork::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, + OVExecNetwork, + ::testing::Combine(::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(multiConfigs)), + OVExecNetwork::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp index 905f0fef266..0413abde981 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp @@ -91,6 +91,15 @@ std::vector disabledTestPatterns() { R"(.*ReduceOpsLayerTest.*type=Mean_.*netPRC=(I64|I32).*)", R"(.*ReduceOpsLayerTest.*type=Mean_.*netPRC=U64.*)", + // TODO: CVS-66526 overrides i/o precisions in execution graph + R"(.*smoke_BehaviorTests.*OVExecNetwork.*type=(i8|i16).*)", + R"(.*smoke_BehaviorTests.*OVExecNetwork.*type=(i64|u16).*)", + R"(.*smoke_BehaviorTests.*OVExecNetwork.*type=(u32|u64).*)", + R"(.*smoke_BehaviorTests.*OVExecNetwork.*type=f16.*)", + R"(.*smoke_(Auto|Multi)_BehaviorTests.*OVExecNetwork.*type=(i8|u32).*)", + R"(.*smoke_(Auto|Multi)_BehaviorTests.*OVExecNetwork.*type=f16.*)", + R"(.*smoke_(Auto|Multi)_BehaviorTests/OVExecNetwork.*type=i8.*)", + // Issue: 62746 R"(smoke_CachingSupportCase_CPU/LoadNetworkCacheTestBase.CompareWithRefImpl/ReadConcatSplitAssign_f32_batch1_CPU)", }; diff --git a/inference-engine/tests/functional/plugin/shared/include/base/ov_behavior_test_utils.hpp b/inference-engine/tests/functional/plugin/shared/include/base/ov_behavior_test_utils.hpp new file mode 100644 index 00000000000..af114d659c1 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/base/ov_behavior_test_utils.hpp @@ -0,0 +1,227 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include +#include +#include +#include +#include + +#include "common_test_utils/test_common.hpp" +#include "functional_test_utils/ov_plugin_cache.hpp" +#include "functional_test_utils/skip_tests_config.hpp" +#include "ngraph_functions/subgraph_builders.hpp" +#include "openvino/runtime/runtime.hpp" + +namespace ov { +namespace test { + +using BehaviorParamsEmptyConfig = std::tuple; // device + +class BehaviorTestsEmptyConfig : public testing::WithParamInterface, + public CommonTestUtils::TestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + std::string targetDevice; + ov::element::Type elementType; + std::tie(elementType, targetDevice) = obj.param; + std::ostringstream result; + result << "element_type=" << elementType; + result << "targetDevice=" << targetDevice; + return result.str(); + } + + void SetUp() override { + std::tie(elementType, targetDevice) = this->GetParam(); + function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType); + } + + void TearDown() override { + function.reset(); + } + + std::shared_ptr ie = PluginCache::get().core(); + std::shared_ptr function; + std::string targetDevice; + ov::element::Type elementType; +}; + +using BehaviorBasicParams = std::tuple>; // config + +class BehaviorTestsBasic : public testing::WithParamInterface, + public CommonTestUtils::TestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + std::string targetDevice; + ov::element::Type elementType; + std::map configuration; + std::tie(elementType, targetDevice, configuration) = obj.param; + std::ostringstream result; + result << "element_type=" << elementType << "_"; + result << "targetDevice=" << targetDevice << "_"; + if (!configuration.empty()) { + for (auto& configItem : configuration) { + result << "configItem=" << configItem.first << "_" << configItem.second << "_"; + } + } + return result.str(); + } + + void SetUp() override { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + std::tie(elementType, targetDevice, configuration) = this->GetParam(); + function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType); + } + + void TearDown() override { + if (!configuration.empty()) { + PluginCache::get().reset(); + } + function.reset(); + } + + std::shared_ptr ie = PluginCache::get().core(); + std::shared_ptr function; + std::string targetDevice; + std::map configuration; + ov::element::Type elementType; +}; + +using InferRequestParams = std::tuple>; // config + +class InferRequestTests : public testing::WithParamInterface, public CommonTestUtils::TestsCommon { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + std::string targetDevice; + ov::element::Type elementType; + std::map configuration; + std::tie(elementType, targetDevice, configuration) = obj.param; + std::ostringstream result; + result << "element_type=" << elementType; + result << "targetDevice=" << targetDevice << "_"; + if (!configuration.empty()) { + for (auto& configItem : configuration) { + result << "configItem=" << configItem.first << "_" << configItem.second << "_"; + } + } + return result.str(); + } + + void SetUp() override { + // Skip test according to plugin specific disabledTestPatterns() (if any) + SKIP_IF_CURRENT_TEST_IS_DISABLED() + std::tie(elementType, targetDevice, configuration) = this->GetParam(); + function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType); + // Load CNNNetwork to target plugins + execNet = ie->compile_model(function, targetDevice, configuration); + } + + void TearDown() override { + if (!configuration.empty()) { + PluginCache::get().reset(); + } + function.reset(); + } + +protected: + ov::runtime::ExecutableNetwork execNet; + std::shared_ptr ie = PluginCache::get().core(); + std::shared_ptr function; + std::string targetDevice; + std::map configuration; + ov::element::Type elementType; +}; + +using BehaviorParamsSingleOption = std::tuple; // key + +class BehaviorTestsSingleOption : public testing::WithParamInterface, + public CommonTestUtils::TestsCommon { +public: + void SetUp() override { + std::tie(elementType, targetDevice, key) = this->GetParam(); + function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType); + } + + void TearDown() override { + function.reset(); + } + + std::shared_ptr ie = PluginCache::get().core(); + std::shared_ptr function; + std::string targetDevice; + std::string key; + ov::element::Type elementType; +}; + +using BehaviorParamsSingleOptionDefault = + std::tuple // Configuration key and its default value + >; + +class BehaviorTestsSingleOptionDefault : public testing::WithParamInterface, + public CommonTestUtils::TestsCommon { +public: + void SetUp() override { + std::pair entry; + std::tie(elementType, targetDevice, entry) = this->GetParam(); + std::tie(key, value) = entry; + function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType); + } + + void TearDown() override { + function.reset(); + } + + std::shared_ptr ie = PluginCache::get().core(); + std::shared_ptr function; + std::string targetDevice; + std::string key; + InferenceEngine::Parameter value; + ov::element::Type elementType; +}; + +using BehaviorParamsSingleOptionCustom = + std::tuple // Configuration key, value and + // reference + >; + +class BehaviorTestsSingleOptionCustom : public testing::WithParamInterface, + public CommonTestUtils::TestsCommon { +public: + void SetUp() override { + std::tuple entry; + std::tie(elementType, targetDevice, entry) = this->GetParam(); + std::tie(key, value, reference) = entry; + function = ngraph::builder::subgraph::makeConvPoolRelu({1, 1, 32, 32}, elementType); + } + + void TearDown() override { + function.reset(); + } + + std::shared_ptr ie = PluginCache::get().core(); + std::shared_ptr function; + std::string targetDevice; + std::string key; + std::string value; + ov::runtime::Parameter reference; + ov::element::Type elementType; +}; + +} // namespace test +} // namespace ov diff --git a/inference-engine/tests/functional/plugin/shared/include/behavior/ov_exec_network.hpp b/inference-engine/tests/functional/plugin/shared/include/behavior/ov_exec_network.hpp new file mode 100644 index 00000000000..f43edb5f574 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/behavior/ov_exec_network.hpp @@ -0,0 +1,71 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include + +#include "base/ov_behavior_test_utils.hpp" +#include +#include "common_test_utils/test_constants.hpp" +#include "openvino/runtime/runtime.hpp" + +namespace ov { +namespace test { +using OVExecNetwork = ov::test::BehaviorTestsBasic; + +// Load correct network to Plugin to get executable network +TEST_P(OVExecNetwork, precisionsAsInOriginalFunction) { + // Skip test according to plugin specific disabledTestPatterns() (if any) + SKIP_IF_CURRENT_TEST_IS_DISABLED() + ov::runtime::ExecutableNetwork execNet; + ASSERT_NO_THROW(execNet = ie->compile_model(function, targetDevice, configuration)); + + EXPECT_EQ(function->get_parameters().size(), execNet.get_parameters().size()); + auto ref_parameter = function->get_parameters().back(); + auto actual_parameter = execNet.get_parameters().back(); + EXPECT_EQ(ref_parameter->get_element_type(), actual_parameter->get_element_type()); + EXPECT_EQ(ref_parameter->get_shape(), actual_parameter->get_shape()); + EXPECT_EQ(ref_parameter->get_friendly_name(), actual_parameter->get_friendly_name()); + + EXPECT_EQ(function->get_results().size(), execNet.get_results().size()); + auto ref_result = function->get_results().back(); + auto actual_result = execNet.get_results().back(); + EXPECT_EQ(ref_result->get_element_type(), actual_result->get_element_type()); + EXPECT_EQ(ref_result->get_shape(), actual_result->get_shape()); + EXPECT_EQ(ref_result->get_friendly_name(), actual_result->get_friendly_name()); +} + +// Load correct network to Plugin to get executable network +TEST_P(OVExecNetwork, precisionsAsInOriginalIR) { + // Skip test according to plugin specific disabledTestPatterns() (if any) + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + const std::string m_out_xml_path_1 = "precisionsAsInOriginalIR.xml"; + const std::string m_out_bin_path_1 = "precisionsAsInOriginalIR.bin"; + ngraph::pass::Serialize(m_out_xml_path_1, m_out_bin_path_1).run_on_function(function); + + ov::runtime::ExecutableNetwork execNet; + ASSERT_NO_THROW(execNet = ie->compile_model(m_out_xml_path_1, targetDevice, configuration)); + + EXPECT_EQ(function->get_parameters().size(), execNet.get_parameters().size()); + auto ref_parameter = function->get_parameters().back(); + auto actual_parameter = execNet.get_parameters().back(); + EXPECT_EQ(elementType, ref_parameter->get_element_type()); + EXPECT_EQ(ref_parameter->get_element_type(), actual_parameter->get_element_type()); + EXPECT_EQ(ref_parameter->get_shape(), actual_parameter->get_shape()); + EXPECT_EQ(ref_parameter->get_friendly_name(), actual_parameter->get_friendly_name()); + + EXPECT_EQ(function->get_results().size(), execNet.get_results().size()); + auto ref_result = function->get_results().back(); + auto actual_result = execNet.get_results().back(); + EXPECT_EQ(ref_result->get_element_type(), actual_result->get_element_type()); + EXPECT_EQ(ref_result->get_shape(), actual_result->get_shape()); + EXPECT_EQ(ref_result->get_friendly_name(), actual_result->get_friendly_name()); +} + +} // namespace test +} // namespace ov