Skip to content

Commit 6c5a86f

Browse files
barnasm1mlukasze
andauthored
[CORE] Handle cache_dir path containing dot ('.') (#32289)
### Details: - Refactor directory creation logic - tests for GPU cache directory handling ### Tickets: - [*173675*](https://jira.devtools.intel.com/browse/CVS-173675) --------- Co-authored-by: Michal Lukaszewski <[email protected]>
1 parent b2eda09 commit 6c5a86f

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/common/util/src/file_util.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,17 @@ void ov::util::create_directory_recursive(const std::wstring& path) {
294294
void ov::util::create_directory_recursive(const std::filesystem::path& path) {
295295
namespace fs = std::filesystem;
296296
auto dir_path = fs::weakly_canonical(path);
297-
if (!dir_path.has_filename() || dir_path.has_extension()) {
298-
dir_path = get_directory(dir_path);
299-
}
300297

301298
if (!dir_path.empty() && !directory_exists(dir_path)) {
302-
if (std::error_code ec; !fs::create_directories(dir_path, ec)) {
299+
// NOTE: Some standard library implementations (MSVC STL, libc++) may return `false`
300+
// from create_directories(path, ec) (with ec == 0) when the path ends with a
301+
// trailing separator (e.g. "a/b/c/"). Internally they create "a", "a/b", "a/b/c"
302+
// and then the extra mkdir on "a/b/c/" yields an "already exists" condition,
303+
// leading to a final `false` even though the directory tree was actually created.
304+
// libstdc++ (GCC) returns `true` in that situation. The extra exists() check
305+
// lets us treat "false + exists()" as success while still detecting a real failure
306+
// ("false + !exists()"), keeping behavior consistent across platforms.
307+
if (std::error_code ec; !fs::create_directories(dir_path, ec) && !std::filesystem::exists(dir_path)) {
303308
std::stringstream ss;
304309
ss << "Couldn't create directory [" << dir_path << "], err=" << ec.message() << ")";
305310
throw std::runtime_error(ss.str());

src/core/src/pass/serialize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool pass::Serialize::run_on_model(const std::shared_ptr<ov::Model>& model) {
110110
if (m_xmlFile && m_binFile) {
111111
serialize_func(*m_xmlFile, *m_binFile, model, m_version);
112112
} else {
113-
ov::util::create_directory_recursive(m_xmlPath);
113+
ov::util::create_directory_recursive(m_xmlPath.parent_path());
114114

115115
std::ofstream bin_file(m_binPath, std::ios::binary);
116116
OPENVINO_ASSERT(bin_file, "Can't open bin file: \"", m_binPath, "\"");

src/plugins/intel_gpu/tests/functional/subgraph_tests/serialize.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "shared_test_classes/base/ov_subgraph.hpp"
66
#include "subgraphs_builders.hpp"
7+
#include "openvino/op/relu.hpp"
78

89
namespace {
910

@@ -65,4 +66,44 @@ TEST_F(LSTMSequenceTest, smoke_serialize) {
6566
TEST_F(GRUSequenceTest, smoke_serialize) {
6667
run();
6768
}
69+
70+
class GpuCacheDirWithDotsParamTest : public ::testing::TestWithParam<std::string> {
71+
protected:
72+
ov::Core core;
73+
std::string cacheDir;
74+
75+
void SetUp() override {
76+
std::stringstream ss;
77+
ss << std::hex << std::hash<std::string>{}(std::string(::testing::UnitTest::GetInstance()->current_test_info()->name()));
78+
79+
// Base (no trailing slash first)
80+
cacheDir = ss.str() + GetParam();
81+
82+
// Clean previous
83+
ov::test::utils::removeFilesWithExt(cacheDir, "blob");
84+
ov::test::utils::removeFilesWithExt(cacheDir, "cl_cache");
85+
ov::test::utils::removeDir(cacheDir);
86+
87+
core.set_property(ov::cache_dir(cacheDir));
88+
}
89+
90+
void TearDown() override {
91+
ov::test::utils::removeFilesWithExt(cacheDir, "blob");
92+
ov::test::utils::removeFilesWithExt(cacheDir, "cl_cache");
93+
ov::test::utils::removeDir(cacheDir);
94+
}
95+
};
96+
97+
TEST_P(GpuCacheDirWithDotsParamTest, smoke_PopulateAndReuseCache) {
98+
auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 8, 8});
99+
auto relu = std::make_shared<ov::op::v0::Relu>(param);
100+
auto res = std::make_shared<ov::op::v0::Result>(relu);
101+
auto model = std::make_shared<ov::Model>(ov::ResultVector{res}, ov::ParameterVector{param}, "CacheDotsModel");
102+
core.compile_model(model, "GPU");
103+
}
104+
105+
INSTANTIATE_TEST_SUITE_P(CacheDirDotVariants,
106+
GpuCacheDirWithDotsParamTest,
107+
::testing::Values("/test_encoder/test_encoder.encrypted/", "/test_encoder/test_encoder.encrypted"));
108+
68109
} // namespace

0 commit comments

Comments
 (0)