Skip to content

Commit fabf116

Browse files
committed
Fix
1 parent 942b9fd commit fabf116

File tree

3 files changed

+99
-6
lines changed

3 files changed

+99
-6
lines changed

src/common/util/include/openvino/util/ov_version.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ struct Version {
1919
size_t patch = 0;
2020
size_t tweak = 0;
2121
size_t build = 0;
22+
std::string postfix;
2223

2324
explicit Version(const char* version_str) {
2425
// Pattern: MAJOR.MINOR.PATCH[.TWEAK]-BUILD-...
25-
std::regex full_pattern(R"(^([0-9]+)\.([0-9]+)\.([0-9]+)(?:\.([0-9]+))?\-([0-9]+)\-.*)");
26+
std::regex full_pattern(R"(^([0-9]+)\.([0-9]+)\.([0-9]+)(?:\.([0-9]+))?\-([0-9]+)\-(.*))");
2627
std::regex build_only_pattern(R"(^[0-9]+$)");
2728
std::cmatch match;
2829

@@ -38,6 +39,7 @@ struct Version {
3839
}
3940

4041
build = std::stoi(match[5].str());
42+
postfix = match[6].str();
4143
} else if (std::regex_match(version_str, build_only_pattern)) {
4244
// Parse as just a build number
4345
build = std::stoi(version_str);
@@ -48,6 +50,19 @@ struct Version {
4850

4951
explicit Version(std::string_view version_str) : Version(version_str.data()) {}
5052

53+
std::string to_string() const {
54+
std::ostringstream oss;
55+
oss << major << "." << minor << "." << patch;
56+
if (tweak != 0) {
57+
oss << "." << tweak;
58+
}
59+
oss << "-" << build;
60+
if (!postfix.empty()) {
61+
oss << "-" << postfix;
62+
}
63+
return oss.str();
64+
}
65+
5166
// Comparison operators
5267
bool operator==(const Version& other) const {
5368
return std::tie(major, minor, patch, tweak, build) ==

src/inference/src/dev/core_impl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,8 +1556,9 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(
15561556
}
15571557
} else {
15581558
// Check whether the runtime version is not older than blob version
1559-
if (!ov::util::is_version_compatible(ov::util::Version(header.get_openvino_version()),
1560-
ov::util::Version(ov::get_openvino_version().buildNumber))) {
1559+
if (!ov::util::is_version_compatible(
1560+
ov::util::Version(header.get_openvino_version()),
1561+
ov::util::Version(ov::get_openvino_version().buildNumber))) {
15611562
// Build number mismatch, don't use this cache
15621563
OPENVINO_THROW("Version does not match");
15631564
}

src/inference/tests/functional/caching_test.cpp

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "openvino/runtime/iremote_context.hpp"
3535
#include "openvino/runtime/properties.hpp"
3636
#include "openvino/runtime/shared_buffer.hpp"
37+
#include "openvino/util/ov_version.hpp"
3738
#include "unit_test_utils/mocks/openvino/runtime/mock_iasync_infer_request.hpp"
3839
#include "unit_test_utils/mocks/openvino/runtime/mock_icompiled_model.hpp"
3940
#include "unit_test_utils/mocks/openvino/runtime/mock_iplugin.hpp"
@@ -1806,7 +1807,7 @@ TEST_P(CachingTest, TestCacheFileCorrupted) {
18061807
}
18071808
}
18081809

1809-
TEST_P(CachingTest, TestCacheFileOldVersion) {
1810+
TEST_P(CachingTest, TestCacheFileIncompartible) {
18101811
EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _)).Times(AnyNumber());
18111812
EXPECT_CALL(*mockPlugin, get_property(ov::device::capability::EXPORT_IMPORT, _)).Times(AnyNumber());
18121813
EXPECT_CALL(*mockPlugin, get_property(ov::device::architecture.name(), _)).Times(AnyNumber());
@@ -1841,10 +1842,12 @@ TEST_P(CachingTest, TestCacheFileOldVersion) {
18411842
content = ostr.str();
18421843
}
18431844
std::string buildNum = ov::get_openvino_version().buildNumber;
1844-
std::string zeroBuild(buildNum.size(), '0');
1845+
auto build_version = ov::util::Version(buildNum);
1846+
// Update build number to make it incompatible, e.g. if it was 2026.0.0.123, make it 2026.0.0.124
1847+
build_version.build += 1;
18451848
auto index = content.find(buildNum);
18461849
if (index != std::string::npos) {
1847-
content.replace(index, buildNum.size(), zeroBuild);
1850+
content.replace(index, buildNum.size(), build_version.to_string());
18481851
} else {
18491852
return; // skip test
18501853
}
@@ -1895,6 +1898,80 @@ TEST_P(CachingTest, TestCacheFileOldVersion) {
18951898
}
18961899
}
18971900

1901+
TEST_P(CachingTest, TestCacheFileOldVersion) {
1902+
EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _)).Times(AnyNumber());
1903+
EXPECT_CALL(*mockPlugin, get_property(ov::device::capability::EXPORT_IMPORT, _)).Times(AnyNumber());
1904+
EXPECT_CALL(*mockPlugin, get_property(ov::device::architecture.name(), _)).Times(AnyNumber());
1905+
EXPECT_CALL(*mockPlugin, get_property(ov::internal::supported_properties.name(), _)).Times(AnyNumber());
1906+
EXPECT_CALL(*mockPlugin, get_property(ov::internal::caching_properties.name(), _)).Times(AnyNumber());
1907+
EXPECT_CALL(*mockPlugin, get_property(ov::device::capabilities.name(), _)).Times(AnyNumber());
1908+
1909+
{
1910+
EXPECT_CALL(*mockPlugin, compile_model(_, _, _)).Times(m_remoteContext ? 1 : 0);
1911+
EXPECT_CALL(*mockPlugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _))
1912+
.Times(!m_remoteContext ? 1 : 0);
1913+
EXPECT_CALL(*mockPlugin, import_model(A<std::istream&>(), _, _)).Times(0);
1914+
EXPECT_CALL(*mockPlugin, import_model(A<std::istream&>(), _)).Times(0);
1915+
EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _, _)).Times(0);
1916+
EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _)).Times(0);
1917+
m_post_mock_net_callbacks.emplace_back([&](MockICompiledModelImpl& net) {
1918+
EXPECT_CALL(net, export_model(_)).Times(1);
1919+
});
1920+
testLoad([&](ov::Core& core) {
1921+
EXPECT_NO_THROW(core.set_property(ov::cache_dir(m_cacheDir)));
1922+
EXPECT_NO_THROW(m_testFunction(core));
1923+
});
1924+
}
1925+
{
1926+
auto blobs = ov::test::utils::listFilesWithExt(m_cacheDir, "blob");
1927+
for (const auto& fileName : blobs) {
1928+
std::string content;
1929+
{
1930+
std::ifstream inp(fileName, std::ios_base::binary);
1931+
std::ostringstream ostr;
1932+
ostr << inp.rdbuf();
1933+
content = ostr.str();
1934+
}
1935+
std::string buildNum = ov::get_openvino_version().buildNumber;
1936+
auto build_version = ov::util::Version(buildNum);
1937+
build_version.build -= 1;
1938+
auto index = content.find(buildNum);
1939+
if (index != std::string::npos) {
1940+
content.replace(index, buildNum.size(), build_version.to_string());
1941+
} else {
1942+
return; // skip test
1943+
}
1944+
1945+
std::filesystem::permissions(fileName,
1946+
std::filesystem::perms::owner_write,
1947+
std::filesystem::perm_options::add);
1948+
std::ofstream out(fileName, std::ios_base::binary);
1949+
out.write(content.c_str(), static_cast<std::streamsize>(content.size()));
1950+
out.close();
1951+
std::filesystem::permissions(fileName,
1952+
std::filesystem::perms::owner_write,
1953+
std::filesystem::perm_options::remove);
1954+
}
1955+
}
1956+
m_post_mock_net_callbacks.pop_back();
1957+
{ // Step 2. Cache file version is older. So cache is valid from Core perspective.
1958+
EXPECT_CALL(*mockPlugin, compile_model(_, _, _)).Times(0);
1959+
EXPECT_CALL(*mockPlugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(0);
1960+
EXPECT_CALL(*mockPlugin, import_model(A<std::istream&>(), _, _)).Times(m_remoteContext ? 1 : 0);
1961+
EXPECT_CALL(*mockPlugin, import_model(A<std::istream&>(), _)).Times(!m_remoteContext ? 1 : 0);
1962+
EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _, _)).Times(0);
1963+
EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _)).Times(0);
1964+
m_post_mock_net_callbacks.emplace_back([&](MockICompiledModelImpl& net) {
1965+
EXPECT_CALL(net, export_model(_)).Times(1);
1966+
});
1967+
testLoad([&](ov::Core& core) {
1968+
EXPECT_NO_THROW(core.set_property(ov::cache_dir(m_cacheDir)));
1969+
EXPECT_NO_THROW(m_testFunction(core));
1970+
});
1971+
}
1972+
m_post_mock_net_callbacks.pop_back();
1973+
}
1974+
18981975
TEST_P(CachingTest, TestCacheFileWithCompiledModelRuntimeProperties) {
18991976
EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _)).Times(AnyNumber());
19001977
EXPECT_CALL(*mockPlugin, get_property(ov::device::capability::EXPORT_IMPORT, _)).Times(AnyNumber());

0 commit comments

Comments
 (0)