-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[NPU]Move VCL API from compiler_adapter to utils #34662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WenjingKangIntel
wants to merge
1
commit into
openvinotoolkit:master
Choose a base branch
from
WenjingKangIntel:wenjing/mv-vclapi-to-utils
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+168
−122
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "vcl.h" | ||
| #include "intel_npu/utils/logger/logger.hpp" | ||
| #include "openvino/core/except.hpp" | ||
| namespace intel_npu { | ||
|
|
||
| // clang-format off | ||
| #define vcl_symbols_list() \ | ||
| vcl_symbol_statement(vclGetVersion) \ | ||
| vcl_symbol_statement(vclCompilerCreate) \ | ||
| vcl_symbol_statement(vclCompilerDestroy) \ | ||
| vcl_symbol_statement(vclCompilerGetProperties) \ | ||
| vcl_symbol_statement(vclQueryNetworkCreate) \ | ||
| vcl_symbol_statement(vclQueryNetwork) \ | ||
| vcl_symbol_statement(vclQueryNetworkDestroy) \ | ||
| vcl_symbol_statement(vclExecutableCreate) \ | ||
| vcl_symbol_statement(vclExecutableDestroy) \ | ||
| vcl_symbol_statement(vclExecutableGetSerializableBlob) \ | ||
| vcl_symbol_statement(vclProfilingCreate) \ | ||
| vcl_symbol_statement(vclGetDecodedProfilingBuffer) \ | ||
| vcl_symbol_statement(vclProfilingDestroy) \ | ||
| vcl_symbol_statement(vclProfilingGetProperties) \ | ||
| vcl_symbol_statement(vclLogHandleGetString) \ | ||
| vcl_symbol_statement(vclAllocatedExecutableCreate2) \ | ||
| vcl_symbol_statement(vclGetCompilerSupportedOptions) \ | ||
| vcl_symbol_statement(vclGetCompilerIsOptionSupported) \ | ||
|
|
||
|
|
||
| // symbols that may not be supported in older versions of vcl | ||
| #define vcl_weak_symbols_list() \ | ||
| vcl_symbol_statement(vclAllocatedExecutableCreateWSOneShot) | ||
| // clang-format on | ||
|
|
||
| class VCLApi { | ||
| public: | ||
| VCLApi(); | ||
| VCLApi(const VCLApi& other) = delete; | ||
| VCLApi(VCLApi&& other) = delete; | ||
| void operator=(const VCLApi&) = delete; | ||
| void operator=(VCLApi&&) = delete; | ||
|
|
||
| static const std::shared_ptr<VCLApi> getInstance(); | ||
| std::shared_ptr<void> getLibrary() const { | ||
| return lib; | ||
| } | ||
|
|
||
| #define vcl_symbol_statement(vcl_symbol) decltype(&::vcl_symbol) vcl_symbol; | ||
| vcl_symbols_list(); | ||
| vcl_weak_symbols_list(); | ||
| #undef vcl_symbol_statement | ||
|
|
||
| private: | ||
| std::shared_ptr<void> lib; | ||
| Logger _logger; | ||
| }; | ||
|
|
||
| #define vcl_symbol_statement(vcl_symbol) \ | ||
| template <typename... Args> \ | ||
| inline typename std::invoke_result<decltype(&::vcl_symbol), Args...>::type wrapped_##vcl_symbol(Args... args) { \ | ||
| const auto& ptr = VCLApi::getInstance(); \ | ||
| if (ptr->vcl_symbol == nullptr) { \ | ||
| OPENVINO_THROW("Unsupported vcl_symbol " #vcl_symbol); \ | ||
| } \ | ||
| return ptr->vcl_symbol(std::forward<Args>(args)...); \ | ||
| } | ||
| vcl_symbols_list(); | ||
| vcl_weak_symbols_list(); | ||
| #undef vcl_symbol_statement | ||
| #define vcl_symbol_statement(vcl_symbol) inline decltype(&::vcl_symbol) vcl_symbol = wrapped_##vcl_symbol; | ||
| vcl_symbols_list(); | ||
| vcl_weak_symbols_list(); | ||
| #undef vcl_symbol_statement | ||
|
|
||
| } // namespace intel_npu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| # | ||
|
|
||
| add_subdirectory(logger) | ||
| add_subdirectory(vcl) | ||
|
|
||
| if(ENABLE_NPU_PLUGIN_ENGINE) | ||
| add_subdirectory(zero) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Copyright (C) 2018-2026 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| set(TARGET_NAME openvino_npu_vcl_utils) | ||
|
|
||
| file(GLOB_RECURSE SOURCES *.cpp) | ||
| source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) | ||
|
|
||
| add_library(${TARGET_NAME} STATIC ${SOURCES}) | ||
| set_target_properties( | ||
| ${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) | ||
| ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) | ||
|
|
||
| add_library(openvino::npu_vcl_utils ALIAS ${TARGET_NAME}) | ||
|
|
||
| target_include_directories(${TARGET_NAME} | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${NPU_UTILS_SOURCE_DIR}/include> | ||
| ) | ||
| target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime::dev openvino_npu_logger_utils) | ||
|
|
||
| # | ||
| # targets install | ||
| # | ||
|
|
||
| ov_install_static_lib(${TARGET_NAME} ${NPU_PLUGIN_COMPONENT}) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #include "intel_npu/utils/vcl/vcl_api.hpp" | ||
|
|
||
| #include <mutex> | ||
|
|
||
| #include "openvino/util/file_util.hpp" | ||
| #include "openvino/util/shared_object.hpp" | ||
|
|
||
| namespace intel_npu { | ||
| VCLApi::VCLApi() : _logger("VCLApi", Logger::global().level()) { | ||
| const std::filesystem::path baseName = "openvino_intel_npu_compiler"; | ||
| try { | ||
| auto libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName); | ||
| _logger.debug("Try to load openvino_intel_npu_compiler"); | ||
| this->lib = ov::util::load_shared_object(libpath); | ||
| } catch (const std::runtime_error& error) { | ||
| _logger.debug("Failed to load openvino_intel_npu_compiler"); | ||
| OPENVINO_THROW(error.what()); | ||
| } | ||
|
|
||
| try { | ||
| #define vcl_symbol_statement(vcl_symbol) \ | ||
| this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol)); | ||
| vcl_symbols_list(); | ||
| #undef vcl_symbol_statement | ||
| } catch (const std::runtime_error& error) { | ||
| _logger.debug("Failed to get formal symbols from openvino_intel_npu_compiler"); | ||
| OPENVINO_THROW(error.what()); | ||
| } | ||
|
|
||
| #define vcl_symbol_statement(vcl_symbol) \ | ||
| try { \ | ||
| this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol)); \ | ||
| } catch (const std::runtime_error&) { \ | ||
| _logger.debug("Failed to get %s from openvino_intel_npu_compiler", #vcl_symbol); \ | ||
| this->vcl_symbol = nullptr; \ | ||
| } | ||
| vcl_weak_symbols_list(); | ||
| #undef vcl_symbol_statement | ||
|
|
||
| #define vcl_symbol_statement(vcl_symbol) vcl_symbol = this->vcl_symbol; | ||
| vcl_symbols_list(); | ||
| vcl_weak_symbols_list(); | ||
| #undef vcl_symbol_statement | ||
| } | ||
|
|
||
| const std::shared_ptr<VCLApi> VCLApi::getInstance() { | ||
| static std::shared_ptr<VCLApi> instance = std::make_shared<VCLApi>(); | ||
| return instance; | ||
| } | ||
|
|
||
| } // namespace intel_npu |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need to expose a new target, as that brings additional coupling we should be able to get away without.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment. Remove the export to avoid exposing this target.