Added OpenVINO util library (#7481)
* Added OpenVINO util library * Fixed code style * Fixed build * Fixed build * Added methods from IE utils * Fixed style * Fixed Windows build * Fixed linux build * Fixed windows build * Try to fix dladdr * Try to fix windows * Fixed typo * Fixed detection dynamic libs from static library * Revert some changes * Revert changes in windows loader * Revert network reader * Removed some methods from plugin API * Fixed fluid tests * Fixed typo * Fixed include * Try to fix CI * Try to fix centos * fix typo
This commit is contained in:
parent
8598ce89a3
commit
55fb542bc6
@ -94,7 +94,7 @@ jobs:
|
|||||||
-DENABLE_PROFILING_ITT=OFF
|
-DENABLE_PROFILING_ITT=OFF
|
||||||
-DENABLE_SAMPLES=OFF
|
-DENABLE_SAMPLES=OFF
|
||||||
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON
|
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON
|
||||||
-DNGRAPH_DEBUG_ENABLE=OFF
|
-DOPENVINO_DEBUG_ENABLE=OFF
|
||||||
$(REPO_DIR)
|
$(REPO_DIR)
|
||||||
workingDirectory: $(BUILD_DIR)
|
workingDirectory: $(BUILD_DIR)
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ RUN cmake .. \
|
|||||||
-DENABLE_PYTHON=ON \
|
-DENABLE_PYTHON=ON \
|
||||||
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
|
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
|
||||||
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON \
|
-DNGRAPH_ONNX_FRONTEND_ENABLE=ON \
|
||||||
-DNGRAPH_DEBUG_ENABLE=OFF \
|
-DOPENVINO_DEBUG_ENABLE=OFF \
|
||||||
-DCMAKE_INSTALL_PREFIX=/openvino/dist \
|
-DCMAKE_INSTALL_PREFIX=/openvino/dist \
|
||||||
-DNGRAPH_USE_PROTOBUF_LITE=${PROTOBUF_LITE}
|
-DNGRAPH_USE_PROTOBUF_LITE=${PROTOBUF_LITE}
|
||||||
RUN make -j $(nproc) install
|
RUN make -j $(nproc) install
|
||||||
|
@ -130,7 +130,7 @@ ie_dependent_option(NGRAPH_USE_SYSTEM_PROTOBUF "Use system protobuf" OFF
|
|||||||
ie_dependent_option(NGRAPH_UNIT_TEST_ENABLE "Enables ngraph unit tests" ON "ENABLE_TESTS;NOT ANDROID" OFF)
|
ie_dependent_option(NGRAPH_UNIT_TEST_ENABLE "Enables ngraph unit tests" ON "ENABLE_TESTS;NOT ANDROID" OFF)
|
||||||
ie_dependent_option(NGRAPH_UNIT_TEST_BACKENDS_ENABLE "Control the building of unit tests using backends" ON
|
ie_dependent_option(NGRAPH_UNIT_TEST_BACKENDS_ENABLE "Control the building of unit tests using backends" ON
|
||||||
"NGRAPH_UNIT_TEST_ENABLE" OFF)
|
"NGRAPH_UNIT_TEST_ENABLE" OFF)
|
||||||
ie_option(NGRAPH_DEBUG_ENABLE "Enable output for NGRAPH_DEBUG statements" OFF)
|
ie_option(OPENVINO_DEBUG_ENABLE "Enable output for OPENVINO_DEBUG statements" OFF)
|
||||||
ie_option(ENABLE_REQUIREMENTS_INSTALL "Dynamic dependencies install" ON)
|
ie_option(ENABLE_REQUIREMENTS_INSTALL "Dynamic dependencies install" ON)
|
||||||
|
|
||||||
# WA for ngraph python build on Windows debug
|
# WA for ngraph python build on Windows debug
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
nGraph representation provides an API to get detailed information about the graph structure.
|
nGraph representation provides an API to get detailed information about the graph structure.
|
||||||
|
|
||||||
To receive additional messages about applied graph modifications, rebuild the nGraph library with
|
To receive additional messages about applied graph modifications, rebuild the nGraph library with
|
||||||
the `-DNGRAPH_DEBUG_ENABLE=ON` option.
|
the `-DOPENVINO_DEBUG_ENABLE=ON` option.
|
||||||
|
|
||||||
To visualize the nGraph function to the xDot format or to an image file, use the
|
To visualize the nGraph function to the xDot format or to an image file, use the
|
||||||
`ngraph::pass::VisualizeTree` graph transformation pass:
|
`ngraph::pass::VisualizeTree` graph transformation pass:
|
||||||
|
@ -28,7 +28,7 @@ namespace CLDNNPlugin {
|
|||||||
|
|
||||||
static void createDirectory(std::string _path) {
|
static void createDirectory(std::string _path) {
|
||||||
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||||
std::wstring widepath = FileUtils::multiByteCharToWString(_path.c_str());
|
std::wstring widepath = ov::util::string_to_wstring(_path.c_str());
|
||||||
const wchar_t* path = widepath.c_str();
|
const wchar_t* path = widepath.c_str();
|
||||||
#else
|
#else
|
||||||
const char* path = _path.c_str();
|
const char* path = _path.c_str();
|
||||||
|
@ -99,7 +99,7 @@ target_include_directories(${TARGET_NAME}_plugin_api INTERFACE
|
|||||||
$<TARGET_PROPERTY:${TARGET_NAME}_preproc,INTERFACE_INCLUDE_DIRECTORIES>
|
$<TARGET_PROPERTY:${TARGET_NAME}_preproc,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
${PUBLIC_HEADERS_DIR} ${PUBLIC_HEADERS_DIR}/ie)
|
${PUBLIC_HEADERS_DIR} ${PUBLIC_HEADERS_DIR}/ie)
|
||||||
|
|
||||||
target_link_libraries(${TARGET_NAME}_plugin_api INTERFACE pugixml::static openvino::itt)
|
target_link_libraries(${TARGET_NAME}_plugin_api INTERFACE pugixml::static openvino::itt openvino::util)
|
||||||
|
|
||||||
set_ie_threading_interface_for(${TARGET_NAME}_plugin_api)
|
set_ie_threading_interface_for(${TARGET_NAME}_plugin_api)
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ target_include_directories(${TARGET_NAME}_obj PRIVATE "${CMAKE_CURRENT_SOURCE_DI
|
|||||||
$<TARGET_PROPERTY:${TARGET_NAME}_transformations,INTERFACE_INCLUDE_DIRECTORIES>
|
$<TARGET_PROPERTY:${TARGET_NAME}_transformations,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
$<TARGET_PROPERTY:${TARGET_NAME}_plugin_api,INTERFACE_INCLUDE_DIRECTORIES>)
|
$<TARGET_PROPERTY:${TARGET_NAME}_plugin_api,INTERFACE_INCLUDE_DIRECTORIES>)
|
||||||
|
|
||||||
target_link_libraries(${TARGET_NAME}_obj PRIVATE ${TARGET_NAME}_reader_api openvino::itt)
|
target_link_libraries(${TARGET_NAME}_obj PRIVATE ${TARGET_NAME}_reader_api openvino::itt openvino::util)
|
||||||
|
|
||||||
set_ie_threading_interface_for(${TARGET_NAME}_obj)
|
set_ie_threading_interface_for(${TARGET_NAME}_obj)
|
||||||
if (TBBBIND_2_4_FOUND)
|
if (TBBBIND_2_4_FOUND)
|
||||||
@ -167,7 +167,7 @@ if (TBBBIND_2_4_FOUND)
|
|||||||
target_link_libraries(${TARGET_NAME} PRIVATE ${TBBBIND_2_4_IMPORTED_TARGETS})
|
target_link_libraries(${TARGET_NAME} PRIVATE ${TBBBIND_2_4_IMPORTED_TARGETS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${TARGET_NAME} PRIVATE pugixml::static openvino::itt ${CMAKE_DL_LIBS} Threads::Threads
|
target_link_libraries(${TARGET_NAME} PRIVATE pugixml::static openvino::itt openvino::util ${CMAKE_DL_LIBS} Threads::Threads
|
||||||
frontend_manager::static inference_engine_transformations
|
frontend_manager::static inference_engine_transformations
|
||||||
PUBLIC ngraph)
|
PUBLIC ngraph)
|
||||||
|
|
||||||
|
@ -66,39 +66,9 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
|
||||||
|
|
||||||
std::string FileUtils::wStringtoMBCSstringChar(const std::wstring& wstr) {
|
|
||||||
# ifdef _WIN32
|
|
||||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
|
|
||||||
std::string strTo(size_needed, 0);
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
|
|
||||||
return strTo;
|
|
||||||
# else
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_decoder;
|
|
||||||
return wstring_decoder.to_bytes(wstr);
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring FileUtils::multiByteCharToWString(const char* str) {
|
|
||||||
# ifdef _WIN32
|
|
||||||
int strSize = static_cast<int>(std::strlen(str));
|
|
||||||
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, strSize, NULL, 0);
|
|
||||||
std::wstring wstrTo(size_needed, 0);
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, str, strSize, &wstrTo[0], size_needed);
|
|
||||||
return wstrTo;
|
|
||||||
# else
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_encoder;
|
|
||||||
std::wstring result = wstring_encoder.from_bytes(str);
|
|
||||||
return result;
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
|
||||||
|
|
||||||
long long FileUtils::fileSize(const char* charfilepath) {
|
long long FileUtils::fileSize(const char* charfilepath) {
|
||||||
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||||
std::wstring widefilename = FileUtils::multiByteCharToWString(charfilepath);
|
std::wstring widefilename = ov::util::string_to_wstring(charfilepath);
|
||||||
const wchar_t* fileName = widefilename.c_str();
|
const wchar_t* fileName = widefilename.c_str();
|
||||||
#elif defined(__ANDROID__) || defined(ANDROID)
|
#elif defined(__ANDROID__) || defined(ANDROID)
|
||||||
std::string fileName = charfilepath;
|
std::string fileName = charfilepath;
|
||||||
@ -138,7 +108,7 @@ void FileUtils::createDirectoryRecursive(const std::string& dirPath) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t pos = dirPath.rfind(FileUtils::FileSeparator);
|
std::size_t pos = dirPath.rfind(ov::util::FileTraits<char>::file_separator);
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
createDirectoryRecursive(dirPath.substr(0, pos));
|
createDirectoryRecursive(dirPath.substr(0, pos));
|
||||||
}
|
}
|
||||||
@ -156,7 +126,7 @@ namespace {
|
|||||||
|
|
||||||
template <typename C, typename = InferenceEngine::details::enableIfSupportedChar<C>>
|
template <typename C, typename = InferenceEngine::details::enableIfSupportedChar<C>>
|
||||||
std::basic_string<C> getPathName(const std::basic_string<C>& s) {
|
std::basic_string<C> getPathName(const std::basic_string<C>& s) {
|
||||||
size_t i = s.rfind(FileUtils::FileTraits<C>::FileSeparator, s.length());
|
size_t i = s.rfind(ov::util::FileTraits<C>::file_separator, s.length());
|
||||||
if (i != std::string::npos) {
|
if (i != std::string::npos) {
|
||||||
return (s.substr(0, i));
|
return (s.substr(0, i));
|
||||||
}
|
}
|
||||||
@ -213,7 +183,7 @@ std::wstring getIELibraryPathW() {
|
|||||||
GetModuleFileNameW(hm, (LPWSTR)ie_library_path, sizeof(ie_library_path) / sizeof(ie_library_path[0]));
|
GetModuleFileNameW(hm, (LPWSTR)ie_library_path, sizeof(ie_library_path) / sizeof(ie_library_path[0]));
|
||||||
return getPathName(std::wstring(ie_library_path));
|
return getPathName(std::wstring(ie_library_path));
|
||||||
# elif defined(__linux__) || defined(__APPLE__)
|
# elif defined(__linux__) || defined(__APPLE__)
|
||||||
return ::FileUtils::multiByteCharToWString(getIELibraryPathA().c_str());
|
return ::ov::util::string_to_wstring(getIELibraryPathA().c_str());
|
||||||
# else
|
# else
|
||||||
# error "Unsupported OS"
|
# error "Unsupported OS"
|
||||||
# endif
|
# endif
|
||||||
@ -223,7 +193,7 @@ std::wstring getIELibraryPathW() {
|
|||||||
|
|
||||||
std::string getIELibraryPath() {
|
std::string getIELibraryPath() {
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
return FileUtils::wStringtoMBCSstringChar(getIELibraryPathW());
|
return ov::util::wstring_to_string(getIELibraryPathW());
|
||||||
#else
|
#else
|
||||||
return getIELibraryPathA();
|
return getIELibraryPathA();
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "ngraph/pass/constant_folding.hpp"
|
#include "ngraph/pass/constant_folding.hpp"
|
||||||
#include "openvino/runtime/core.hpp"
|
#include "openvino/runtime/core.hpp"
|
||||||
#include "openvino/runtime/executable_network.hpp"
|
#include "openvino/runtime/executable_network.hpp"
|
||||||
|
#include "openvino/util/file_util.hpp"
|
||||||
#include "xml_parse_utils.h"
|
#include "xml_parse_utils.h"
|
||||||
|
|
||||||
using namespace InferenceEngine::PluginConfigParams;
|
using namespace InferenceEngine::PluginConfigParams;
|
||||||
@ -48,9 +49,9 @@ std::string parseXmlConfig(const std::string& xmlFile) {
|
|||||||
std::string xmlConfigFile_ = xmlFile;
|
std::string xmlConfigFile_ = xmlFile;
|
||||||
if (xmlConfigFile_.empty()) {
|
if (xmlConfigFile_.empty()) {
|
||||||
// register plugins from default plugins.xml config
|
// register plugins from default plugins.xml config
|
||||||
FileUtils::FilePath xmlConfigFileDefault =
|
ov::util::FilePath xmlConfigFileDefault =
|
||||||
FileUtils::makePath(ie::getInferenceEngineLibraryPath(), FileUtils::toFilePath("plugins.xml"));
|
FileUtils::makePath(ie::getInferenceEngineLibraryPath(), ov::util::to_file_path("plugins.xml"));
|
||||||
xmlConfigFile_ = FileUtils::fromFilePath(xmlConfigFileDefault);
|
xmlConfigFile_ = ov::util::from_file_path(xmlConfigFileDefault);
|
||||||
}
|
}
|
||||||
return xmlConfigFile_;
|
return xmlConfigFile_;
|
||||||
}
|
}
|
||||||
@ -165,9 +166,9 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this<ie::ICore
|
|||||||
ie::CacheGuard cacheGuard;
|
ie::CacheGuard cacheGuard;
|
||||||
|
|
||||||
struct PluginDescriptor {
|
struct PluginDescriptor {
|
||||||
FileUtils::FilePath libraryLocation;
|
ov::util::FilePath libraryLocation;
|
||||||
std::map<std::string, std::string> defaultConfig;
|
std::map<std::string, std::string> defaultConfig;
|
||||||
std::vector<FileUtils::FilePath> listOfExtentions;
|
std::vector<ov::util::FilePath> listOfExtentions;
|
||||||
};
|
};
|
||||||
|
|
||||||
mutable std::unordered_set<std::string> opsetNames;
|
mutable std::unordered_set<std::string> opsetNames;
|
||||||
@ -374,7 +375,7 @@ public:
|
|||||||
|
|
||||||
FOREACH_CHILD (pluginNode, devicesNode, "plugin") {
|
FOREACH_CHILD (pluginNode, devicesNode, "plugin") {
|
||||||
std::string deviceName = GetStrAttr(pluginNode, "name");
|
std::string deviceName = GetStrAttr(pluginNode, "name");
|
||||||
FileUtils::FilePath pluginPath = FileUtils::toFilePath(GetStrAttr(pluginNode, "location").c_str());
|
ov::util::FilePath pluginPath = ov::util::to_file_path(GetStrAttr(pluginNode, "location").c_str());
|
||||||
|
|
||||||
if (deviceName.find('.') != std::string::npos) {
|
if (deviceName.find('.') != std::string::npos) {
|
||||||
IE_THROW() << "Device name must not contain dot '.' symbol";
|
IE_THROW() << "Device name must not contain dot '.' symbol";
|
||||||
@ -382,7 +383,7 @@ public:
|
|||||||
|
|
||||||
// append IR library path for default IE plugins
|
// append IR library path for default IE plugins
|
||||||
{
|
{
|
||||||
FileUtils::FilePath absFilePath = FileUtils::makePath(ie::getInferenceEngineLibraryPath(), pluginPath);
|
ov::util::FilePath absFilePath = FileUtils::makePath(ie::getInferenceEngineLibraryPath(), pluginPath);
|
||||||
if (FileUtils::fileExist(absFilePath))
|
if (FileUtils::fileExist(absFilePath))
|
||||||
pluginPath = absFilePath;
|
pluginPath = absFilePath;
|
||||||
}
|
}
|
||||||
@ -401,12 +402,12 @@ public:
|
|||||||
|
|
||||||
// check extensions
|
// check extensions
|
||||||
auto extensionsNode = pluginNode.child("extensions");
|
auto extensionsNode = pluginNode.child("extensions");
|
||||||
std::vector<FileUtils::FilePath> listOfExtentions;
|
std::vector<ov::util::FilePath> listOfExtentions;
|
||||||
|
|
||||||
if (extensionsNode) {
|
if (extensionsNode) {
|
||||||
FOREACH_CHILD (extensionNode, extensionsNode, "extension") {
|
FOREACH_CHILD (extensionNode, extensionsNode, "extension") {
|
||||||
FileUtils::FilePath extensionLocation =
|
ov::util::FilePath extensionLocation =
|
||||||
FileUtils::toFilePath(GetStrAttr(extensionNode, "location").c_str());
|
ov::util::to_file_path(GetStrAttr(extensionNode, "location").c_str());
|
||||||
listOfExtentions.push_back(extensionLocation);
|
listOfExtentions.push_back(extensionLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -695,7 +696,7 @@ public:
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (const ie::Exception& ex) {
|
} catch (const ie::Exception& ex) {
|
||||||
IE_THROW() << "Failed to create plugin " << FileUtils::fromFilePath(desc.libraryLocation)
|
IE_THROW() << "Failed to create plugin " << ov::util::from_file_path(desc.libraryLocation)
|
||||||
<< " for device " << deviceName << "\n"
|
<< " for device " << deviceName << "\n"
|
||||||
<< "Please, check your environment\n"
|
<< "Please, check your environment\n"
|
||||||
<< ex.what() << "\n";
|
<< ex.what() << "\n";
|
||||||
@ -736,11 +737,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// append IR library path for default IE plugins
|
// append IR library path for default IE plugins
|
||||||
FileUtils::FilePath pluginPath;
|
ov::util::FilePath pluginPath;
|
||||||
{
|
{
|
||||||
pluginPath = FileUtils::makePluginLibraryName({}, FileUtils::toFilePath(pluginName.c_str()));
|
pluginPath = FileUtils::makePluginLibraryName({}, ov::util::to_file_path(pluginName.c_str()));
|
||||||
|
|
||||||
FileUtils::FilePath absFilePath = FileUtils::makePath(ie::getInferenceEngineLibraryPath(), pluginPath);
|
ov::util::FilePath absFilePath = FileUtils::makePath(ie::getInferenceEngineLibraryPath(), pluginPath);
|
||||||
if (FileUtils::fileExist(absFilePath))
|
if (FileUtils::fileExist(absFilePath))
|
||||||
pluginPath = absFilePath;
|
pluginPath = absFilePath;
|
||||||
}
|
}
|
||||||
@ -980,7 +981,7 @@ std::map<std::string, Version> Core::GetVersions(const std::string& deviceName)
|
|||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
CNNNetwork Core::ReadNetwork(const std::wstring& modelPath, const std::wstring& binPath) const {
|
CNNNetwork Core::ReadNetwork(const std::wstring& modelPath, const std::wstring& binPath) const {
|
||||||
return ReadNetwork(FileUtils::wStringtoMBCSstringChar(modelPath), FileUtils::wStringtoMBCSstringChar(binPath));
|
return ReadNetwork(ov::util::wstring_to_string(modelPath), ov::util::wstring_to_string(binPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1234,8 +1235,7 @@ std::map<std::string, ie::Version> Core::get_versions(const std::string& deviceN
|
|||||||
|
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
std::shared_ptr<ngraph::Function> Core::read_model(const std::wstring& modelPath, const std::wstring& binPath) const {
|
std::shared_ptr<ngraph::Function> Core::read_model(const std::wstring& modelPath, const std::wstring& binPath) const {
|
||||||
return _impl
|
return _impl->ReadNetwork(ov::util::wstring_to_string(modelPath), ov::util::wstring_to_string(binPath))
|
||||||
->ReadNetwork(FileUtils::wStringtoMBCSstringChar(modelPath), FileUtils::wStringtoMBCSstringChar(binPath))
|
|
||||||
.getFunction();
|
.getFunction();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,13 +45,13 @@ class Reader : public IReader {
|
|||||||
|
|
||||||
InferenceEngine::details::SOPointer<IReader> getReaderPtr() {
|
InferenceEngine::details::SOPointer<IReader> getReaderPtr() {
|
||||||
std::call_once(readFlag, [&]() {
|
std::call_once(readFlag, [&]() {
|
||||||
FileUtils::FilePath libraryName = FileUtils::toFilePath(location);
|
ov::util::FilePath libraryName = ov::util::to_file_path(location);
|
||||||
FileUtils::FilePath readersLibraryPath =
|
ov::util::FilePath readersLibraryPath =
|
||||||
FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
|
FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
|
||||||
|
|
||||||
if (!FileUtils::fileExist(readersLibraryPath)) {
|
if (!FileUtils::fileExist(readersLibraryPath)) {
|
||||||
IE_THROW() << "Please, make sure that Inference Engine ONNX reader library "
|
IE_THROW() << "Please, make sure that Inference Engine ONNX reader library "
|
||||||
<< FileUtils::fromFilePath(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in "
|
<< ov::util::from_file_path(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in "
|
||||||
<< getIELibraryPath();
|
<< getIELibraryPath();
|
||||||
}
|
}
|
||||||
ptr = {readersLibraryPath};
|
ptr = {readersLibraryPath};
|
||||||
@ -111,8 +111,8 @@ void registerReaders() {
|
|||||||
|
|
||||||
// TODO: Read readers info from XML
|
// TODO: Read readers info from XML
|
||||||
auto create_if_exists = [](const std::string name, const std::string library_name) {
|
auto create_if_exists = [](const std::string name, const std::string library_name) {
|
||||||
FileUtils::FilePath libraryName = FileUtils::toFilePath(library_name);
|
ov::util::FilePath libraryName = ov::util::to_file_path(library_name);
|
||||||
FileUtils::FilePath readersLibraryPath =
|
ov::util::FilePath readersLibraryPath =
|
||||||
FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
|
FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
|
||||||
|
|
||||||
if (!FileUtils::fileExist(readersLibraryPath))
|
if (!FileUtils::fileExist(readersLibraryPath))
|
||||||
@ -165,7 +165,7 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath,
|
|||||||
|
|
||||||
// Fix unicode name
|
// Fix unicode name
|
||||||
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||||
std::wstring model_path = FileUtils::multiByteCharToWString(modelPath.c_str());
|
std::wstring model_path = ov::util::string_to_wstring(modelPath.c_str());
|
||||||
#else
|
#else
|
||||||
std::string model_path = modelPath;
|
std::string model_path = modelPath;
|
||||||
#endif
|
#endif
|
||||||
@ -201,7 +201,7 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath,
|
|||||||
if (!bPath.empty()) {
|
if (!bPath.empty()) {
|
||||||
// Open weights file
|
// Open weights file
|
||||||
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||||
std::wstring weights_path = FileUtils::multiByteCharToWString(bPath.c_str());
|
std::wstring weights_path = ov::util::string_to_wstring(bPath.c_str());
|
||||||
#else
|
#else
|
||||||
std::string weights_path = bPath;
|
std::string weights_path = bPath;
|
||||||
#endif
|
#endif
|
||||||
@ -238,7 +238,7 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath,
|
|||||||
ngraph::frontend::InputModel::Ptr inputModel;
|
ngraph::frontend::InputModel::Ptr inputModel;
|
||||||
if (!binPath.empty()) {
|
if (!binPath.empty()) {
|
||||||
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||||
std::wstring weights_path = FileUtils::multiByteCharToWString(binPath.c_str());
|
std::wstring weights_path = ov::util::string_to_wstring(binPath.c_str());
|
||||||
#else
|
#else
|
||||||
std::string weights_path = binPath;
|
std::string weights_path = binPath;
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "details/ie_so_loader.h"
|
#include "details/ie_so_loader.h"
|
||||||
#include "file_utils.h"
|
#include "file_utils.h"
|
||||||
|
#include "openvino/util/file_util.hpp"
|
||||||
#include "shared_object.hpp"
|
#include "shared_object.hpp"
|
||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
@ -28,7 +29,7 @@ std::shared_ptr<void> load_shared_object(const char* path) {
|
|||||||
|
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
std::shared_ptr<void> load_shared_object(const wchar_t* path) {
|
std::shared_ptr<void> load_shared_object(const wchar_t* path) {
|
||||||
return load_shared_object(FileUtils::wStringtoMBCSstringChar(path).c_str());
|
return load_shared_object(ov::util::wstring_to_string(path).c_str());
|
||||||
}
|
}
|
||||||
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ struct SharedObjectLoader::Impl {
|
|||||||
explicit Impl(const char* pluginName) : shared_object{ov::runtime::load_shared_object(pluginName)} {}
|
explicit Impl(const char* pluginName) : shared_object{ov::runtime::load_shared_object(pluginName)} {}
|
||||||
|
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
explicit Impl(const wchar_t* pluginName) : Impl(FileUtils::wStringtoMBCSstringChar(pluginName).c_str()) {}
|
explicit Impl(const wchar_t* pluginName) : Impl(ov::util::wstring_to_string(pluginName).c_str()) {}
|
||||||
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
void* get_symbol(const char* symbolName) const {
|
void* get_symbol(const char* symbolName) const {
|
||||||
|
@ -159,7 +159,7 @@ std::shared_ptr<void> load_shared_object(const wchar_t* path) {
|
|||||||
}
|
}
|
||||||
if (!shared_object) {
|
if (!shared_object) {
|
||||||
char cwd[1024];
|
char cwd[1024];
|
||||||
IE_THROW() << "Cannot load library '" << FileUtils::wStringtoMBCSstringChar(std::wstring(path)) << "': " << GetLastError()
|
IE_THROW() << "Cannot load library '" << ov::util::wstring_to_string(std::wstring(path)) << "': " << GetLastError()
|
||||||
<< " from cwd: " << _getcwd(cwd, sizeof(cwd));
|
<< " from cwd: " << _getcwd(cwd, sizeof(cwd));
|
||||||
}
|
}
|
||||||
return {shared_object,
|
return {shared_object,
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "pruning.hpp"
|
#include "pruning.hpp"
|
||||||
#include "mask_attribute.hpp"
|
|
||||||
|
|
||||||
#include <ngraph/pass/visualize_tree.hpp>
|
#include <algorithm>
|
||||||
#include <ngraph/pass/constant_folding.hpp>
|
|
||||||
#include <ngraph/log.hpp>
|
#include <ngraph/log.hpp>
|
||||||
|
#include <ngraph/pass/constant_folding.hpp>
|
||||||
|
#include <ngraph/pass/visualize_tree.hpp>
|
||||||
|
|
||||||
|
#include "mask_attribute.hpp"
|
||||||
|
|
||||||
NGRAPH_RTTI_DEFINITION(ngraph::pass::Pruning, "Pruning", 0);
|
NGRAPH_RTTI_DEFINITION(ngraph::pass::Pruning, "Pruning", 0);
|
||||||
|
|
||||||
@ -21,8 +21,7 @@ bool ngraph::pass::Pruning::run_on_function(std::shared_ptr<Function> f) {
|
|||||||
manager.register_pass<InitMasks>();
|
manager.register_pass<InitMasks>();
|
||||||
manager.register_pass<PropagateMasks>();
|
manager.register_pass<PropagateMasks>();
|
||||||
|
|
||||||
|
#ifdef OPENVINO_DEBUG_ENABLE
|
||||||
#ifdef NGRAPH_DEBUG_ENABLE
|
|
||||||
// VisualizeTree modifier helps to print Masks and mark nodes with masks
|
// VisualizeTree modifier helps to print Masks and mark nodes with masks
|
||||||
/*
|
/*
|
||||||
auto modifier = [](const Node& node, std::vector<std::string>& attributes) {
|
auto modifier = [](const Node& node, std::vector<std::string>& attributes) {
|
||||||
@ -57,7 +56,7 @@ bool ngraph::pass::Pruning::run_on_function(std::shared_ptr<Function> f) {
|
|||||||
|
|
||||||
manager.register_pass<ShrinkWeights>();
|
manager.register_pass<ShrinkWeights>();
|
||||||
|
|
||||||
#ifdef NGRAPH_DEBUG_ENABLE
|
#ifdef OPENVINO_DEBUG_ENABLE
|
||||||
// Uncomment following line and change path to resulting svg file
|
// Uncomment following line and change path to resulting svg file
|
||||||
// manager.register_pass<VisualizeTree>("/tmp/after.svg");
|
// manager.register_pass<VisualizeTree>("/tmp/after.svg");
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,72 +15,10 @@
|
|||||||
|
|
||||||
#include "ie_api.h"
|
#include "ie_api.h"
|
||||||
#include "details/ie_so_pointer.hpp"
|
#include "details/ie_so_pointer.hpp"
|
||||||
|
#include "openvino/util/file_util.hpp"
|
||||||
|
|
||||||
namespace FileUtils {
|
namespace FileUtils {
|
||||||
|
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Conversion from wide character string to a single-byte chain.
|
|
||||||
* @param wstr A wide-char string
|
|
||||||
* @return A multi-byte string
|
|
||||||
*/
|
|
||||||
INFERENCE_ENGINE_API_CPP(std::string) wStringtoMBCSstringChar(const std::wstring& wstr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Conversion from single-byte chain to wide character string.
|
|
||||||
* @param str A null-terminated string
|
|
||||||
* @return A wide-char string
|
|
||||||
*/
|
|
||||||
INFERENCE_ENGINE_API_CPP(std::wstring) multiByteCharToWString(const char* str);
|
|
||||||
|
|
||||||
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
|
||||||
|
|
||||||
template <typename T> struct FileTraits;
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
/// @brief File path separator
|
|
||||||
const char FileSeparator = '\\';
|
|
||||||
|
|
||||||
template<> struct FileTraits<char> {
|
|
||||||
constexpr static const auto FileSeparator = ::FileUtils::FileSeparator;
|
|
||||||
static std::string PluginLibraryPrefix() { return { }; }
|
|
||||||
static std::string PluginLibraryExt() { return { "dll" }; }
|
|
||||||
};
|
|
||||||
template<> struct FileTraits<wchar_t> {
|
|
||||||
constexpr static const auto FileSeparator = L'\\';
|
|
||||||
static std::wstring PluginLibraryPrefix() { return { }; }
|
|
||||||
static std::wstring PluginLibraryExt() { return { L"dll" }; }
|
|
||||||
};
|
|
||||||
#elif defined __APPLE__
|
|
||||||
/// @brief File path separator
|
|
||||||
const char FileSeparator = '/';
|
|
||||||
template<> struct FileTraits<char> {
|
|
||||||
constexpr static const auto FileSeparator = ::FileUtils::FileSeparator;
|
|
||||||
static std::string PluginLibraryPrefix() { return { "lib" }; }
|
|
||||||
static std::string PluginLibraryExt() { return { "so" }; }
|
|
||||||
};
|
|
||||||
template<> struct FileTraits<wchar_t> {
|
|
||||||
constexpr static const auto FileSeparator = L'/';
|
|
||||||
static std::wstring PluginLibraryPrefix() { return { L"lib" }; }
|
|
||||||
static std::wstring PluginLibraryExt() { return { L"so" }; }
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
/// @brief File path separator
|
|
||||||
const char FileSeparator = '/';
|
|
||||||
template<> struct FileTraits<char> {
|
|
||||||
constexpr static const auto FileSeparator = ::FileUtils::FileSeparator;
|
|
||||||
static std::string PluginLibraryPrefix() { return { "lib" }; }
|
|
||||||
static std::string PluginLibraryExt() { return { "so" }; }
|
|
||||||
};
|
|
||||||
template<> struct FileTraits<wchar_t> {
|
|
||||||
constexpr static const auto FileSeparator = L'/';
|
|
||||||
static std::wstring PluginLibraryPrefix() { return { L"lib" }; }
|
|
||||||
static std::wstring PluginLibraryExt() { return { L"so" }; }
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Interface function to get absolute path of file
|
* @brief Interface function to get absolute path of file
|
||||||
* @ingroup ie_dev_api_file_utils
|
* @ingroup ie_dev_api_file_utils
|
||||||
@ -125,7 +63,7 @@ INFERENCE_ENGINE_API(long long) fileSize(const char *fileName);
|
|||||||
* @return { description_of_the_return_value }
|
* @return { description_of_the_return_value }
|
||||||
*/
|
*/
|
||||||
inline long long fileSize(const wchar_t* fileName) {
|
inline long long fileSize(const wchar_t* fileName) {
|
||||||
return fileSize(::FileUtils::wStringtoMBCSstringChar(fileName).c_str());
|
return fileSize(::ov::util::wstring_to_string(fileName).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
||||||
@ -175,13 +113,9 @@ template <typename C, typename = InferenceEngine::details::enableIfSupportedChar
|
|||||||
inline std::basic_string<C> makePath(const std::basic_string<C> &folder, const std::basic_string<C> &file) {
|
inline std::basic_string<C> makePath(const std::basic_string<C> &folder, const std::basic_string<C> &file) {
|
||||||
if (folder.empty())
|
if (folder.empty())
|
||||||
return file;
|
return file;
|
||||||
return folder + FileTraits<C>::FileSeparator + file;
|
return folder + ov::util::FileTraits<C>::file_separator + file;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename C> struct DotSymbol;
|
|
||||||
template <> struct DotSymbol<char> { constexpr static const char value = '.'; };
|
|
||||||
template <> struct DotSymbol<wchar_t> { constexpr static const wchar_t value = L'.'; };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief CPP Interface function to extract extension from filename
|
* @brief CPP Interface function to extract extension from filename
|
||||||
* @ingroup ie_dev_api_file_utils
|
* @ingroup ie_dev_api_file_utils
|
||||||
@ -190,7 +124,7 @@ template <> struct DotSymbol<wchar_t> { constexpr static const wchar_t value = L
|
|||||||
*/
|
*/
|
||||||
template <typename C, typename = InferenceEngine::details::enableIfSupportedChar<C>>
|
template <typename C, typename = InferenceEngine::details::enableIfSupportedChar<C>>
|
||||||
inline std::basic_string<C> fileExt(const std::basic_string<C> &filename) {
|
inline std::basic_string<C> fileExt(const std::basic_string<C> &filename) {
|
||||||
auto pos = filename.rfind(DotSymbol<C>::value);
|
auto pos = filename.rfind(ov::util::FileTraits<C>::dot_symbol);
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
return {};
|
return {};
|
||||||
return filename.substr(pos + 1);
|
return filename.substr(pos + 1);
|
||||||
@ -198,38 +132,12 @@ inline std::basic_string<C> fileExt(const std::basic_string<C> &filename) {
|
|||||||
|
|
||||||
template <typename C, typename = InferenceEngine::details::enableIfSupportedChar<C>>
|
template <typename C, typename = InferenceEngine::details::enableIfSupportedChar<C>>
|
||||||
inline std::basic_string<C> makePluginLibraryName(const std::basic_string<C> &path, const std::basic_string<C> &input) {
|
inline std::basic_string<C> makePluginLibraryName(const std::basic_string<C> &path, const std::basic_string<C> &input) {
|
||||||
std::basic_string<C> separator(1, FileTraits<C>::FileSeparator);
|
std::basic_string<C> separator(1, ov::util::FileTraits<C>::file_separator);
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
separator = {};
|
separator = {};
|
||||||
return path + separator + FileTraits<C>::PluginLibraryPrefix() + input + DotSymbol<C>::value + FileTraits<C>::PluginLibraryExt();
|
return path + separator + ov::util::FileTraits<C>::library_prefix() + input + ov::util::FileTraits<C>::dot_symbol + ov::util::FileTraits<C>::library_ext();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
|
||||||
|
|
||||||
using FilePath = std::wstring;
|
|
||||||
|
|
||||||
inline std::string fromFilePath(const FilePath & path) {
|
|
||||||
return ::FileUtils::wStringtoMBCSstringChar(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline FilePath toFilePath(const std::string & path) {
|
|
||||||
return ::FileUtils::multiByteCharToWString(path.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
using FilePath = std::string;
|
|
||||||
|
|
||||||
inline std::string fromFilePath(const FilePath & path) {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline FilePath toFilePath(const std::string & path) {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
|
||||||
|
|
||||||
} // namespace FileUtils
|
} // namespace FileUtils
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
@ -251,13 +159,13 @@ INFERENCE_ENGINE_API_CPP(std::string) getIELibraryPath();
|
|||||||
*/
|
*/
|
||||||
INFERENCE_ENGINE_API_CPP(std::wstring) getIELibraryPathW();
|
INFERENCE_ENGINE_API_CPP(std::wstring) getIELibraryPathW();
|
||||||
|
|
||||||
inline ::FileUtils::FilePath getInferenceEngineLibraryPath() {
|
inline ::ov::util::FilePath getInferenceEngineLibraryPath() {
|
||||||
return getIELibraryPathW();
|
return getIELibraryPathW();
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
inline ::FileUtils::FilePath getInferenceEngineLibraryPath() {
|
inline ::ov::util::FilePath getInferenceEngineLibraryPath() {
|
||||||
return getIELibraryPath();
|
return getIELibraryPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ struct parse_result {
|
|||||||
*/
|
*/
|
||||||
inline parse_result ParseXml(const char* file_path) {
|
inline parse_result ParseXml(const char* file_path) {
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
std::wstring wFilePath = FileUtils::multiByteCharToWString(file_path);
|
std::wstring wFilePath = ov::util::string_to_wstring(file_path);
|
||||||
const wchar_t* resolvedFilepath = wFilePath.c_str();
|
const wchar_t* resolvedFilepath = wFilePath.c_str();
|
||||||
#else
|
#else
|
||||||
const char* resolvedFilepath = file_path;
|
const char* resolvedFilepath = file_path;
|
||||||
|
@ -123,7 +123,7 @@ ie_add_vs_version_file(NAME ${TARGET_NAME}
|
|||||||
|
|
||||||
set_ie_threading_interface_for(${TARGET_NAME})
|
set_ie_threading_interface_for(${TARGET_NAME})
|
||||||
|
|
||||||
target_link_libraries(${TARGET_NAME} PRIVATE fluid openvino::itt
|
target_link_libraries(${TARGET_NAME} PRIVATE fluid openvino::itt openvino::util
|
||||||
PUBLIC inference_engine)
|
PUBLIC inference_engine)
|
||||||
|
|
||||||
target_include_directories(${TARGET_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
|
target_include_directories(${TARGET_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
@ -88,12 +88,12 @@ public:
|
|||||||
using PreProcessDataPtr = InferenceEngine::details::SOPointer<IPreProcessData>;
|
using PreProcessDataPtr = InferenceEngine::details::SOPointer<IPreProcessData>;
|
||||||
|
|
||||||
inline PreProcessDataPtr CreatePreprocDataHelper() {
|
inline PreProcessDataPtr CreatePreprocDataHelper() {
|
||||||
FileUtils::FilePath libraryName = FileUtils::toFilePath(std::string("inference_engine_preproc") + std::string(IE_BUILD_POSTFIX));
|
ov::util::FilePath libraryName = ov::util::to_file_path(std::string("inference_engine_preproc") + std::string(IE_BUILD_POSTFIX));
|
||||||
FileUtils::FilePath preprocLibraryPath = FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
|
ov::util::FilePath preprocLibraryPath = FileUtils::makePluginLibraryName(getInferenceEngineLibraryPath(), libraryName);
|
||||||
|
|
||||||
if (!FileUtils::fileExist(preprocLibraryPath)) {
|
if (!FileUtils::fileExist(preprocLibraryPath)) {
|
||||||
IE_THROW() << "Please, make sure that pre-processing library "
|
IE_THROW() << "Please, make sure that pre-processing library "
|
||||||
<< FileUtils::fromFilePath(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in "
|
<< ov::util::from_file_path(::FileUtils::makePluginLibraryName({}, libraryName)) << " is in "
|
||||||
<< getIELibraryPath();
|
<< getIELibraryPath();
|
||||||
}
|
}
|
||||||
return {preprocLibraryPath};
|
return {preprocLibraryPath};
|
||||||
|
@ -72,7 +72,7 @@ void readAllFile(const std::string& string_file_name, void* buffer, size_t maxSi
|
|||||||
std::ifstream inputFile;
|
std::ifstream inputFile;
|
||||||
|
|
||||||
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||||
std::wstring file_name = FileUtils::multiByteCharToWString(string_file_name.c_str());
|
std::wstring file_name = ov::util::string_to_wstring(string_file_name.c_str());
|
||||||
#else
|
#else
|
||||||
std::string file_name = string_file_name;
|
std::string file_name = string_file_name;
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,6 +13,7 @@ set(LINK_LIBRARIES
|
|||||||
lptNgraphFunctions
|
lptNgraphFunctions
|
||||||
inference_engine_transformations
|
inference_engine_transformations
|
||||||
openvino::itt
|
openvino::itt
|
||||||
|
openvino::util
|
||||||
openvino::conditional_compilation
|
openvino::conditional_compilation
|
||||||
sharedTestClasses
|
sharedTestClasses
|
||||||
inference_engine_snippets
|
inference_engine_snippets
|
||||||
|
@ -95,16 +95,16 @@ TEST_F(CoreThreadingTests, RegisterPlugins) {
|
|||||||
auto getPluginXml = [&] () -> std::tuple<std::string, std::string> {
|
auto getPluginXml = [&] () -> std::tuple<std::string, std::string> {
|
||||||
std::string indexStr = std::to_string(index++);
|
std::string indexStr = std::to_string(index++);
|
||||||
std::string pluginsXML = InferenceEngine::getIELibraryPath() +
|
std::string pluginsXML = InferenceEngine::getIELibraryPath() +
|
||||||
FileUtils::FileSeparator +
|
ov::util::FileTraits<char>::file_separator +
|
||||||
"test_plugins" + indexStr + ".xml";
|
"test_plugins" + indexStr + ".xml";
|
||||||
std::ofstream file(pluginsXML);
|
std::ofstream file(pluginsXML);
|
||||||
|
|
||||||
file << "<ie><plugins><plugin location=\"";
|
file << "<ie><plugins><plugin location=\"";
|
||||||
file << FileUtils::FileTraits<char>::PluginLibraryPrefix();
|
file << ov::util::FileTraits<char>::library_prefix();
|
||||||
file << "mock_engine";
|
file << "mock_engine";
|
||||||
file << IE_BUILD_POSTFIX;
|
file << IE_BUILD_POSTFIX;
|
||||||
file << FileUtils::DotSymbol<char>::value;
|
file << ov::util::FileTraits<char>::dot_symbol;
|
||||||
file << FileUtils::FileTraits<char>::PluginLibraryExt();
|
file << ov::util::FileTraits<char>::library_ext();
|
||||||
file << "\" name=\"";
|
file << "\" name=\"";
|
||||||
file << indexStr;
|
file << indexStr;
|
||||||
file << "\"></plugin></plugins></ie>";
|
file << "\"></plugin></plugins></ie>";
|
||||||
|
@ -85,12 +85,12 @@ TEST_P(NetReaderTest, ReadCorrectModelWithWeightsUnicodePath) {
|
|||||||
is_copy_successfully = CommonTestUtils::copyFile(_modelPath, modelPath);
|
is_copy_successfully = CommonTestUtils::copyFile(_modelPath, modelPath);
|
||||||
if (!is_copy_successfully) {
|
if (!is_copy_successfully) {
|
||||||
FAIL() << "Unable to copy from '" << _modelPath << "' to '"
|
FAIL() << "Unable to copy from '" << _modelPath << "' to '"
|
||||||
<< FileUtils::wStringtoMBCSstringChar(modelPath) << "'";
|
<< ov::util::wstring_to_string(modelPath) << "'";
|
||||||
}
|
}
|
||||||
is_copy_successfully = CommonTestUtils::copyFile(_weightsPath, weightsPath);
|
is_copy_successfully = CommonTestUtils::copyFile(_weightsPath, weightsPath);
|
||||||
if (!is_copy_successfully) {
|
if (!is_copy_successfully) {
|
||||||
FAIL() << "Unable to copy from '" << _weightsPath << "' to '"
|
FAIL() << "Unable to copy from '" << _weightsPath << "' to '"
|
||||||
<< FileUtils::wStringtoMBCSstringChar(weightsPath) << "'";
|
<< ov::util::wstring_to_string(weightsPath) << "'";
|
||||||
}
|
}
|
||||||
GTEST_COUT << "Test " << testIndex << std::endl;
|
GTEST_COUT << "Test " << testIndex << std::endl;
|
||||||
InferenceEngine::Core ie;
|
InferenceEngine::Core ie;
|
||||||
|
@ -86,7 +86,7 @@ TEST(ONNX_Reader_Tests, ImportModelWithExternalDataFromWstringNamedFile) {
|
|||||||
bool is_copy_successfully = CommonTestUtils::copyFile(win_dir_path, wmodel);
|
bool is_copy_successfully = CommonTestUtils::copyFile(win_dir_path, wmodel);
|
||||||
if (!is_copy_successfully) {
|
if (!is_copy_successfully) {
|
||||||
FAIL() << "Unable to copy from '" << win_dir_path << "' to '"
|
FAIL() << "Unable to copy from '" << win_dir_path << "' to '"
|
||||||
<< FileUtils::wStringtoMBCSstringChar(wmodel) << "'";
|
<< ov::util::wstring_to_string(wmodel) << "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cnnNetwork = ie.ReadNetwork(wmodel, L"");
|
auto cnnNetwork = ie.ReadNetwork(wmodel, L"");
|
||||||
|
@ -55,7 +55,7 @@ TEST(PDPD_Reader_Tests, ImportBasicModelToCoreWstring) {
|
|||||||
bool is_copy_successfully = CommonTestUtils::copyFile(win_dir_path, wmodel);
|
bool is_copy_successfully = CommonTestUtils::copyFile(win_dir_path, wmodel);
|
||||||
if (!is_copy_successfully) {
|
if (!is_copy_successfully) {
|
||||||
FAIL() << "Unable to copy from '" << win_dir_path << "' to '"
|
FAIL() << "Unable to copy from '" << win_dir_path << "' to '"
|
||||||
<< FileUtils::wStringtoMBCSstringChar(wmodel) << "'";
|
<< ov::util::wstring_to_string(wmodel) << "'";
|
||||||
}
|
}
|
||||||
InferenceEngine::Core ie;
|
InferenceEngine::Core ie;
|
||||||
auto cnnNetwork = ie.ReadNetwork(wmodel);
|
auto cnnNetwork = ie.ReadNetwork(wmodel);
|
||||||
|
@ -60,7 +60,7 @@ TEST_F(CompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinariesUnicodePath) {
|
|||||||
std::wstring cache_path_w = CommonTestUtils::addUnicodePostfixToPath(cache_path, postfix);
|
std::wstring cache_path_w = CommonTestUtils::addUnicodePostfixToPath(cache_path, postfix);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto cache_path_mb = FileUtils::wStringtoMBCSstringChar(cache_path_w);
|
auto cache_path_mb = ov::util::wstring_to_string(cache_path_w);
|
||||||
std::map<std::string, std::string> config = {{ CONFIG_KEY(CACHE_DIR), cache_path_mb }};
|
std::map<std::string, std::string> config = {{ CONFIG_KEY(CACHE_DIR), cache_path_mb }};
|
||||||
// Load CNNNetwork to target plugins
|
// Load CNNNetwork to target plugins
|
||||||
auto execNet = ie->LoadNetwork(cnnNet, "GPU", config);
|
auto execNet = ie->LoadNetwork(cnnNet, "GPU", config);
|
||||||
|
@ -26,6 +26,7 @@ addIeTarget(
|
|||||||
lptNgraphFunctions
|
lptNgraphFunctions
|
||||||
sharedTestClasses
|
sharedTestClasses
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
openvino::util
|
||||||
inference_engine_transformations
|
inference_engine_transformations
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
inference_engine
|
inference_engine
|
||||||
|
@ -280,14 +280,14 @@ TEST_P(IEClassBasicTestP, smoke_registerPluginsXMLUnicodePath) {
|
|||||||
bool is_copy_successfully;
|
bool is_copy_successfully;
|
||||||
is_copy_successfully = CommonTestUtils::copyFile(pluginXML, pluginsXmlW);
|
is_copy_successfully = CommonTestUtils::copyFile(pluginXML, pluginsXmlW);
|
||||||
if (!is_copy_successfully) {
|
if (!is_copy_successfully) {
|
||||||
FAIL() << "Unable to copy from '" << pluginXML << "' to '" << ::FileUtils::wStringtoMBCSstringChar(pluginsXmlW) << "'";
|
FAIL() << "Unable to copy from '" << pluginXML << "' to '" << ::ov::util::wstring_to_string(pluginsXmlW) << "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
GTEST_COUT << "Test " << testIndex << std::endl;
|
GTEST_COUT << "Test " << testIndex << std::endl;
|
||||||
|
|
||||||
Core ie = createCoreWithTemplate();
|
Core ie = createCoreWithTemplate();
|
||||||
GTEST_COUT << "Core created " << testIndex << std::endl;
|
GTEST_COUT << "Core created " << testIndex << std::endl;
|
||||||
ASSERT_NO_THROW(ie.RegisterPlugins(::FileUtils::wStringtoMBCSstringChar(pluginsXmlW)));
|
ASSERT_NO_THROW(ie.RegisterPlugins(::ov::util::wstring_to_string(pluginsXmlW)));
|
||||||
CommonTestUtils::removeFile(pluginsXmlW);
|
CommonTestUtils::removeFile(pluginsXmlW);
|
||||||
#if defined __linux__ && !defined(__APPLE__)
|
#if defined __linux__ && !defined(__APPLE__)
|
||||||
ASSERT_NO_THROW(ie.GetVersions("mock")); // from pluginXML
|
ASSERT_NO_THROW(ie.GetVersions("mock")); // from pluginXML
|
||||||
|
@ -276,14 +276,14 @@ TEST_P(OVClassBasicTestP, smoke_registerPluginsXMLUnicodePath) {
|
|||||||
is_copy_successfully = CommonTestUtils::copyFile(pluginXML, pluginsXmlW);
|
is_copy_successfully = CommonTestUtils::copyFile(pluginXML, pluginsXmlW);
|
||||||
if (!is_copy_successfully) {
|
if (!is_copy_successfully) {
|
||||||
FAIL() << "Unable to copy from '" << pluginXML << "' to '"
|
FAIL() << "Unable to copy from '" << pluginXML << "' to '"
|
||||||
<< ::FileUtils::wStringtoMBCSstringChar(pluginsXmlW) << "'";
|
<< ::ov::util::wstring_to_string(pluginsXmlW) << "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
GTEST_COUT << "Test " << testIndex << std::endl;
|
GTEST_COUT << "Test " << testIndex << std::endl;
|
||||||
|
|
||||||
ov::runtime::Core ie = createCoreWithTemplate();
|
ov::runtime::Core ie = createCoreWithTemplate();
|
||||||
GTEST_COUT << "Core created " << testIndex << std::endl;
|
GTEST_COUT << "Core created " << testIndex << std::endl;
|
||||||
ASSERT_NO_THROW(ie.register_plugins(::FileUtils::wStringtoMBCSstringChar(pluginsXmlW)));
|
ASSERT_NO_THROW(ie.register_plugins(::ov::util::wstring_to_string(pluginsXmlW)));
|
||||||
CommonTestUtils::removeFile(pluginsXmlW);
|
CommonTestUtils::removeFile(pluginsXmlW);
|
||||||
# if defined __linux__ && !defined(__APPLE__)
|
# if defined __linux__ && !defined(__APPLE__)
|
||||||
ASSERT_NO_THROW(ie.get_versions("mock")); // from pluginXML
|
ASSERT_NO_THROW(ie.get_versions("mock")); // from pluginXML
|
||||||
|
@ -19,6 +19,8 @@ function(add_common_utils ADD_TARGET_NAME)
|
|||||||
gtest
|
gtest
|
||||||
gtest_main
|
gtest_main
|
||||||
inference_engine_transformations
|
inference_engine_transformations
|
||||||
|
PRIVATE
|
||||||
|
openvino::util
|
||||||
)
|
)
|
||||||
|
|
||||||
# USE_STATIC_IE is passed
|
# USE_STATIC_IE is passed
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <ngraph/file_util.hpp>
|
#include <openvino/util/file_util.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@ -20,7 +20,6 @@
|
|||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
|
||||||
namespace CommonTestUtils {
|
namespace CommonTestUtils {
|
||||||
|
|
||||||
std::string getExecutableDirectory() {
|
std::string getExecutableDirectory() {
|
||||||
@ -41,11 +40,11 @@ std::string getExecutableDirectory() {
|
|||||||
throw "Can't get test executable path name";
|
throw "Can't get test executable path name";
|
||||||
}
|
}
|
||||||
path = std::string(buffer, len);
|
path = std::string(buffer, len);
|
||||||
return ngraph::file_util::get_directory(path);
|
return ov::util::get_directory(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getModelFromTestModelZoo(const std::string & relModelPath) {
|
std::string getModelFromTestModelZoo(const std::string & relModelPath) {
|
||||||
return ngraph::file_util::path_join(CommonTestUtils::getExecutableDirectory(), relModelPath);
|
return ov::util::path_join({CommonTestUtils::getExecutableDirectory(), relModelPath});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CommonTestUtils
|
} // namespace CommonTestUtils
|
||||||
|
@ -26,13 +26,13 @@ inline void fixSlashes(std::wstring &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline std::wstring stringToWString(std::string input) {
|
inline std::wstring stringToWString(std::string input) {
|
||||||
return ::FileUtils::multiByteCharToWString(input.c_str());
|
return ::ov::util::string_to_wstring(input.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool copyFile(std::wstring source_path, std::wstring dest_path) {
|
inline bool copyFile(std::wstring source_path, std::wstring dest_path) {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
std::ifstream source(FileUtils::wStringtoMBCSstringChar(source_path), std::ios::binary);
|
std::ifstream source(ov::util::wstring_to_string(source_path), std::ios::binary);
|
||||||
std::ofstream dest(FileUtils::wStringtoMBCSstringChar(dest_path), std::ios::binary);
|
std::ofstream dest(ov::util::wstring_to_string(dest_path), std::ios::binary);
|
||||||
#else
|
#else
|
||||||
fixSlashes(source_path);
|
fixSlashes(source_path);
|
||||||
fixSlashes(dest_path);
|
fixSlashes(dest_path);
|
||||||
@ -70,7 +70,7 @@ inline void removeFile(std::wstring path) {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
result = _wremove(path.c_str());
|
result = _wremove(path.c_str());
|
||||||
#else
|
#else
|
||||||
result = remove(FileUtils::wStringtoMBCSstringChar(path).c_str());
|
result = remove(ov::util::wstring_to_string(path).c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
(void)result;
|
(void)result;
|
||||||
@ -107,8 +107,8 @@ inline int removeFilesWithExt(std::wstring path, std::wstring ext) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
auto path_mb = FileUtils::wStringtoMBCSstringChar(path);
|
auto path_mb = ov::util::wstring_to_string(path);
|
||||||
auto ext_mb = FileUtils::wStringtoMBCSstringChar(ext);
|
auto ext_mb = ov::util::wstring_to_string(ext);
|
||||||
DIR *dir = opendir(path_mb.c_str());
|
DIR *dir = opendir(path_mb.c_str());
|
||||||
if (dir != nullptr) {
|
if (dir != nullptr) {
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
@ -136,7 +136,7 @@ inline int removeDir(std::wstring path) {
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
result = _wrmdir(path.c_str());
|
result = _wrmdir(path.c_str());
|
||||||
#else
|
#else
|
||||||
result = rmdir(FileUtils::wStringtoMBCSstringChar(path).c_str());
|
result = rmdir(ov::util::wstring_to_string(path).c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -150,7 +150,7 @@ inline bool directoryExists(const std::wstring &path) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (stat(FileUtils::wStringtoMBCSstringChar(path).c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
|
if (stat(ov::util::wstring_to_string(path).c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,6 +12,7 @@ addIeTargetTest(
|
|||||||
gtest_main
|
gtest_main
|
||||||
commonTestUtils
|
commonTestUtils
|
||||||
onnx_ngraph_frontend
|
onnx_ngraph_frontend
|
||||||
|
openvino::util
|
||||||
DEFINES
|
DEFINES
|
||||||
ONNX_MODELS_DIR=\"${TEST_MODEL_ZOO}/onnx_import\"
|
ONNX_MODELS_DIR=\"${TEST_MODEL_ZOO}/onnx_import\"
|
||||||
ADD_CPPLINT
|
ADD_CPPLINT
|
||||||
|
@ -8,14 +8,12 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "common_test_utils/file_utils.hpp"
|
#include "common_test_utils/file_utils.hpp"
|
||||||
#include "ngraph/file_util.hpp"
|
#include "openvino/util/file_util.hpp"
|
||||||
#include "onnx_import/onnx.hpp"
|
#include "onnx_import/onnx.hpp"
|
||||||
|
|
||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
|
||||||
|
|
||||||
TEST(ONNX_Importer_Tests, ImportBasicModel) {
|
TEST(ONNX_Importer_Tests, ImportBasicModel) {
|
||||||
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
||||||
ngraph::file_util::path_join(ONNX_MODELS_DIR, "add_abc_initializers.onnx"));
|
ov::util::path_join({ONNX_MODELS_DIR, "add_abc_initializers.onnx"}));
|
||||||
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
||||||
|
|
||||||
int count_additions = 0;
|
int count_additions = 0;
|
||||||
@ -40,7 +38,7 @@ TEST(ONNX_Importer_Tests, ImportBasicModel) {
|
|||||||
|
|
||||||
TEST(ONNX_Importer_Tests, ImportModelWithFusedOp) {
|
TEST(ONNX_Importer_Tests, ImportModelWithFusedOp) {
|
||||||
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
||||||
ngraph::file_util::path_join(ONNX_MODELS_DIR, "selu.onnx"));
|
ov::util::path_join({ONNX_MODELS_DIR, "selu.onnx"}));
|
||||||
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
||||||
|
|
||||||
int count_selu = 0;
|
int count_selu = 0;
|
||||||
@ -65,7 +63,7 @@ TEST(ONNX_Importer_Tests, ImportModelWithFusedOp) {
|
|||||||
|
|
||||||
TEST(ONNX_Importer_Tests, ImportModelWithMultiOutput) {
|
TEST(ONNX_Importer_Tests, ImportModelWithMultiOutput) {
|
||||||
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
||||||
ngraph::file_util::path_join(ONNX_MODELS_DIR, "topk.onnx"));
|
ov::util::path_join({ONNX_MODELS_DIR, "topk.onnx"}));
|
||||||
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
||||||
|
|
||||||
int count_topk = 0;
|
int count_topk = 0;
|
||||||
@ -93,7 +91,7 @@ TEST(ONNX_Importer_Tests, ImportModelWithMultiOutput) {
|
|||||||
|
|
||||||
TEST(ONNX_Importer_Tests, ImportModelWithNotSupportedOp) {
|
TEST(ONNX_Importer_Tests, ImportModelWithNotSupportedOp) {
|
||||||
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
||||||
ngraph::file_util::path_join(ONNX_MODELS_DIR, "not_supported.onnx"));
|
ov::util::path_join({ONNX_MODELS_DIR, "not_supported.onnx"}));
|
||||||
try {
|
try {
|
||||||
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
||||||
FAIL() << "Any expection was thrown despite the ONNX model is not supported";
|
FAIL() << "Any expection was thrown despite the ONNX model is not supported";
|
||||||
@ -108,7 +106,7 @@ TEST(ONNX_Importer_Tests, ImportModelWithNotSupportedOp) {
|
|||||||
|
|
||||||
TEST(ONNX_Importer_Tests, ImportModelWhenFileDoesNotExist) {
|
TEST(ONNX_Importer_Tests, ImportModelWhenFileDoesNotExist) {
|
||||||
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
||||||
ngraph::file_util::path_join(ONNX_MODELS_DIR, "not_exist_file.onnx"));
|
ov::util::path_join({ONNX_MODELS_DIR, "not_exist_file.onnx"}));
|
||||||
try {
|
try {
|
||||||
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
auto function = ngraph::onnx_import::import_onnx_model(model_file_path);
|
||||||
FAIL() << "Any expection was thrown despite the ONNX model file does not exist";
|
FAIL() << "Any expection was thrown despite the ONNX model file does not exist";
|
||||||
@ -124,7 +122,7 @@ TEST(ONNX_Importer_Tests, ImportModelWhenFileDoesNotExist) {
|
|||||||
// TODO: CVS-61224
|
// TODO: CVS-61224
|
||||||
TEST(ONNX_Importer_Tests, DISABLED_ImportModelFromStream) {
|
TEST(ONNX_Importer_Tests, DISABLED_ImportModelFromStream) {
|
||||||
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
auto model_file_path = CommonTestUtils::getModelFromTestModelZoo(
|
||||||
ngraph::file_util::path_join(ONNX_MODELS_DIR, "addmul_abc.onnx"));
|
ov::util::path_join({ONNX_MODELS_DIR, "addmul_abc.onnx"}));
|
||||||
std::ifstream model_file_stream(model_file_path);
|
std::ifstream model_file_stream(model_file_path);
|
||||||
ASSERT_TRUE(model_file_stream.is_open());
|
ASSERT_TRUE(model_file_stream.is_open());
|
||||||
int count_adds = 0;
|
int count_adds = 0;
|
||||||
|
@ -23,7 +23,7 @@ target_include_directories(${TARGET} PRIVATE
|
|||||||
$<TARGET_PROPERTY:inference_engine_plugin_api,INTERFACE_INCLUDE_DIRECTORIES>
|
$<TARGET_PROPERTY:inference_engine_plugin_api,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
$<TARGET_PROPERTY:inference_engine_preproc,INTERFACE_INCLUDE_DIRECTORIES>)
|
$<TARGET_PROPERTY:inference_engine_preproc,INTERFACE_INCLUDE_DIRECTORIES>)
|
||||||
|
|
||||||
target_link_libraries(${TARGET} PRIVATE opencv_core opencv_imgproc
|
target_link_libraries(${TARGET} PRIVATE opencv_core opencv_imgproc openvino::util
|
||||||
inference_engine fluid_test_computations gtest gtest_main)
|
inference_engine fluid_test_computations gtest gtest_main)
|
||||||
|
|
||||||
if(GAPI_TEST_PERF)
|
if(GAPI_TEST_PERF)
|
||||||
|
@ -39,7 +39,7 @@ if(COMMAND ie_add_vs_version_file)
|
|||||||
FILEDESCRIPTION "nGraph library")
|
FILEDESCRIPTION "nGraph library")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(ngraph PRIVATE ngraph::builder ngraph::reference)
|
target_link_libraries(ngraph PRIVATE ngraph::builder ngraph::reference openvino::util)
|
||||||
|
|
||||||
ie_mark_target_as_cc(ngraph)
|
ie_mark_target_as_cc(ngraph)
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ void default_logger_handler_func(const std::string& s);
|
|||||||
ngraph::default_logger_handler_func) \
|
ngraph::default_logger_handler_func) \
|
||||||
.stream()
|
.stream()
|
||||||
|
|
||||||
#ifdef NGRAPH_DEBUG_ENABLE
|
#ifdef OPENVINO_DEBUG_ENABLE
|
||||||
# define NGRAPH_DEBUG \
|
# define NGRAPH_DEBUG \
|
||||||
ngraph::LogHelper(ngraph::LOG_TYPE::_LOG_TYPE_DEBUG, \
|
ngraph::LogHelper(ngraph::LOG_TYPE::_LOG_TYPE_DEBUG, \
|
||||||
ngraph::trim_file_name(PROJECT_ROOT_DIR, __FILE__), \
|
ngraph::trim_file_name(PROJECT_ROOT_DIR, __FILE__), \
|
||||||
|
@ -190,6 +190,7 @@ NGRAPH_DEPRECATED("This method is deprecated and will be removed soon")
|
|||||||
void ngraph_free(void*);
|
void ngraph_free(void*);
|
||||||
|
|
||||||
NGRAPH_API
|
NGRAPH_API
|
||||||
|
NGRAPH_DEPRECATED("This method is deprecated and will be removed soon")
|
||||||
size_t round_up(size_t size, size_t alignment);
|
size_t round_up(size_t size, size_t alignment);
|
||||||
|
|
||||||
NGRAPH_DEPRECATED("This method is deprecated and will be removed soon")
|
NGRAPH_DEPRECATED("This method is deprecated and will be removed soon")
|
||||||
|
@ -8,59 +8,18 @@
|
|||||||
|
|
||||||
#include "ngraph/log.hpp"
|
#include "ngraph/log.hpp"
|
||||||
#include "ngraph/util.hpp"
|
#include "ngraph/util.hpp"
|
||||||
|
#include "openvino/util/env_util.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
std::string ngraph::getenv_string(const char* env_var) {
|
std::string ngraph::getenv_string(const char* env_var) {
|
||||||
const char* env_p = ::getenv(env_var);
|
return ov::util::getenv_string(env_var);
|
||||||
return env_p != nullptr ? string(env_p) : "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ngraph::getenv_int(const char* env_var, int32_t default_value) {
|
int32_t ngraph::getenv_int(const char* env_var, int32_t default_value) {
|
||||||
const char* env_p = ::getenv(env_var);
|
return ov::util::getenv_int(env_var, default_value);
|
||||||
int32_t env = default_value;
|
|
||||||
// If env_var is not "" or undefined
|
|
||||||
if (env_p && *env_p) {
|
|
||||||
errno = 0;
|
|
||||||
char* err;
|
|
||||||
env = strtol(env_p, &err, 0);
|
|
||||||
// if conversion leads to an overflow
|
|
||||||
if (errno) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "Environment variable \"" << env_var << "\"=\"" << env_p << "\" converted to different value \""
|
|
||||||
<< env << "\" due to overflow." << std::endl;
|
|
||||||
throw runtime_error(ss.str());
|
|
||||||
}
|
|
||||||
// if syntax error is there - conversion will still happen
|
|
||||||
// but warn user of syntax error
|
|
||||||
if (*err) {
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "Environment variable \"" << env_var << "\"=\"" << env_p << "\" converted to different value \""
|
|
||||||
<< env << "\" due to syntax error \"" << err << '\"' << std::endl;
|
|
||||||
throw runtime_error(ss.str());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
NGRAPH_DEBUG << "Environment variable (" << env_var << ") empty or undefined, "
|
|
||||||
<< " defaulted to " << default_value << " here.";
|
|
||||||
}
|
|
||||||
return env;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ngraph::getenv_bool(const char* env_var, bool default_value) {
|
bool ngraph::getenv_bool(const char* env_var, bool default_value) {
|
||||||
string value = to_lower(getenv_string(env_var));
|
return ov::util::getenv_bool(env_var, default_value);
|
||||||
set<string> off = {"0", "false", "off"};
|
|
||||||
set<string> on = {"1", "true", "on"};
|
|
||||||
bool rc;
|
|
||||||
if (value == "") {
|
|
||||||
rc = default_value;
|
|
||||||
} else if (off.find(value) != off.end()) {
|
|
||||||
rc = false;
|
|
||||||
} else if (on.find(value) != on.end()) {
|
|
||||||
rc = true;
|
|
||||||
} else {
|
|
||||||
stringstream ss;
|
|
||||||
ss << "environment variable '" << env_var << "' value '" << value << "' invalid. Must be boolean.";
|
|
||||||
throw runtime_error(ss.str());
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
@ -2,45 +2,9 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
# ifndef NOMINMAX
|
|
||||||
# define NOMINMAX
|
|
||||||
# endif
|
|
||||||
# include <windows.h>
|
|
||||||
#else
|
|
||||||
# include <dirent.h>
|
|
||||||
# include <ftw.h>
|
|
||||||
# include <sys/file.h>
|
|
||||||
# include <sys/time.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "ngraph/env_util.hpp"
|
|
||||||
#include "ngraph/file_util.hpp"
|
#include "ngraph/file_util.hpp"
|
||||||
#include "ngraph/log.hpp"
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#include "openvino/util/file_util.hpp"
|
||||||
# define RMDIR(a) RemoveDirectoryA(a)
|
|
||||||
# define RMFILE(a) DeleteFileA(a)
|
|
||||||
#else
|
|
||||||
# define RMDIR(a) rmdir(a)
|
|
||||||
# define RMFILE(a) remove(a)
|
|
||||||
# ifdef ENABLE_UNICODE_PATH_SUPPORT
|
|
||||||
# include <codecvt>
|
|
||||||
# include <locale>
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||||
|
|
||||||
@ -48,202 +12,51 @@ using namespace std;
|
|||||||
using namespace ngraph;
|
using namespace ngraph;
|
||||||
|
|
||||||
string file_util::get_file_name(const string& s) {
|
string file_util::get_file_name(const string& s) {
|
||||||
string rc = s;
|
return ov::util::get_file_name(s);
|
||||||
auto pos = s.find_last_of('/');
|
|
||||||
if (pos != string::npos) {
|
|
||||||
rc = s.substr(pos + 1);
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string file_util::get_file_ext(const string& s) {
|
string file_util::get_file_ext(const string& s) {
|
||||||
string rc = get_file_name(s);
|
return ov::util::get_file_ext(s);
|
||||||
auto pos = rc.find_last_of('.');
|
|
||||||
if (pos != string::npos) {
|
|
||||||
rc = rc.substr(pos);
|
|
||||||
} else {
|
|
||||||
rc = "";
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string file_util::get_directory(const string& s) {
|
string file_util::get_directory(const string& s) {
|
||||||
string rc = s;
|
return ov::util::get_directory(s);
|
||||||
// Linux-style separator
|
|
||||||
auto pos = s.find_last_of('/');
|
|
||||||
if (pos != string::npos) {
|
|
||||||
rc = s.substr(0, pos);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
// Windows-style separator
|
|
||||||
pos = s.find_last_of('\\');
|
|
||||||
if (pos != string::npos) {
|
|
||||||
rc = s.substr(0, pos);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string file_util::path_join(const string& s1, const string& s2, const string& s3) {
|
string file_util::path_join(const string& s1, const string& s2, const string& s3) {
|
||||||
return path_join(path_join(s1, s2), s3);
|
return ov::util::path_join({s1, s2, s3});
|
||||||
}
|
}
|
||||||
|
|
||||||
string file_util::path_join(const string& s1, const string& s2, const string& s3, const string& s4) {
|
string file_util::path_join(const string& s1, const string& s2, const string& s3, const string& s4) {
|
||||||
return path_join(path_join(path_join(s1, s2), s3), s4);
|
return ov::util::path_join({s1, s2, s3, s4});
|
||||||
}
|
}
|
||||||
|
|
||||||
string file_util::path_join(const string& s1, const string& s2) {
|
string file_util::path_join(const string& s1, const string& s2) {
|
||||||
string rc;
|
return ov::util::path_join({s1, s2});
|
||||||
if (s2.size() > 0) {
|
|
||||||
if (s2[0] == '/') {
|
|
||||||
rc = s2;
|
|
||||||
} else if (s1.size() > 0) {
|
|
||||||
rc = s1;
|
|
||||||
if (rc[rc.size() - 1] != '/') {
|
|
||||||
rc += "/";
|
|
||||||
}
|
|
||||||
rc += s2;
|
|
||||||
} else {
|
|
||||||
rc = s2;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rc = s1;
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
static void iterate_files_worker(const string& path,
|
|
||||||
function<void(const string& file, bool is_dir)> func,
|
|
||||||
bool recurse,
|
|
||||||
bool include_links) {
|
|
||||||
DIR* dir;
|
|
||||||
struct dirent* ent;
|
|
||||||
if ((dir = opendir(path.c_str())) != nullptr) {
|
|
||||||
try {
|
|
||||||
while ((ent = readdir(dir)) != nullptr) {
|
|
||||||
string name = ent->d_name;
|
|
||||||
string path_name = file_util::path_join(path, name);
|
|
||||||
switch (ent->d_type) {
|
|
||||||
case DT_DIR:
|
|
||||||
if (name != "." && name != "..") {
|
|
||||||
if (recurse) {
|
|
||||||
file_util::iterate_files(path_name, func, recurse);
|
|
||||||
}
|
|
||||||
func(path_name, true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DT_LNK:
|
|
||||||
if (include_links) {
|
|
||||||
func(path_name, false);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DT_REG:
|
|
||||||
func(path_name, false);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
exception_ptr p = current_exception();
|
|
||||||
closedir(dir);
|
|
||||||
rethrow_exception(p);
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
} else {
|
|
||||||
throw runtime_error("error enumerating file " + path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void file_util::iterate_files(const string& path,
|
void file_util::iterate_files(const string& path,
|
||||||
function<void(const string& file, bool is_dir)> func,
|
function<void(const string& file, bool is_dir)> func,
|
||||||
bool recurse,
|
bool recurse,
|
||||||
bool include_links) {
|
bool include_links) {
|
||||||
vector<string> files;
|
return ov::util::iterate_files(path, func, recurse, include_links);
|
||||||
vector<string> dirs;
|
|
||||||
#ifdef _WIN32
|
|
||||||
std::string file_match = path_join(path, "*");
|
|
||||||
WIN32_FIND_DATAA data;
|
|
||||||
HANDLE hFind = FindFirstFileA(file_match.c_str(), &data);
|
|
||||||
if (hFind != INVALID_HANDLE_VALUE) {
|
|
||||||
do {
|
|
||||||
bool is_dir = data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
|
||||||
if (is_dir) {
|
|
||||||
if (string(data.cFileName) != "." && string(data.cFileName) != "..") {
|
|
||||||
string dir_path = path_join(path, data.cFileName);
|
|
||||||
if (recurse) {
|
|
||||||
iterate_files(dir_path, func, recurse);
|
|
||||||
}
|
|
||||||
func(dir_path, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
string file_name = path_join(path, data.cFileName);
|
|
||||||
func(file_name, false);
|
|
||||||
}
|
|
||||||
} while (FindNextFileA(hFind, &data));
|
|
||||||
FindClose(hFind);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
iterate_files_worker(
|
|
||||||
path,
|
|
||||||
[&files, &dirs](const string& file, bool is_dir) {
|
|
||||||
if (is_dir) {
|
|
||||||
dirs.push_back(file);
|
|
||||||
} else {
|
|
||||||
files.push_back(file);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
recurse,
|
|
||||||
include_links);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (auto f : files) {
|
|
||||||
func(f, false);
|
|
||||||
}
|
|
||||||
for (auto f : dirs) {
|
|
||||||
func(f, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string file_util::sanitize_path(const std::string& path) {
|
std::string file_util::sanitize_path(const std::string& path) {
|
||||||
const auto colon_pos = path.find(":");
|
return ov::util::sanitize_path(path);
|
||||||
const auto sanitized_path = path.substr(colon_pos == std::string::npos ? 0 : colon_pos + 1);
|
|
||||||
const std::string to_erase = "/.\\";
|
|
||||||
const auto start = sanitized_path.find_first_not_of(to_erase);
|
|
||||||
return (start == std::string::npos) ? "" : sanitized_path.substr(start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NGRAPH_API void file_util::convert_path_win_style(std::string& path) {
|
void file_util::convert_path_win_style(std::string& path) {
|
||||||
std::replace(path.begin(), path.end(), '/', '\\');
|
ov::util::convert_path_win_style(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
std::string file_util::wstring_to_string(const std::wstring& wstr) {
|
std::string file_util::wstring_to_string(const std::wstring& wstr) {
|
||||||
# ifdef _WIN32
|
return ov::util::wstring_to_string(wstr);
|
||||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); // NOLINT
|
|
||||||
std::string strTo(size_needed, 0);
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); // NOLINT
|
|
||||||
return strTo;
|
|
||||||
# else
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_decoder;
|
|
||||||
return wstring_decoder.to_bytes(wstr);
|
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring file_util::multi_byte_char_to_wstring(const char* str) {
|
std::wstring file_util::multi_byte_char_to_wstring(const char* str) {
|
||||||
# ifdef _WIN32
|
return ov::util::string_to_wstring(str);
|
||||||
int strSize = static_cast<int>(std::strlen(str));
|
|
||||||
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, strSize, NULL, 0);
|
|
||||||
std::wstring wstrTo(size_needed, 0);
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, str, strSize, &wstrTo[0], size_needed);
|
|
||||||
return wstrTo;
|
|
||||||
# else
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_encoder;
|
|
||||||
std::wstring result = wstring_encoder.from_bytes(str);
|
|
||||||
return result;
|
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "itt.hpp"
|
#include "itt.hpp"
|
||||||
#include "ngraph/env_util.hpp"
|
|
||||||
#include "ngraph/function.hpp"
|
#include "ngraph/function.hpp"
|
||||||
#include "ngraph/graph_util.hpp"
|
#include "ngraph/graph_util.hpp"
|
||||||
#include "ngraph/log.hpp"
|
#include "ngraph/log.hpp"
|
||||||
@ -21,6 +20,7 @@
|
|||||||
#include "ngraph/pass/pass.hpp"
|
#include "ngraph/pass/pass.hpp"
|
||||||
#include "ngraph/pass/visualize_tree.hpp"
|
#include "ngraph/pass/visualize_tree.hpp"
|
||||||
#include "ngraph/util.hpp"
|
#include "ngraph/util.hpp"
|
||||||
|
#include "openvino/util/env_util.hpp"
|
||||||
#include "perf_counters.hpp"
|
#include "perf_counters.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -38,7 +38,7 @@ PerfCounters& perf_counters() {
|
|||||||
|
|
||||||
ov::pass::Manager::Manager()
|
ov::pass::Manager::Manager()
|
||||||
: m_pass_config(std::make_shared<PassConfig>()),
|
: m_pass_config(std::make_shared<PassConfig>()),
|
||||||
m_visualize(ngraph::getenv_bool("NGRAPH_ENABLE_VISUALIZE_TRACING")) {}
|
m_visualize(ov::util::getenv_bool("NGRAPH_ENABLE_VISUALIZE_TRACING")) {}
|
||||||
|
|
||||||
ov::pass::Manager::~Manager() = default;
|
ov::pass::Manager::~Manager() = default;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ void ov::pass::Manager::run_passes(shared_ptr<ov::Function> func) {
|
|||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||||
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "pass::Manager::run_passes");
|
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "pass::Manager::run_passes");
|
||||||
|
|
||||||
static bool profile_enabled = ngraph::getenv_bool("NGRAPH_PROFILE_PASS_ENABLE");
|
static bool profile_enabled = ov::util::getenv_bool("NGRAPH_PROFILE_PASS_ENABLE");
|
||||||
|
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
ngraph::stopwatch pass_timer;
|
ngraph::stopwatch pass_timer;
|
||||||
@ -114,7 +114,7 @@ void ov::pass::Manager::run_passes(shared_ptr<ov::Function> func) {
|
|||||||
auto base_filename = func->get_name() + std::string("_") + index_str + std::string("_") + pass->get_name();
|
auto base_filename = func->get_name() + std::string("_") + index_str + std::string("_") + pass->get_name();
|
||||||
|
|
||||||
if (m_visualize) {
|
if (m_visualize) {
|
||||||
static const string format = ngraph::getenv_string("NGRAPH_VISUALIZE_TRACING_FORMAT");
|
static const string format = ov::util::getenv_string("NGRAPH_VISUALIZE_TRACING_FORMAT");
|
||||||
auto file_ext = format.empty() ? "svg" : format;
|
auto file_ext = format.empty() ? "svg" : format;
|
||||||
pass::VisualizeTree vt(base_filename + std::string(".") + file_ext);
|
pass::VisualizeTree vt(base_filename + std::string(".") + file_ext);
|
||||||
vt.run_on_function(func);
|
vt.run_on_function(func);
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include "ngraph/env_util.hpp"
|
|
||||||
#include "ngraph/graph_util.hpp"
|
#include "ngraph/graph_util.hpp"
|
||||||
#include "ngraph/log.hpp"
|
#include "ngraph/log.hpp"
|
||||||
#include "ngraph/op/parameter.hpp"
|
#include "ngraph/op/parameter.hpp"
|
||||||
#include "ngraph/op/util/op_types.hpp"
|
#include "ngraph/op/util/op_types.hpp"
|
||||||
|
#include "openvino/util/env_util.hpp"
|
||||||
|
|
||||||
namespace ov {
|
namespace ov {
|
||||||
namespace pass {
|
namespace pass {
|
||||||
@ -109,7 +109,7 @@ bool Matcher::match_value(const ngraph::Output<Node>& pattern_value, const ngrap
|
|||||||
// This env var allows one to specify node name patterns to abort pattern matching
|
// This env var allows one to specify node name patterns to abort pattern matching
|
||||||
// at particular nodes. The upshot is that one can quickly zero in on an offending
|
// at particular nodes. The upshot is that one can quickly zero in on an offending
|
||||||
// fusion by disabling individual fusions or optimizations that use Matcher.
|
// fusion by disabling individual fusions or optimizations that use Matcher.
|
||||||
static const std::string node_skip_cregex = ngraph::getenv_string("NGRAPH_FAIL_MATCH_AT");
|
static const std::string node_skip_cregex = ov::util::getenv_string("NGRAPH_FAIL_MATCH_AT");
|
||||||
if (!node_skip_cregex.empty()) {
|
if (!node_skip_cregex.empty()) {
|
||||||
static const std::regex node_skip_regex(node_skip_cregex);
|
static const std::regex node_skip_regex(node_skip_cregex);
|
||||||
if (std::regex_match(graph_node->get_name(), node_skip_regex)) {
|
if (std::regex_match(graph_node->get_name(), node_skip_regex)) {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "ngraph/op/result.hpp"
|
#include "ngraph/op/result.hpp"
|
||||||
#include "ngraph/partial_shape.hpp"
|
#include "ngraph/partial_shape.hpp"
|
||||||
#include "ngraph/shape.hpp"
|
#include "ngraph/shape.hpp"
|
||||||
|
#include "openvino/util/common_util.hpp"
|
||||||
|
|
||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -61,54 +62,19 @@ void ngraph::dump(ostream& out, const void* _data, size_t _size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string ngraph::to_lower(const std::string& s) {
|
std::string ngraph::to_lower(const std::string& s) {
|
||||||
std::string rc = s;
|
return ov::util::to_lower(s);
|
||||||
std::transform(rc.begin(), rc.end(), rc.begin(), ::tolower);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ngraph::to_upper(const std::string& s) {
|
std::string ngraph::to_upper(const std::string& s) {
|
||||||
std::string rc = s;
|
return ov::util::to_upper(s);
|
||||||
std::transform(rc.begin(), rc.end(), rc.begin(), ::toupper);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string ngraph::trim(const string& s) {
|
string ngraph::trim(const string& s) {
|
||||||
string rc = s;
|
return ov::util::trim(s);
|
||||||
// trim trailing spaces
|
|
||||||
size_t pos = rc.find_last_not_of(" \t");
|
|
||||||
if (string::npos != pos) {
|
|
||||||
rc = rc.substr(0, pos + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// trim leading spaces
|
|
||||||
pos = rc.find_first_not_of(" \t");
|
|
||||||
if (string::npos != pos) {
|
|
||||||
rc = rc.substr(pos);
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> ngraph::split(const string& src, char delimiter, bool do_trim) {
|
vector<string> ngraph::split(const string& src, char delimiter, bool do_trim) {
|
||||||
size_t pos;
|
return ov::util::split(src, delimiter, do_trim);
|
||||||
string token;
|
|
||||||
size_t start = 0;
|
|
||||||
vector<string> rc;
|
|
||||||
while ((pos = src.find(delimiter, start)) != std::string::npos) {
|
|
||||||
token = src.substr(start, pos - start);
|
|
||||||
start = pos + 1;
|
|
||||||
if (do_trim) {
|
|
||||||
token = trim(token);
|
|
||||||
}
|
|
||||||
rc.push_back(token);
|
|
||||||
}
|
|
||||||
if (start <= src.size()) {
|
|
||||||
token = src.substr(start);
|
|
||||||
if (do_trim) {
|
|
||||||
token = trim(token);
|
|
||||||
}
|
|
||||||
rc.push_back(token);
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ngraph::hash_combine(const std::vector<size_t>& list) {
|
size_t ngraph::hash_combine(const std::vector<size_t>& list) {
|
||||||
|
@ -18,7 +18,7 @@ source_group("public include" FILES ${LIBRARY_PUBLIC_HEADERS})
|
|||||||
|
|
||||||
add_library(${TARGET_NAME}_static STATIC ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${LIBRARY_PUBLIC_HEADERS})
|
add_library(${TARGET_NAME}_static STATIC ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${LIBRARY_PUBLIC_HEADERS})
|
||||||
add_library(${TARGET_NAME}::static ALIAS ${TARGET_NAME}_static)
|
add_library(${TARGET_NAME}::static ALIAS ${TARGET_NAME}_static)
|
||||||
target_link_libraries(${TARGET_NAME}_static PRIVATE ${CMAKE_DL_LIBS} PUBLIC ngraph)
|
target_link_libraries(${TARGET_NAME}_static PRIVATE ${CMAKE_DL_LIBS} openvino::util PUBLIC ngraph)
|
||||||
target_include_directories(${TARGET_NAME}_static PUBLIC ${FRONTEND_INCLUDE_DIR})
|
target_include_directories(${TARGET_NAME}_static PUBLIC ${FRONTEND_INCLUDE_DIR})
|
||||||
target_include_directories(${TARGET_NAME}_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
target_include_directories(${TARGET_NAME}_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
target_compile_definitions(${TARGET_NAME}_static PUBLIC USE_STATIC_FRONTEND_MANAGER)
|
target_compile_definitions(${TARGET_NAME}_static PUBLIC USE_STATIC_FRONTEND_MANAGER)
|
||||||
@ -34,7 +34,7 @@ target_include_directories(${TARGET_NAME} PUBLIC
|
|||||||
$<BUILD_INTERFACE:${FRONTEND_INCLUDE_DIR}>
|
$<BUILD_INTERFACE:${FRONTEND_INCLUDE_DIR}>
|
||||||
$<INSTALL_INTERFACE:${FRONTEND_INSTALL_INCLUDE}>)
|
$<INSTALL_INTERFACE:${FRONTEND_INSTALL_INCLUDE}>)
|
||||||
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS} PUBLIC ngraph)
|
target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS} openvino::util PUBLIC ngraph)
|
||||||
|
|
||||||
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
|
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#include "frontend_manager/frontend_manager.hpp"
|
#include "frontend_manager/frontend_manager.hpp"
|
||||||
|
|
||||||
#include <frontend_manager/place.hpp>
|
#include <frontend_manager/place.hpp>
|
||||||
#include <ngraph/env_util.hpp>
|
|
||||||
#include <ngraph/except.hpp>
|
#include <ngraph/except.hpp>
|
||||||
|
#include <openvino/util/env_util.hpp>
|
||||||
|
|
||||||
#include "frontend_manager/frontend_exceptions.hpp"
|
#include "frontend_manager/frontend_exceptions.hpp"
|
||||||
#include "plugin_loader.hpp"
|
#include "plugin_loader.hpp"
|
||||||
@ -72,7 +72,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::string env_path = ngraph::getenv_string("OV_FRONTEND_PATH");
|
std::string env_path = ov::util::getenv_string("OV_FRONTEND_PATH");
|
||||||
if (!env_path.empty()) {
|
if (!env_path.empty()) {
|
||||||
auto start = 0u;
|
auto start = 0u;
|
||||||
auto sep_pos = env_path.find(PathSeparator, start);
|
auto sep_pos = env_path.find(PathSeparator, start);
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "ngraph/file_util.hpp"
|
#include "openvino/util/file_util.hpp"
|
||||||
#include "plugin_loader.hpp"
|
#include "plugin_loader.hpp"
|
||||||
|
|
||||||
using namespace ngraph;
|
using namespace ngraph;
|
||||||
@ -40,7 +40,7 @@ static std::vector<std::string> list_files(const std::string& path) {
|
|||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||||
std::vector<std::string> res;
|
std::vector<std::string> res;
|
||||||
try {
|
try {
|
||||||
ngraph::file_util::iterate_files(
|
ov::util::iterate_files(
|
||||||
path,
|
path,
|
||||||
[&res](const std::string& file, bool is_dir) {
|
[&res](const std::string& file, bool is_dir) {
|
||||||
if (!is_dir && file.find("_ngraph_frontend") != std::string::npos) {
|
if (!is_dir && file.find("_ngraph_frontend") != std::string::npos) {
|
||||||
|
@ -46,7 +46,7 @@ if(COMMAND ie_add_vs_version_file)
|
|||||||
FILEDESCRIPTION "nGraph ONNX frontend library")
|
FILEDESCRIPTION "nGraph ONNX frontend library")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${TARGET_NAME} PUBLIC ngraph PRIVATE frontend_manager ngraph::builder onnx_common inference_engine_transformations)
|
target_link_libraries(${TARGET_NAME} PUBLIC ngraph PRIVATE frontend_manager ngraph::builder openvino::util onnx_common inference_engine_transformations)
|
||||||
|
|
||||||
target_include_directories(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${ONNX_FRONTEND_INCLUDE_DIR}>
|
target_include_directories(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${ONNX_FRONTEND_INCLUDE_DIR}>
|
||||||
$<INSTALL_INTERFACE:${FRONTEND_INSTALL_INCLUDE}>)
|
$<INSTALL_INTERFACE:${FRONTEND_INSTALL_INCLUDE}>)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "exceptions.hpp"
|
#include "exceptions.hpp"
|
||||||
#include "ngraph/file_util.hpp"
|
#include "ngraph/file_util.hpp"
|
||||||
#include "ngraph/log.hpp"
|
#include "ngraph/log.hpp"
|
||||||
|
#include "openvino/util/file_util.hpp"
|
||||||
|
|
||||||
namespace ngraph {
|
namespace ngraph {
|
||||||
namespace onnx_import {
|
namespace onnx_import {
|
||||||
@ -30,7 +31,7 @@ TensorExternalData::TensorExternalData(const ONNX_NAMESPACE::TensorProto& tensor
|
|||||||
std::string TensorExternalData::load_external_data() const {
|
std::string TensorExternalData::load_external_data() const {
|
||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||||
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||||
std::wstring path = file_util::multi_byte_char_to_wstring(m_data_location.c_str());
|
std::wstring path = ov::util::string_to_wstring(m_data_location);
|
||||||
#else
|
#else
|
||||||
std::string path = m_data_location;
|
std::string path = m_data_location;
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,6 +12,6 @@ add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${LIBRARY_HEADERS})
|
|||||||
target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../..)
|
target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../..)
|
||||||
target_link_libraries(${TARGET_NAME} PUBLIC frontend_manager
|
target_link_libraries(${TARGET_NAME} PUBLIC frontend_manager
|
||||||
ngraph::ngraph cnpy ie_backend ngraph_test_util commonTestUtils)
|
ngraph::ngraph cnpy ie_backend ngraph_test_util commonTestUtils openvino::util)
|
||||||
|
|
||||||
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
|
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
#include "backend.hpp"
|
#include "backend.hpp"
|
||||||
#include "common_test_utils/file_utils.hpp"
|
#include "common_test_utils/file_utils.hpp"
|
||||||
#include "ngraph/env_util.hpp"
|
#include "openvino/util/env_util.hpp"
|
||||||
#include "ngraph/file_util.hpp"
|
#include "openvino/util/file_util.hpp"
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
namespace FrontEndTestUtils {
|
namespace FrontEndTestUtils {
|
||||||
@ -54,7 +54,7 @@ inline int set_test_env(const char* name, const char* value) {
|
|||||||
inline void setupTestEnv() {
|
inline void setupTestEnv() {
|
||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||||
std::string fePath =
|
std::string fePath =
|
||||||
ngraph::file_util::get_directory(ngraph::runtime::Backend::get_backend_shared_library_search_directory());
|
ov::util::get_directory(ngraph::runtime::Backend::get_backend_shared_library_search_directory());
|
||||||
set_test_env("OV_FRONTEND_PATH", fePath.c_str());
|
set_test_env("OV_FRONTEND_PATH", fePath.c_str());
|
||||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "ie_executable.hpp"
|
#include "ie_executable.hpp"
|
||||||
|
|
||||||
#include "ie_tensor.hpp"
|
#include "ie_tensor.hpp"
|
||||||
#include "ngraph/opsets/opset.hpp"
|
#include "ngraph/opsets/opset.hpp"
|
||||||
#include "ngraph/pass/manager.hpp"
|
#include "ngraph/pass/manager.hpp"
|
||||||
@ -14,95 +15,122 @@ using namespace ngraph;
|
|||||||
|
|
||||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
InferenceEngine::Blob::Ptr fill_blob(InferenceEngine::SizeVector shape,
|
||||||
InferenceEngine::Blob::Ptr fill_blob(InferenceEngine::SizeVector shape,
|
const void* data,
|
||||||
const void* data,
|
size_t data_size,
|
||||||
size_t data_size,
|
const element::Type& elem_type) {
|
||||||
const element::Type& elem_type)
|
InferenceEngine::Layout layout;
|
||||||
{
|
switch (shape.size()) {
|
||||||
InferenceEngine::Layout layout;
|
case 0:
|
||||||
switch (shape.size())
|
layout = InferenceEngine::Layout::SCALAR;
|
||||||
{
|
break;
|
||||||
case 0: layout = InferenceEngine::Layout::SCALAR; break;
|
case 1:
|
||||||
case 1: layout = InferenceEngine::Layout::C; break;
|
layout = InferenceEngine::Layout::C;
|
||||||
case 2: layout = InferenceEngine::Layout::NC; break;
|
break;
|
||||||
case 3: layout = InferenceEngine::Layout::CHW; break;
|
case 2:
|
||||||
case 4: layout = InferenceEngine::Layout::NCHW; break;
|
layout = InferenceEngine::Layout::NC;
|
||||||
case 5: layout = InferenceEngine::Layout::NCDHW; break;
|
break;
|
||||||
case 6: layout = InferenceEngine::Layout::GOIDHW; break;
|
case 3:
|
||||||
default: IE_THROW() << "Can't convert dims " << shape.size() << " to Layout!";
|
layout = InferenceEngine::Layout::CHW;
|
||||||
}
|
break;
|
||||||
|
case 4:
|
||||||
|
layout = InferenceEngine::Layout::NCHW;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
layout = InferenceEngine::Layout::NCDHW;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
layout = InferenceEngine::Layout::GOIDHW;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
IE_THROW() << "Can't convert dims " << shape.size() << " to Layout!";
|
||||||
|
}
|
||||||
|
|
||||||
InferenceEngine::MemoryBlob::Ptr blob;
|
InferenceEngine::MemoryBlob::Ptr blob;
|
||||||
|
|
||||||
#define MAKE_IE_TBLOB(type_, precision_, shape_, layout_) \
|
#define MAKE_IE_TBLOB(type_, precision_, shape_, layout_) \
|
||||||
make_shared<InferenceEngine::TBlob<type_>>( \
|
make_shared<InferenceEngine::TBlob<type_>>( \
|
||||||
InferenceEngine::TensorDesc{InferenceEngine::Precision::precision_, shape_, layout_})
|
InferenceEngine::TensorDesc{InferenceEngine::Precision::precision_, shape_, layout_})
|
||||||
|
|
||||||
switch (elem_type)
|
switch (elem_type) {
|
||||||
{
|
case element::Type_t::f32:
|
||||||
case element::Type_t::f32: blob = MAKE_IE_TBLOB(float, FP32, shape, layout); break;
|
blob = MAKE_IE_TBLOB(float, FP32, shape, layout);
|
||||||
case element::Type_t::f64: blob = MAKE_IE_TBLOB(double, FP64, shape, layout); break;
|
break;
|
||||||
case element::Type_t::i16: blob = MAKE_IE_TBLOB(int16_t, I16, shape, layout); break;
|
case element::Type_t::f64:
|
||||||
case element::Type_t::u8: blob = MAKE_IE_TBLOB(uint8_t, U8, shape, layout); break;
|
blob = MAKE_IE_TBLOB(double, FP64, shape, layout);
|
||||||
case element::Type_t::i8: blob = MAKE_IE_TBLOB(int8_t, I8, shape, layout); break;
|
break;
|
||||||
case element::Type_t::u16: blob = MAKE_IE_TBLOB(uint16_t, U16, shape, layout); break;
|
case element::Type_t::i16:
|
||||||
case element::Type_t::i32: blob = MAKE_IE_TBLOB(int32_t, I32, shape, layout); break;
|
blob = MAKE_IE_TBLOB(int16_t, I16, shape, layout);
|
||||||
case element::Type_t::u32: blob = MAKE_IE_TBLOB(uint32_t, U32, shape, layout); break;
|
break;
|
||||||
case element::Type_t::i64: blob = MAKE_IE_TBLOB(int64_t, I64, shape, layout); break;
|
case element::Type_t::u8:
|
||||||
case element::Type_t::u64: blob = MAKE_IE_TBLOB(uint64_t, U64, shape, layout); break;
|
blob = MAKE_IE_TBLOB(uint8_t, U8, shape, layout);
|
||||||
case element::Type_t::boolean: blob = MAKE_IE_TBLOB(uint8_t, BOOL, shape, layout); break;
|
break;
|
||||||
default: IE_THROW() << "Can't convert type " << elem_type << " to IE Precision!";
|
case element::Type_t::i8:
|
||||||
}
|
blob = MAKE_IE_TBLOB(int8_t, I8, shape, layout);
|
||||||
|
break;
|
||||||
|
case element::Type_t::u16:
|
||||||
|
blob = MAKE_IE_TBLOB(uint16_t, U16, shape, layout);
|
||||||
|
break;
|
||||||
|
case element::Type_t::i32:
|
||||||
|
blob = MAKE_IE_TBLOB(int32_t, I32, shape, layout);
|
||||||
|
break;
|
||||||
|
case element::Type_t::u32:
|
||||||
|
blob = MAKE_IE_TBLOB(uint32_t, U32, shape, layout);
|
||||||
|
break;
|
||||||
|
case element::Type_t::i64:
|
||||||
|
blob = MAKE_IE_TBLOB(int64_t, I64, shape, layout);
|
||||||
|
break;
|
||||||
|
case element::Type_t::u64:
|
||||||
|
blob = MAKE_IE_TBLOB(uint64_t, U64, shape, layout);
|
||||||
|
break;
|
||||||
|
case element::Type_t::boolean:
|
||||||
|
blob = MAKE_IE_TBLOB(uint8_t, BOOL, shape, layout);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
IE_THROW() << "Can't convert type " << elem_type << " to IE Precision!";
|
||||||
|
}
|
||||||
#undef MAKE_IE_TBLOB
|
#undef MAKE_IE_TBLOB
|
||||||
|
|
||||||
blob->allocate();
|
blob->allocate();
|
||||||
uint8_t* blob_ptr = blob->rwmap().as<uint8_t*>();
|
uint8_t* blob_ptr = blob->rwmap().as<uint8_t*>();
|
||||||
memcpy(blob_ptr, data, data_size * elem_type.size());
|
memcpy(blob_ptr, data, data_size * elem_type.size());
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
std::set<NodeTypeInfo> get_ie_ops() {
|
||||||
std::set<NodeTypeInfo> get_ie_ops()
|
std::set<NodeTypeInfo> ie_ops = get_opset1().get_type_info_set();
|
||||||
{
|
auto& opset2 = get_opset2().get_type_info_set();
|
||||||
std::set<NodeTypeInfo> ie_ops = get_opset1().get_type_info_set();
|
ie_ops.insert(opset2.begin(), opset2.end());
|
||||||
auto& opset2 = get_opset2().get_type_info_set();
|
auto& opset3 = get_opset3().get_type_info_set();
|
||||||
ie_ops.insert(opset2.begin(), opset2.end());
|
ie_ops.insert(opset3.begin(), opset3.end());
|
||||||
auto& opset3 = get_opset3().get_type_info_set();
|
auto& opset4 = get_opset4().get_type_info_set();
|
||||||
ie_ops.insert(opset3.begin(), opset3.end());
|
ie_ops.insert(opset4.begin(), opset4.end());
|
||||||
auto& opset4 = get_opset4().get_type_info_set();
|
auto& opset5 = get_opset5().get_type_info_set();
|
||||||
ie_ops.insert(opset4.begin(), opset4.end());
|
ie_ops.insert(opset5.begin(), opset5.end());
|
||||||
auto& opset5 = get_opset5().get_type_info_set();
|
auto& opset6 = get_opset6().get_type_info_set();
|
||||||
ie_ops.insert(opset5.begin(), opset5.end());
|
ie_ops.insert(opset6.begin(), opset6.end());
|
||||||
auto& opset6 = get_opset6().get_type_info_set();
|
auto& opset7 = get_opset7().get_type_info_set();
|
||||||
ie_ops.insert(opset6.begin(), opset6.end());
|
ie_ops.insert(opset7.begin(), opset7.end());
|
||||||
auto& opset7 = get_opset7().get_type_info_set();
|
return ie_ops;
|
||||||
ie_ops.insert(opset7.begin(), opset7.end());
|
}
|
||||||
return ie_ops;
|
} // namespace
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
runtime::ie::IE_Executable::IE_Executable(shared_ptr<Function> func, string device)
|
runtime::ie::IE_Executable::IE_Executable(shared_ptr<Function> func, string device) : m_device{device} {
|
||||||
: m_device{device}
|
|
||||||
{
|
|
||||||
static std::set<NodeTypeInfo> ie_ops = get_ie_ops();
|
static std::set<NodeTypeInfo> ie_ops = get_ie_ops();
|
||||||
|
|
||||||
for (const auto& node : func->get_ops())
|
for (const auto& node : func->get_ops()) {
|
||||||
{
|
if (ie_ops.find(node->get_type_info()) == ie_ops.end()) {
|
||||||
if (ie_ops.find(node->get_type_info()) == ie_ops.end())
|
|
||||||
{
|
|
||||||
cout << "UNSUPPORTED OP DETECTED: " << node->get_type_info().name << endl;
|
cout << "UNSUPPORTED OP DETECTED: " << node->get_type_info().name << endl;
|
||||||
IE_THROW() << "Detected op not belonging to opset1!";
|
IE_THROW() << "Detected op not belonging to opset1!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NGRAPH_DEBUG_ENABLE
|
#ifdef OPENVINO_DEBUG_ENABLE
|
||||||
cout << "Nodes in test: ";
|
cout << "Nodes in test: ";
|
||||||
for (const auto& node : func->get_ops())
|
for (const auto& node : func->get_ops()) {
|
||||||
{
|
|
||||||
cout << node << endl;
|
cout << node << endl;
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
@ -113,8 +141,7 @@ runtime::ie::IE_Executable::IE_Executable(shared_ptr<Function> func, string devi
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool runtime::ie::IE_Executable::call(const vector<shared_ptr<runtime::Tensor>>& outputs,
|
bool runtime::ie::IE_Executable::call(const vector<shared_ptr<runtime::Tensor>>& outputs,
|
||||||
const vector<shared_ptr<runtime::Tensor>>& inputs)
|
const vector<shared_ptr<runtime::Tensor>>& inputs) {
|
||||||
{
|
|
||||||
InferenceEngine::Core ie;
|
InferenceEngine::Core ie;
|
||||||
|
|
||||||
// Loading model to the plugin (BACKEND_NAME)
|
// Loading model to the plugin (BACKEND_NAME)
|
||||||
@ -124,16 +151,13 @@ bool runtime::ie::IE_Executable::call(const vector<shared_ptr<runtime::Tensor>>&
|
|||||||
// Prepare input and output blobs
|
// Prepare input and output blobs
|
||||||
InferenceEngine::InputsDataMap input_info = m_network.getInputsInfo();
|
InferenceEngine::InputsDataMap input_info = m_network.getInputsInfo();
|
||||||
|
|
||||||
if (input_info.size() != inputs.size())
|
if (input_info.size() != inputs.size()) {
|
||||||
{
|
|
||||||
IE_THROW() << "Function inputs number differ from number of given inputs";
|
IE_THROW() << "Function inputs number differ from number of given inputs";
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (const auto& it : input_info)
|
for (const auto& it : input_info) {
|
||||||
{
|
shared_ptr<runtime::ie::IETensor> tv = static_pointer_cast<runtime::ie::IETensor>(inputs[i]);
|
||||||
shared_ptr<runtime::ie::IETensor> tv =
|
|
||||||
static_pointer_cast<runtime::ie::IETensor>(inputs[i]);
|
|
||||||
infer_request.SetBlob(it.first,
|
infer_request.SetBlob(it.first,
|
||||||
fill_blob(it.second->getTensorDesc().getDims(),
|
fill_blob(it.second->getTensorDesc().getDims(),
|
||||||
tv->get_data_ptr(),
|
tv->get_data_ptr(),
|
||||||
@ -151,10 +175,8 @@ bool runtime::ie::IE_Executable::call(const vector<shared_ptr<runtime::Tensor>>&
|
|||||||
infer_request.Infer();
|
infer_request.Infer();
|
||||||
InferenceEngine::Blob::Ptr output = infer_request.GetBlob(output_name);
|
InferenceEngine::Blob::Ptr output = infer_request.GetBlob(output_name);
|
||||||
|
|
||||||
InferenceEngine::MemoryBlob::Ptr moutput =
|
InferenceEngine::MemoryBlob::Ptr moutput = InferenceEngine::as<InferenceEngine::MemoryBlob>(output);
|
||||||
InferenceEngine::as<InferenceEngine::MemoryBlob>(output);
|
if (!moutput) {
|
||||||
if (!moutput)
|
|
||||||
{
|
|
||||||
IE_THROW() << "Cannot get output MemoryBlob in call_with_validate()";
|
IE_THROW() << "Cannot get output MemoryBlob in call_with_validate()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
add_subdirectory(pp)
|
add_subdirectory(pp)
|
||||||
add_subdirectory(itt)
|
add_subdirectory(itt)
|
||||||
add_subdirectory(conditional_compilation)
|
add_subdirectory(conditional_compilation)
|
||||||
|
add_subdirectory(util)
|
||||||
|
|
||||||
openvino_developer_export_targets(COMPONENT openvino_common TARGETS openvino::pp openvino::itt openvino::conditional_compilation)
|
openvino_developer_export_targets(COMPONENT openvino_common TARGETS openvino::pp openvino::itt openvino::conditional_compilation)
|
||||||
|
28
openvino/util/.clang-format
Normal file
28
openvino/util/.clang-format
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
BasedOnStyle: Google
|
||||||
|
IndentWidth: 4
|
||||||
|
UseTab: Never
|
||||||
|
ColumnLimit: 120
|
||||||
|
|
||||||
|
Language: Cpp
|
||||||
|
Standard: Cpp11
|
||||||
|
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignConsecutiveMacros: true
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
AllowAllConstructorInitializersOnNextLine: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLambdasOnASingleLine: Empty
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
CommentPragmas: '^#'
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentPPDirectives: AfterHash
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- FOREACH_CHILD
|
30
openvino/util/CMakeLists.txt
Normal file
30
openvino/util/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
set(TARGET_NAME util)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
||||||
|
file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp)
|
||||||
|
|
||||||
|
set(UTIL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
||||||
|
|
||||||
|
# Create named folders for the sources within the .vcproj
|
||||||
|
# Empty name lists them directly under the .vcproj
|
||||||
|
|
||||||
|
source_group("src" FILES ${LIBRARY_SRC})
|
||||||
|
source_group("include" FILES ${PUBLIC_HEADERS})
|
||||||
|
|
||||||
|
# Create shared library
|
||||||
|
add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS})
|
||||||
|
|
||||||
|
add_library(openvino::util ALIAS ${TARGET_NAME})
|
||||||
|
|
||||||
|
target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS})
|
||||||
|
target_include_directories(${TARGET_NAME} PUBLIC ${UTIL_INCLUDE_DIR})
|
||||||
|
|
||||||
|
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
|
||||||
|
ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME}
|
||||||
|
INCLUDE_DIRECTORY ${UTIL_INCLUDE_DIR})
|
||||||
|
|
||||||
|
openvino_developer_export_targets(COMPONENT openvino_common TARGETS ${TARGET_NAME})
|
101
openvino/util/include/openvino/util/common_util.hpp
Normal file
101
openvino/util/include/openvino/util/common_util.hpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
// Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstring>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace ov {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::string join(const T& v, const std::string& sep = ", ") {
|
||||||
|
std::ostringstream ss;
|
||||||
|
size_t count = 0;
|
||||||
|
for (const auto& x : v) {
|
||||||
|
if (count++ > 0) {
|
||||||
|
ss << sep;
|
||||||
|
}
|
||||||
|
ss << x;
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::string vector_to_string(const T& v) {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "[ " << ov::util::join(v) << " ]";
|
||||||
|
return os.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string to_lower(const std::string& s);
|
||||||
|
|
||||||
|
std::string to_upper(const std::string& s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief trim from start (in place)
|
||||||
|
* @param s - string to trim
|
||||||
|
*/
|
||||||
|
inline std::string ltrim(const std::string& s) {
|
||||||
|
std::string ret = s;
|
||||||
|
ret.erase(ret.begin(), std::find_if(ret.begin(), ret.end(), [](int c) {
|
||||||
|
return !std::isspace(c);
|
||||||
|
}));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief trim from end (in place)
|
||||||
|
* @param s - string to trim
|
||||||
|
*/
|
||||||
|
inline std::string rtrim(const std::string& s) {
|
||||||
|
std::string ret = s;
|
||||||
|
ret.erase(std::find_if(ret.rbegin(),
|
||||||
|
ret.rend(),
|
||||||
|
[](int c) {
|
||||||
|
return !std::isspace(c);
|
||||||
|
})
|
||||||
|
.base(),
|
||||||
|
ret.end());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Trims std::string from both ends (in place)
|
||||||
|
* @ingroup ie_dev_api_error_debug
|
||||||
|
* @param s A reference to a std::tring to trim
|
||||||
|
* @return A reference to a trimmed std::string
|
||||||
|
*/
|
||||||
|
inline std::string trim(const std::string& s) {
|
||||||
|
std::string ret = ltrim(s);
|
||||||
|
ret = rtrim(ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief check string end with given substring
|
||||||
|
* @param src - string to check
|
||||||
|
* @param with - given substring
|
||||||
|
* @return true if string end with given substring
|
||||||
|
*/
|
||||||
|
inline bool ends_with(const std::string& src, const char* with) {
|
||||||
|
int wl = static_cast<int>(strlen(with));
|
||||||
|
int so = static_cast<int>(src.length()) - wl;
|
||||||
|
if (so < 0)
|
||||||
|
return false;
|
||||||
|
return 0 == strncmp(with, &src[so], wl);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> split(const std::string& s, char delimiter, bool trim = false);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T ceil_div(const T& x, const T& y) {
|
||||||
|
return (x == 0 ? 0 : (1 + (x - 1) / y));
|
||||||
|
}
|
||||||
|
} // namespace util
|
||||||
|
} // namespace ov
|
34
openvino/util/include/openvino/util/env_util.hpp
Normal file
34
openvino/util/include/openvino/util/env_util.hpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace ov {
|
||||||
|
namespace util {
|
||||||
|
/// \brief Get the names environment variable as a string.
|
||||||
|
/// \param env_var The string name of the environment variable to get.
|
||||||
|
/// \return Returns string by value or an empty string if the environment
|
||||||
|
/// variable is not set.
|
||||||
|
std::string getenv_string(const char* env_var);
|
||||||
|
|
||||||
|
/// \brief Get the names environment variable as an integer. If the value is not a
|
||||||
|
/// valid integer then an exception is thrown.
|
||||||
|
/// \param env_var The string name of the environment variable to get.
|
||||||
|
/// \param default_value The value to return if the environment variable is not set.
|
||||||
|
/// \return Returns value or default_value if the environment variable is not set.
|
||||||
|
int32_t getenv_int(const char* env_var, int32_t default_value = -1);
|
||||||
|
|
||||||
|
/// \brief Get the names environment variable as a boolean. If the value is not a
|
||||||
|
/// valid boolean then an exception is thrown. Valid booleans are one of
|
||||||
|
/// 1, 0, on, off, true, false
|
||||||
|
/// All values are case insensitive.
|
||||||
|
/// If the environment variable is not set the default_value is returned.
|
||||||
|
/// \param env_var The string name of the environment variable to get.
|
||||||
|
/// \param default_value The value to return if the environment variable is not set.
|
||||||
|
/// \return Returns the boolean value of the environment variable.
|
||||||
|
bool getenv_bool(const char* env_var, bool default_value = false);
|
||||||
|
} // namespace util
|
||||||
|
} // namespace ov
|
251
openvino/util/include/openvino/util/file_util.hpp
Normal file
251
openvino/util/include/openvino/util/file_util.hpp
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
// Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
# ifdef _WIN32
|
||||||
|
# if defined __INTEL_COMPILER || defined _MSC_VER
|
||||||
|
# define ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
# endif
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 2)) || defined(__clang__)
|
||||||
|
# define ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ov {
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
/// OS specific file traits
|
||||||
|
template <class C>
|
||||||
|
struct FileTraits;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct FileTraits<char> {
|
||||||
|
static constexpr const auto file_separator =
|
||||||
|
#ifdef _WIN32
|
||||||
|
'\\';
|
||||||
|
#else
|
||||||
|
'/';
|
||||||
|
#endif
|
||||||
|
static constexpr const auto dot_symbol = '.';
|
||||||
|
static std::string library_ext() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return {"dll"};
|
||||||
|
#else
|
||||||
|
return {"so"};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
static std::string library_prefix() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return {""};
|
||||||
|
#else
|
||||||
|
return {"lib"};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct FileTraits<wchar_t> {
|
||||||
|
static constexpr const auto file_separator =
|
||||||
|
#ifdef _WIN32
|
||||||
|
L'\\';
|
||||||
|
#else
|
||||||
|
L'/';
|
||||||
|
#endif
|
||||||
|
static constexpr const auto dot_symbol = L'.';
|
||||||
|
static std::wstring library_ext() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return {L"dll"};
|
||||||
|
#else
|
||||||
|
return {L"so"};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
static std::wstring library_prefix() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return {L""};
|
||||||
|
#else
|
||||||
|
return {L"lib"};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
/**
|
||||||
|
* @brief Conversion from wide character string to a single-byte chain.
|
||||||
|
* @param wstr A wide-char string
|
||||||
|
* @return A multi-byte string
|
||||||
|
*/
|
||||||
|
std::string wstring_to_string(const std::wstring& wstr);
|
||||||
|
/**
|
||||||
|
* @brief Conversion from single-byte chain to wide character string.
|
||||||
|
* @param str A null-terminated string
|
||||||
|
* @return A wide-char string
|
||||||
|
*/
|
||||||
|
std::wstring string_to_wstring(const std::string& str);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// \brief Remove path components which would allow traversing up a directory tree.
|
||||||
|
/// \param path A path to file
|
||||||
|
/// \return A sanitiazed path
|
||||||
|
std::string sanitize_path(const std::string& path);
|
||||||
|
|
||||||
|
/// \brief Returns the name with extension for a given path
|
||||||
|
/// \param path The path to the output file
|
||||||
|
std::string get_file_name(const std::string& path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Interface function to get absolute path of file
|
||||||
|
* @param path - path to file, can be relative to current working directory
|
||||||
|
* @return Absolute path of file
|
||||||
|
* @throw runtime_exception if any error occurred
|
||||||
|
*/
|
||||||
|
std::string get_absolute_file_path(const std::string& path);
|
||||||
|
/**
|
||||||
|
* @brief Interface function to create directorty recursively by given path
|
||||||
|
* @param path - path to file, can be relative to current working directory
|
||||||
|
* @throw runtime_exception if any error occurred
|
||||||
|
*/
|
||||||
|
void create_directory_recursive(const std::string& path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Interface function to check if directory exists for given path
|
||||||
|
* @param path - path to directory
|
||||||
|
* @return true if directory exists, false otherwise
|
||||||
|
*/
|
||||||
|
bool directory_exists(const std::string& path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns file size for file
|
||||||
|
* @param[in] path The file name
|
||||||
|
* @return file size
|
||||||
|
*/
|
||||||
|
inline uint64_t file_size(const char* path) {
|
||||||
|
#if defined(ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
|
||||||
|
std::wstring widefilename = ov::util::string_to_wstring(path);
|
||||||
|
const wchar_t* file_name = widefilename.c_str();
|
||||||
|
#elif defined(__ANDROID__) || defined(ANDROID)
|
||||||
|
std::string file_name = path;
|
||||||
|
std::string::size_type pos = file_name.find('!');
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
file_name = file_name.substr(0, pos);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
const char* file_name = path;
|
||||||
|
#endif
|
||||||
|
std::ifstream in(file_name, std::ios_base::binary | std::ios_base::ate);
|
||||||
|
return in.tellg();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns file size for file
|
||||||
|
* @param[in] path The file name
|
||||||
|
* @return file size
|
||||||
|
*/
|
||||||
|
inline uint64_t file_size(const std::wstring& path) {
|
||||||
|
return file_size(wstring_to_string(path).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns file size for file
|
||||||
|
* @param[in] path The file name
|
||||||
|
* @return file size
|
||||||
|
*/
|
||||||
|
inline uint64_t file_size(const std::string& path) {
|
||||||
|
return file_size(path.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns true if file exists
|
||||||
|
* @param[in] path The path to file
|
||||||
|
* @return true if file exists
|
||||||
|
*/
|
||||||
|
template <typename C,
|
||||||
|
typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type>
|
||||||
|
inline bool file_exists(const std::basic_string<C>& path) {
|
||||||
|
return file_size(path) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_file_ext(const std::string& path);
|
||||||
|
std::string get_directory(const std::string& path);
|
||||||
|
std::string path_join(const std::vector<std::string>& paths);
|
||||||
|
|
||||||
|
void iterate_files(const std::string& path,
|
||||||
|
const std::function<void(const std::string& file, bool is_dir)>& func,
|
||||||
|
bool recurse = false,
|
||||||
|
bool include_links = false);
|
||||||
|
|
||||||
|
void convert_path_win_style(std::string& path);
|
||||||
|
|
||||||
|
std::string get_ov_lib_path();
|
||||||
|
|
||||||
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
|
using FilePath = std::wstring;
|
||||||
|
|
||||||
|
inline std::string from_file_path(const FilePath& path) {
|
||||||
|
return wstring_to_string(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline FilePath to_file_path(const std::string& path) {
|
||||||
|
return string_to_wstring(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
using FilePath = std::string;
|
||||||
|
|
||||||
|
inline std::string from_file_path(const FilePath& path) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline FilePath to_file_path(const std::string& path) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a unicode path to openvino libraries
|
||||||
|
* @return A `std::wstring` path to openvino libraries
|
||||||
|
*/
|
||||||
|
std::wstring get_ov_lib_path_w();
|
||||||
|
|
||||||
|
inline std::wstring get_ov_library_path() {
|
||||||
|
return get_ov_lib_path_w();
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
inline std::string get_ov_library_path() {
|
||||||
|
return get_ov_lib_path();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
|
template <typename C,
|
||||||
|
typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type>
|
||||||
|
inline std::basic_string<C> make_plugin_library_name(const std::basic_string<C>& path,
|
||||||
|
const std::basic_string<C>& input) {
|
||||||
|
std::basic_string<C> separator(1, FileTraits<C>::file_separator);
|
||||||
|
if (path.empty())
|
||||||
|
separator = {};
|
||||||
|
return path + separator + FileTraits<C>::library_prefix() + input + FileTraits<C>::dot_symbol +
|
||||||
|
FileTraits<C>::library_ext();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
} // namespace ov
|
144
openvino/util/include/openvino/util/log.hpp
Normal file
144
openvino/util/include/openvino/util/log.hpp
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
// Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
#include <functional>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace ov {
|
||||||
|
namespace util {
|
||||||
|
class ConstString {
|
||||||
|
public:
|
||||||
|
template <size_t SIZE>
|
||||||
|
constexpr ConstString(const char (&p)[SIZE]) : m_string(p),
|
||||||
|
m_size(SIZE) {}
|
||||||
|
|
||||||
|
constexpr char operator[](size_t i) const {
|
||||||
|
return i < m_size ? m_string[i] : throw std::out_of_range("");
|
||||||
|
}
|
||||||
|
constexpr const char* get_ptr(size_t offset) const {
|
||||||
|
return offset < m_size ? &m_string[offset] : m_string;
|
||||||
|
}
|
||||||
|
constexpr size_t size() const {
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* m_string;
|
||||||
|
size_t m_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr const char* find_last(ConstString s, size_t offset, char ch) {
|
||||||
|
return offset == 0 ? s.get_ptr(0) : (s[offset] == ch ? s.get_ptr(offset + 1) : find_last(s, offset - 1, ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr const char* find_last(ConstString s, char ch) {
|
||||||
|
return find_last(s, s.size() - 1, ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr const char* get_file_name(ConstString s) {
|
||||||
|
return find_last(s, '/');
|
||||||
|
}
|
||||||
|
constexpr const char* trim_file_name(ConstString root, ConstString s) {
|
||||||
|
return s.get_ptr(root.size());
|
||||||
|
}
|
||||||
|
enum class LOG_TYPE {
|
||||||
|
_LOG_TYPE_ERROR,
|
||||||
|
_LOG_TYPE_WARNING,
|
||||||
|
_LOG_TYPE_INFO,
|
||||||
|
_LOG_TYPE_DEBUG,
|
||||||
|
};
|
||||||
|
|
||||||
|
class LogHelper {
|
||||||
|
public:
|
||||||
|
LogHelper(LOG_TYPE, const char* file, int line, std::function<void(const std::string&)> m_handler_func);
|
||||||
|
~LogHelper();
|
||||||
|
|
||||||
|
std::ostream& stream() {
|
||||||
|
return m_stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::function<void(const std::string&)> m_handler_func;
|
||||||
|
std::stringstream m_stream;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
friend class LogHelper;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void set_log_path(const std::string& path);
|
||||||
|
static void start();
|
||||||
|
static void stop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void log_item(const std::string& s);
|
||||||
|
static void process_event(const std::string& s);
|
||||||
|
static void thread_entry(void* param);
|
||||||
|
static std::string m_log_path;
|
||||||
|
static std::deque<std::string> m_queue;
|
||||||
|
};
|
||||||
|
|
||||||
|
void default_logger_handler_func(const std::string& s);
|
||||||
|
|
||||||
|
#ifndef PROJECT_ROOT_DIR
|
||||||
|
# define PROJECT_ROOT_DIR ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define OPENVINO_ERR \
|
||||||
|
::ov::util::LogHelper(::ov::util::LOG_TYPE::_LOG_TYPE_ERROR, \
|
||||||
|
::ov::util::trim_file_name(PROJECT_ROOT_DIR, __FILE__), \
|
||||||
|
__LINE__, \
|
||||||
|
::ov::util::default_logger_handler_func) \
|
||||||
|
.stream()
|
||||||
|
|
||||||
|
#define OPENVINO_WARN \
|
||||||
|
::ov::util::LogHelper(::ov::util::LOG_TYPE::_LOG_TYPE_WARNING, \
|
||||||
|
::ov::util::trim_file_name(PROJECT_ROOT_DIR, __FILE__), \
|
||||||
|
__LINE__, \
|
||||||
|
::ov::util::default_logger_handler_func) \
|
||||||
|
.stream()
|
||||||
|
|
||||||
|
#define OPENVINO_INFO \
|
||||||
|
::ov::util::LogHelper(::ov::util::LOG_TYPE::_LOG_TYPE_INFO, \
|
||||||
|
::ov::util::trim_file_name(PROJECT_ROOT_DIR, __FILE__), \
|
||||||
|
__LINE__, \
|
||||||
|
::ov::util::default_logger_handler_func) \
|
||||||
|
.stream()
|
||||||
|
|
||||||
|
#ifdef OPENVINO_DEBUG_ENABLE
|
||||||
|
# define OPENVINO_DEBUG \
|
||||||
|
::ov::util::LogHelper(::ov::util::LOG_TYPE::_LOG_TYPE_DEBUG, \
|
||||||
|
::ov::util::trim_file_name(PROJECT_ROOT_DIR, __FILE__), \
|
||||||
|
__LINE__, \
|
||||||
|
::ov::util::default_logger_handler_func) \
|
||||||
|
.stream()
|
||||||
|
#else
|
||||||
|
|
||||||
|
struct NullLogger {};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
NullLogger&& operator<<(NullLogger&& logger, T&&) {
|
||||||
|
return std::move(logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
NullLogger&& operator<<(NullLogger&& logger, const T&) {
|
||||||
|
return std::move(logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline NullLogger&& operator<<(
|
||||||
|
NullLogger&& logger,
|
||||||
|
std::basic_ostream<char, std::char_traits<char>>& (&)(std::basic_ostream<char, std::char_traits<char>>&)) {
|
||||||
|
return std::move(logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
# define OPENVINO_DEBUG \
|
||||||
|
::ov::util::NullLogger {}
|
||||||
|
#endif
|
||||||
|
} // namespace util
|
||||||
|
} // namespace ov
|
42
openvino/util/src/common_util.cpp
Normal file
42
openvino/util/src/common_util.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "openvino/util/common_util.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
std::string ov::util::to_lower(const std::string& s) {
|
||||||
|
std::string rc = s;
|
||||||
|
std::transform(rc.begin(), rc.end(), rc.begin(), ::tolower);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ov::util::to_upper(const std::string& s) {
|
||||||
|
std::string rc = s;
|
||||||
|
std::transform(rc.begin(), rc.end(), rc.begin(), ::toupper);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ov::util::split(const std::string& src, char delimiter, bool do_trim) {
|
||||||
|
size_t pos;
|
||||||
|
std::string token;
|
||||||
|
size_t start = 0;
|
||||||
|
std::vector<std::string> rc;
|
||||||
|
while ((pos = src.find(delimiter, start)) != std::string::npos) {
|
||||||
|
token = src.substr(start, pos - start);
|
||||||
|
start = pos + 1;
|
||||||
|
if (do_trim) {
|
||||||
|
token = trim(token);
|
||||||
|
}
|
||||||
|
rc.push_back(token);
|
||||||
|
}
|
||||||
|
if (start <= src.size()) {
|
||||||
|
token = src.substr(start);
|
||||||
|
if (do_trim) {
|
||||||
|
token = trim(token);
|
||||||
|
}
|
||||||
|
rc.push_back(token);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
65
openvino/util/src/env_util.cpp
Normal file
65
openvino/util/src/env_util.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "openvino/util/env_util.hpp"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "openvino/util/common_util.hpp"
|
||||||
|
#include "openvino/util/log.hpp"
|
||||||
|
|
||||||
|
std::string ov::util::getenv_string(const char* env_var) {
|
||||||
|
const char* env_p = ::getenv(env_var);
|
||||||
|
return env_p != nullptr ? std::string(env_p) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ov::util::getenv_int(const char* env_var, int32_t default_value) {
|
||||||
|
const char* env_p = ::getenv(env_var);
|
||||||
|
int32_t env = default_value;
|
||||||
|
// If env_var is not "" or undefined
|
||||||
|
if (env_p && *env_p) {
|
||||||
|
errno = 0;
|
||||||
|
char* err;
|
||||||
|
env = strtol(env_p, &err, 0);
|
||||||
|
// if conversion leads to an overflow
|
||||||
|
if (errno) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Environment variable \"" << env_var << "\"=\"" << env_p << "\" converted to different value \""
|
||||||
|
<< env << "\" due to overflow." << std::endl;
|
||||||
|
throw std::runtime_error(ss.str());
|
||||||
|
}
|
||||||
|
// if syntax error is there - conversion will still happen
|
||||||
|
// but warn user of syntax error
|
||||||
|
if (*err) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Environment variable \"" << env_var << "\"=\"" << env_p << "\" converted to different value \""
|
||||||
|
<< env << "\" due to syntax error \"" << err << '\"' << std::endl;
|
||||||
|
throw std::runtime_error(ss.str());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
OPENVINO_DEBUG << "Environment variable (" << env_var << ") empty or undefined, "
|
||||||
|
<< " defaulted to " << default_value << " here.";
|
||||||
|
}
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ov::util::getenv_bool(const char* env_var, bool default_value) {
|
||||||
|
std::string value = ov::util::to_lower(ov::util::getenv_string(env_var));
|
||||||
|
std::set<std::string> off = {"0", "false", "off"};
|
||||||
|
std::set<std::string> on = {"1", "true", "on"};
|
||||||
|
bool rc;
|
||||||
|
if (value == "") {
|
||||||
|
rc = default_value;
|
||||||
|
} else if (off.find(value) != off.end()) {
|
||||||
|
rc = false;
|
||||||
|
} else if (on.find(value) != on.end()) {
|
||||||
|
rc = true;
|
||||||
|
} else {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "environment variable '" << env_var << "' value '" << value << "' invalid. Must be boolean.";
|
||||||
|
throw std::runtime_error(ss.str());
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
372
openvino/util/src/file_util.cpp
Normal file
372
openvino/util/src/file_util.cpp
Normal file
@ -0,0 +1,372 @@
|
|||||||
|
// Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
#include "openvino/util/file_util.hpp"
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "openvino/util/common_util.hpp"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
# ifndef NOMINMAX
|
||||||
|
# define NOMINMAX
|
||||||
|
# endif
|
||||||
|
# include <direct.h>
|
||||||
|
# include <windows.h>
|
||||||
|
/// @brief Max length of absolute file path
|
||||||
|
# define MAX_ABS_PATH _MAX_PATH
|
||||||
|
/// @brief Get absolute file path, returns NULL in case of error
|
||||||
|
# define get_absolute_path(result, path) _fullpath(result, path.c_str(), MAX_ABS_PATH)
|
||||||
|
/// @brief Windows-specific 'stat' wrapper
|
||||||
|
# define stat _stat
|
||||||
|
/// @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)
|
||||||
|
#else
|
||||||
|
# include <dirent.h>
|
||||||
|
# include <dlfcn.h>
|
||||||
|
# include <ftw.h>
|
||||||
|
# include <sys/file.h>
|
||||||
|
# include <sys/time.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
|
||||||
|
# ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
# include <codecvt>
|
||||||
|
# include <locale>
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/// @brief Max length of absolute file path
|
||||||
|
# define MAX_ABS_PATH PATH_MAX
|
||||||
|
/// @brief Get absolute file path, returns NULL in case of error
|
||||||
|
# define get_absolute_path(result, path) realpath(path.c_str(), result)
|
||||||
|
/// @brief mkdir wrapper
|
||||||
|
# define makedir(dir) mkdir(dir, 0755)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string ov::util::get_file_name(const std::string& s) {
|
||||||
|
std::string rc = s;
|
||||||
|
auto pos = s.find_last_of('/');
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
rc = s.substr(pos + 1);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ov::util::get_file_ext(const std::string& s) {
|
||||||
|
std::string rc = get_file_name(s);
|
||||||
|
auto pos = rc.find_last_of('.');
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
rc = rc.substr(pos);
|
||||||
|
} else {
|
||||||
|
rc = "";
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ov::util::get_directory(const std::string& s) {
|
||||||
|
std::string rc = s;
|
||||||
|
// Linux-style separator
|
||||||
|
auto pos = s.find_last_of('/');
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
rc = s.substr(0, pos);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
// Windows-style separator
|
||||||
|
pos = s.find_last_of('\\');
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
rc = s.substr(0, pos);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
std::string join_paths(const std::string& s1, const std::string& s2) {
|
||||||
|
std::string rc;
|
||||||
|
if (s2.size() > 0) {
|
||||||
|
if (s2[0] == '/') {
|
||||||
|
rc = s2;
|
||||||
|
} else if (s1.size() > 0) {
|
||||||
|
rc = s1;
|
||||||
|
if (rc[rc.size() - 1] != '/') {
|
||||||
|
rc += '/';
|
||||||
|
}
|
||||||
|
rc += s2;
|
||||||
|
} else {
|
||||||
|
rc = s2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rc = s1;
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::string ov::util::path_join(const std::vector<std::string>& paths) {
|
||||||
|
std::string result;
|
||||||
|
if (paths.empty()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = paths[0];
|
||||||
|
for (size_t i = 1; i < paths.size(); i++) {
|
||||||
|
result = join_paths(result, paths[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
static void iterate_files_worker(const std::string& path,
|
||||||
|
const std::function<void(const std::string& file, bool is_dir)>& func,
|
||||||
|
bool recurse,
|
||||||
|
bool include_links) {
|
||||||
|
DIR* dir;
|
||||||
|
struct dirent* ent;
|
||||||
|
if ((dir = opendir(path.c_str())) != nullptr) {
|
||||||
|
try {
|
||||||
|
while ((ent = readdir(dir)) != nullptr) {
|
||||||
|
std::string name = ent->d_name;
|
||||||
|
std::string path_name = ov::util::path_join({path, name});
|
||||||
|
switch (ent->d_type) {
|
||||||
|
case DT_DIR:
|
||||||
|
if (name != "." && name != "..") {
|
||||||
|
if (recurse) {
|
||||||
|
ov::util::iterate_files(path_name, func, recurse);
|
||||||
|
}
|
||||||
|
func(path_name, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DT_LNK:
|
||||||
|
if (include_links) {
|
||||||
|
func(path_name, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DT_REG:
|
||||||
|
func(path_name, false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
std::exception_ptr p = std::current_exception();
|
||||||
|
closedir(dir);
|
||||||
|
std::rethrow_exception(p);
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("error enumerating file " + path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ov::util::iterate_files(const std::string& path,
|
||||||
|
const std::function<void(const std::string& file, bool is_dir)>& func,
|
||||||
|
bool recurse,
|
||||||
|
bool include_links) {
|
||||||
|
std::vector<std::string> files;
|
||||||
|
std::vector<std::string> dirs;
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string file_match = path_join({path, "*"});
|
||||||
|
WIN32_FIND_DATAA data;
|
||||||
|
HANDLE hFind = FindFirstFileA(file_match.c_str(), &data);
|
||||||
|
if (hFind != INVALID_HANDLE_VALUE) {
|
||||||
|
do {
|
||||||
|
bool is_dir = data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
||||||
|
if (is_dir) {
|
||||||
|
if (std::string(data.cFileName) != "." && std::string(data.cFileName) != "..") {
|
||||||
|
std::string dir_path = path_join({path, data.cFileName});
|
||||||
|
if (recurse) {
|
||||||
|
iterate_files(dir_path, func, recurse);
|
||||||
|
}
|
||||||
|
func(dir_path, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::string file_name = path_join({path, data.cFileName});
|
||||||
|
func(file_name, false);
|
||||||
|
}
|
||||||
|
} while (FindNextFileA(hFind, &data));
|
||||||
|
FindClose(hFind);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
iterate_files_worker(
|
||||||
|
path,
|
||||||
|
[&files, &dirs](const std::string& file, bool is_dir) {
|
||||||
|
if (is_dir) {
|
||||||
|
dirs.push_back(file);
|
||||||
|
} else {
|
||||||
|
files.push_back(file);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
recurse,
|
||||||
|
include_links);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (const auto& f : files) {
|
||||||
|
func(f, false);
|
||||||
|
}
|
||||||
|
for (const auto& f : dirs) {
|
||||||
|
func(f, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ov::util::sanitize_path(const std::string& path) {
|
||||||
|
const auto colon_pos = path.find(':');
|
||||||
|
const auto sanitized_path = path.substr(colon_pos == std::string::npos ? 0 : colon_pos + 1);
|
||||||
|
const std::string to_erase = "/.\\";
|
||||||
|
const auto start = sanitized_path.find_first_not_of(to_erase);
|
||||||
|
return (start == std::string::npos) ? "" : sanitized_path.substr(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ov::util::convert_path_win_style(std::string& path) {
|
||||||
|
std::replace(path.begin(), path.end(), '/', '\\');
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
std::string ov::util::wstring_to_string(const std::wstring& wstr) {
|
||||||
|
# ifdef _WIN32
|
||||||
|
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
|
||||||
|
std::string strTo(size_needed, 0);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
|
||||||
|
return strTo;
|
||||||
|
# else
|
||||||
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_decoder;
|
||||||
|
return wstring_decoder.to_bytes(wstr);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring ov::util::string_to_wstring(const std::string& string) {
|
||||||
|
const char* str = string.c_str();
|
||||||
|
# ifdef _WIN32
|
||||||
|
int strSize = static_cast<int>(std::strlen(str));
|
||||||
|
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, strSize, NULL, 0);
|
||||||
|
std::wstring wstrTo(size_needed, 0);
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, str, strSize, &wstrTo[0], size_needed);
|
||||||
|
return wstrTo;
|
||||||
|
# else
|
||||||
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_encoder;
|
||||||
|
std::wstring result = wstring_encoder.from_bytes(str);
|
||||||
|
return result;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string ov::util::get_absolute_file_path(const std::string& path) {
|
||||||
|
std::string absolutePath;
|
||||||
|
absolutePath.resize(MAX_ABS_PATH);
|
||||||
|
auto absPath = get_absolute_path(&absolutePath[0], path);
|
||||||
|
if (!absPath) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Can't get absolute file path for [" << path << "], err = " << strerror(errno);
|
||||||
|
throw std::runtime_error(ss.str());
|
||||||
|
}
|
||||||
|
absolutePath.resize(strlen(absPath));
|
||||||
|
return absolutePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ov::util::create_directory_recursive(const std::string& path) {
|
||||||
|
if (path.empty() || directory_exists(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t pos = path.rfind(ov::util::FileTraits<char>::file_separator);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
create_directory_recursive(path.substr(0, pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
int err = makedir(path.c_str());
|
||||||
|
if (err != 0 && errno != EEXIST) {
|
||||||
|
std::stringstream ss;
|
||||||
|
// TODO: in case of exception it may be needed to remove all created sub-directories
|
||||||
|
ss << "Couldn't create directory [" << path << "], err=" << strerror(errno) << ")";
|
||||||
|
throw std::runtime_error(ss.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ov::util::directory_exists(const std::string& path) {
|
||||||
|
struct stat sb;
|
||||||
|
|
||||||
|
if (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template <typename C,
|
||||||
|
typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type>
|
||||||
|
std::basic_string<C> get_path_name(const std::basic_string<C>& s) {
|
||||||
|
size_t i = s.rfind(ov::util::FileTraits<C>::file_separator, s.length());
|
||||||
|
if (i != std::string::npos) {
|
||||||
|
return (s.substr(0, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string get_ov_library_path_a() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
CHAR ov_library_path[MAX_PATH];
|
||||||
|
HMODULE hm = NULL;
|
||||||
|
if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||||
|
reinterpret_cast<LPSTR>(ov::util::get_ov_lib_path),
|
||||||
|
&hm)) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "GetModuleHandle returned " << GetLastError();
|
||||||
|
throw std::runtime_error(ss.str());
|
||||||
|
}
|
||||||
|
GetModuleFileNameA(hm, (LPSTR)ov_library_path, sizeof(ov_library_path));
|
||||||
|
return get_path_name(std::string(ov_library_path));
|
||||||
|
#elif defined(__APPLE__) || defined(__linux__)
|
||||||
|
Dl_info info;
|
||||||
|
dladdr(reinterpret_cast<void*>(ov::util::get_ov_lib_path), &info);
|
||||||
|
std::string result = get_path_name(std::string(info.dli_fname)).c_str();
|
||||||
|
if (!ov::util::ends_with(result, "/lib") && !ov::util::ends_with(result, "/lib/"))
|
||||||
|
result = ov::util::path_join({result, "lib"});
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
|
# error "Unsupported OS"
|
||||||
|
#endif // _WIN32
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::string ov::util::get_ov_lib_path() {
|
||||||
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
return ov::util::wstring_to_string(ov::util::get_ov_lib_path_w());
|
||||||
|
#else
|
||||||
|
return get_ov_library_path_a();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_UNICODE_PATH_SUPPORT
|
||||||
|
|
||||||
|
std::wstring ov::util::get_ov_lib_path_w() {
|
||||||
|
# ifdef _WIN32
|
||||||
|
WCHAR ov_library_path[MAX_PATH];
|
||||||
|
HMODULE hm = NULL;
|
||||||
|
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||||
|
reinterpret_cast<LPCWSTR>(get_ov_lib_path),
|
||||||
|
&hm)) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "GetModuleHandle returned " << GetLastError();
|
||||||
|
throw std::runtime_error(ss.str());
|
||||||
|
}
|
||||||
|
GetModuleFileNameW(hm, (LPWSTR)ov_library_path, sizeof(ov_library_path) / sizeof(ov_library_path[0]));
|
||||||
|
return get_path_name(std::wstring(ov_library_path));
|
||||||
|
# elif defined(__linux__) || defined(__APPLE__)
|
||||||
|
return ov::util::string_to_wstring(get_ov_library_path_a());
|
||||||
|
# else
|
||||||
|
# error "Unsupported OS"
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ENABLE_UNICODE_PATH_SUPPORT
|
54
openvino/util/src/log.cpp
Normal file
54
openvino/util/src/log.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (C) 2018-2021 Intel Corporation
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "openvino/util/log.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <ctime>
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void ov::util::default_logger_handler_func(const std::string& s) {
|
||||||
|
std::cout << s << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ov::util::LogHelper::LogHelper(LOG_TYPE type,
|
||||||
|
const char* file,
|
||||||
|
int line,
|
||||||
|
std::function<void(const std::string&)> handler_func)
|
||||||
|
: m_handler_func(std::move(handler_func)) {
|
||||||
|
switch (type) {
|
||||||
|
case LOG_TYPE::_LOG_TYPE_ERROR:
|
||||||
|
m_stream << "[ERR] ";
|
||||||
|
break;
|
||||||
|
case LOG_TYPE::_LOG_TYPE_WARNING:
|
||||||
|
m_stream << "[WARN] ";
|
||||||
|
break;
|
||||||
|
case LOG_TYPE::_LOG_TYPE_INFO:
|
||||||
|
m_stream << "[INFO] ";
|
||||||
|
break;
|
||||||
|
case LOG_TYPE::_LOG_TYPE_DEBUG:
|
||||||
|
m_stream << "[DEBUG] ";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||||
|
auto tm = gmtime(&tt);
|
||||||
|
if (tm) {
|
||||||
|
char buffer[256];
|
||||||
|
strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%Sz", tm);
|
||||||
|
m_stream << buffer << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
m_stream << file;
|
||||||
|
m_stream << " " << line;
|
||||||
|
m_stream << "\t";
|
||||||
|
}
|
||||||
|
|
||||||
|
ov::util::LogHelper::~LogHelper() {
|
||||||
|
if (m_handler_func) {
|
||||||
|
m_handler_func(m_stream.str());
|
||||||
|
}
|
||||||
|
// Logger::log_item(m_stream.str());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user