Skip to content

Commit

Permalink
Dont' need to create new deleter, add extra test case
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Pereanu <bogdan.pereanu@intel.com>
  • Loading branch information
pereanub committed Jan 31, 2025
1 parent acb0b4f commit f71a8be
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
14 changes: 1 addition & 13 deletions src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,8 @@ std::shared_ptr<CommandQueue> CommandQueuePool::getCommandQueue(
}
} // otherwise create a new object

// Create shared_ptr with a deleter
_log.debug("Create Command Queue");
auto new_obj = std::shared_ptr<CommandQueue>(
new CommandQueue(init_structs, desc, group_ordinal),
[this, hash](CommandQueue* ptr) {
std::lock_guard<std::mutex> 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<CommandQueue>(init_structs, desc, group_ordinal);

auto pair = std::make_pair(hash, new_obj);
_pool.emplace(pair);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>(), 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>(), 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) {
Expand Down

0 comments on commit f71a8be

Please sign in to comment.