diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 2039173f027a65..bc42ffca8a3cf6 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -89,6 +89,8 @@ ov_build_target_faster(openvino_core_obj ov_add_version_defines(src/version.cpp openvino_core_obj) +ov_set_threading_interface_for(openvino_core_obj) + target_link_libraries(openvino_core_obj PRIVATE openvino::reference openvino::util openvino::pugixml openvino::shape_inference openvino::core::dev) diff --git a/src/core/src/pass/serialize.cpp b/src/core/src/pass/serialize.cpp index f4f3b7d0184697..17da51b5831c99 100644 --- a/src/core/src/pass/serialize.cpp +++ b/src/core/src/pass/serialize.cpp @@ -16,6 +16,7 @@ #include "openvino/core/except.hpp" #include "openvino/core/meta_data.hpp" #include "openvino/core/model.hpp" +#include "openvino/core/parallel.hpp" #include "openvino/core/type/float16.hpp" #include "openvino/op/util/framework_node.hpp" #include "openvino/opsets/opset1.hpp" @@ -1385,7 +1386,7 @@ static uint64_t hash_combine(uint64_t seed, const T& a) { } class OstreamHashWrapper final : public std::streambuf { - uint64_t m_res = 0; + uint64_t m_res = 0lu; public: uint64_t getResult() const { @@ -1393,18 +1394,19 @@ class OstreamHashWrapper final : public std::streambuf { } std::streamsize xsputn(const char* s, std::streamsize n) override { - auto* intS = (const std::streamsize*)s; - std::streamsize n64 = n / static_cast(sizeof(std::streamsize)); - std::streamsize i = 0; - // Using 64-bit values executes much faster than char - while (i++ < n64) { - m_res += *(intS++); - } + // Reinterpret data as uint32_t and accumulate in uint64_t to avoid overflow fluctuations in parallel_sum. + auto* int_sum = reinterpret_cast(s); + const uint64_t n32 = n / sizeof(uint32_t); + + m_res += parallel_sum(n32, uint64_t(0lu), [&](size_t k) -> uint32_t { + return int_sum[k]; + }); - std::streamsize rest = n % static_cast(sizeof(std::streamsize)); - for (i = 0; i < rest; i++) { + const uint64_t rest = n % sizeof(uint32_t); + for (uint64_t i = 0lu; i < rest; i++) { m_res += s[n - rest + i]; } + return n; } };