Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/inference/dev_api/openvino/runtime/icore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class OPENVINO_RUNTIME_API ICore {
* @param properties Optional map of pairs: (property name, property value) relevant only for this read operation.
* @return shared pointer to ov::Model
*/
virtual std::shared_ptr<ov::Model> read_model(const std::string& model_path,
const std::string& bin_path,
const AnyMap& properties) const = 0;
virtual std::shared_ptr<ov::Model> read_model(const std::filesystem::path& model_path,
const std::filesystem::path& bin_path,
const ov::AnyMap& properties) const = 0;

virtual ov::AnyMap create_compile_config(const std::string& device_name, const ov::AnyMap& origConfig) const = 0;

Expand Down
22 changes: 11 additions & 11 deletions src/inference/include/openvino/runtime/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,18 @@ class OPENVINO_RUNTIME_API Core {
const std::string& bin_path = {},
const ov::AnyMap& properties = {}) const;

template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
std::shared_ptr<ov::Model> read_model(const std::filesystem::path& model_path,
const std::filesystem::path& bin_path = {},
const ov::AnyMap& properties = {}) const;

template <class Path>
auto read_model(const Path& model_path, const Path& bin_path = {}, const ov::AnyMap& properties = {}) const {
if constexpr (std::is_same_v<typename Path::value_type, wchar_t>) {
return read_model(model_path.wstring(), bin_path.wstring(), properties);
if constexpr (std::is_constructible_v<std::string, Path>) {
return read_model(std::string(model_path), std::string(bin_path), properties);
} else if constexpr (std::is_constructible_v<std::wstring, Path>) {
return read_model(std::wstring(model_path), std::wstring(bin_path), properties);
} else {
// use string conversion as default
return read_model(model_path.string(), bin_path.string(), properties);
return read_model(std::filesystem::path(model_path), std::filesystem::path(bin_path), properties);
}
}
/// @}
Expand Down Expand Up @@ -152,12 +157,7 @@ class OPENVINO_RUNTIME_API Core {
class... Properties,
std::enable_if_t<std::is_same_v<Path, std::filesystem::path> && (sizeof...(Properties) > 0)>* = nullptr>
auto read_model(const Path& model_path, const Path& bin_path, Properties&&... properties) const {
if constexpr (std::is_same_v<typename Path::value_type, wchar_t>) {
return read_model(model_path.wstring(), bin_path.wstring(), std::forward<Properties>(properties)...);
} else {
// use string conversion as default
return read_model(model_path.string(), bin_path.string(), std::forward<Properties>(properties)...);
}
return read_model(model_path, bin_path, AnyMap{std::forward<Properties>(properties)...});
}
/// @}

Expand Down
17 changes: 12 additions & 5 deletions src/inference/src/cpp/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,30 @@ Core::Core(const std::filesystem::path& xml_config_file) : _impl(std::make_share
}

std::map<std::string, Version> Core::get_versions(const std::string& device_name) const {
OV_CORE_CALL_STATEMENT({ return _impl->get_versions(device_name); })}
OV_CORE_CALL_STATEMENT(return _impl->get_versions(device_name););
}

std::shared_ptr<ov::Model> Core::read_model(const std::filesystem::path& model_path,
const std::filesystem::path& bin_path,
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::OV, "Read model");
OV_CORE_CALL_STATEMENT(return _impl->read_model(model_path, bin_path, properties););
}

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
std::shared_ptr<ov::Model> Core::read_model(const std::wstring& model_path,
const std::wstring& bin_path,
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::OV, "Read model");
OV_CORE_CALL_STATEMENT(return _impl->read_model(ov::util::wstring_to_string(model_path),
ov::util::wstring_to_string(bin_path),
properties););
return read_model(ov::util::make_path(model_path), ov::util::make_path(bin_path), properties);
}
#endif

std::shared_ptr<ov::Model> Core::read_model(const std::string& model_path,
const std::string& bin_path,
const AnyMap& properties) const {
OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::OV, "Read model");
OV_CORE_CALL_STATEMENT(return _impl->read_model(model_path, bin_path, properties););
return read_model(ov::util::make_path(model_path), ov::util::make_path(bin_path), properties);
}

