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] Use llvm as key work to detect new format of blob (#34448)
Xin Wang9b92b3e3cca6
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hppindex 23a16a35724..08ae828fb1c 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp@@ -105,14 +105,12 @@ public:};DynamicGraph(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,- std::optional<ov::Tensor> blob,+ ov::Tensor blob,bool blobAllocatedByPlugin,const FilteredConfig& config);std::pair<uint64_t, std::optional<std::vector<uint64_t>>> export_blob(std::ostream& stream) const override;- std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData) const override;-void set_argument_value(uint32_t argi, const void* argv) const override;void set_argument_value_with_strides(uint32_t id,diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cppindex dbd2f70cb0c..0fd0b684481 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp@@ -404,7 +404,7 @@ void DynamicGraphImpl::predictOutputShape(std::vector<MemRefType>& inputDescript}DynamicGraph::DynamicGraph(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,- std::optional<ov::Tensor> blob,+ ov::Tensor blob,bool blobAllocatedByPlugin,const FilteredConfig& config): _zeroInitStruct(zeroInitStruct),@@ -518,16 +518,6 @@ void DynamicGraph::set_workload_type(const ov::WorkloadType workloadType) const_commandQueue->setWorkloadType(zeWorkloadType);}-std::vector<ov::ProfilingInfo> DynamicGraph::process_profiling_output(const std::vector<uint8_t>& profData) const {- auto compiler = VCLCompilerImpl::getInstance();- OPENVINO_ASSERT(compiler != nullptr, "VCL compiler is nullptr");-- std::vector<uint8_t> blob(_blob->get_byte_size());- blob.assign(reinterpret_cast<const uint8_t*>(_blob->data()),- reinterpret_cast<const uint8_t*>(_blob->data()) + _blob->get_byte_size());- return compiler->process_profiling_output(profData, blob);-}-void DynamicGraph::set_argument_value(uint32_t argi, const void* argv) const {if (_impl == nullptr) {_logger.warning("Graph handle is null, dynamic pipeline to handle set_argument_value");diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/parser.cppindex 2449e024475..c1f221367d7 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp@@ -29,7 +29,7 @@ std::shared_ptr<IGraph> Parser::parse(const ov::Tensor& mainBlob,std::optional<std::shared_ptr<const ov::Model>>&& model) const {OV_ITT_TASK_CHAIN(PARSE_BLOB, itt::domains::NPUPlugin, "Parser", "parse");-#ifdef NPU_PLUGIN_DEVELOPER_BUILD+ // Detect blob formatconst void* data = mainBlob.data();size_t size = mainBlob.get_byte_size();std::string header;@@ -38,11 +38,10 @@ std::shared_ptr<IGraph> Parser::parse(const ov::Tensor& mainBlob,} else {header.assign(static_cast<const char*>(data), size);}- if (header.find("ELF") == std::string::npos) {- _logger.debug("Create graph for LLVM IR!");+ if (header.find("llvm") != std::string::npos) {+ _logger.debug("Create graph for LLVM IR, use internal function to get metadata!");return std::make_shared<DynamicGraph>(_zeroInitStruct, mainBlob, true, config);}-#endifGraphDescriptor mainGraphDesc;NetworkMetadata mainNetworkMetadata;diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cppindex eda35fa8c83..d74a2cc518c 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp@@ -71,8 +71,8 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<contensor = std::move(networkDesc.compiledNetworkTensor);if (config.get<COMPILATION_MODE>() == "HostCompile") {- // no _compiler::parse call is required. networkmetadata will be obtained in DynamicGraph constructor- _logger.debug("blob is not ELF format, create graph for LLVM IR!");+ // metadata will be obtained in initialze() of DynamicGraph+ _logger.debug("Use dynamicGraph to hold blob for HostCompile mode!");return std::make_shared<DynamicGraph>(_zeroInitStruct, std::move(tensor), true, config);}diff --git a/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.cpp b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.cppsimilarity index 100%rename from src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.cpprename to src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.cppdiff --git a/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.hpp b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.hppsimilarity index 79%rename from src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.hpprename to src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.hppindex 25c158abafb..582b4ff1c46 100644--- a/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.hpp+++ b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.hpp@@ -74,6 +74,25 @@ public:APIBaseTest::SetUp();}+ bool isLLVMFormat(std::stringstream& modelStream) {+ auto pos = modelStream.tellg();+ if (pos == std::streampos(-1)) {+ return false;+ }++ modelStream.seekg(0, std::ios::beg);++ // Assume the first 20 char of LLVM blob shall have key word 'llvm'+ std::string region(20, '\0');+ modelStream.read(®ion[0], 20);+ region.resize(modelStream.gcount());++ modelStream.clear();+ modelStream.seekg(pos);++ return region.find("llvm") != std::string::npos;+ }+protected:std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();ov::AnyMap configuration;@@ -92,33 +111,13 @@ TEST_P(InferWithHostCompileTests, Compile) {OV_ASSERT_NO_THROW(compiledModel.export_model(modelStream));// With HostCompile, the modelStream shall contain "llvm.func"- std::string line;- auto pos = modelStream.tellg();- modelStream.seekg(0, std::ios::beg);- bool isLLVMStream = false;- int searchRegion = 10;- while (std::getline(modelStream, line)) {- if (line.find("llvm.func") != std::string::npos) {- modelStream.clear();- modelStream.seekg(pos);- isLLVMStream = true;- break;- }- if (searchRegion-- < 0) {- break;- }- }- modelStream.clear();- modelStream.seekg(pos);- ASSERT_TRUE(isLLVMStream) << "CompiledStream from HostCompile mode shall has 'llvm.func' inside it";+ ASSERT_TRUE(isLLVMFormat(modelStream)) << "CompiledStream from HostCompile mode shall has 'llvm.func' inside it";ov::InferRequest reqDynamic;// Add shape check once npu_mlir_runtime is inside test packageEXPECT_THROW(reqDynamic = compiledModel.create_infer_request(), ov::Exception);}-#ifdef NPU_PLUGIN_DEVELOPER_BUILD-TEST_P(InferWithHostCompileTests, CompileAndImport) {// Skip test according to plugin specific disabledTestPatterns() (if any)SKIP_IF_CURRENT_TEST_IS_DISABLED()@@ -132,25 +131,7 @@ TEST_P(InferWithHostCompileTests, CompileAndImport) {OV_ASSERT_NO_THROW(compiledModel.export_model(modelStream));// With HostCompile, the modelStream shall contain "llvm.func"- std::string line;- auto pos = modelStream.tellg();- modelStream.seekg(0, std::ios::beg);- bool isLLVMStream = false;- int searchRegion = 10;- while (std::getline(modelStream, line)) {- if (line.find("llvm.func") != std::string::npos) {- modelStream.clear();- modelStream.seekg(pos);- isLLVMStream = true;- break;- }- if (searchRegion-- < 0) {- break;- }- }- modelStream.clear();- modelStream.seekg(pos);- ASSERT_TRUE(isLLVMStream) << "CompiledStream from HostCompile mode shall has 'llvm.func' inside it";+ ASSERT_TRUE(isLLVMFormat(modelStream)) << "CompiledStream from HostCompile mode shall has 'llvm.func' inside it";ov::CompiledModel importedModel;OV_ASSERT_NO_THROW(core->import_model(modelStream, target_device, configuration));@@ -160,8 +141,6 @@ TEST_P(InferWithHostCompileTests, CompileAndImport) {EXPECT_THROW(reqDynamic = importedModel.create_infer_request(), ov::Exception);}-#endif-} // namespace behavior} // namespace test} // namespace ov