Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE] OV file utils file_size use std file path #28462

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

barnasm1
Copy link
Contributor

Details:

  • refactor file_size function to accept ov::util::Path / std::filesystem::path. Be backward compatible with previous version.

Tickets:

@barnasm1 barnasm1 added the category: Core OpenVINO Core (aka ngraph) label Jan 15, 2025
@barnasm1 barnasm1 self-assigned this Jan 15, 2025
@barnasm1 barnasm1 requested review from a team as code owners January 15, 2025 15:26
@github-actions github-actions bot added the category: build OpenVINO cmake script / infra label Jan 15, 2025
@praasz praasz self-assigned this Jan 16, 2025
@praasz praasz added this to the 2025.1 milestone Jan 16, 2025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions are not cast rename file or keep them in original header.
Why these function are moved to new file?

Comment on lines +40 to 51
#if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17)
inline ov::util::Path WPath(const std::wstring& wpath) {
return {ov::util::wstring_to_string(wpath)};
}
#else
inline ov::util::Path WPath(const std::wstring& wpath) {
return {wpath};
}
#endif

} // namespace util
} // namespace ov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17)
inline ov::util::Path WPath(const std::wstring& wpath) {
return {ov::util::wstring_to_string(wpath)};
}
#else
inline ov::util::Path WPath(const std::wstring& wpath) {
return {wpath};
}
#endif
} // namespace util
} // namespace ov
} // namespace util
} // namespace ov
#if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17)
template<>
ov::util::Path::path<std::wstring>(const std::wstring& source, format fmt) : path(ov::util::wstring_to_string(source), std::move(fmt)) {}
#endif

Consider add specialization for compiler version where is bug with path creation then WPath function is not required and path can be create always in same way.
Optionally: If any issue because specialization already defined add some trait check to detect it and avoid define it in OV.

#endif

#if defined(__GNUC__) && (__GNUC__ < 12 || __GNUC__ == 12 && __GNUC_MINOR__ < 3)
# define GCC_VER_LESS_THEN_12_3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# define GCC_VER_LESS_THEN_12_3
# define GCC_VER_LESS_THAN_12_3

Use than in case where something is compared.

@@ -172,26 +161,30 @@ bool directory_exists(const std::string& path);
bool directory_exists(const std::wstring& path);
#endif

inline ov::util::Path cut_android_path(const ov::util::Path& file_name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not required can be still internal part of file_size

if (pos != std::string::npos) {
file_name = file_name.substr(0, pos);
}
inline int64_t file_size(const ov::util::Path& path) {
Copy link
Contributor

@praasz praasz Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inline int64_t file_size(const ov::util::Path& path) {
inline int64_t file_size(const ov::util::Path& path) {
#if defined(__ANDROID__) || defined(ANDROID)
// apply cuting if std::filesytem not support it well.
#endif
return std::filesystem::file_size(path);
}

This function should probably be wrapper to std implementation if works.

}
{
std::ofstream outfile("test_file_21.txt");
outfile << "This is a test file." << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outfile << "This is a test file." << std::endl;

Remove there is no need to print messages if there is no failures.

{
std::ofstream outfile("test_file_21.txt");
outfile << "This is a test file." << std::endl;
outfile.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required? It should be closed when outfile will go out of scope of this block.

Comment on lines +464 to +465
ov::util::Path file_name = std::get<0>(GetParam());
ov::util::Path expected = std::get<1>(GetParam());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ov::util::Path file_name = std::get<0>(GetParam());
ov::util::Path expected = std::get<1>(GetParam());
const auto& [file_name, expected] = GetParam();

In cpp17 it should work.

/**
* @brief Returns file size for file
* @param[in] path The file name
* @return file size
*/
inline int64_t file_size(const char* path) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still this version should be kept and marked deprecated before remove.

@@ -0,0 +1,31 @@
// Copyright (C) 2018-2024 Intel Corporation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Copyright (C) 2018-2024 Intel Corporation
// Copyright (C) 2018-2025 Intel Corporation

Check all modified files

#endif

#if defined(__GNUC__) && (__GNUC__ < 12 || __GNUC__ == 12 && __GNUC_MINOR__ < 3)
# define GCC_VER_LESS_THEN_12_3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# define GCC_VER_LESS_THEN_12_3
# define GCC_VER_LESS_THAN_12_3

#endif

#if defined(__clang__) && __clang_major__ < 17
# define CLANG_VER_LESS_THEN_17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# define CLANG_VER_LESS_THEN_17
# define CLANG_VER_LESS_THAN_17

@@ -30,5 +37,15 @@ using Path = std::filesystem::path;
using Path = std::experimental::filesystem::path;
#endif

#if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17)
#if defined(GCC_VER_LESS_THAN_12_3) || defined(CLANG_VER_LESS_THAN_17)

namespace ov {
namespace util {

#if defined(OPENVINO_HAS_FILESYSTEM)
// There are known issues related with usage of std::filesystem::path unocode represenataion:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// There are known issues related with usage of std::filesystem::path unocode represenataion:
// There are known issues with usage of std::filesystem::path unicode representation:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build OpenVINO cmake script / infra category: Core OpenVINO Core (aka ngraph)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants