Skip to content

Commit

Permalink
OV file path definition (#27954)
Browse files Browse the repository at this point in the history
### Details:
 - Add Path alias
 - Test char, wchar, utf8,16,32 casts 

### Tickets:
 - [*158902*](https://jira.devtools.intel.com/browse/CVS-158902)

---------

Co-authored-by: Michal Lukaszewski <michal.lukaszewski@intel.com>
  • Loading branch information
barnasm1 and mlukasze authored Jan 14, 2025
1 parent 1522455 commit 4cd4e44
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 41 deletions.
35 changes: 35 additions & 0 deletions src/common/util/include/openvino/util/cpp_version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once
/**
* @brief Define a separate value for every version of C++ standard upto currently supported by build setup.
*/
#if !(defined(_MSC_VER) && __cplusplus == 199711L)
# if __cplusplus >= 201103L
# define OPENVINO_CPP_VER_AT_LEAST_11
# if __cplusplus >= 201402L
# define OPENVINO_CPP_VER_AT_LEAST_14
# if __cplusplus >= 201703L
# define OPENVINO_CPP_VER_AT_LEAST_17
# if __cplusplus >= 202002L
# define OPENVINO_CPP_VER_AT_LEAST_20
# endif
# endif
# endif
# endif
#elif defined(_MSC_VER) && __cplusplus == 199711L
# if _MSVC_LANG >= 201103L
# define OPENVINO_CPP_VER_AT_LEAST_11
# if _MSVC_LANG >= 201402L
# define OPENVINO_CPP_VER_AT_LEAST_14
# if _MSVC_LANG >= 201703L
# define OPENVINO_CPP_VER_AT_LEAST_17
# if _MSVC_LANG >= 202002L
# define OPENVINO_CPP_VER_AT_LEAST_20
# endif
# endif
# endif
# endif
#endif
34 changes: 34 additions & 0 deletions src/common/util/include/openvino/util/file_path.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <cstdio>

#include "openvino/util/filesystem.hpp"
namespace ov {
namespace util {

#if defined(OPENVINO_HAS_FILESYSTEM)
using Path = std::filesystem::path;
#elif defined(OPENVINO_HAS_EXP_FILESYSTEM)
// Known issues:
// * error C2280: 'std::u32string std::experimental::filesystem::v1::path::u32string(void) const': attempting to
// * filesystem error: Cannot convert character sequence: Invalid in or incomplete multibyte or wide character

///
/// @typedef Path
/// @brief Alias for std::experimental::filesystem::path.
///
/// This alias is used to simplify the usage of filesystem paths.
///
/// @note The experimental version of std::filesystem::path may not support all features correctly.
/// It is recommended to use this alias with caution and consider upgrading to C++17 or higher
/// for full support of std::filesystem::path.
///
using Path = std::experimental::filesystem::path;
#endif

} // namespace util
} // namespace ov
18 changes: 9 additions & 9 deletions src/common/util/include/openvino/util/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@

#pragma once

#include "openvino/core/visibility.hpp"
#include "openvino/util/cpp_version.hpp"

#if defined(_MSC_VER) && defined(OPENVINO_CPP_VER_11)
#if defined(_MSC_VER) && defined(OPENVINO_CPP_VER_AT_LEAST_17)
# define OPENVINO_HAS_FILESYSTEM
#elif defined(_MSC_VER) && defined(OPENVINO_CPP_VER_AT_LEAST_11)
# define OPENVINO_HAS_EXP_FILESYSTEM
# define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
# define _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM
#elif defined(__has_include)
# if defined(OPENVINO_CPP_VER_17) && (__has_include(<filesystem>)) && (!__has_include(<experimental/filesystem>))
# if defined(OPENVINO_CPP_VER_AT_LEAST_17) && (__has_include(<filesystem>))
# define OPENVINO_HAS_FILESYSTEM
# elif defined(OPENVINO_CPP_VER_11) && (__has_include(<experimental/filesystem>))
# elif defined(OPENVINO_CPP_VER_AT_LEAST_11) && (__has_include(<experimental/filesystem>))
# define OPENVINO_HAS_EXP_FILESYSTEM
# define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
# define _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM
# endif
#endif

#if !defined(OPENVINO_HAS_FILESYSTEM) && !defined(OPENVINO_HAS_EXP_FILESYSTEM)
# error "Neither #include <filesystem> nor #include <experimental/filesystem> is available."
#elif defined(OPENVINO_HAS_FILESYSTEM)
#if defined(OPENVINO_HAS_FILESYSTEM)
# include <filesystem>
namespace std_fs = std::filesystem;
#elif defined(OPENVINO_HAS_EXP_FILESYSTEM)
# include <experimental/filesystem>
namespace std_fs = std::experimental::filesystem;
#else
# error "Neither #include <filesystem> nor #include <experimental/filesystem> is available."
#endif
6 changes: 3 additions & 3 deletions src/core/include/openvino/core/graph_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "openvino/op/parameter.hpp"
#include "openvino/pass/serialize.hpp"

#ifdef OPENVINO_CPP_VER_17
#ifdef OPENVINO_CPP_VER_AT_LEAST_17
# include <filesystem>
#endif

Expand Down Expand Up @@ -299,7 +299,7 @@ void serialize(const std::shared_ptr<const ov::Model>& m,
const std::string& bin_path = "",
ov::pass::Serialize::Version version = ov::pass::Serialize::Version::UNSPECIFIED);

#ifdef OPENVINO_CPP_VER_17
#ifdef OPENVINO_CPP_VER_AT_LEAST_17
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
void serialize(const std::shared_ptr<const ov::Model>& m,
const Path& xml_path,
Expand Down Expand Up @@ -327,7 +327,7 @@ void save_model(const std::shared_ptr<const ov::Model>& model,
bool compress_to_fp16 = true);
#endif

#ifdef OPENVINO_CPP_VER_17
#ifdef OPENVINO_CPP_VER_AT_LEAST_17
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
void save_model(const std::shared_ptr<const ov::Model>& model, const Path& output_model, bool compress_to_fp16 = true) {
save_model(model, output_model.string(), compress_to_fp16);
Expand Down
16 changes: 8 additions & 8 deletions src/core/include/openvino/core/visibility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,26 @@

#if !(defined(_MSC_VER) && __cplusplus == 199711L)
# if __cplusplus >= 201103L
# define OPENVINO_CPP_VER_11
# define OPENVINO_CPP_VER_AT_LEAST_11
# if __cplusplus >= 201402L
# define OPENVINO_CPP_VER_14
# define OPENVINO_CPP_VER_AT_LEAST_14
# if __cplusplus >= 201703L
# define OPENVINO_CPP_VER_17
# define OPENVINO_CPP_VER_AT_LEAST_17
# if __cplusplus >= 202002L
# define OPENVINO_CPP_VER_20
# define OPENVINO_CPP_VER_AT_LEAST_20
# endif
# endif
# endif
# endif
#elif defined(_MSC_VER) && __cplusplus == 199711L
# if _MSVC_LANG >= 201103L
# define OPENVINO_CPP_VER_11
# define OPENVINO_CPP_VER_AT_LEAST_11
# if _MSVC_LANG >= 201402L
# define OPENVINO_CPP_VER_14
# define OPENVINO_CPP_VER_AT_LEAST_14
# if _MSVC_LANG >= 201703L
# define OPENVINO_CPP_VER_17
# define OPENVINO_CPP_VER_AT_LEAST_17
# if _MSVC_LANG >= 202002L
# define OPENVINO_CPP_VER_20
# define OPENVINO_CPP_VER_AT_LEAST_20
# endif
# endif
# endif
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/openvino/pass/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "openvino/opsets/opset.hpp"
#include "openvino/pass/pass.hpp"

#ifdef OPENVINO_CPP_VER_17
#ifdef OPENVINO_CPP_VER_AT_LEAST_17
# include <filesystem>
#endif

Expand Down Expand Up @@ -39,7 +39,7 @@ class OPENVINO_API Serialize : public ov::pass::ModelPass {

Serialize(const std::string& xmlPath, const std::string& binPath, Version version = Version::UNSPECIFIED);

#ifdef OPENVINO_CPP_VER_17
#ifdef OPENVINO_CPP_VER_AT_LEAST_17
Serialize(const std::filesystem::path& xmlPath,
const std::filesystem::path& binPath,
Version version = Version::UNSPECIFIED)
Expand Down
Loading

0 comments on commit 4cd4e44

Please sign in to comment.