Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/plugins/intel_npu/src/plugin/include/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <map>
#include <memory>
#include <optional>
#include <string>

#include "backends_registry.hpp"
Expand Down Expand Up @@ -62,6 +63,21 @@ class Plugin : public ov::IPlugin {
const ov::AnyMap& properties) const override;

private:
// applies ov::log::level from per-call properties and restores the previous level on scope exit
// permanent level changes belong in set_property(); per-call properties are scoped to the call
class LogLevelScope {
public:
LogLevelScope(const ov::AnyMap& props, Logger& instanceLogger);
~LogLevelScope();
LogLevelScope(const LogLevelScope&) = delete;
LogLevelScope& operator=(const LogLevelScope&) = delete;

private:
Logger& _instanceLogger;
std::optional<ov::log::Level> _prevGlobal;
std::optional<ov::log::Level> _prevInstance;
};

void update_log_level(const ov::AnyMap& properties) const;

/**
Expand Down
45 changes: 38 additions & 7 deletions src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <fstream>
#include <numeric>
#include <optional>

#include "compiled_model.hpp"
#include "intel_npu/common/compiler_adapter_factory.hpp"
Expand Down Expand Up @@ -327,6 +328,14 @@ void init_config(const IEngineBackend* backend, OptionsDesc& options, FilteredCo
}
}

std::optional<ov::log::Level> read_log_level(const ov::AnyMap& properties) {
const auto it = properties.find(ov::log::level.name());
if (it == properties.end()) {
return std::nullopt;
}
return it->second.as<ov::log::Level>();
}

} // namespace

namespace intel_npu {
Expand Down Expand Up @@ -389,7 +398,7 @@ bool Plugin::is_property_supported(const std::string& name, const ov::AnyMap& ar
std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::compile_model");
update_log_level(properties);
LogLevelScope logScope(properties, _logger);
Comment thread
alexandruenache1111 marked this conversation as resolved.

// Before going any further: if
// ... 1 - NPUW mode is activated
Expand Down Expand Up @@ -631,7 +640,7 @@ ov::SoPtr<ov::IRemoteContext> Plugin::get_default_context(const ov::AnyMap&) con

std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::import_model");
update_log_level(properties);
LogLevelScope logScope(properties, _logger);

if (properties.find(ov::hint::compiled_blob.name()) != properties.end()) {
_logger.warning("ov::hint::compiled_blob is no longer supported for import_model(stream) API! Please use new "
Expand Down Expand Up @@ -698,7 +707,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream,
std::shared_ptr<ov::ICompiledModel> Plugin::import_model(const ov::Tensor& compiledBlob,
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::import_model");
update_log_level(properties);
LogLevelScope logScope(properties, _logger);

// Need to create intermediate istream for NPUW
ov::SharedStreamBuffer buffer{compiledBlob.data(), compiledBlob.get_byte_size()};
Expand Down Expand Up @@ -758,7 +767,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(const ov::Tensor& compi
ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::query_model");
update_log_level(properties);
LogLevelScope logScope(properties, _logger);

auto localProperties = properties;

Expand Down Expand Up @@ -975,11 +984,33 @@ std::shared_ptr<ov::ICompiledModel> Plugin::parse(const ov::Tensor& tensorBig,
return std::make_shared<CompiledModel>(modelDummy, shared_from_this(), device, graph, localConfig, batchSize);
}

Plugin::LogLevelScope::LogLevelScope(const ov::AnyMap& props, Logger& instanceLogger)
: _instanceLogger(instanceLogger) {
const auto lvl = read_log_level(props);
if (!lvl) {
return;
}
_prevGlobal = Logger::global().level();
_prevInstance = _instanceLogger.level();
Logger::global().setLevel(*lvl);
_instanceLogger.setLevel(*lvl);
}

Plugin::LogLevelScope::~LogLevelScope() {
if (!_prevGlobal) {
return;
}
Logger::global().setLevel(*_prevGlobal);
_instanceLogger.setLevel(*_prevInstance);
}
Comment thread
alexandruenache1111 marked this conversation as resolved.

void Plugin::update_log_level(const ov::AnyMap& properties) const {
if (properties.count(ov::log::level.name()) != 0) {
Logger::global().setLevel(properties.at(ov::log::level.name()).as<ov::log::Level>());
_logger.setLevel(properties.at(ov::log::level.name()).as<ov::log::Level>());
const auto lvl = read_log_level(properties);
if (!lvl) {
return;
}
Logger::global().setLevel(*lvl);
_logger.setLevel(*lvl);
}

std::atomic<int> Plugin::_compiledModelLoadCounter{1};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ class ClassCompatibilityStringTestNPU : public OVCompiledModelPropertiesBase,
std::string deviceName;
ov::Core core;

private:
std::optional<utils::LoggerLevelGuard> _logGuard;

public:
void SetUp() override {
_logGuard.emplace(::intel_npu::Logger::global().level());
SKIP_IF_CURRENT_TEST_IS_DISABLED();
OVCompiledModelPropertiesBase::SetUp();
deviceName = GetParam();
}

void TearDown() override {
_logGuard.reset();
OVCompiledModelPropertiesBase::TearDown();
}
static std::string getTestCaseName(testing::TestParamInfo<std::string> obj) {
auto targetDevice = obj.param;
std::replace(targetDevice.begin(), targetDevice.end(), ':', '_');
Expand Down Expand Up @@ -114,11 +123,11 @@ TEST_P(ClassCompatibilityStringTestSuite, RuntimeRequirementsIsSupported) {
ASSERT_FALSE(it->is_mutable());
OV_ASSERT_NO_THROW(auto requirements = compiledModel.get_property(ov::runtime_requirements));

OV_ASSERT_NO_THROW(compiledModel = core.compile_model(
model,
deviceName,
{ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER),
ov::intel_npu::bypass_umd_caching(true)}));
OV_ASSERT_NO_THROW(compiledModel =
core.compile_model(model,
deviceName,
{ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER),
ov::intel_npu::bypass_umd_caching(true)}));
// Test that RUNTIME_REQUIREMENTS is supported for CID when the L0 graph extension version >= 1.16,
// and unsupported for earlier driver versions. CIP always supports it.
OV_ASSERT_NO_THROW(properties = compiledModel.get_property(ov::supported_properties));
Expand Down Expand Up @@ -155,11 +164,11 @@ TEST_P(ClassCompatibilityStringTestSuite, RuntimeRequirementsValueIsReadableWhen
OV_ASSERT_NO_THROW(requirements = compiledModel.get_property(ov::runtime_requirements));
ASSERT_FALSE(requirements.empty());

OV_ASSERT_NO_THROW(compiledModel = core.compile_model(
model,
deviceName,
{ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER),
ov::intel_npu::bypass_umd_caching(true)}));
OV_ASSERT_NO_THROW(compiledModel =
core.compile_model(model,
deviceName,
{ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER),
ov::intel_npu::bypass_umd_caching(true)}));

OV_ASSERT_NO_THROW(properties = compiledModel.get_property(ov::supported_properties));
it = find(properties.cbegin(), properties.cend(), ov::runtime_requirements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,26 @@ class ClassExecutableNetworkGetPropertiesTestNPU
ov::Any configValue;
ov::Core ie;

private:
std::optional<ov::test::utils::LoggerLevelGuard> _logGuard;

public:
void SetUp() override {
_logGuard.emplace(::intel_npu::Logger::global().level());
SKIP_IF_CURRENT_TEST_IS_DISABLED();

OVCompiledModelPropertiesBase::SetUp();

deviceName = std::get<0>(GetParam());
std::tie(configKey, configValue) = std::get<1>(GetParam());

model = ov::test::utils::make_conv_pool_relu();
}
Comment thread
alexandruenache1111 marked this conversation as resolved.

void TearDown() override {
_logGuard.reset();
OVCompiledModelPropertiesBase::TearDown();
}
static std::string getTestCaseName(
testing::TestParamInfo<std::tuple<std::string, std::pair<std::string, ov::Any>>> obj) {
std::string targetDevice;
Expand Down Expand Up @@ -366,6 +377,7 @@ TEST_P(CheckCompilerTypeProperty, CheckLogAfterSettingExtraConfigToGetProperty)
std::string logs;
std::mutex logs_mutex;
ov::Core core;
ov::test::utils::LoggerLevelGuard levelGuard(::intel_npu::Logger::global().level());

// Keep this std::function alive while logging is active.
std::function<void(std::string_view)> log_cb = [&](std::string_view msg) {
Expand Down Expand Up @@ -397,6 +409,7 @@ TEST_P(CheckCompilerTypeProperty, CheckLogAfterGettingPropertyWithExtraConfig) {
std::string logs;
std::mutex logs_mutex;
ov::Core core;
ov::test::utils::LoggerLevelGuard levelGuard(::intel_npu::Logger::global().level());

core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));

Expand Down Expand Up @@ -433,6 +446,7 @@ TEST_P(CheckCompilerTypeProperty, SetRuntimeProperty) {
std::string logs;
std::mutex logs_mutex;
ov::Core core;
ov::test::utils::LoggerLevelGuard levelGuard(::intel_npu::Logger::global().level());

core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));

Expand Down Expand Up @@ -466,6 +480,7 @@ TEST_P(CheckCompilerTypeProperty, SetCompilerPropertyForDifferentCompiler) {
std::string logs;
std::mutex logs_mutex;
ov::Core core;
ov::test::utils::LoggerLevelGuard levelGuard(::intel_npu::Logger::global().level());

core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));

Expand Down Expand Up @@ -515,6 +530,7 @@ TEST_P(CheckCompilerTypeProperty, GetCompilerVersion) {
std::string logs;
std::mutex logs_mutex;
ov::Core core;
ov::test::utils::LoggerLevelGuard levelGuard(::intel_npu::Logger::global().level());

core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));

Expand Down Expand Up @@ -615,6 +631,7 @@ TEST_P(CheckCompilerPropertyWhenImporting, ExpectedNoThrowFromImportWithCompiler
ov::Core core_compile, core_import;
ov::CompiledModel compiled_model;
std::stringstream export_stream;
ov::test::utils::LoggerLevelGuard levelGuard(::intel_npu::Logger::global().level());

OV_ASSERT_NO_THROW(compiled_model = core_compile.compile_model(model, deviceName));
OV_ASSERT_NO_THROW(compiled_model.export_model(export_stream));
Expand Down Expand Up @@ -697,6 +714,7 @@ TEST_P(CheckCompilerPropertyWhenImporting, CheckImportWithCompilerProperty) {
ov::Core core_for_importing;
ov::CompiledModel compiled_model;
std::stringstream export_stream;
ov::test::utils::LoggerLevelGuard levelGuard(::intel_npu::Logger::global().level());

OV_ASSERT_NO_THROW(compiled_model = core_for_compiler.compile_model(model, deviceName));
OV_ASSERT_NO_THROW(compiled_model.export_model(export_stream));
Expand Down Expand Up @@ -737,6 +755,7 @@ TEST_P(CheckCompilerPropertyWhenImporting, CheckImportWithCompilerPropertyAfterC
ov::Core core;
ov::CompiledModel compiled_model;
std::stringstream export_stream;
ov::test::utils::LoggerLevelGuard levelGuard(::intel_npu::Logger::global().level());

OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, deviceName));
OV_ASSERT_NO_THROW(compiled_model.export_model(export_stream));
Expand Down Expand Up @@ -778,9 +797,8 @@ TEST_P(CheckCpuPinning, CheckCompileModelWithCpuPinningFromSetProperty) {
ov::Core core;
ov::CompiledModel compiled_model;

ov::log::Level previous_log_level = ov::log::Level::NO;
OV_ASSERT_NO_THROW(previous_log_level = core.get_property(deviceName, ov::log::level));
core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));
ov::test::utils::LoggerLevelGuard logGuard(ov::log::Level::WARNING);
core.set_property(deviceName, ov::log::level(ov::log::Level::WARNING));
Comment thread
alexandruenache1111 marked this conversation as resolved.

// Keep this std::function alive while logging is active.
std::function<void(std::string_view)> log_cb = [&](std::string_view msg) {
Expand All @@ -794,7 +812,6 @@ TEST_P(CheckCpuPinning, CheckCompileModelWithCpuPinningFromSetProperty) {
OV_ASSERT_NO_THROW(core.set_property(deviceName, ov::hint::enable_cpu_pinning(true)));
OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, deviceName));
}
Comment thread
alexandruenache1111 marked this conversation as resolved.
OV_ASSERT_NO_THROW(core.set_property(deviceName, ov::log::level(previous_log_level)));

bool enable_cpu_pinning = false;
OV_ASSERT_NO_THROW(enable_cpu_pinning = compiled_model.get_property(ov::hint::enable_cpu_pinning));
Expand Down Expand Up @@ -824,9 +841,7 @@ TEST_P(CheckCpuPinning, CheckCompileModelWithCpuPinningFromCompileProperty) {
ov::Core core;
ov::CompiledModel compiled_model;

ov::log::Level previous_log_level = ov::log::Level::NO;
OV_ASSERT_NO_THROW(previous_log_level = core.get_property(deviceName, ov::log::level));
core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));
ov::test::utils::LoggerLevelGuard logGuard(ov::log::Level::WARNING);

// Keep this std::function alive while logging is active.
std::function<void(std::string_view)> log_cb = [&](std::string_view msg) {
Expand All @@ -837,10 +852,11 @@ TEST_P(CheckCpuPinning, CheckCompileModelWithCpuPinningFromCompileProperty) {

{
ov::test::utils::LogCallbackGuard log_callback_guard(log_cb);
OV_ASSERT_NO_THROW(compiled_model =
core.compile_model(model, deviceName, {ov::hint::enable_cpu_pinning(true)}));
OV_ASSERT_NO_THROW(compiled_model = core.compile_model(
model,
deviceName,
{ov::hint::enable_cpu_pinning(true), ov::log::level(ov::log::Level::WARNING)}));
}
OV_ASSERT_NO_THROW(core.set_property(deviceName, ov::log::level(previous_log_level)));

bool enable_cpu_pinning = false;
OV_ASSERT_NO_THROW(enable_cpu_pinning = compiled_model.get_property(ov::hint::enable_cpu_pinning));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2305,11 +2305,10 @@ TEST_P(CpuVaTensorsTests, checkResultsAfterRawMemoryIsDestroyedAndReallocatedAft
logs.push_back('\n');
};

internal_core.set_property(target_device, ov::log::level(ov::log::Level::DEBUG));
{
// don't flood console with messages from model compilation
utils::LogCallbackGuard log_callback_guard(log_cb);
ov::CompiledModel compiled_model = internal_core.compile_model(model, target_device, configuration);
internal_core.set_property(target_device, ov::log::level(ov::log::Level::DEBUG));
inference_request = compiled_model.create_infer_request();
}
logs.clear();
Expand Down Expand Up @@ -2369,11 +2368,10 @@ TEST_P(CpuVaTensorsTests, checkResultsAfterRunningWithSameRawMemoryMultipleTimes
float* input_data = static_cast<float*>(::operator new(shape_size * sizeof(float), std::align_val_t(4096)));
float* output_data = static_cast<float*>(::operator new(shape_size * sizeof(float), std::align_val_t(4096)));

internal_core.set_property(target_device, ov::log::level(ov::log::Level::DEBUG));
{
// don't flood console with messages from model compilation
utils::LogCallbackGuard log_callback_guard(log_cb);
ov::CompiledModel compiled_model = internal_core.compile_model(model, target_device, configuration);
internal_core.set_property(target_device, ov::log::level(ov::log::Level::DEBUG));
inference_request = compiled_model.create_infer_request();
inference_request.set_input_tensor(ov::Tensor{ov::element::f32, shape, input_data});
inference_request.set_output_tensor(ov::Tensor{ov::element::f32, shape, output_data});
Expand Down Expand Up @@ -2435,11 +2433,10 @@ TEST_P(CpuVaTensorsTests, checkResultsAfterRunningWithSameZeroTensorMultipleTime
logs.push_back('\n');
};

internal_core.set_property(target_device, ov::log::level(ov::log::Level::DEBUG));
{
// don't flood console with messages from model compilation
utils::LogCallbackGuard log_callback_guard(log_cb);
ov::CompiledModel compiled_model = internal_core.compile_model(model, target_device, configuration);
internal_core.set_property(target_device, ov::log::level(ov::log::Level::DEBUG));
inference_request = compiled_model.create_infer_request();
input_tensor = inference_request.get_input_tensor();
output_tensor = inference_request.get_output_tensor();
Expand Down Expand Up @@ -2500,11 +2497,10 @@ TEST_P(CpuVaTensorsTests, checkResultsAfterRunningWithSameZeroHostTensorMultiple
float* input_data = input_tensor.data<float>();
float* output_data = output_tensor.data<float>();

internal_core.set_property(target_device, ov::log::level(ov::log::Level::DEBUG));
{
// don't flood console with messages from model compilation
utils::LogCallbackGuard log_callback_guard(log_cb);
ov::CompiledModel compiled_model = internal_core.compile_model(model, target_device, configuration);
internal_core.set_property(target_device, ov::log::level(ov::log::Level::DEBUG));
inference_request = compiled_model.create_infer_request();
inference_request.set_input_tensor(input_tensor);
inference_request.set_output_tensor(output_tensor);
Expand Down Expand Up @@ -2580,8 +2576,7 @@ TEST_P(CpuVaTensorsTests, checkResultsAfterRunningWithSameRawMemoryMultipleTimes
::operator delete(output_data, std::align_val_t(4096));
}

class DynamicBoundsTests : public InferRequestRunTests
{
class DynamicBoundsTests : public InferRequestRunTests {
public:
void SetUp() override {
InferRequestRunTests::SetUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static std::string getTestCaseName(const testing::TestParamInfo<std::string>& ob
}
} // namespace OVClassNetworkTestName

const std::vector<ov::AnyMap> configs = {{}};
const std::vector<ov::AnyMap> configs = {{ov::log::level(ov::log::Level::ERR)}};

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTests_OVClassBasicTestP,
Expand Down
Loading
Loading