Skip to content

Commit

Permalink
S_ISDIR is already defined and std::ifstream<wchar_t> is not supporte… (
Browse files Browse the repository at this point in the history
openvinotoolkit#21927)

* S_ISDIR is already defined and std::ifstream<wchar_t> is not supported in MinGW, only ifstream<char>

* Update src/common/util/src/file_util.cpp

Co-authored-by: Roman Kazantsev <[email protected]>

* Update input_model.cpp

* Update graph_iterator_proto.hpp

* Update graph_iterator_proto_txt.hpp

* Update graph_iterator_flatbuffer.hpp

---------

Co-authored-by: Roman Kazantsev <[email protected]>
  • Loading branch information
testdrive-profiling-master and rkazants authored Jan 8, 2024
1 parent fa8ae94 commit 9638b89
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/common/util/src/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
/// @brief Windows-specific 'mkdir' wrapper
# define makedir(dir) _mkdir(dir)
// Copied from linux libc sys/stat.h:
# define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
# if !defined(__MINGW32__) && !defined(__MINGW64__)
# define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
# endif
#else
# include <dirent.h>
# include <dlfcn.h>
Expand Down
8 changes: 8 additions & 0 deletions src/frontends/paddle/src/input_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "input_model.hpp"

#include <fstream>
#if defined(__MINGW32__) || defined(__MINGW64__)
# include <filesystem>
#endif
#include <queue>

#include "decoder_proto.hpp"
Expand Down Expand Up @@ -291,7 +294,12 @@ void InputModel::InputModelImpl::load_consts(const std::basic_string<T>& folder_

bool read_succeed = false;
if (!folder_with_weights.empty()) {
#if defined(__MINGW32__) || defined(__MINGW64__)
std::ifstream is(std::filesystem::path(get_const_path(folder_with_weights, name)),
std::ios::in | std::ifstream::binary);
#else
std::ifstream is(get_const_path(folder_with_weights, name), std::ios::in | std::ifstream::binary);
#endif
FRONT_END_GENERAL_CHECK(is && is.is_open(), "Cannot open file for constant value.");
const size_t header_size = 16;
std::vector<char> header(header_size);
Expand Down
11 changes: 11 additions & 0 deletions src/frontends/tensorflow/src/graph_iterator_proto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#pragma once

#include <fstream>
#if defined(__MINGW32__) || defined(__MINGW64__)
# include <filesystem>
#endif
#include <vector>

#include "checkpoint_v1_reader.hpp"
Expand Down Expand Up @@ -108,7 +111,11 @@ class GraphIteratorProto : public GraphIterator {
: m_graph_def(std::make_shared<::tensorflow::GraphDef>()),
m_func_def(nullptr),
m_checkpoint_v1_reader(nullptr) {
#if defined(__MINGW32__) || defined(__MINGW64__)
std::ifstream pb_stream(std::filesystem::path(model_path), std::ios::in | std::ifstream::binary);
#else
std::ifstream pb_stream(model_path, std::ios::in | std::ifstream::binary);
#endif

FRONT_END_GENERAL_CHECK(pb_stream && pb_stream.is_open(), "Model file does not exist");
FRONT_END_GENERAL_CHECK(m_graph_def->ParseFromIstream(&pb_stream), "Model cannot be parsed");
Expand All @@ -135,7 +142,11 @@ class GraphIteratorProto : public GraphIterator {
template <typename T>
static bool is_supported(const std::basic_string<T>& path) {
try {
#if defined(__MINGW32__) || defined(__MINGW64__)
std::ifstream pb_stream(std::filesystem::path(path), std::ios::in | std::ifstream::binary);
#else
std::ifstream pb_stream(path, std::ios::in | std::ifstream::binary);
#endif
auto graph_def = std::make_shared<::tensorflow::GraphDef>();
return pb_stream && pb_stream.is_open() && graph_def->ParsePartialFromIstream(&pb_stream) &&
graph_def->node_size() > 0;
Expand Down
7 changes: 7 additions & 0 deletions src/frontends/tensorflow/src/graph_iterator_proto_txt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#pragma once

#include <fstream>
#if defined(__MINGW32__) || defined(__MINGW64__)
# include <filesystem>
#endif

#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/text_format.h"
Expand All @@ -20,7 +23,11 @@ class GraphIteratorProtoTxt : public GraphIteratorProto {
/// \brief Construct GraphIterator for the frozen model in text format without v1 checkpoints
template <typename T>
GraphIteratorProtoTxt(const std::basic_string<T>& path) : GraphIteratorProto() {
#if defined(__MINGW32__) || defined(__MINGW64__)
std::ifstream pbtxt_stream(std::filesystem::path(path), std::ios::in);
#else
std::ifstream pbtxt_stream(path, std::ios::in);
#endif
FRONT_END_GENERAL_CHECK(pbtxt_stream && pbtxt_stream.is_open(), "Model file does not exist");
auto input_stream = std::make_shared<::google::protobuf::io::IstreamInputStream>(&pbtxt_stream);
FRONT_END_GENERAL_CHECK(input_stream, "Model cannot be read");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#pragma once

#include <fstream>
#if defined(__MINGW32__) || defined(__MINGW64__)
# include <filesystem>
#endif

#include "openvino/core/any.hpp"
#include "openvino/frontend/exception.hpp"
Expand Down Expand Up @@ -64,7 +67,11 @@ class GraphIteratorFlatBuffer {
if (file_size < offset_size) {
return false;
}
#if defined(__MINGW32__) || defined(__MINGW64__)
std::ifstream tflite_stream(std::filesystem::path(path), std::ios::in | std::ifstream::binary);
#else
std::ifstream tflite_stream(path, std::ios::in | std::ifstream::binary);
#endif
char buf[offset_size * 2] = {};
tflite_stream.read(buf, offset_size * 2);
// If we have enough readed bytes - try to detect prefixed identifier, else try without size prefix
Expand Down

0 comments on commit 9638b89

Please sign in to comment.