-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add NPU compile_tool and single-image-test #24784
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
Merged
akladiev
merged 7 commits into
openvinotoolkit:master
from
Maxim-Doronin:md/integrate_npu_tools
Jun 28, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
23f3789
Add NPU compile_tool and single-image-test
Maxim-Doronin 391ba14
cmake fixes
Maxim-Doronin d4fce1b
cpplint fixes
Maxim-Doronin c4051fe
Add npu_internal cpack target
Maxim-Doronin b9da6c0
Fix warnings
Maxim-Doronin 29a1319
Copyright fixes
Maxim-Doronin dc6ebe6
Merge branch 'master' into md/integrate_npu_tools
akladiev 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # | ||
| # Copyright (C) 2024 Intel Corporation. | ||
| # SPDX-License-Identifier: Apache 2.0 | ||
| # | ||
|
|
||
| add_subdirectory(common) | ||
| add_subdirectory(compile_tool) | ||
| add_subdirectory(single-image-test) |
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,29 @@ | ||
| # | ||
| # Copyright (C) 2024 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| set(TARGET_NAME "npu_tools_utils") | ||
|
|
||
| # | ||
| # Define the target | ||
| # | ||
|
|
||
| ov_add_target(ADD_CPPLINT | ||
| TYPE STATIC | ||
| NAME ${TARGET_NAME} | ||
| ROOT ${CMAKE_CURRENT_SOURCE_DIR} | ||
| INCLUDES | ||
| PUBLIC | ||
| "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" | ||
| LINK_LIBRARIES | ||
| PRIVATE | ||
| openvino::runtime) | ||
|
|
||
| set_target_properties(${TARGET_NAME} PROPERTIES | ||
| FOLDER ${CMAKE_CURRENT_SOURCE_DIR} | ||
| CXX_STANDARD 17) | ||
|
|
||
| if (CMAKE_COMPILER_IS_GNUCXX) | ||
| target_compile_options(${TARGET_NAME} PRIVATE -Wall) | ||
| endif() |
272 changes: 272 additions & 0 deletions
272
src/plugins/intel_npu/tools/common/include/data_type_converters.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,272 @@ | ||
| // | ||
| // Copyright (C) 2024 Intel Corporation. | ||
| // SPDX-License-Identifier: Apache 2.0 | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "openvino/core/except.hpp" | ||
| #include "openvino/core/type.hpp" | ||
| #include "openvino/core/type/element_type.hpp" | ||
| #include "openvino/core/type/element_type_traits.hpp" | ||
|
|
||
| #include <limits> | ||
|
|
||
| namespace npu { | ||
| namespace utils { | ||
|
|
||
| namespace details { | ||
|
|
||
| template <bool Cond, class Func> | ||
| std::enable_if_t<Cond> staticIf(Func&& func) { | ||
| func(); | ||
| } | ||
|
|
||
| template <bool Cond, class Func> | ||
| std::enable_if_t<!Cond> staticIf(Func&&) { | ||
| } | ||
|
|
||
| // To overcome the syntax parse error, when `>` comparison operator is treated as | ||
| // template closing bracket | ||
| template <typename T1, typename T2> | ||
| constexpr bool Greater(T1&& v1, T2&& v2) { | ||
| return v1 > v2; | ||
| } | ||
|
|
||
| } // namespace details | ||
|
|
||
| // | ||
| // Bool logic | ||
| // | ||
|
|
||
| template <typename T> | ||
| using not_ = std::negation<T>; | ||
|
|
||
| template <typename... Ts> | ||
| using or_ = std::disjunction<Ts...>; | ||
|
|
||
| template <typename... Ts> | ||
| using and_ = std::conjunction<Ts...>; | ||
|
|
||
| // | ||
| // enable_if | ||
| // | ||
|
|
||
| template <typename T, typename... Args> | ||
| using enable_t = std::enable_if_t<(Args::value && ...), T>; | ||
|
|
||
| // | ||
| // Standart data types | ||
| // | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_same<OutT, InT>> checked_cast(InT value) { | ||
| return value; | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_integral<InT>, std::is_signed<InT>, std::is_integral<OutT>, std::is_signed<OutT>, | ||
| not_<std::is_same<OutT, InT>>> | ||
| checked_cast(InT value) { | ||
| details::staticIf<std::numeric_limits<InT>::lowest() < std::numeric_limits<OutT>::lowest()>([&] { | ||
| OPENVINO_ASSERT(value >= std::numeric_limits<OutT>::lowest(), "Can not safely cast ", | ||
| static_cast<int64_t>(value), " from ", ov::element::from<InT>(), " to ", | ||
| ov::element::from<OutT>()); | ||
| }); | ||
|
|
||
| details::staticIf<details::Greater(std::numeric_limits<InT>::max(), std::numeric_limits<OutT>::max())>([&] { | ||
| OPENVINO_ASSERT(value <= std::numeric_limits<OutT>::max(), "Can not safely cast ", static_cast<int64_t>(value), | ||
| " from ", ov::element::from<InT>(), " to ", ov::element::from<OutT>()); | ||
| }); | ||
|
|
||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_integral<InT>, std::is_unsigned<InT>, std::is_integral<OutT>, std::is_unsigned<OutT>, | ||
| not_<std::is_same<OutT, InT>>> | ||
| checked_cast(InT value) { | ||
| details::staticIf<details::Greater(std::numeric_limits<InT>::max(), std::numeric_limits<OutT>::max())>([&] { | ||
| OPENVINO_ASSERT(value <= std::numeric_limits<OutT>::max(), "Can not safely cast ", static_cast<uint64_t>(value), | ||
| " from ", ov::element::from<InT>(), " to ", ov::element::from<OutT>()); | ||
| }); | ||
|
|
||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_integral<InT>, std::is_unsigned<InT>, std::is_integral<OutT>, std::is_signed<OutT>> checked_cast( | ||
| InT value) { | ||
| details::staticIf<details::Greater(std::numeric_limits<InT>::max(), | ||
| static_cast<std::make_unsigned_t<OutT>>(std::numeric_limits<OutT>::max()))>([&] { | ||
| OPENVINO_ASSERT(value <= static_cast<std::make_unsigned_t<OutT>>(std::numeric_limits<OutT>::max()), | ||
| "Can not safely cast ", static_cast<uint64_t>(value), " from ", ov::element::from<InT>(), | ||
| " to ", ov::element::from<OutT>()); | ||
| }); | ||
|
|
||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_integral<InT>, std::is_signed<InT>, std::is_integral<OutT>, std::is_unsigned<OutT>> checked_cast( | ||
| InT value) { | ||
| OPENVINO_ASSERT(value >= 0, "Can not safely cast ", static_cast<int64_t>(value), " from ", ov::element::from<InT>(), | ||
| " to ", ov::element::from<OutT>()); | ||
|
|
||
| details::staticIf<details::Greater(static_cast<std::make_unsigned_t<InT>>(std::numeric_limits<InT>::max()), | ||
| std::numeric_limits<OutT>::max())>([&] { | ||
| OPENVINO_ASSERT(static_cast<std::make_unsigned_t<InT>>(value) <= std::numeric_limits<OutT>::max(), | ||
| "Can not safely cast ", static_cast<int64_t>(value), " from ", ov::element::from<InT>(), " to ", | ||
| ov::element::from<OutT>()); | ||
| }); | ||
|
|
||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_floating_point<InT>, std::is_integral<OutT>> checked_cast(InT value) { | ||
| OPENVINO_ASSERT(value <= static_cast<InT>(std::numeric_limits<OutT>::max()), "Can not safely cast ", value, | ||
| " from ", ov::element::from<InT>(), " to ", ov::element::from<OutT>()); | ||
|
|
||
| OPENVINO_ASSERT(value >= static_cast<InT>(std::numeric_limits<OutT>::lowest()), "Can not safely cast ", value, | ||
| " from ", ov::element::from<InT>(), " to ", ov::element::from<OutT>()); | ||
|
|
||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_integral<InT>, std::is_signed<InT>, std::is_floating_point<OutT>> checked_cast(InT value) { | ||
| OPENVINO_ASSERT(static_cast<InT>(static_cast<OutT>(value)) == value, "Can not safely cast ", | ||
| static_cast<int64_t>(value), " from ", ov::element::from<InT>(), " to ", ov::element::from<OutT>()); | ||
|
|
||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_integral<InT>, std::is_unsigned<InT>, std::is_floating_point<OutT>> checked_cast(InT value) { | ||
| OPENVINO_ASSERT(static_cast<InT>(static_cast<OutT>(value)) == value, "Can not safely cast ", | ||
| static_cast<uint64_t>(value), " from ", ov::element::from<InT>(), " to ", | ||
| ov::element::from<OutT>()); | ||
|
|
||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_same<double, InT>, std::is_same<float, OutT>> checked_cast(InT value) { | ||
| OPENVINO_ASSERT(static_cast<InT>(static_cast<OutT>(value)) == value, "Can not safely cast ", value, " from ", | ||
| ov::element::from<InT>(), " to ", ov::element::from<OutT>()); | ||
|
|
||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_same<float, InT>, std::is_same<double, OutT>> checked_cast(InT value) { | ||
| return static_cast<OutT>(value); | ||
| } | ||
|
|
||
| // | ||
| // Custom float types | ||
| // | ||
|
|
||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float16, OutT>> checked_cast(ov::bfloat16 val) { | ||
| return ov::float16(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float8_e4m3, OutT>> checked_cast(ov::bfloat16 val) { | ||
| return ov::float8_e4m3(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float8_e5m2, OutT>> checked_cast(ov::bfloat16 val) { | ||
| return ov::float8_e5m2(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::bfloat16, OutT>> checked_cast(ov::float16 val) { | ||
| return ov::bfloat16(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float8_e4m3, OutT>> checked_cast(ov::float16 val) { | ||
| return ov::float8_e4m3(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float8_e5m2, OutT>> checked_cast(ov::float16 val) { | ||
| return ov::float8_e5m2(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float8_e5m2, OutT>> checked_cast(ov::float8_e4m3 val) { | ||
| return ov::float8_e5m2(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float16, OutT>> checked_cast(ov::float8_e4m3 val) { | ||
| return ov::float16(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::bfloat16, OutT>> checked_cast(ov::float8_e4m3 val) { | ||
| return ov::bfloat16(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float8_e4m3, OutT>> checked_cast(ov::float8_e5m2 val) { | ||
| return ov::float8_e4m3(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::float16, OutT>> checked_cast(ov::float8_e5m2 val) { | ||
| return ov::float16(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, std::is_same<ov::bfloat16, OutT>> checked_cast(ov::float8_e5m2 val) { | ||
| return ov::bfloat16(static_cast<float>(val)); | ||
| } | ||
|
|
||
| template <typename OutT> | ||
| enable_t<OutT, not_<or_<std::is_same<ov::float8_e4m3, OutT>, std::is_same<ov::float8_e5m2, OutT>, | ||
| std::is_same<ov::float16, OutT>>>> | ||
| checked_cast(ov::bfloat16 val) { | ||
| return checked_cast<OutT>(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, not_<or_<std::is_same<ov::float8_e4m3, OutT>, std::is_same<ov::float8_e5m2, OutT>, | ||
| std::is_same<ov::bfloat16, OutT>>>> | ||
| checked_cast(ov::float16 val) { | ||
| return checked_cast<OutT>(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, not_<or_<std::is_same<ov::float8_e5m2, OutT>, std::is_same<ov::bfloat16, OutT>, | ||
| std::is_same<ov::float16, OutT>>>> | ||
| checked_cast(ov::float8_e4m3 val) { | ||
| return checked_cast<OutT>(static_cast<float>(val)); | ||
| } | ||
| template <typename OutT> | ||
| enable_t<OutT, not_<or_<std::is_same<ov::float8_e4m3, OutT>, std::is_same<ov::bfloat16, OutT>, | ||
| std::is_same<ov::float16, OutT>>>> | ||
| checked_cast(ov::float8_e5m2 val) { | ||
| return checked_cast<OutT>(static_cast<float>(val)); | ||
| } | ||
|
|
||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_same<ov::bfloat16, OutT>> checked_cast(InT val) { | ||
| return ov::bfloat16(checked_cast<float>(val)); | ||
| } | ||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_same<ov::float16, OutT>> checked_cast(InT val) { | ||
| return ov::float16(checked_cast<float>(val)); | ||
| } | ||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_same<ov::float8_e4m3, OutT>> checked_cast(InT val) { | ||
| return ov::float8_e4m3(checked_cast<float>(val)); | ||
| } | ||
| template <typename OutT, typename InT> | ||
| enable_t<OutT, std::is_same<ov::float8_e5m2, OutT>> checked_cast(InT val) { | ||
| return ov::float8_e5m2(checked_cast<float>(val)); | ||
| } | ||
|
|
||
| // | ||
| // Wrapper | ||
| // | ||
|
|
||
| template <typename OutT, typename InT> | ||
| OutT convertValuePrecision(InT value) { | ||
| return checked_cast<OutT>(value); | ||
| } | ||
|
|
||
| } // namespace utils | ||
| } // namespace 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.
Hi @ilya-lavrenov! Could you please take a look at this part with cpack configs?
Idea: npu_internal cpack target available in CI cache to be imported by NPU CI and NPU release build infrastructure for preparing extended packages.
Requirement: npu_internal must not be included in OpenVINO releases and dev drops. As I understand it is already controlled by product-configs in packaging/config.json#L381