From 35ba009cd6bfdfa398065884e32e3da72dca605d Mon Sep 17 00:00:00 2001 From: yanlan song Date: Fri, 20 May 2022 10:17:40 +0800 Subject: [PATCH] Bell/cache refine (#11414) * cache compliance Signed-off-by: fishbell * clang format Signed-off-by: fishbell * fix crash Signed-off-by: fishbell * enable test cases Signed-off-by: fishbell * enable more tests Signed-off-by: fishbell * refine cases Signed-off-by: fishbell * do not use try catch Signed-off-by: fishbell * case refine Signed-off-by: fishbell * fix unicode failure Signed-off-by: fishbell * use model_path.empty instead of try catch Signed-off-by: fishbell * add mock test Signed-off-by: fishbell * add more mock test Signed-off-by: fishbell * disable unicode test on windows Signed-off-by: fishbell * add hetero caching/stateful mode support Signed-off-by: fishbell * remove the disable label for CPU Signed-off-by: fishbell * resolve the CI failure Signed-off-by: fishbell remove redundant lines Signed-off-by: fishbell Co-authored-by: Chen Peter --- .../behavior/ov_plugin/caching_tests.cpp | 3 +- src/plugins/auto/executable_network.cpp | 3 +- src/plugins/auto/plugin.cpp | 26 +++- .../inference_engine/caching_test.cpp | 61 ++++++++ .../src/behavior/ov_plugin/caching_tests.cpp | 3 +- .../behavior/ov_plugin/caching_tests.cpp | 38 ++++- .../skip_tests_config.cpp | 3 - .../behavior/ov_plugin/caching_tests.cpp | 3 +- .../functional/plugin/gpu/behavior/cache.cpp | 119 -------------- .../behavior/ov_plugin/caching_tests.cpp | 22 ++- .../behavior/plugin/caching_tests.cpp | 22 +++ .../behavior/ov_plugin/caching_tests.cpp | 6 +- .../behavior/ov_plugin/caching_tests.hpp | 38 ++++- .../include/behavior/plugin/caching_tests.hpp | 37 ++++- .../src/behavior/ov_plugin/caching_tests.cpp | 136 +++++++++++++++- .../src/behavior/plugin/caching_tests.cpp | 145 +++++++++++++++++- 16 files changed, 525 insertions(+), 140 deletions(-) delete mode 100644 src/tests/functional/plugin/gpu/behavior/cache.cpp diff --git a/docs/template_plugin/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp index 636631e3e19..9e6a74486c7 100644 --- a/docs/template_plugin/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp +++ b/docs/template_plugin/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp @@ -20,6 +20,7 @@ namespace { ::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), ::testing::ValuesIn(precisionsTemplate), ::testing::ValuesIn(batchSizesTemplate), - ::testing::Values(CommonTestUtils::DEVICE_TEMPLATE)), + ::testing::Values(CommonTestUtils::DEVICE_TEMPLATE), + ::testing::Values(ov::AnyMap{})), CompileModelCacheTestBase::getTestCaseName); } // namespace diff --git a/src/plugins/auto/executable_network.cpp b/src/plugins/auto/executable_network.cpp index 2ff6646ed76..d41bdecb8bd 100644 --- a/src/plugins/auto/executable_network.cpp +++ b/src/plugins/auto/executable_network.cpp @@ -184,7 +184,8 @@ MultiDeviceExecutableNetwork::MultiDeviceExecutableNetwork(const std::string& // loadContext[ACTUALDEVICE] is always enabled, // when there is CPU and there are more than two devices, loadContext[CPU] is enabled _loadContext[ACTUALDEVICE].isEnabled = true; - _loadContext[ACTUALDEVICE].networkPrecision = GetNetworkPrecision(network); + if (modelPath.empty()) + _loadContext[ACTUALDEVICE].networkPrecision = GetNetworkPrecision(network); _loadContext[ACTUALDEVICE].metaDevices = metaDevices; if (isCumulative) { diff --git a/src/plugins/auto/plugin.cpp b/src/plugins/auto/plugin.cpp index f10037b8e3d..742965b041c 100644 --- a/src/plugins/auto/plugin.cpp +++ b/src/plugins/auto/plugin.cpp @@ -333,7 +333,26 @@ IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetworkImpl(cons if (supportDevicesByConfig.size() == 0) { IE_THROW() << "There is no device support the configure"; } - auto supportDevices = FilterDeviceByNetwork(supportDevicesByConfig, network); + auto supportDevices = supportDevicesByConfig; + CNNNetwork clonedNetwork; + std::string clonedModelPath = modelPath; + if (modelPath.empty()) { + // if network is valid + LOG_INFO("[AUTOPLUGIN]:load with CNN network"); + supportDevices = FilterDeviceByNetwork(supportDevicesByConfig, network); + // clone the network, in case of reshape conflict + clonedNetwork = InferenceEngine::details::cloneNetwork(network); + } else { + // model path, enable model load with single device situation + if (supportDevices.size() > 1) { + clonedNetwork = GetCore()->ReadNetwork(modelPath, std::string()); + // do we really need to disable model path? + clonedModelPath = ""; + LOG_INFO("[AUTOPLUGIN]:load with CNN network"); + } else { + LOG_INFO("[AUTOPLUGIN]:load with model path"); + } + } // replace the configure with configure that auto want to pass to device // and reset the strDevices to support devices auto validConfigKey = PerfHintsConfig::SupportedKeys(); @@ -360,10 +379,9 @@ IExecutableNetworkInternal::Ptr MultiDeviceInferencePlugin::LoadNetworkImpl(cons strDevices += ((iter + 1) == supportDevices.end()) ? "" : ","; LOG_INFO("[AUTOPLUGIN]:device:%s, priority:%ld", iter->deviceName.c_str(), iter->devicePriority); } - // clone the network, in case of reshape conflict - CNNNetwork clonedNetwork = InferenceEngine::details::cloneNetwork(network); - return std::make_shared(modelPath, clonedNetwork, supportDevices, strDevices, this, context, context.needPerfCounters); + return std::make_shared(clonedModelPath, clonedNetwork, supportDevices, strDevices, + this, context, context.needPerfCounters); } OV_ITT_SCOPED_TASK(itt::domains::MULTIPlugin, "MultiDeviceInferencePlugin::LoadNetworkImpl:MultiMode"); if (priorities == fullConfig.end()) { diff --git a/src/tests/functional/inference_engine/caching_test.cpp b/src/tests/functional/inference_engine/caching_test.cpp index 24aaf72512d..35f46344d37 100644 --- a/src/tests/functional/inference_engine/caching_test.cpp +++ b/src/tests/functional/inference_engine/caching_test.cpp @@ -1953,6 +1953,67 @@ TEST_P(CachingTest, LoadHetero_MultiArchs_TargetFallback_FromCore) { } } +//AUTO-DEVICE test +//Single device +TEST_P(CachingTest, LoadAUTO_OneDevice) { + const auto TEST_COUNT = 2; + EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); + EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); + if (m_remoteContext) { + return; // skip the remote Context test for Auto plugin + } + int index = 0; + m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { + EXPECT_CALL(net, Export(_)).Times(1); + }); + std::string cacheDir = m_cacheDir; + MkDirGuard guard(cacheDir); + for (index; index < TEST_COUNT; index++) { + deviceToLoad = CommonTestUtils::DEVICE_AUTO; + deviceToLoad += ":mock.0"; + EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(TEST_COUNT - index - 1); + EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(index); + ASSERT_NO_THROW(testLoad([&](Core &ie) { + ie.SetConfig({{CONFIG_KEY(CACHE_DIR), cacheDir}}); + m_testFunction(ie); + })); + } + std::cout << "Caching LoadAuto Test completed. Tried " << index << " times" << std::endl; +} +//Single device not support import/export +TEST_P(CachingTest, LoadAUTO_OneDeviceNoImportExport) { + EXPECT_CALL(*mockPlugin, GetMetric(_, _)).Times(AnyNumber()); + EXPECT_CALL(*mockPlugin, QueryNetwork(_, _)).Times(AnyNumber()); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(IMPORT_EXPORT_SUPPORT), _)) + .Times(AnyNumber()).WillRepeatedly(Return(false)); + EXPECT_CALL(*mockPlugin, GetMetric(ov::device::capabilities.name(), _)).Times(AnyNumber()). + WillRepeatedly(Return(decltype(ov::device::capabilities)::value_type{})); + EXPECT_CALL(*mockPlugin, GetMetric(METRIC_KEY(DEVICE_ARCHITECTURE), _)).Times(AnyNumber()); + if (m_remoteContext) { + return; // skip the remote Context test for Auto plugin + } + EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _, _)).Times(m_remoteContext ? 2 : 0); + EXPECT_CALL(*mockPlugin, LoadExeNetworkImpl(_, _)).Times(!m_remoteContext ? 2 : 0); + EXPECT_CALL(*mockPlugin, OnLoadNetworkFromFile()).Times(m_type == TestLoadType::EModelName ? 2 : 0); + EXPECT_CALL(*mockPlugin, ImportNetwork(_, _, _)).Times(0); + EXPECT_CALL(*mockPlugin, ImportNetwork(_, _)).Times(0); + testLoad([&](Core &ie) { + m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { + EXPECT_CALL(net, Export(_)).Times(0); + }); + deviceToLoad = CommonTestUtils::DEVICE_AUTO; + deviceToLoad += ":mock.0"; + ie.SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheDir}}); + m_testFunction(ie); + m_post_mock_net_callbacks.pop_back(); + m_post_mock_net_callbacks.emplace_back([&](MockExecutableNetwork& net) { + EXPECT_CALL(net, Export(_)).Times(0); + }); + m_testFunction(ie); + }); +} + // MULTI-DEVICE test // Test that it is safe to load multiple devices sharing same cache // In case of sporadic failures - increase 'TEST_DURATION_MS' 100x times for better reproducibility diff --git a/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/src/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/src/behavior/ov_plugin/caching_tests.cpp index c1571c55629..1499ff3a94d 100644 --- a/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/src/behavior/ov_plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/conformance/test_runner/api_conformance_runner/src/behavior/ov_plugin/caching_tests.cpp @@ -35,6 +35,7 @@ INSTANTIATE_TEST_SUITE_P(ov_plugin, CompileModelCacheTestBase, ::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), ::testing::ValuesIn(ovElemTypesTemplate), ::testing::ValuesIn(ovBatchSizesTemplate), - ::testing::ValuesIn(return_all_possible_device_combination())), + ::testing::ValuesIn(return_all_possible_device_combination()), + ::testing::Values(ov::AnyMap{})), CompileModelCacheTestBase::getTestCaseName); } // namespace diff --git a/src/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp index c6906840b01..577a76a1539 100644 --- a/src/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/cpu/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp @@ -83,7 +83,8 @@ namespace { ::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), ::testing::ValuesIn(precisionsCPU), ::testing::ValuesIn(batchSizesCPU), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(ov::AnyMap{})), CompileModelCacheTestBase::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_CachingSupportCase_CPU_Internal, CompileModelCacheTestBase, @@ -91,6 +92,39 @@ namespace { ::testing::ValuesIn(internal_functions_cpu()), ::testing::ValuesIn(precisionsCPUInternal), ::testing::ValuesIn(batchSizesCPUInternal), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(ov::AnyMap{})), CompileModelCacheTestBase::getTestCaseName); + + const std::vector autoConfigs = { + {ov::device::priorities(CommonTestUtils::DEVICE_CPU)} + }; + + INSTANTIATE_TEST_SUITE_P(smoke_Hetero_CachingSupportCase, CompileModelCacheTestBase, + ::testing::Combine( + ::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), + ::testing::ValuesIn(precisionsCPU), + ::testing::ValuesIn(batchSizesCPU), + ::testing::Values(CommonTestUtils::DEVICE_HETERO), + ::testing::ValuesIn(autoConfigs)), + CompileModelCacheTestBase::getTestCaseName); + + INSTANTIATE_TEST_SUITE_P(smoke_Auto_CachingSupportCase_CPU, CompileModelCacheTestBase, + ::testing::Combine( + ::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), + ::testing::ValuesIn(precisionsCPU), + ::testing::ValuesIn(batchSizesCPU), + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(autoConfigs)), + CompileModelCacheTestBase::getTestCaseName); + + INSTANTIATE_TEST_SUITE_P(smoke_Auto_CachingSupportCase_CPU_Internal, CompileModelCacheTestBase, + ::testing::Combine( + ::testing::ValuesIn(internal_functions_cpu()), + ::testing::ValuesIn(precisionsCPUInternal), + ::testing::ValuesIn(batchSizesCPUInternal), + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(autoConfigs)), + CompileModelCacheTestBase::getTestCaseName); + } // namespace diff --git a/src/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp b/src/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp index bea976d291d..1776d6bb731 100644 --- a/src/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp +++ b/src/tests/functional/plugin/cpu/shared_tests_instances/skip_tests_config.cpp @@ -101,9 +101,6 @@ std::vector disabledTestPatterns() { R"(.*Hetero.*Behavior.*ExecutableNetworkBaseTest.*ExecGraphInfo.*)", R"(.*Hetero.*Behavior.*ExecutableNetworkBaseTest.*CanCreateTwoExeNetworksAndCheckFunction.*)", - // CPU plugin does not support some precisions - R"(smoke_CachingSupportCase_CPU/LoadNetworkCacheTestBase.CompareWithRefImpl/ReadConcatSplitAssign_f32_batch1_CPU)", - // CPU does not support dynamic rank // Issue: CVS-66778 R"(.*smoke_BehaviorTests.*InferFullyDynamicNetworkWith(S|G)etTensor.*)", diff --git a/src/tests/functional/plugin/gna/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/plugin/gna/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp index fbacc45010b..3b57aa9293d 100644 --- a/src/tests/functional/plugin/gna/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/gna/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp @@ -23,6 +23,7 @@ namespace { ::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), ::testing::ValuesIn(precisionsGNA), ::testing::ValuesIn(batchSizesGNA), - ::testing::Values(CommonTestUtils::DEVICE_GNA)), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::Values(ov::AnyMap{})), CompileModelCacheTestBase::getTestCaseName); } // namespace diff --git a/src/tests/functional/plugin/gpu/behavior/cache.cpp b/src/tests/functional/plugin/gpu/behavior/cache.cpp deleted file mode 100644 index 853e2612497..00000000000 --- a/src/tests/functional/plugin/gpu/behavior/cache.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (C) 2018-2022 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "common_test_utils/test_common.hpp" -#include "common_test_utils/file_utils.hpp" -#include "common_test_utils/unicode_utils.hpp" -#include "ngraph_functions/utils/ngraph_helpers.hpp" -#include "functional_test_utils/plugin_cache.hpp" -#include "ngraph_functions/subgraph_builders.hpp" -#include -#include - -class CompiledKernelsCacheTest : public CommonTestUtils::TestsCommon { -protected: - std::string test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name(); - std::shared_ptr function; - std::string cache_path; - - void SetUp() override { - function = ngraph::builder::subgraph::makeConvPoolRelu(); - cache_path = test_name + "_cache"; - } -}; - -TEST_F(CompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinaries) { - std::shared_ptr ie = PluginCache::get().ie(); - // Create CNNNetwork from ngraph::Function - InferenceEngine::CNNNetwork cnnNet(function); - std::map config = {{ CONFIG_KEY(CACHE_DIR), cache_path }}; - try { - // Load CNNNetwork to target plugins - auto execNet = ie->LoadNetwork(cnnNet, "GPU", config); - - // Check that directory with cached kernels exists after loading network - ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path)) << "Directory with cached kernels doesn't exist"; - // Check that folder contains cache files and remove them - ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path, "cl_cache"), 0); - // Remove directory and check that it doesn't exist anymore - ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); - ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path)); - } catch (std::exception& ex) { - // Cleanup in case of any exception - if (CommonTestUtils::directoryExists(cache_path)) { - ASSERT_GE(CommonTestUtils::removeFilesWithExt(cache_path, "cl_cache"), 0); - ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); - } - FAIL() << ex.what() << std::endl; - } -} - -TEST_F(CompiledKernelsCacheTest, TwoNetworksWithSameModelCreatesSameCache) { - std::shared_ptr ie = PluginCache::get().ie(); - // Create two CNNNetwork from same ngraph::Function - InferenceEngine::CNNNetwork cnnNet1(function); - InferenceEngine::CNNNetwork cnnNet2(function); - std::map config = {{ CONFIG_KEY(CACHE_DIR), cache_path }}; - try { - // Load 1st CNNNetwork - auto execNet1 = ie->LoadNetwork(cnnNet1, "GPU", config); - auto n_cache_files = CommonTestUtils::listFilesWithExt(cache_path, "cl_cache").size(); - - // Check that directory with cached kernels exists after loading network - ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path)) << "Directory with cached kernels doesn't exist"; - // Load 2nd CNNNetwork - auto execNet2 = ie->LoadNetwork(cnnNet2, "GPU", config); - - // Check that two loaded networks with same function creates same caches - ASSERT_EQ(CommonTestUtils::removeFilesWithExt(cache_path, "cl_cache"), n_cache_files); - - // Remove directory and check that it doesn't exist anymore - ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); - ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path)); - } catch (std::exception& ex) { - // Cleanup in case of any exception - if (CommonTestUtils::directoryExists(cache_path)) { - ASSERT_GE(CommonTestUtils::removeFilesWithExt(cache_path, "cl_cache"), 0); - ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); - } - FAIL() << ex.what() << std::endl; - } -} - - -#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - -TEST_F(CompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinariesUnicodePath) { - std::shared_ptr ie = PluginCache::get().ie(); - // Create CNNNetwork from ngraph::Function - InferenceEngine::CNNNetwork cnnNet(function); - for (std::size_t testIndex = 0; testIndex < CommonTestUtils::test_unicode_postfix_vector.size(); testIndex++) { - std::wstring postfix = L"_" + CommonTestUtils::test_unicode_postfix_vector[testIndex]; - std::wstring cache_path_w = CommonTestUtils::addUnicodePostfixToPath(cache_path, postfix); - - try { - auto cache_path_mb = ov::util::wstring_to_string(cache_path_w); - std::map config = {{ CONFIG_KEY(CACHE_DIR), cache_path_mb }}; - // Load CNNNetwork to target plugins - auto execNet = ie->LoadNetwork(cnnNet, "GPU", config); - - // Check that directory with cached kernels exists after loading network - ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path_w)) << "Directory with cached kernels doesn't exist"; - // Check that folder contains cache files and remove them - ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path_w, L"cl_cache"), 0); - // Remove directory and check that it doesn't exist anymore - ASSERT_EQ(CommonTestUtils::removeDir(cache_path_w), 0); - ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path_w)); - } catch (std::exception& ex) { - // Cleanup in case of any exception - if (CommonTestUtils::directoryExists(cache_path_w)) { - ASSERT_GE(CommonTestUtils::removeFilesWithExt(cache_path_w, L"cl_cache"), 0); - ASSERT_EQ(CommonTestUtils::removeDir(cache_path_w), 0); - } - FAIL() << ex.what() << std::endl; - } - } -} - -#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT diff --git a/src/tests/functional/plugin/gpu/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/plugin/gpu/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp index 94d1aba355d..94b09a9b1c5 100644 --- a/src/tests/functional/plugin/gpu/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/gpu/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp @@ -27,6 +27,26 @@ namespace { ::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), ::testing::ValuesIn(precisionsGPU), ::testing::ValuesIn(batchSizesGPU), - ::testing::Values(CommonTestUtils::DEVICE_GPU)), + ::testing::Values(CommonTestUtils::DEVICE_GPU), + ::testing::Values(ov::AnyMap{})), CompileModelCacheTestBase::getTestCaseName); + + INSTANTIATE_TEST_SUITE_P(smoke_KernelCachingSupportCase_GPU, CompiledKernelsCacheTest, + ::testing::Combine( + ::testing::Values(CommonTestUtils::DEVICE_GPU), + ::testing::Values(std::make_pair(ov::AnyMap{}, "cl_cache"))), + CompiledKernelsCacheTest::getTestCaseName); + + std::vector> autoConfigs = { + std::make_pair(ov::AnyMap{{ov::device::priorities(CommonTestUtils::DEVICE_GPU)}}, "cl_cache"), + std::make_pair(ov::AnyMap{{ov::device::priorities(CommonTestUtils::DEVICE_GPU, CommonTestUtils::DEVICE_CPU)}}, "blob,cl_cache"), + std::make_pair(ov::AnyMap{{ov::device::priorities(CommonTestUtils::DEVICE_CPU, CommonTestUtils::DEVICE_GPU)}}, "blob") + }; + + INSTANTIATE_TEST_SUITE_P(smoke_Auto_KernelCachingSupportCase_GPU, CompiledKernelsCacheTest, + ::testing::Combine( + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(autoConfigs)), + CompiledKernelsCacheTest::getTestCaseName); + } // namespace diff --git a/src/tests/functional/plugin/gpu/shared_tests_instances/behavior/plugin/caching_tests.cpp b/src/tests/functional/plugin/gpu/shared_tests_instances/behavior/plugin/caching_tests.cpp index 076f0de87a2..bd2f30246ac 100644 --- a/src/tests/functional/plugin/gpu/shared_tests_instances/behavior/plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/gpu/shared_tests_instances/behavior/plugin/caching_tests.cpp @@ -29,4 +29,26 @@ namespace { ::testing::ValuesIn(batchSizesGPU), ::testing::Values(CommonTestUtils::DEVICE_GPU)), LoadNetworkCacheTestBase::getTestCaseName); + + INSTANTIATE_TEST_SUITE_P(smoke_KernelCachingSupportCase_GPU, LoadNetworkCompiledKernelsCacheTest, + ::testing::Combine( + ::testing::Values(CommonTestUtils::DEVICE_GPU), + ::testing::Values(std::make_pair(std::map(), "cl_cache"))), + LoadNetworkCompiledKernelsCacheTest::getTestCaseName); + + typedef std::map conftype; + std::vector> autoConfigs = { + std::make_pair(conftype{{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, CommonTestUtils::DEVICE_GPU}}, "cl_cache"), + std::make_pair(conftype{{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, + (std::string(CommonTestUtils::DEVICE_GPU) + "," + CommonTestUtils::DEVICE_CPU)}}, "blob,cl_cache"), + std::make_pair(conftype{{InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, + (std::string(CommonTestUtils::DEVICE_CPU) + "," + CommonTestUtils::DEVICE_GPU)}}, "blob") + }; + + INSTANTIATE_TEST_SUITE_P(smoke_Auto_KernelCachingSupportCase_GPU, LoadNetworkCompiledKernelsCacheTest, + ::testing::Combine( + ::testing::Values(CommonTestUtils::DEVICE_AUTO), + ::testing::ValuesIn(autoConfigs)), + LoadNetworkCompiledKernelsCacheTest::getTestCaseName); + } // namespace diff --git a/src/tests/functional/plugin/myriad/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/plugin/myriad/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp index 3a28919bad2..4b49dc9f6ac 100644 --- a/src/tests/functional/plugin/myriad/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/myriad/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp @@ -36,7 +36,8 @@ namespace { ::testing::ValuesIn(smoke_functions()), ::testing::ValuesIn(smoke_precisionsMyriad), ::testing::ValuesIn(batchSizesMyriad), - ::testing::Values(CommonTestUtils::DEVICE_MYRIAD)), + ::testing::Values(CommonTestUtils::DEVICE_MYRIAD), + ::testing::Values(ov::AnyMap{})), CompileModelCacheTestBase::getTestCaseName); INSTANTIATE_TEST_SUITE_P(nightly_CachingSupportCase_Myriad, CompileModelCacheTestBase, @@ -44,6 +45,7 @@ namespace { ::testing::ValuesIn(CompileModelCacheTestBase::getStandardFunctions()), ::testing::ValuesIn(nightly_precisionsMyriad), ::testing::ValuesIn(batchSizesMyriad), - ::testing::Values(CommonTestUtils::DEVICE_MYRIAD)), + ::testing::Values(CommonTestUtils::DEVICE_MYRIAD), + ::testing::Values(ov::AnyMap{})), CompileModelCacheTestBase::getTestCaseName); } // namespace diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/caching_tests.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/caching_tests.hpp index d60a23a9709..6f02b717815 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/caching_tests.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/caching_tests.hpp @@ -9,6 +9,10 @@ #include "shared_test_classes/base/ov_subgraph.hpp" #include "ngraph/function.hpp" +#include "ngraph_functions/subgraph_builders.hpp" +#include "functional_test_utils/plugin_cache.hpp" +#include "common_test_utils/unicode_utils.hpp" +#include "openvino/util/common_util.hpp" #include #include @@ -24,7 +28,8 @@ using compileModelCacheParams = std::tuple< ovModelWithName, // openvino model with friendly name ov::element::Type, // element type size_t, // batch size - std::string // device name + std::string, // device name + ov::AnyMap // device configuration >; class CompileModelCacheTestBase : public testing::WithParamInterface, @@ -46,6 +51,37 @@ public: static std::vector getStandardFunctions(); }; +using compileKernelsCacheParams = std::tuple< + std::string, // device name + std::pair // device and cache configuration +>; +class CompiledKernelsCacheTest : virtual public SubgraphBaseTest, + public testing::WithParamInterface { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); +protected: + std::string test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name(); + std::shared_ptr function; + std::string cache_path; + std::vector m_extList; + void SetUp() override { + function = ngraph::builder::subgraph::makeConvPoolRelu(); + std::pair userConfig; + std::tie(targetDevice, userConfig) = GetParam(); + configuration = userConfig.first; + std::string ext = userConfig.second; + std::string::size_type pos = 0; + if ((pos = ext.find(",", pos)) != std::string::npos) { + m_extList.push_back(ext.substr(0, pos)); + m_extList.push_back(ext.substr(pos + 1)); + } else { + m_extList.push_back(ext); + } + std::replace(test_name.begin(), test_name.end(), '/', '_'); + std::replace(test_name.begin(), test_name.end(), '\\', '_'); + cache_path = "compiledModel" + test_name + "_cache"; + } +}; } // namespace behavior } // namespace test } // namespace ov diff --git a/src/tests/functional/plugin/shared/include/behavior/plugin/caching_tests.hpp b/src/tests/functional/plugin/shared/include/behavior/plugin/caching_tests.hpp index 27df7d9dd7d..11c90150ab3 100644 --- a/src/tests/functional/plugin/shared/include/behavior/plugin/caching_tests.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/plugin/caching_tests.hpp @@ -9,6 +9,10 @@ #include "shared_test_classes/base/layer_test_utils.hpp" #include "ngraph/function.hpp" +#include "ngraph_functions/subgraph_builders.hpp" +#include "functional_test_utils/plugin_cache.hpp" +#include "common_test_utils/unicode_utils.hpp" +#include "openvino/util/common_util.hpp" #include #include @@ -20,7 +24,7 @@ using loadNetworkCacheParams = std::tuple< nGraphFunctionWithName, // ngraph function with friendly name ngraph::element::Type, // precision std::size_t, // batch size - std::string // device name + std::string // device name >; namespace LayerTestsDefinitions { @@ -43,4 +47,35 @@ public: static std::vector getStandardFunctions(); }; +using compileKernelsCacheParams = std::tuple< + std::string, // device name + std::pair, std::string> // device and cache configuration +>; +class LoadNetworkCompiledKernelsCacheTest : virtual public LayerTestsUtils::LayerTestsCommon, + public testing::WithParamInterface { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); +protected: + std::string test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name(); + std::shared_ptr function; + std::string cache_path; + std::vector m_extList; + void SetUp() override { + function = ngraph::builder::subgraph::makeConvPoolRelu(); + std::pair, std::string> userConfig; + std::tie(targetDevice, userConfig) = GetParam(); + configuration = userConfig.first; + std::string ext = userConfig.second; + std::string::size_type pos = 0; + if ((pos = ext.find(",", pos)) != std::string::npos) { + m_extList.push_back(ext.substr(0, pos)); + m_extList.push_back(ext.substr(pos + 1)); + } else { + m_extList.push_back(ext); + } + std::replace(test_name.begin(), test_name.end(), '/', '_'); + std::replace(test_name.begin(), test_name.end(), '\\', '_'); + cache_path = "LoadNetwork" + test_name + "_cache"; + } +}; } // namespace LayerTestsDefinitions diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/caching_tests.cpp index 5a1bab8ea00..d7096d9338d 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/caching_tests.cpp @@ -138,7 +138,7 @@ std::string CompileModelCacheTestBase::getTestCaseName(testing::TestParamInfo(funcPair); m_functionName = std::get<1>(funcPair); try { @@ -150,6 +150,9 @@ void CompileModelCacheTestBase::SetUp() { std::stringstream ss; auto hash = std::hash()(GetTestName()); ss << "testCache_" << std::to_string(hash) << "_" << std::this_thread::get_id() << "_" << GetTimestamp(); + for (auto& iter : configuration) { + ss << "_" << iter.first << "_" << iter.second.as() << "_"; + } m_cacheFolderName = ss.str(); core->set_property(ov::cache_dir()); } @@ -172,7 +175,7 @@ void CompileModelCacheTestBase::run() { } init_input_shapes(static_shapes_to_test_representation(inShapes)); } - if (!importExportSupported(*core)) { + if ((targetDevice.find("AUTO") == std::string::npos) && !importExportSupported(*core)) { GTEST_COUT << "Plugin doesn't support import and export - skipping test" << std::endl; GTEST_SKIP(); } @@ -194,6 +197,7 @@ void CompileModelCacheTestBase::run() { for (int i = 0; i < 2; i++) { // Step 2: Load with cache. Export or import shall not throw compiledModel = {}; // Destroy network object + inferRequest = {}; { core->set_property(ov::cache_dir(m_cacheFolderName)); ASSERT_NO_THROW(compiledModel = core->compile_model(function, targetDevice, configuration)); @@ -210,6 +214,134 @@ TEST_P(CompileModelCacheTestBase, CompareWithRefImpl) { run(); } +std::string CompiledKernelsCacheTest::getTestCaseName(testing::TestParamInfo obj) { + auto param = obj.param; + std::string deviceName; + std::pair userConfig; + std::tie(deviceName, userConfig) = obj.param; + auto properties = userConfig.first; + std::ostringstream result; + result << "device_name=" << deviceName << "_"; + if (!properties.empty()) { + result << "properties=" << util::join(util::split(util::to_string(properties), ' '), "_"); + } + result << userConfig.second; + return result.str(); +} + +TEST_P(CompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinaries) { + core->set_property(ov::cache_dir(cache_path)); + try { + // Load CNNNetwork to target plugins + auto execNet = core->compile_model(function, targetDevice, configuration); + execNet = {}; + // Check that directory with cached kernels exists after loading network + ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path)) << "Directory with cached kernels doesn't exist"; + // Check that folder contains cache files and remove them + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path, ext), 0); + } + // Remove directory and check that it doesn't exist anymore + ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); + ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path)); + } catch (std::exception& ex) { + // Cleanup in case of any exception + if (CommonTestUtils::directoryExists(cache_path)) { + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path, ext), 0); + } + ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); + } + FAIL() << ex.what() << std::endl; + } +} + +TEST_P(CompiledKernelsCacheTest, TwoNetworksWithSameModelCreatesSameCache) { + core->set_property(ov::cache_dir(cache_path)); + try { + // Load 1st CNNNetwork + auto execNet1 = core->compile_model(function, targetDevice, configuration); + execNet1 = {}; + size_t n_cache_files = 0; + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + n_cache_files += CommonTestUtils::listFilesWithExt(cache_path, ext).size(); + } + + // Check that directory with cached kernels exists after loading network + ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path)) << "Directory with cached kernels doesn't exist"; + // Load 2nd CNNNetwork + auto execNet2 = core->compile_model(function, targetDevice, configuration); + execNet2 = {}; + size_t n_cache_files_compare = 0; + // Check that two loaded networks with same function creates same caches + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + n_cache_files_compare += CommonTestUtils::listFilesWithExt(cache_path, ext).size(); + ASSERT_TRUE(CommonTestUtils::removeFilesWithExt(cache_path, ext)); + } + ASSERT_EQ(n_cache_files_compare, n_cache_files); + + // Remove directory and check that it doesn't exist anymore + ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); + ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path)); + } catch (std::exception& ex) { + // Cleanup in case of any exception + if (CommonTestUtils::directoryExists(cache_path)) { + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GE(CommonTestUtils::removeFilesWithExt(cache_path, ext), 0); + } + ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); + } + FAIL() << ex.what() << std::endl; + } +} + + +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT + +TEST_P(CompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinariesUnicodePath) { + #if defined(_WIN32) || defined(_WIN64) + GTEST_SKIP(); + #else + for (std::size_t testIndex = 0; testIndex < CommonTestUtils::test_unicode_postfix_vector.size(); testIndex++) { + std::wstring postfix = L"_" + CommonTestUtils::test_unicode_postfix_vector[testIndex]; + std::wstring cache_path_w = CommonTestUtils::stringToWString(cache_path) + postfix; + + try { + auto cache_path_mb = ov::util::wstring_to_string(cache_path_w); + core->set_property(ov::cache_dir(cache_path_mb)); + // Load CNNNetwork to target plugins + auto execNet = core->compile_model(function, targetDevice, configuration); + execNet = {}; + // Check that directory with cached kernels exists after loading network + ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path_w)) << "Directory with cached kernels doesn't exist"; + // Check that folder contains cache files and remove them + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path_w, CommonTestUtils::stringToWString(ext)), 0); + } + // Remove directory and check that it doesn't exist anymore + ASSERT_EQ(CommonTestUtils::removeDir(cache_path_w), 0); + ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path_w)); + } catch (std::exception& ex) { + // Cleanup in case of any exception + if (CommonTestUtils::directoryExists(cache_path_w)) { + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path_w, CommonTestUtils::stringToWString(ext)), 0); + } + ASSERT_EQ(CommonTestUtils::removeDir(cache_path_w), 0); + } + FAIL() << ex.what() << std::endl; + } + } + #endif +} +#endif } // namespace behavior } // namespace test } // namespace ov diff --git a/src/tests/functional/plugin/shared/src/behavior/plugin/caching_tests.cpp b/src/tests/functional/plugin/shared/src/behavior/plugin/caching_tests.cpp index bb239adb779..94912565efc 100644 --- a/src/tests/functional/plugin/shared/src/behavior/plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/plugin/caching_tests.cpp @@ -148,6 +148,9 @@ void LoadNetworkCacheTestBase::SetUp() { std::stringstream ss; auto hash = std::hash()(GetTestName()); ss << "testCache_" << std::to_string(hash) << "_" << std::this_thread::get_id() << "_" << GetTimestamp(); + for (auto& iter : configuration) { + ss << "_" << iter.first << "_" << iter.second << "_"; + } m_cacheFolderName = ss.str(); core->SetConfig({{CONFIG_KEY(CACHE_DIR), {}}}); } @@ -173,7 +176,7 @@ void LoadNetworkCacheTestBase::Run() { GTEST_COUT << "Can't create function " << m_functionName << " with precision " << m_precision.get_type_name() << std::endl; GTEST_SKIP(); } - if (!importExportSupported(*core)) { + if ((targetDevice.find("AUTO") == std::string::npos) && !importExportSupported(*core)) { GTEST_COUT << "Plugin doesn't support import and export - skipping test" << std::endl; GTEST_SKIP(); } @@ -196,6 +199,7 @@ void LoadNetworkCacheTestBase::Run() { for (int i = 0; i < 2; i++) { // Step 2: Load with cache. Export or import shall not throw executableNetwork = {}; // Destroy network object + inferRequest = {}; { core->SetConfig({{CONFIG_KEY(CACHE_DIR), m_cacheFolderName}}); ASSERT_NO_THROW(executableNetwork = core->LoadNetwork(cnnNetwork, targetDevice, configuration)); @@ -212,4 +216,143 @@ TEST_P(LoadNetworkCacheTestBase, CompareWithRefImpl) { Run(); } +std::string LoadNetworkCompiledKernelsCacheTest::getTestCaseName(testing::TestParamInfo obj) { + auto param = obj.param; + std::string deviceName; + std::pair, std::string> userConfig; + std::tie(deviceName, userConfig) = obj.param; + std::map confstr = userConfig.first; + std::ostringstream result; + result << "device_name=" << deviceName << "_"; + for (auto& tmp : confstr) { + result << tmp.first << "_" << tmp.second << "_"; + } + result << userConfig.second; + return result.str(); +} + +TEST_P(LoadNetworkCompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinaries) { + std::shared_ptr ie = PluginCache::get().ie(); + // Create CNNNetwork from ngraph::Function + InferenceEngine::CNNNetwork cnnNet(function); + ie->SetConfig({{ CONFIG_KEY(CACHE_DIR), cache_path }}); + try { + // Load CNNNetwork to target plugins + auto execNet = ie->LoadNetwork(cnnNet, targetDevice, configuration); + execNet = {}; + // Check that directory with cached kernels exists after loading network + ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path)) << "Directory with cached kernels doesn't exist"; + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path, ext), 0); + } + // Remove directory and check that it doesn't exist anymore + ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); + ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path)); + } catch (std::exception& ex) { + // Cleanup in case of any exception + if (CommonTestUtils::directoryExists(cache_path)) { + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GE(CommonTestUtils::removeFilesWithExt(cache_path, ext), 0); + } + ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); + } + FAIL() << ex.what() << std::endl; + } +} + +TEST_P(LoadNetworkCompiledKernelsCacheTest, TwoNetworksWithSameModelCreatesSameCache) { + std::shared_ptr ie = PluginCache::get().ie(); + // Create two CNNNetwork from same ngraph::Function + InferenceEngine::CNNNetwork cnnNet1(function); + InferenceEngine::CNNNetwork cnnNet2(function); + ie->SetConfig({{ CONFIG_KEY(CACHE_DIR), cache_path }}); + try { + // Load 1st CNNNetwork + auto execNet1 = ie->LoadNetwork(cnnNet1, targetDevice, configuration); + size_t n_cache_files = 0; + execNet1 = {}; + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + n_cache_files += CommonTestUtils::listFilesWithExt(cache_path, ext).size(); + } + + // Check that directory with cached kernels exists after loading network + ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path)) << "Directory with cached kernels doesn't exist"; + // Load 2nd CNNNetwork + auto execNet2 = ie->LoadNetwork(cnnNet2, targetDevice, configuration); + execNet2 = {}; + size_t n_cache_files_compare = 0; + // Check that two loaded networks with same function creates same caches + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + n_cache_files_compare += CommonTestUtils::listFilesWithExt(cache_path, ext).size(); + ASSERT_TRUE(CommonTestUtils::removeFilesWithExt(cache_path, ext)); + } + + ASSERT_EQ(n_cache_files_compare, n_cache_files); + + // Remove directory and check that it doesn't exist anymore + ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); + ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path)); + } catch (std::exception& ex) { + // Cleanup in case of any exception + if (CommonTestUtils::directoryExists(cache_path)) { + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GE(CommonTestUtils::removeFilesWithExt(cache_path, ext), 0); + } + ASSERT_EQ(CommonTestUtils::removeDir(cache_path), 0); + } + FAIL() << ex.what() << std::endl; + } +} + + +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT + +TEST_P(LoadNetworkCompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinariesUnicodePath) { + #if defined(_WIN32) || defined(_WIN64) + GTEST_SKIP(); + #else + std::shared_ptr ie = PluginCache::get().ie(); + // Create CNNNetwork from ngraph::Function + InferenceEngine::CNNNetwork cnnNet(function); + for (std::size_t testIndex = 0; testIndex < CommonTestUtils::test_unicode_postfix_vector.size(); testIndex++) { + std::wstring postfix = L"_" + CommonTestUtils::test_unicode_postfix_vector[testIndex]; + std::wstring cache_path_w = CommonTestUtils::stringToWString(cache_path) + postfix; + + try { + auto cache_path_mb = ov::util::wstring_to_string(cache_path_w); + ie->SetConfig({{ CONFIG_KEY(CACHE_DIR), cache_path_mb }}); + // Load CNNNetwork to target plugins + auto execNet = ie->LoadNetwork(cnnNet, targetDevice, configuration); + execNet = {}; + // Check that directory with cached kernels exists after loading network + ASSERT_TRUE(CommonTestUtils::directoryExists(cache_path_w)) << "Directory with cached kernels doesn't exist"; + // Check that folder contains cache files and remove them + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path_w, CommonTestUtils::stringToWString(ext)), 0); + } + //ASSERT_GT(CommonTestUtils::removeFilesWithExt(cache_path_w, L"cl_cache"), 0); + // Remove directory and check that it doesn't exist anymore + ASSERT_EQ(CommonTestUtils::removeDir(cache_path_w), 0); + ASSERT_FALSE(CommonTestUtils::directoryExists(cache_path_w)); + } catch (std::exception& ex) { + // Cleanup in case of any exception + if (CommonTestUtils::directoryExists(cache_path_w)) { + for (auto& ext : m_extList) { + // Check that folder contains cache files and remove them + ASSERT_GE(CommonTestUtils::removeFilesWithExt(cache_path_w, CommonTestUtils::stringToWString(ext)), 0); + } + ASSERT_EQ(CommonTestUtils::removeDir(cache_path_w), 0); + } + FAIL() << ex.what() << std::endl; + } + } + #endif +} +#endif } // namespace LayerTestsDefinitions