Skip to content

Commit

Permalink
[Core] rearrange pugixml and performance heuristics (openvinotoolkit#…
Browse files Browse the repository at this point in the history
…22234)

* Move performance_heuristics.hpp to openvino folder

* Refactor pugixml::utils

1. move pugixml::util from src/inference to openvino/util
2. move duplicated pugixml::utils implement to opeenvino/util

* Fix build error and rename namespace

  1. fix build error caused by library dependency
  2. rename openvino::util::pugixml
  3. NamingConventionCheck issue
  4. Clang format issue
  5. smoke_createMockEngineConfigThrows failure due to pugixml exception type

* Use friendly namespace

* Update

* update cmake

* update
  • Loading branch information
riverlijunjie authored Jan 22, 2024
1 parent 92cc4f5 commit c538d03
Show file tree
Hide file tree
Showing 19 changed files with 418 additions and 562 deletions.
2 changes: 1 addition & 1 deletion src/common/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ add_library(${TARGET_NAME} STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS})
add_library(openvino::util ALIAS ${TARGET_NAME})
set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME util)

target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS})
target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS} PUBLIC openvino::pugixml)
if (WIN32)
target_link_libraries(${TARGET_NAME} PRIVATE Shlwapi)
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (C) 2018-2023 Intel Corporation
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

/**
* @brief Basic functions to safely extract values from `pugi::xml_node` and open `pugi::xml_document`
* @file xml_parse_utils.h
* @file xml_parse_utils.hpp
*/

#pragma once

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <memory>
Expand All @@ -17,14 +17,9 @@
#include <string>
#include <utility>

#include "file_utils.h"
#include "ie_api.h"
#include "ie_common.h"
#include "ie_precision.hpp"
#include "openvino/util/file_util.hpp"

IE_SUPPRESS_DEPRECATED_START
/**
* @ingroup ie_dev_api_xml
* @brief Defines convinient for-each based cycle to iterate over node children
*
* @param c Child node name
Expand All @@ -33,27 +28,22 @@ IE_SUPPRESS_DEPRECATED_START
*/
#define FOREACH_CHILD(c, p, tag) for (auto c = p.child(tag); !c.empty(); c = c.next_sibling(tag))

