Skip to content

Commit

Permalink
[FE] Add support for cpp17 path in frontend API (openvinotoolkit#28070)
Browse files Browse the repository at this point in the history
### Details:
 - Extend frontend API to support cpp path class.

### Tickets:
 - CVS-158888

Signed-off-by: Raasz, Pawel <[email protected]>
  • Loading branch information
praasz authored Dec 13, 2024
1 parent f790885 commit 357eb54
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/core/tests/frontend/frontend_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,29 @@ TEST(FrontEndManagerTest, Exception_Safety_Input_Model_set_tensor_value) {
TEST(FrontEndManagerTest, Exception_Safety_Input_Model_set_tensor_partial_value) {
CHECK_EXCEPTION_INPUT_MODEL(input_model->set_tensor_partial_value({}, {}, {}))
}

#ifdef OPENVINO_CPP_VER_17

TEST(FrontEndManagerTest, testFEMDestroy_InputModelHolderUsingPath) {
InputModel::Ptr input_model;
{
std::shared_ptr<ov::Model> model;
FrontEndManager fem;
fem.register_front_end("mock1", mock_fe_path());
auto fe = fem.load_by_framework("mock1");
input_model = fe->load(std::filesystem::path("test"));
model = fe->convert(input_model);
EXPECT_EQ(model->get_friendly_name(), "mock1_model");
}
ASSERT_TRUE(input_model);
}

TEST(FrontEndManagerTest, Exception_Safety_FrontEnd_Supported_By_Path) {
EXPECT_ANY_THROW({
FrontEndManager fem;
fem.register_front_end("mock1", mock_fe_path());
auto fe = fem.load_by_framework("mock1");
fe->supported(std::filesystem::path("throw_now"));
});
}
#endif
37 changes: 35 additions & 2 deletions src/frontends/common/include/openvino/frontend/frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "openvino/frontend/input_model.hpp"
#include "openvino/frontend/visibility.hpp"

#ifdef OPENVINO_CPP_VER_17
# include <filesystem>
#endif

namespace ov {
namespace frontend {
/// \brief An interface for identifying a frontend for a particular framework.
Expand Down Expand Up @@ -50,7 +54,12 @@ class FRONTEND_API FrontEnd {
/// \return true if model recognized, false - otherwise.
template <typename... Types>
inline bool supported(const Types&... vars) const {
return supported_impl({ov::Any(vars)...});
#ifdef OPENVINO_CPP_VER_17
if constexpr ((std::is_same_v<std::filesystem::path, Types> || ...)) {
return supported_impl({path_as_str_or_forward(vars)...});
} else
#endif
return supported_impl({ov::Any(vars)...});
}
inline bool supported(const ov::AnyVector& vars) const {
return supported_impl(vars);
Expand All @@ -65,7 +74,12 @@ class FRONTEND_API FrontEnd {
/// \return Loaded input model.
template <typename... Types>
inline InputModel::Ptr load(const Types&... vars) const {
return load_impl({ov::Any{vars}...});
#ifdef OPENVINO_CPP_VER_17
if constexpr ((std::is_same_v<std::filesystem::path, Types> || ...)) {
return load_impl({path_as_str_or_forward(vars)...});
} else
#endif
return load_impl({ov::Any{vars}...});
}

inline InputModel::Ptr load(const ov::AnyVector& vars) const {
Expand Down Expand Up @@ -118,8 +132,16 @@ class FRONTEND_API FrontEnd {

/// \brief Registers extension
/// \param library_path path to library with ov::Extension
/// \{
void add_extension(const std::string& library_path);

#ifdef OPENVINO_CPP_VER_17
void add_extension(const std::filesystem::path& library_path) {
add_extension(library_path.string());
}
#endif
/// \}

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT

/// \brief Registers extension
Expand Down Expand Up @@ -162,6 +184,17 @@ class FRONTEND_API FrontEnd {
private:
static std::shared_ptr<ov::Model> create_copy(const std::shared_ptr<ov::Model>& ov_model,
const std::shared_ptr<void>& shared_object);

#ifdef OPENVINO_CPP_VER_17
template <class T>
static constexpr auto path_as_str_or_forward(T&& p) {
if constexpr (std::is_same_v<std::filesystem::path, std::decay_t<T>>) {
return p.string();
} else {
return std::forward<T>(p);
}
}
#endif
};

template <>
Expand Down
14 changes: 14 additions & 0 deletions src/frontends/tests/frontend/shared/src/conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,17 @@ TEST_P(FrontEndConversionExtensionTest, TestConversionExtensionViaSO) {
OV_ASSERT_NO_THROW(model = frontend->convert(input_model));
ASSERT_NE(model, nullptr);
}

#ifdef OPENVINO_CPP_VER_17
TEST_P(FrontEndConversionExtensionTest, TestConversionExtensionViaSOByPath) {
auto frontend = m_param.m_frontend;
const std::filesystem::path lib_path = get_lib_path("test_builtin_extensions");
frontend->add_extension(lib_path);
std::shared_ptr<InputModel> input_model;
OV_ASSERT_NO_THROW(input_model = frontend->load(m_param.m_modelName));
ASSERT_NE(input_model, nullptr);
std::shared_ptr<ov::Model> model;
OV_ASSERT_NO_THROW(model = frontend->convert(input_model));
ASSERT_NE(model, nullptr);
}
#endif

0 comments on commit 357eb54

Please sign in to comment.