Skip to content

Commit

Permalink
Fix clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
olpipi committed Sep 20, 2024
1 parent e890042 commit 216a980
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
17 changes: 6 additions & 11 deletions src/core/dev_api/openvino/runtime/shared_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ class SharedBuffer : public ov::AlignedBuffer {
T _shared_object;
};


/// \brief SharedStreamBuffer class to store pointer to pre-acclocated buffer and provide streambuf interface.
class SharedStreamBuffer : public std::streambuf {
public:
SharedStreamBuffer(char* data, size_t size) :
m_data(data),
m_size(size),
m_offset(0) {
}
SharedStreamBuffer(char* data, size_t size) : m_data(data), m_size(size), m_offset(0) {}

protected:
std::streamsize xsgetn(char* s, std::streamsize count) override{
auto real_count = std::min<std::streamsize>(m_size - m_offset, + count);
std::streamsize xsgetn(char* s, std::streamsize count) override {
auto real_count = std::min<std::streamsize>(m_size - m_offset, count);
std::memcpy(s, m_data + m_offset, real_count);
m_offset += real_count;
return real_count;
Expand All @@ -63,10 +58,11 @@ class SharedStreamBuffer : public std::streambuf {
size_t m_offset;
};

/// \brief OwningSharedStreamBuffer is a SharedStreamBuffer which owns its shared object. Can return AlignedBuffer to shared memory
/// \brief OwningSharedStreamBuffer is a SharedStreamBuffer which owns its shared object. Can return AlignedBuffer to
/// shared memory
class OwningSharedStreamBuffer : public SharedStreamBuffer {
public:
template<typename T>
template <typename T>
OwningSharedStreamBuffer(char* data, size_t size, const T& shared_object)
: SharedStreamBuffer(data, size),
m_alligned_buffer(std::make_shared<SharedBuffer<T>>(data, size, shared_object)) {}
Expand All @@ -79,5 +75,4 @@ class OwningSharedStreamBuffer : public SharedStreamBuffer {
std::shared_ptr<AlignedBuffer> m_alligned_buffer;
};


} // namespace ov
2 changes: 1 addition & 1 deletion src/inference/src/cache_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <memory>
#include <string>

#include "openvino/runtime/shared_buffer.hpp"
#include "openvino/util/file_util.hpp"
#include "openvino/util/mmap_object.hpp"
#include "openvino/runtime/shared_buffer.hpp"

namespace ov {

Expand Down
68 changes: 36 additions & 32 deletions src/inference/src/dev/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,42 +1407,46 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(

OPENVINO_ASSERT(cacheContent.cacheManager != nullptr);
try {
cacheContent.cacheManager->read_cache_entry(cacheContent.blobId, coreConfig.get_enable_mmap(), [&](std::istream& networkStream) {
OV_ITT_SCOPE(FIRST_INFERENCE,
ov::itt::domains::LoadTime,
"Core::load_model_from_cache::ReadStreamAndImport");
try {
ov::CompiledBlobHeader header;
networkStream >> header;
if (header.get_file_info() != ov::ModelCache::calculate_file_info(cacheContent.modelPath)) {
// Original file is changed, don't use cache
OPENVINO_THROW("Original model file is changed");
}
if (util::contains(plugin.get_property(ov::internal::supported_properties),
ov::internal::compiled_model_runtime_properties_supported.name())) {
ov::AnyMap compiled_model_runtime_properties = {
{ov::internal::compiled_model_runtime_properties.name(),
std::string(header.get_runtime_info())}};
auto res = plugin.get_property(ov::internal::compiled_model_runtime_properties_supported.name(),
compiled_model_runtime_properties);
if (!res.as<bool>()) {
OPENVINO_THROW("Original model runtime properties have been changed, not supported anymore!");
cacheContent.cacheManager->read_cache_entry(
cacheContent.blobId,
coreConfig.get_enable_mmap(),
[&](std::istream& networkStream) {
OV_ITT_SCOPE(FIRST_INFERENCE,
ov::itt::domains::LoadTime,
"Core::load_model_from_cache::ReadStreamAndImport");
try {
ov::CompiledBlobHeader header;
networkStream >> header;
if (header.get_file_info() != ov::ModelCache::calculate_file_info(cacheContent.modelPath)) {
// Original file is changed, don't use cache
OPENVINO_THROW("Original model file is changed");
}
} else {
if (header.get_openvino_version() != ov::get_openvino_version().buildNumber) {
// Build number mismatch, don't use this cache
OPENVINO_THROW("Version does not match");
if (util::contains(plugin.get_property(ov::internal::supported_properties),
ov::internal::compiled_model_runtime_properties_supported.name())) {
ov::AnyMap compiled_model_runtime_properties = {
{ov::internal::compiled_model_runtime_properties.name(),
std::string(header.get_runtime_info())}};
auto res = plugin.get_property(ov::internal::compiled_model_runtime_properties_supported.name(),
compiled_model_runtime_properties);
if (!res.as<bool>()) {
OPENVINO_THROW(
"Original model runtime properties have been changed, not supported anymore!");
}
} else {
if (header.get_openvino_version() != ov::get_openvino_version().buildNumber) {
// Build number mismatch, don't use this cache
OPENVINO_THROW("Version does not match");
}
}
} catch (...) {
throw HeaderException();
}
} catch (...) {
throw HeaderException();
}

ov::AnyMap update_config = config;
update_config[ov::loaded_from_cache.name()] = true;
compiled_model = context ? plugin.import_model(networkStream, context, update_config)
: plugin.import_model(networkStream, update_config);
});
ov::AnyMap update_config = config;
update_config[ov::loaded_from_cache.name()] = true;
compiled_model = context ? plugin.import_model(networkStream, context, update_config)
: plugin.import_model(networkStream, update_config);
});
} catch (const HeaderException&) {
// For these exceptions just remove old cache and set that import didn't work
cacheContent.cacheManager->remove_cache_entry(cacheContent.blobId);
Expand Down

0 comments on commit 216a980

Please sign in to comment.