/**
* @brief XML helpers function to extract values from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*/
namespace pugixml {
namespace ov {
namespace util {

/**
* @brief XML helpers function to extract values from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*/
namespace utils {
namespace pugixml {

/**
* @brief Gets the integer attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string
* @return An integer value
*/
INFERENCE_ENGINE_API_CPP(int) GetIntAttr(const pugi::xml_node& node, const char* str);
int get_int_attr(const pugi::xml_node& node, const char* str);

/**
* @brief Gets the integer attribute from `pugi::xml_node`
Expand All @@ -63,182 +53,144 @@ INFERENCE_ENGINE_API_CPP(int) GetIntAttr(const pugi::xml_node& node, const char*
* @param[in] defVal The default value
* @return An integer value
*/
INFERENCE_ENGINE_API_CPP(int) GetIntAttr(const pugi::xml_node& node, const char* str, int defVal);
int get_int_attr(const pugi::xml_node& node, const char* str, int defVal);

/**
* @brief Gets the `int64_t` attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @return An `int64_t` value
*/
INFERENCE_ENGINE_API_CPP(int64_t) GetInt64Attr(const pugi::xml_node& node, const char* str);
int64_t get_int64_attr(const pugi::xml_node& node, const char* str);

/**
* @brief Gets the `int64_t` attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @param[in] defVal The default value
* @return An `int64_t` value
*/
INFERENCE_ENGINE_API_CPP(int64_t) GetInt64Attr(const pugi::xml_node& node, const char* str, int64_t defVal);
int64_t get_int64_attr(const pugi::xml_node& node, const char* str, int64_t defVal);

/**
* @brief Gets the `uint64_t` attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @return An `uint64_t` value
*/
INFERENCE_ENGINE_API_CPP(uint64_t) GetUInt64Attr(const pugi::xml_node& node, const char* str);
uint64_t get_uint64_attr(const pugi::xml_node& node, const char* str);

/**
* @brief Gets the `uint64_t` attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @param[in] defVal The default value
* @return An `uint64_t` value
*/
INFERENCE_ENGINE_API_CPP(uint64_t) GetUInt64Attr(const pugi::xml_node& node, const char* str, uint64_t defVal);
uint64_t get_uint64_attr(const pugi::xml_node& node, const char* str, uint64_t defVal);

/**
* @brief Gets the unsigned integer attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @return An unsigned integer value
*/
INFERENCE_ENGINE_API_CPP(unsigned int) GetUIntAttr(const pugi::xml_node& node, const char* str);
unsigned int get_uint_attr(const pugi::xml_node& node, const char* str);

/**
* @brief Gets the unsigned integer attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @param[in] defVal The default value
* @return An unsigned integer value
*/
INFERENCE_ENGINE_API_CPP(unsigned int) GetUIntAttr(const pugi::xml_node& node, const char* str, unsigned int defVal);
unsigned int get_uint_attr(const pugi::xml_node& node, const char* str, unsigned int defVal);

/**
* @brief Gets the string attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @return A string value
*/
INFERENCE_ENGINE_API_CPP(std::string) GetStrAttr(const pugi::xml_node& node, const char* str);
std::string get_str_attr(const pugi::xml_node& node, const char* str);

/**
* @brief Gets the string attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @param[in] def The default value
* @return A string value
*/
INFERENCE_ENGINE_API_CPP(std::string) GetStrAttr(const pugi::xml_node& node, const char* str, const char* def);
std::string get_str_attr(const pugi::xml_node& node, const char* str, const char* def);

/**
* @brief Gets the bool attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @return A boolean value
*/
INFERENCE_ENGINE_API_CPP(bool) GetBoolAttr(const pugi::xml_node& node, const char* str);
bool get_bool_attr(const pugi::xml_node& node, const char* str);

/**
* @brief Gets the bool attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @param[in] def The default value
* @return A boolean value
*/
INFERENCE_ENGINE_API_CPP(bool) GetBoolAttr(const pugi::xml_node& node, const char* str, const bool def);
bool get_bool_attr(const pugi::xml_node& node, const char* str, const bool def);

/**
* @brief Gets the float attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @return A single-precision floating point value
*/
INFERENCE_ENGINE_API_CPP(float) GetFloatAttr(const pugi::xml_node& node, const char* str);
float get_float_attr(const pugi::xml_node& node, const char* str);

/**
* @brief Gets the float attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @param[in] defVal The default value
* @return A single-precision floating point value
*/
INFERENCE_ENGINE_API_CPP(float) GetFloatAttr(const pugi::xml_node& node, const char* str, float defVal);

/**
* @brief Gets the Precision attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @return A Precision value
*/
INFERENCE_ENGINE_API_CPP(InferenceEngine::Precision) GetPrecisionAttr(const pugi::xml_node& node, const char* str);

/**
* @brief Gets the Precision attribute from `pugi::xml_node`
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string identifying value name
* @param[in] def The default value
* @return A Precision value
*/
INFERENCE_ENGINE_API_CPP(InferenceEngine::Precision)
GetPrecisionAttr(const pugi::xml_node& node, const char* str, InferenceEngine::Precision def);
float get_float_attr(const pugi::xml_node& node, const char* str, float defVal);

/**
* @brief Gets the integer value located in a child node.
* @ingroup ie_dev_api_xml
*
* @param[in] node The node
* @param[in] str The string value identifying a child node
* @param[in] defVal The default value
* @return An ingeter value located in a child node, @p devVal otherwise.
*/
INFERENCE_ENGINE_API_CPP(int) GetIntChild(const pugi::xml_node& node, const char* str, int defVal);

} // namespace utils
} // namespace pugixml
int get_int_child(const pugi::xml_node& node, const char* str, int defVal);

/**
* @brief A XML parse result structure with an error message and the `pugi::xml_document` document.
* @ingroup ie_dev_api_xml
*/
struct parse_result {
struct ParseResult {
/**
* @brief Constructs parse_result with `pugi::xml_document` and an error message
* @brief Constructs ParseResult with `pugi::xml_document` and an error message
*
* @param xml The `pugi::xml_document`
* @param[in] error_msg The error message
*/
parse_result(std::unique_ptr<pugi::xml_document>&& xml, std::string error_msg)
ParseResult(std::unique_ptr<pugi::xml_document>&& xml, std::string error_msg)
: xml(std::move(xml)),
error_msg(std::move(error_msg)) {}

Expand All @@ -254,14 +206,14 @@ struct parse_result {
};

/**
* @brief Parses a file and returns parse_result
* @brief Parses a file and returns ParseResult
* @ingroup ie_dev_api_xml
*
* @param[in] file_path The file path
*
* @return The parse_result.
* @return The ParseResult.
*/
inline parse_result ParseXml(const char* file_path) {
inline ParseResult parse_xml(const char* file_path) {
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
std::wstring wFilePath = ov::util::string_to_wstring(file_path);
const wchar_t* resolvedFilepath = wFilePath.c_str();
Expand Down Expand Up @@ -297,5 +249,6 @@ inline parse_result ParseXml(const char* file_path) {
return {std::move(nullptr), std::string("Error loading XML file: ") + e.what()};
}
}

IE_SUPPRESS_DEPRECATED_END
} // namespace pugixml
} // namespace util
} // namespace ov
Loading

0 comments on commit c538d03

Please sign in to comment.