Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmake/developer_package/packaging/archive.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ macro(ov_define_component_include_rules)
set(OV_CPACK_COMP_PKG_CONFIG_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# symbolic links
set(OV_CPACK_COMP_LINKS_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# npu internal tools
Copy link
Contributor Author

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

unset(OV_CPACK_COMP_NPU_INTERNAL_EXCLUDE_ALL)
endmacro()

ov_define_component_include_rules()
Expand Down
2 changes: 2 additions & 0 deletions cmake/developer_package/packaging/common-libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ macro(ov_define_component_include_rules)
set(OV_CPACK_COMP_PKG_CONFIG_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# symbolic links
set(OV_CPACK_COMP_LINKS_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# npu internal tools
set(OV_CPACK_COMP_NPU_INTERNAL_EXCLUDE_ALL EXCLUDE_FROM_ALL)
endmacro()

ov_define_component_include_rules()
Expand Down
2 changes: 2 additions & 0 deletions cmake/developer_package/packaging/debian/debian.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ macro(ov_define_component_include_rules)
set(OV_CPACK_COMP_PKG_CONFIG_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# symbolic links
set(OV_CPACK_COMP_LINKS_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# npu internal tools
set(OV_CPACK_COMP_NPU_INTERNAL_EXCLUDE_ALL EXCLUDE_FROM_ALL)
endmacro()

ov_define_component_include_rules()
Expand Down
2 changes: 2 additions & 0 deletions cmake/developer_package/packaging/npm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ macro(ov_define_component_include_rules)
unset(OV_CPACK_COMP_PKG_CONFIG_EXCLUDE_ALL)
# symbolic links
unset(OV_CPACK_COMP_LINKS_EXCLUDE_ALL)
# npu internal tools
set(OV_CPACK_COMP_NPU_INTERNAL_EXCLUDE_ALL EXCLUDE_FROM_ALL)
endmacro()

ov_define_component_include_rules()
Expand Down
2 changes: 2 additions & 0 deletions cmake/developer_package/packaging/nsis.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ macro(ov_define_component_include_rules)
set(OV_CPACK_COMP_PKG_CONFIG_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# symbolic links
set(OV_CPACK_COMP_LINKS_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# npu internal tools
set(OV_CPACK_COMP_NPU_INTERNAL_EXCLUDE_ALL EXCLUDE_FROM_ALL)
endmacro()

ov_define_component_include_rules()
2 changes: 2 additions & 0 deletions cmake/developer_package/packaging/rpm/rpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ macro(ov_define_component_include_rules)
set(OV_CPACK_COMP_PKG_CONFIG_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# symbolic links
set(OV_CPACK_COMP_LINKS_EXCLUDE_ALL ${OV_CPACK_COMP_CORE_DEV_EXCLUDE_ALL})
# npu internal tools
set(OV_CPACK_COMP_NPU_INTERNAL_EXCLUDE_ALL EXCLUDE_FROM_ALL)
endmacro()

ov_define_component_include_rules()
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/intel_npu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ add_subdirectory(src)
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()

add_subdirectory(tools)

ov_cpack_add_component(${NPU_INTERNAL_COMPONENT} HIDDEN)
8 changes: 8 additions & 0 deletions src/plugins/intel_npu/tools/CMakeLists.txt
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)
29 changes: 29 additions & 0 deletions src/plugins/intel_npu/tools/common/CMakeLists.txt
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 src/plugins/intel_npu/tools/common/include/data_type_converters.hpp
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
Loading