From f71a8beed3e6454bbbd45703f709cae7eed114d6 Mon Sep 17 00:00:00 2001 From: Bogdan Pereanu Date: Fri, 31 Jan 2025 12:40:21 +0200 Subject: [PATCH] Dont' need to create new deleter, add extra test case Signed-off-by: Bogdan Pereanu --- .../src/utils/src/zero/zero_wrappers.cpp | 14 +---- .../internal/overload/compile_and_infer.hpp | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp index 22d5e3f03f55d7..8cb67f50ff8955 100644 --- a/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp +++ b/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp @@ -252,20 +252,8 @@ std::shared_ptr CommandQueuePool::getCommandQueue( } } // otherwise create a new object - // Create shared_ptr with a deleter _log.debug("Create Command Queue"); - auto new_obj = std::shared_ptr( - new CommandQueue(init_structs, desc, group_ordinal), - [this, hash](CommandQueue* ptr) { - std::lock_guard lock(_mutex); - if (_pool.at(hash).lock()) { - _log.debug("Don't destroy the command queue in case the shared ptr is in use!"); - return; - } - _pool.erase(hash); - _log.debug("Destroy Command Queue"); - delete ptr; - }); + auto new_obj = std::make_shared(init_structs, desc, group_ordinal); auto pair = std::make_pair(hash, new_obj); _pool.emplace(pair); diff --git a/src/plugins/intel_npu/tests/functional/internal/overload/compile_and_infer.hpp b/src/plugins/intel_npu/tests/functional/internal/overload/compile_and_infer.hpp index 20bbbb6fbe2346..6066b4d42089bf 100644 --- a/src/plugins/intel_npu/tests/functional/internal/overload/compile_and_infer.hpp +++ b/src/plugins/intel_npu/tests/functional/internal/overload/compile_and_infer.hpp @@ -208,6 +208,60 @@ TEST_P(OVCompileAndInferRequest, CompiledModelWorkloadTypeUpdateAfterCompilation } } +TEST_P(OVCompileAndInferRequest, CompiledModelWorkloadTypeUpdateAfterCompilationWithMultipleInfers) { + if (isCommandQueueExtSupported()) { + OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration)); + + auto secondCompiledModel = core->compile_model(function, target_device, configuration); + + ov::InferRequest req1, req2, req3; + OV_ASSERT_NO_THROW(req1 = execNet.create_infer_request()); + OV_ASSERT_NO_THROW(req3 = secondCompiledModel.create_infer_request()); + bool isCalled = false; + OV_ASSERT_NO_THROW(req1.set_callback([&](std::exception_ptr exception_ptr) { + ASSERT_EQ(exception_ptr, nullptr); + isCalled = true; + })); + OV_ASSERT_NO_THROW(req1.start_async()); + OV_ASSERT_NO_THROW(req1.wait()); + ASSERT_TRUE(isCalled); + + OV_ASSERT_NO_THROW(req3.infer()); + + req1 = {}; + + ov::AnyMap modelConfiguration; + modelConfiguration[workload_type.name()] = WorkloadType::EFFICIENT; + OV_ASSERT_NO_THROW(execNet.set_property(modelConfiguration)); + ASSERT_EQ(execNet.get_property(workload_type.name()).as(), WorkloadType::EFFICIENT); + OV_ASSERT_NO_THROW(req2 = execNet.create_infer_request()) + OV_ASSERT_NO_THROW(req2.infer()); + + modelConfiguration[workload_type.name()] = WorkloadType::DEFAULT; + OV_ASSERT_NO_THROW(execNet.set_property(modelConfiguration)); + ASSERT_EQ(execNet.get_property(workload_type.name()).as(), WorkloadType::DEFAULT); + isCalled = false; + OV_ASSERT_NO_THROW(req2.set_callback([&](std::exception_ptr exception_ptr) { + ASSERT_EQ(exception_ptr, nullptr); + isCalled = true; + })); + OV_ASSERT_NO_THROW(req2.start_async()); + OV_ASSERT_NO_THROW(req2.wait()); + ASSERT_TRUE(isCalled); + + req2 = {}; + req3 = {}; + + OV_ASSERT_NO_THROW(req1 = execNet.create_infer_request()); + OV_ASSERT_NO_THROW(req2 = secondCompiledModel.create_infer_request()); + OV_ASSERT_NO_THROW(req1.infer()); + OV_ASSERT_NO_THROW(req3 = execNet.create_infer_request()); + OV_ASSERT_NO_THROW(req2.infer()); + OV_ASSERT_NO_THROW(req3.infer()); + OV_ASSERT_NO_THROW(req3.infer()); + } +} + using OVCompileAndInferRequestTurbo = OVCompileAndInferRequest; TEST_P(OVCompileAndInferRequestTurbo, CompiledModelTurbo) {