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`] [`DOCUMENTATION`] [`TEST FIXES`] [`ENCRYPTION`] Add documentation & test fixes for `CACHE_ENCRYPTION_CALLBACKS` option (#35681)
Mircea-Aurelian Dan2492324617a7
diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/npu-device.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/npu-device.rstindex fa6295237a5..72933b5beb8 100644--- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/npu-device.rst+++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/npu-device.rst@@ -184,6 +184,11 @@ The NPU device is currently supported by AUTO inference modesov::intel_npu::compiler_versionov::intel_npu::max_tiles+ .. tab-item:: Write-only properties++ .. code-block::++ ov::cache_encryption_callbacks.. note::@@ -313,6 +318,66 @@ Example: Setting ``performance-hint-override=latency`` through ``ov::intel_npu::to use all available resources for the given platform. If ``ov::intel_npu::max_tiles`` is not provided,the compiler falls back to a fixed lookup table embedded in the library to determine available resources, which might not be representative of all SKUs.+**ov::cache_encryption_callbacks**++Enables blob encryption and decryption using user-provided callbacks. This is a write-only property that accepts a struct with encryption and decryption callback functions.+Can be used for both model caching and user requested export or import of compiled models (blobs) scenarios.++.. note::++ If user compiles a model using ``Compiler-In-Driver``, currently there is no secure compilation available in driver until ``32.0.100.4724`` (inclusively) and a warning+ describing this potential security flaw will be issued if encryption callbacks were set.++Usage example:++.. note::++ Will set OV provided ``codec_xor`` utility encryption and decryption at plugin level, every compiled model created will inherit these callbacks if not changed explicitly.++.. code-block::++ core.set_property("NPU", ov::cache_encryption_callbacks(ov::EncryptionCallbacks(ov::util::codec_xor, ov::util::codec_xor)));++ core.compile_model(ov_model, "NPU").export_model(encrypted_blob_stream);++ core.import_model(encrypted_blob_stream, "NPU");++.. note::++ Also force decryption function by providing it as a property to ``import_model`` API++.. code-block::++ core.import_model(encrypted_blob_stream, "NPU", {ov::cache_encryption_callbacks(ov::EncryptionCallbacks{nullptr, ov::util::codec_xor})});++.. note::++ Force other encryption and decryption callbacks for compiled model below++.. code-block::++ auto compile_model = core.compile_model(ov_model, "NPU", {ov::cache_encryption_callbacks(ov::EncryptionCallbacks{[](const std::string& str) {+ auto custom_encryption = str;+ // user encryption logic here...+ return custom_encryption;+ }, nullptr})});++ compiled_model.export_model(custom_encrypted_blob_stream);++or++.. code-block::++ auto compile_model = core.compile_model(ov_model, "NPU");++ compiled_model.set_property(ov::cache_encryption_callbacks(ov::EncryptionCallbacks{[](const std::string& str) {+ auto custom_encryption = str;+ // user encryption logic here...+ return custom_encryption;+ }, nullptr}));++ compiled_model.export_model(custom_encrypted_blob_stream);+Limitations#############################diff --git a/src/plugins/intel_npu/src/plugin/src/properties.cpp b/src/plugins/intel_npu/src/plugin/src/properties.cppindex 66acba2aaae..829266f8ab5 100644--- a/src/plugins/intel_npu/src/plugin/src/properties.cpp+++ b/src/plugins/intel_npu/src/plugin/src/properties.cpp@@ -598,15 +598,7 @@ void Properties::registerPluginProperties() {});TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::enable_cpu_pinning, ENABLE_CPU_PINNING);- FORCE_REGISTER_CUSTOM_PROPERTY(ov::hint::model,- MODEL_PTR,- true,- ov::PropertyMutability::RO,- [](const Config& /* unusedConfig */) {- return std::shared_ptr<const ov::Model>(nullptr);- });-- FORCE_REGISTER_CUSTOM_PROPERTY(+ TRY_REGISTER_CUSTOM_PROPERTY(ov::cache_encryption_callbacks,CACHE_ENCRYPTION_CALLBACKS,true,@@ -615,9 +607,17 @@ void Properties::registerPluginProperties() {return (ov::EncryptionCallbacks{nullptr,nullptr}); // enclosed in parentheses due to warning C4002 treated as error: too many arguments for- // function-like macro invocation 'FORCE_REGISTER_CUSTOM_PROPERTY'+ // function-like macro invocation 'TRY_REGISTER_CUSTOM_PROPERTY'});+ FORCE_REGISTER_CUSTOM_PROPERTY(ov::hint::model,+ MODEL_PTR,+ true,+ ov::PropertyMutability::RO,+ [](const Config& /* unusedConfig */) {+ return std::shared_ptr<const ov::Model>(nullptr);+ });+// NPUW properties are requested by OV Core during caching and have no effect on the NPU plugin. But we still need// to enable those for OV Core to query.for_each_exposed_npuw_option([&](auto tag) {@@ -799,6 +799,18 @@ void Properties::registerCompiledModelProperties() {return config.get<WORKLOAD_TYPE>();});+ TRY_REGISTER_CUSTOM_PROPERTY(+ ov::cache_encryption_callbacks,+ CACHE_ENCRYPTION_CALLBACKS,+ true,+ ov::PropertyMutability::WO,+ [](const Config& /* unusedConfig */) {+ return (ov::EncryptionCallbacks{+ nullptr,+ nullptr}); // enclosed in parentheses due to warning C4002 treated as error: too many arguments for+ // function-like macro invocation 'TRY_REGISTER_CUSTOM_PROPERTY'+ });+FORCE_REGISTER_CUSTOM_PROPERTY(ov::hint::model,MODEL_PTR,true,@@ -816,18 +828,6 @@ void Properties::registerCompiledModelProperties() {return std::string("");});- FORCE_REGISTER_CUSTOM_PROPERTY(- ov::cache_encryption_callbacks,- CACHE_ENCRYPTION_CALLBACKS,- true,- ov::PropertyMutability::WO,- [](const Config& /* unusedConfig */) {- return (ov::EncryptionCallbacks{- nullptr,- nullptr}); // enclosed in parentheses due to warning C4002 treated as error: too many arguments for- // function-like macro invocation 'FORCE_REGISTER_CUSTOM_PROPERTY'- });-// 2. Metrics (static device and enviroment properties)// ========// REGISTER_SIMPLE_METRIC format: (property, public true/false, return value)diff --git a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/model_cache.cpp b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/model_cache.cppindex a05648e1219..6aefb45e1ba 100644--- a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/model_cache.cpp+++ b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/model_cache.cpp@@ -16,18 +16,32 @@ std::vector<ov::AnyMap> config = {{},{ov::enable_weightless(true),ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN), // only CIP is allowed for ONE_SHOTov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ONE_SHOT),ov::enable_mmap(false)}, // enable_mmap for both `import_model(stream)` and `import_model(tensor)` paths{ov::enable_weightless(true),ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN),ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ONE_SHOT),ov::enable_mmap(true)},{ov::enable_weightless(true),ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER),ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ITERATIVE),ov::enable_mmap(false)},{ov::enable_weightless(true),ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER),+ ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ITERATIVE),+ ov::enable_mmap(true)},+ {ov::enable_weightless(true),+ ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN),+ ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ITERATIVE),+ ov::enable_mmap(false)},+ {ov::enable_weightless(true),+ ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN),ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ITERATIVE),ov::enable_mmap(true)}};diff --git a/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/compiled_model/model_cache.cpp b/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/compiled_model/model_cache.cppindex 4cf2aacb3f6..9881f607b71 100644--- a/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/compiled_model/model_cache.cpp+++ b/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/compiled_model/model_cache.cpp@@ -17,18 +17,32 @@ std::vector<ov::AnyMap> config = {{},{ov::enable_weightless(true),ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN), // only CIP is allowed for ONE_SHOTov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ONE_SHOT),ov::enable_mmap(false)}, // enable_mmap for both `import_model(stream)` and `import_model(tensor)` paths{ov::enable_weightless(true),ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN),ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ONE_SHOT),ov::enable_mmap(true)},{ov::enable_weightless(true),ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER),ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ITERATIVE),ov::enable_mmap(false)},{ov::enable_weightless(true),ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER),+ ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ITERATIVE),+ ov::enable_mmap(true)},+ {ov::enable_weightless(true),+ ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN),+ ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ITERATIVE),+ ov::enable_mmap(false)},+ {ov::enable_weightless(true),+ ov::cache_mode(ov::CacheMode::OPTIMIZE_SIZE),+ ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN),ov::intel_npu::separate_weights_version(ov::intel_npu::WSVersion::ITERATIVE),ov::enable_mmap(true)}};diff --git a/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml b/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xmlindex 4df134f9242..6dadc83b528 100644--- a/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml+++ b/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml@@ -888,7 +888,7 @@ Example:<backend>LEVEL0</backend></enable_rules><filters>- <filter>.*WeightlessCacheAccuracy.*ENABLE_WEIGHTLESS.*NPU3720.*</filter>+ <filter>.*WeightlessCacheAccuracy.*ENABLE_WEIGHTLESS.*NPU_COMPILER_TYPE.*DRIVER.*</filter></filters></skip_config>