Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[core] Fix hash store on windows (#33944)

Pawel Raaszae1979cb10b3
diff --git a/src/common/transformations/tests/hash_tests.cpp b/src/common/transformations/tests/hash_tests.cpp
index 4366a1e84f0..ecd7845323d 100644
--- a/src/common/transformations/tests/hash_tests.cpp
+++ b/src/common/transformations/tests/hash_tests.cpp
@@ -8,6 +8,7 @@
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/parameter.hpp"
+#include "openvino/util/common_util.hpp"
#include "transformations/hash.hpp"
namespace v0 = ov::op::v0;
@@ -69,4 +70,30 @@ TEST(HashTest, same_model_struct_different_weigth) {
EXPECT_NE(hash1, hash2);
}
+TEST(HashTest, same_model_struct_different_weigth_by_offset) {
+ constexpr auto weights = ov::util::make_array<int>(11, 11, 12);
+
+ uint64_t hash1 = 0, hash2 = 0;
+ {
+ auto out = std::make_shared<Add>(std::make_shared<Parameter>(element::i32, Shape{1}),
+ std::make_shared<Constant>(element::i32, Shape{1}, weights.data()));
+ out = std::make_shared<Add>(out, std::make_shared<Constant>(element::i32, Shape{1}, weights.data() + 1));
+ auto model = std::make_shared<Model>(OutputVector{out}, "TestModel");
+
+ ov::pass::Hash hasher(hash1);
+ hasher.run_on_model(model);
+ }
+ {
+ auto out = std::make_shared<Add>(std::make_shared<Parameter>(element::i32, Shape{1}),
+ std::make_shared<Constant>(element::i32, Shape{1}, weights.data()));
+ out = std::make_shared<Add>(out, std::make_shared<Constant>(element::i32, Shape{1}, weights.data() + 2));
+ auto model = std::make_shared<Model>(OutputVector{out}, "TestModel");
+
+ ov::pass::Hash hasher(hash2);
+ hasher.run_on_model(model);
+ }
+
+ EXPECT_NE(hash1, hash2);
+}
+
} // namespace ov::test
diff --git a/src/core/src/xml_util/constant_writer.cpp b/src/core/src/xml_util/constant_writer.cpp
index e5e112a6338..82cfe4d3934 100644
--- a/src/core/src/xml_util/constant_writer.cpp
+++ b/src/core/src/xml_util/constant_writer.cpp
@@ -82,7 +82,7 @@ ConstantWriter::FilePosition ConstantWriter::write(const char* ptr,
}
if (m_write_hash_value) {
// hash stored with special ostream only
- m_binary_output.get().write(reinterpret_cast<const char*>(&hash), hash);
+ m_binary_output.get().rdbuf()->sputn(reinterpret_cast<const char*>(&hash), hash);
} else {
m_binary_output.get().write(ptr_to_write, new_size);
}