OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Add offline compilation unit tests (#34161)
Alexandru Enache54edbc1e8924
diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txtindex 3973cdd4172..91b28fbad36 100644--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt@@ -13,6 +13,7 @@ set(MANDATORY_UNIT_TESTS_LIBS"openvino::reference""openvino::npu_al""openvino::npu_logger_utils"+ "openvino_npu_common""openvino::npu_ops")@@ -21,6 +22,7 @@ ov_add_test_target(ROOT ${CMAKE_CURRENT_SOURCE_DIR}ADDITIONAL_SOURCE_DIRS${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/partitioning+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/backend/srcDEPENDENCIESopenvino::runtimeINCLUDES@@ -31,6 +33,9 @@ ov_add_test_target(${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/include${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/al/include${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/backend/include/+ ${OpenVINO_SOURCE_DIR}/thirdparty/level_zero/level-zero+ ${OpenVINO_SOURCE_DIR}/thirdparty/level_zero/level-zero/includeOBJECT_FILES${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/src/metadata.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.cppdiff --git a/src/plugins/intel_npu/tests/unit/main.cpp b/src/plugins/intel_npu/tests/unit/main.cppindex 0ff604a329b..73cb83389ab 100644--- a/src/plugins/intel_npu/tests/unit/main.cpp+++ b/src/plugins/intel_npu/tests/unit/main.cpp@@ -4,7 +4,13 @@#include <signal.h>+#include <openvino/runtime/intel_npu/properties.hpp>#include <sstream>++#include "intel_npu/utils/zero/zero_api.hpp"+#include "openvino/util/file_util.hpp"+#include "openvino/util/shared_object.hpp"+#include "ze_api.h"#ifdef WIN32# include <process.h>#endif@@ -21,6 +27,23 @@ int main(int argc, char** argv, char** envp) {// register crashHandler for SIGSEGV signalsignal(SIGSEGV, sigsegv_handler);+ std::shared_ptr<void> lib;+ try {+ using zelSetDriverTeardownF = ze_result_t (*)();+ zelSetDriverTeardownF zelSetDriverTeardown = nullptr;++ auto libpath = ov::util::make_plugin_library_name({}, "ze_loader");+#if !defined(_WIN32) && !defined(ANDROID)+ libpath += LIB_ZE_LOADER_SUFFIX;+#endif+ lib = ov::util::load_shared_object(libpath);+ zelSetDriverTeardown =+ reinterpret_cast<zelSetDriverTeardownF>(ov::util::get_symbol(lib, "zelSetDriverTeardown"));+ zelSetDriverTeardown();+ } catch (...) {+ // ze_loader not present on the system, probably it is not an NPU host+ }+std::ostringstream oss;oss << "Command line args (" << argc << "): ";for (int c = 0; c < argc; ++c) {diff --git a/src/plugins/intel_npu/tests/unit/npu/offline_compilation.cpp b/src/plugins/intel_npu/tests/unit/npu/offline_compilation.cppnew file mode 100644index 00000000000..bfa2763c4cc--- /dev/null+++ b/src/plugins/intel_npu/tests/unit/npu/offline_compilation.cpp@@ -0,0 +1,60 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gtest/gtest.h>++#include "common_test_utils/subgraph_builders/multi_single_conv.hpp"+#include "common_test_utils/test_assertions.hpp"+#include "common_test_utils/test_constants.hpp"+#include "intel_npu/npu_private_properties.hpp"+#include "openvino/runtime/core.hpp"+#include "openvino/runtime/intel_npu/properties.hpp"+#include "openvino/runtime/properties.hpp"+#include "zero_backend.hpp"++using namespace ov::intel_npu;+using namespace ov::test::utils;++class OfflineCompilationUnitTests : public ::testing::Test {+protected:+ void SetUp() override {+ std::vector<std::string> availableDevices = core.get_available_devices();+ auto it = std::find(availableDevices.begin(), availableDevices.end(), DEVICE_NPU);+ ASSERT_TRUE(it == availableDevices.end());+ }++ ov::Core core;+};++TEST_F(OfflineCompilationUnitTests, CompileWithCiPWhenDriverNotInstalledSetProperty) {+ ov::AnyMap config;++ config[ov::intel_npu::compiler_type.name()] = ov::intel_npu::CompilerType::PLUGIN;+ config[ov::intel_npu::platform.name()] = ov::intel_npu::Platform::NPU5010;+ core.set_property(DEVICE_NPU, config);++ std::shared_ptr<ov::Model> model = ov::test::utils::make_multi_single_conv();+ OV_ASSERT_NO_THROW(core.compile_model(model, DEVICE_NPU));+}++TEST_F(OfflineCompilationUnitTests, CompileWithCiPWhenDriverNotInstalled) {+ ov::AnyMap config;++ config[ov::intel_npu::compiler_type.name()] = ov::intel_npu::CompilerType::PLUGIN;+ config[ov::intel_npu::platform.name()] = ov::intel_npu::Platform::NPU5010;++ std::shared_ptr<ov::Model> model = ov::test::utils::make_multi_single_conv();+ OV_ASSERT_NO_THROW(core.compile_model(model, DEVICE_NPU, config));+}++using UnavailableDeviceTests = ::testing::Test;++TEST_F(UnavailableDeviceTests, GetDeviceNotAvailable) {+ ov::Core core;+ OV_ASSERT_NO_THROW(+ core.set_property("NPU", {{ov::intel_npu::compiler_type.name(), ov::intel_npu::CompilerType::DRIVER}}));++ std::shared_ptr<intel_npu::ZeroEngineBackend> backend;+ ASSERT_ANY_THROW(backend = std::make_shared<intel_npu::ZeroEngineBackend>());+}