Skip to content

Commit

Permalink
Set worklokad type
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 30, 2025
1 parent 6d4ab81 commit 81f15a6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ void DriverGraph::create_new_command_queue() {
_ze_workload_type,
_group_ordinal,
_turbo);

if (_ze_workload_type.has_value()) {
_logger.debug("Set workload type");
_command_queue->setWorkloadType(*_ze_workload_type);
}
}

bool DriverGraph::release_blob(const Config& config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ void PluginGraph::create_new_command_queue() {
_ze_workload_type,
_group_ordinal,
_turbo);

if (_ze_workload_type.has_value()) {
_logger.debug("Set workload type");
_command_queue->setWorkloadType(*_ze_workload_type);
}
}

PluginGraph::~PluginGraph() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ TEST_P(OVCompileAndInferRequest, PluginWorkloadType) {
return property == workload_type.name();
});

OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));

ov::InferRequest req;

if (isCommandQueueExtSupported()) {
ASSERT_TRUE(workloadTypeSupported);
ov::InferRequest req;
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));

const auto properties = execNet.get_property(supported_properties.name()).as<std::vector<PropertyName>>();
ASSERT_TRUE(std::any_of(properties.begin(), properties.end(), [](const PropertyName& property) {
return property == workload_type.name();
Expand All @@ -124,9 +123,8 @@ TEST_P(OVCompileAndInferRequest, PluginWorkloadType) {
OV_ASSERT_NO_THROW(req.wait());
ASSERT_TRUE(is_called);
} else {
OV_ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_FALSE(workloadTypeSupported);
OV_EXPECT_THROW_HAS_SUBSTRING(req.infer(),
OV_EXPECT_THROW_HAS_SUBSTRING(core->compile_model(function, target_device, configuration),
ov::Exception,
"WorkloadType property is not supported by the current Driver Version!");
}
Expand All @@ -142,11 +140,10 @@ TEST_P(OVCompileAndInferRequest, CompiledModelWorkloadType) {
return property == workload_type.name();
});

ov::InferRequest req;

if (isCommandQueueExtSupported()) {
ASSERT_TRUE(workloadTypeSupported);
OV_ASSERT_NO_THROW(execNet.set_property(modelConfiguration));
ov::InferRequest req;
OV_ASSERT_NO_THROW(req = execNet.create_infer_request());
bool is_called = false;
OV_ASSERT_NO_THROW(req.set_callback([&](std::exception_ptr exception_ptr) {
Expand All @@ -157,10 +154,8 @@ TEST_P(OVCompileAndInferRequest, CompiledModelWorkloadType) {
OV_ASSERT_NO_THROW(req.wait());
ASSERT_TRUE(is_called);
} else {
OV_ASSERT_NO_THROW(req = execNet.create_infer_request());
ASSERT_FALSE(workloadTypeSupported);
OV_ASSERT_NO_THROW(execNet.set_property(modelConfiguration));
OV_EXPECT_THROW_HAS_SUBSTRING(req.infer(),
OV_EXPECT_THROW_HAS_SUBSTRING(execNet.set_property(modelConfiguration),
ov::Exception,
"WorkloadType property is not supported by the current Driver Version!");
}
Expand All @@ -172,9 +167,9 @@ TEST_P(OVCompileAndInferRequest, CompiledModelWorkloadTypeDelayedExecutor) {
ov::AnyMap modelConfiguration;
modelConfiguration[workload_type.name()] = WorkloadType::DEFAULT;
OV_ASSERT_NO_THROW(execNet.set_property(modelConfiguration));
ov::InferRequest req;

if (isCommandQueueExtSupported()) {
ov::InferRequest req;
OV_ASSERT_NO_THROW(req = execNet.create_infer_request());
bool is_called = false;
OV_ASSERT_NO_THROW(req.set_callback([&](std::exception_ptr exception_ptr) {
Expand All @@ -185,8 +180,7 @@ TEST_P(OVCompileAndInferRequest, CompiledModelWorkloadTypeDelayedExecutor) {
OV_ASSERT_NO_THROW(req.wait());
ASSERT_TRUE(is_called);
} else {
OV_ASSERT_NO_THROW(req = execNet.create_infer_request());
OV_EXPECT_THROW_HAS_SUBSTRING(req.infer(),
OV_EXPECT_THROW_HAS_SUBSTRING(execNet.create_infer_request(),
ov::Exception,
"WorkloadType property is not supported by the current Driver Version!");
}
Expand Down Expand Up @@ -215,60 +209,6 @@ 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::DEFAULT;
OV_ASSERT_NO_THROW(execNet.set_property(modelConfiguration));
ASSERT_EQ(execNet.get_property(workload_type.name()).as<WorkloadType>(), WorkloadType::DEFAULT);
OV_ASSERT_NO_THROW(req2 = execNet.create_infer_request())
OV_ASSERT_NO_THROW(req2.infer());

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);
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 All @@ -280,13 +220,12 @@ TEST_P(OVCompileAndInferRequestTurbo, CompiledModelTurbo) {
return property == intel_npu::turbo.name();
});

ov::InferRequest req;

if (isCommandQueueExtSupported()) {
ASSERT_TRUE(isTurboSupported);
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
auto turbosetting_compiled_model = execNet.get_property(intel_npu::turbo.name());
OV_ASSERT_NO_THROW(turbosetting_compiled_model = true);
ov::InferRequest req;
OV_ASSERT_NO_THROW(req = execNet.create_infer_request());
bool is_called = false;
OV_ASSERT_NO_THROW(req.set_callback([&](std::exception_ptr exception_ptr) {
Expand All @@ -297,9 +236,17 @@ TEST_P(OVCompileAndInferRequestTurbo, CompiledModelTurbo) {
OV_ASSERT_NO_THROW(req.wait());
ASSERT_TRUE(is_called);
} else {
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
OV_ASSERT_NO_THROW(req = execNet.create_infer_request());
OV_EXPECT_THROW_HAS_SUBSTRING(req.infer(), ov::Exception, "Turbo is not supported by the current driver");
auto cr_ex = configuration.find(intel_npu::defer_weights_load.name());
if (cr_ex->second.as<bool>() == false) {
OV_EXPECT_THROW_HAS_SUBSTRING(core->compile_model(function, target_device, configuration),
ov::Exception,
"Turbo is not supported by the current driver");
} else {
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
OV_EXPECT_THROW_HAS_SUBSTRING(execNet.create_infer_request(),
ov::Exception,
"Turbo is not supported by the current driver");
}
}
}

Expand Down

0 comments on commit 81f15a6

Please sign in to comment.