std::shared_ptr<ov::Model> Core::read_model(const std::string& model, const ov::Tensor& weights) const {
Expand Down
8 changes: 4 additions & 4 deletions src/inference/src/dev/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& mod
const auto lock = m_cache_guard.get_hash_lock(cache_content.m_blob_id);
compiled_model = load_model_from_cache(cache_content, plugin, parsed.m_config, {}, [&]() {
const auto model =
util::read_model(model_path, "", get_extensions_copy(), parsed.m_core_config.get_enable_mmap());
util::read_model(util::make_path(model_path), "", get_extensions_copy(), parsed.m_core_config.get_enable_mmap());
return compile_model_and_cache(plugin, model, parsed.m_config, {}, cache_content);
});
} else {
Expand Down Expand Up @@ -1726,13 +1726,13 @@ void ov::CoreImpl::add_mutex(const std::string& dev_name) {
m_dev_mutexes[dev_name];
}

std::shared_ptr<ov::Model> ov::CoreImpl::read_model(const std::string& modelPath,
const std::string& binPath,
std::shared_ptr<ov::Model> ov::CoreImpl::read_model(const std::filesystem::path& model_path,
const std::filesystem::path& bin_path,
const AnyMap& properties) const {
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::ReadTime, "CoreImpl::read_model from file");
auto local_core_config = m_core_config;
local_core_config.set(properties, {});
return ov::util::read_model(modelPath, binPath, get_extensions_copy(), local_core_config.get_enable_mmap());
return ov::util::read_model(model_path, bin_path, get_extensions_copy(), local_core_config.get_enable_mmap());
}

std::shared_ptr<ov::Model> ov::CoreImpl::read_model(const std::string& model,
Expand Down
6 changes: 3 additions & 3 deletions src/inference/src/dev/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore
std::shared_ptr<ov::Model> read_model(const std::shared_ptr<AlignedBuffer>& model,
const std::shared_ptr<AlignedBuffer>& weights) const override;

std::shared_ptr<ov::Model> read_model(const std::string& model_path,
const std::string& bin_path,
const AnyMap& properties) const override;
std::shared_ptr<ov::Model> read_model(const std::filesystem::path& model_path,
const std::filesystem::path& bin_path,
const ov::AnyMap& properties) const override;

ov::SoPtr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const std::string& device_name,
Expand Down
2 changes: 1 addition & 1 deletion src/inference/src/dev/iplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ std::shared_ptr<ov::ICompiledModel> ov::IPlugin::compile_model(const std::string
const ov::AnyMap& properties) const {
auto core = get_core();
OPENVINO_ASSERT(core);
const auto model = core->read_model(model_path, {}, properties);
const auto model = core->read_model(util::make_path(model_path), {}, properties);
auto local_properties = properties;
if (!ov::is_virtual_device(get_device_name())) {
CoreConfig::remove_core(local_properties);
Expand Down
27 changes: 7 additions & 20 deletions src/inference/src/model_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,19 @@ void update_v10_model(std::shared_ptr<ov::Model>& model, bool frontendMode = fal
namespace ov {
namespace util {

std::shared_ptr<ov::Model> read_model(const std::string& modelPath,
const std::string& binPath,
std::shared_ptr<ov::Model> read_model(const std::filesystem::path& model_path,
const std::filesystem::path& bin_path,
const std::vector<ov::Extension::Ptr>& extensions,
bool enable_mmap) {
// Fix unicode name
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
std::wstring model_path = ov::util::string_to_wstring(modelPath.c_str());
#else
std::string model_path = modelPath;
#endif

// Try to load with FrontEndManager
ov::frontend::FrontEndManager manager;
ov::frontend::FrontEnd::Ptr FE;
ov::frontend::InputModel::Ptr inputModel;

ov::AnyVector params{model_path};
ov::AnyVector params{model_path.native()};

if (!binPath.empty()) {
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
const std::wstring& weights_path = ov::util::string_to_wstring(binPath.c_str());
#else
const std::string& weights_path = binPath;
#endif
params.emplace_back(weights_path);
if (!bin_path.empty()) {
params.emplace_back(bin_path.native());
}
params.emplace_back(enable_mmap);

Expand All @@ -153,14 +141,13 @@ std::shared_ptr<ov::Model> read_model(const std::string& modelPath,
return model;
}

const auto fileExt = modelPath.substr(modelPath.find_last_of(".") + 1);
std::string FEs;
for (const auto& fe_name : manager.get_available_front_ends())
FEs += fe_name + " ";
OPENVINO_THROW("Unable to read the model: ",
modelPath,
model_path,
" Please check that model format: ",
fileExt,
model_path.extension(),
" is supported and the model is correct.",
" Available frontends: ",
FEs);
Expand Down
8 changes: 4 additions & 4 deletions src/inference/src/model_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ namespace util {

/**
* @brief Reads model
* @param modelPath path to Model file
* @param binPath optional path for model weights. If empty for IR we will find bin file with the model name.
* @param model_path path to Model file
* @param bin_path optional path for model weights. If empty for IR we will find bin file with the model name.
* if bin file with the same name was not found, will load IR without weights.
* @param extensions vector with OpenVINO extensions
* @param enable_mmap boolean to enable/disable `mmap` use in Frontend
* @return Shared pointer to ov::Model
*/
std::shared_ptr<ov::Model> read_model(const std::string& modelPath,
const std::string& binPath,
std::shared_ptr<ov::Model> read_model(const std::filesystem::path& model_path,
const std::filesystem::path& bin_path,
const std::vector<ov::Extension::Ptr>& extensions,
bool enable_mmap);

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::parse(const ov::Tensor& tensorBig,
". A \".bin\" or \".onnx\" extension was expected.");
}

originalModel = get_core()->read_model(xmlPath, weightsPath, properties);
originalModel =
get_core()->read_model(ov::util::make_path(xmlPath), ov::util::make_path(weightsPath), properties);
} else {
OPENVINO_THROW("Attempted to load a weightless compiled model, but no weights have been provided");
}
Expand Down
Loading