Skip to content

Commit

Permalink
Enable mmap only for gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
olpipi committed Oct 7, 2024
1 parent 385d657 commit 09904dc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/inference/dev_api/openvino/runtime/iplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ class OPENVINO_RUNTIME_API IPlugin : public std::enable_shared_from_this<IPlugin
*/
const std::shared_ptr<ov::threading::ExecutorManager>& get_executor_manager() const;

/**
* @brief Check if plugin support mmap for cached model reading. Returns false is the method is not overrided by plugin.
* @return true if mmap is supported, false otherwise
*/
virtual bool support_mmap_for_caching() const;

virtual ~IPlugin() = default;

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/inference/src/dev/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ bool ov::CoreImpl::device_supports_internal_property(const ov::Plugin& plugin, c
}

bool ov::CoreImpl::device_supports_model_caching(const ov::Plugin& plugin) const {
return plugin.supports_model_caching();
return plugin.supports_model_caching() == ov::Plugin::CachingMode::unsupported ? false : true;
}

bool ov::CoreImpl::device_supports_cache_dir(const ov::Plugin& plugin) const {
Expand Down Expand Up @@ -1409,7 +1409,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(
try {
cacheContent.cacheManager->read_cache_entry(
cacheContent.blobId,
coreConfig.get_enable_mmap(),
coreConfig.get_enable_mmap() && plugin.supports_model_caching() == ov::Plugin::CachingMode::mmap,
[&](std::istream& networkStream) {
OV_ITT_SCOPE(FIRST_INFERENCE,
ov::itt::domains::LoadTime,
Expand Down
4 changes: 4 additions & 0 deletions src/inference/src/dev/iplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ std::shared_ptr<ov::ICore> ov::IPlugin::get_core() const {
return m_core.lock();
}

bool ov::IPlugin::support_mmap_for_caching() const {
return false;
}

const std::shared_ptr<ov::threading::ExecutorManager>& ov::IPlugin::get_executor_manager() const {
return m_executor_manager;
}
Expand Down
16 changes: 11 additions & 5 deletions src/inference/src/dev/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,16 @@ ov::Any ov::Plugin::get_property(const std::string& name, const AnyMap& argument
return {m_ptr->get_property(name, arguments), {m_so}};
}

bool ov::Plugin::supports_model_caching() const {
bool supported(false);
supported = util::contains(get_property(ov::supported_properties), ov::device::capabilities) &&
util::contains(get_property(ov::device::capabilities), ov::device::capability::EXPORT_IMPORT) &&
util::contains(get_property(ov::internal::supported_properties), ov::internal::caching_properties);
ov::Plugin::CachingMode ov::Plugin::supports_model_caching() const {
ov::Plugin::CachingMode supported = ov::Plugin::CachingMode::unsupported;
if (util::contains(get_property(ov::supported_properties), ov::device::capabilities) &&
util::contains(get_property(ov::device::capabilities), ov::device::capability::EXPORT_IMPORT) &&
util::contains(get_property(ov::internal::supported_properties), ov::internal::caching_properties)) {
bool support_mmap = false;
OV_PLUGIN_CALL_STATEMENT(
support_mmap = m_ptr->support_mmap_for_caching();
);
supported = support_mmap ? ov::Plugin::CachingMode::mmap : ov::Plugin::CachingMode::legacy;
}
return supported;
}
8 changes: 7 additions & 1 deletion src/inference/src/dev/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ class Plugin {
T get_property(const ov::Property<T, M>& property, const AnyMap& arguments) const {
return get_property(property.name(), arguments).template as<T>();
}
bool supports_model_caching() const;

enum class CachingMode {
legacy,
mmap,
unsupported
};
CachingMode supports_model_caching() const;
};

} // namespace ov
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Plugin : public ov::IPlugin {
const ov::AnyMap& properties) const override;
ov::SoPtr<ov::IRemoteContext> create_context(const ov::AnyMap& remote_properties) const override;
ov::SoPtr<ov::IRemoteContext> get_default_context(const ov::AnyMap& remote_properties) const override;
bool support_mmap_for_caching() const override;
};

} // namespace intel_gpu
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/intel_gpu/src/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ ov::SoPtr<ov::IRemoteContext> Plugin::get_default_context(const AnyMap& params)
return get_default_context(device_id);
}

bool Plugin::support_mmap_for_caching() const {
return true;
}

void Plugin::set_property(const ov::AnyMap &config) {
auto update_config = [](ExecutionConfig& config, const ov::AnyMap& user_config) {
config.set_user_property(user_config);
Expand Down

0 comments on commit 09904dc

Please sign in to comment.