Skip to content

Commit

Permalink
Fix clang formats
Browse files Browse the repository at this point in the history
  • Loading branch information
MirceaDan99 committed Dec 9, 2024
1 parent d29e036 commit 539c459
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 92 deletions.
4 changes: 2 additions & 2 deletions src/core/dev_api/openvino/runtime/shared_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class OwningSharedStreamBuffer : public SharedStreamBuffer {
}

pos_type seekoff(off_type off,
std::ios_base::seekdir dir,
std::ios_base::openmode which = std::ios_base::in) override {
std::ios_base::seekdir dir,
std::ios_base::openmode which = std::ios_base::in) override {
auto pos = SharedStreamBuffer::seekoff(off, dir, which);
m_shared_obj->updateOffset(m_offset);
return pos;
Expand Down
3 changes: 2 additions & 1 deletion src/inference/src/cache_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ class FileStorageCacheManager final : public ICacheManager {
reader(stream, shared_buffer);
} else {
std::ifstream stream(blob_file_name, std::ios_base::binary);
reader(stream, nullptr); }
reader(stream, nullptr);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/inference/src/dev/compilation_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ std::string ModelCache::compute_hash(const std::string& modelStr,

//////////////////////////////////////////////////

CompiledBlobHeader::CompiledBlobHeader(std::shared_ptr<ov::AlignedBuffer> model_buffer) : m_model_buffer(model_buffer) {}
CompiledBlobHeader::CompiledBlobHeader(std::shared_ptr<ov::AlignedBuffer> model_buffer)
: m_model_buffer(model_buffer) {}

CompiledBlobHeader::CompiledBlobHeader(const std::string& ieVersion,
const std::string& fileInfo,
Expand Down
4 changes: 2 additions & 2 deletions src/inference/src/dev/iplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ const std::string& ov::IPlugin::get_device_name() const {

std::shared_ptr<ov::ICompiledModel> ov::IPlugin::import_model(std::istream& model,
std::shared_ptr<ov::AlignedBuffer> model_buffer,
const ov::AnyMap& properties) const{
const ov::AnyMap& properties) const {
OPENVINO_THROW_NOT_IMPLEMENTED("This method is not implemented");
}

std::shared_ptr<ov::ICompiledModel> ov::IPlugin::import_model(std::istream& model,
std::shared_ptr<ov::AlignedBuffer> model_buffer,
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const{
const ov::AnyMap& properties) const {
OPENVINO_THROW_NOT_IMPLEMENTED("This method is not implemented");
}

Expand Down
4 changes: 3 additions & 1 deletion src/inference/src/dev/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ ov::SoPtr<ov::ICompiledModel> ov::Plugin::import_model(std::istream& model,
OV_PLUGIN_CALL_STATEMENT(return {m_ptr->import_model(model, context, config), m_so});
}

ov::SoPtr<ov::ICompiledModel> ov::Plugin::import_model(std::istream& model, std::shared_ptr<ov::AlignedBuffer> model_buffer, const ov::AnyMap& properties) const {
ov::SoPtr<ov::ICompiledModel> ov::Plugin::import_model(std::istream& model,
std::shared_ptr<ov::AlignedBuffer> model_buffer,
const ov::AnyMap& properties) const {
OV_PLUGIN_CALL_STATEMENT(return {m_ptr->import_model(model, model_buffer, properties), m_so});
}

Expand Down
5 changes: 3 additions & 2 deletions src/inference/src/dev/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class Plugin {
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& config) const;

SoPtr<ov::ICompiledModel> import_model(std::istream& model, std::shared_ptr<ov::AlignedBuffer> model_buffer, const ov::AnyMap& properties) const;
SoPtr<ov::ICompiledModel> import_model(std::istream& model,
std::shared_ptr<ov::AlignedBuffer> model_buffer,
const ov::AnyMap& properties) const;

SoPtr<ov::ICompiledModel> import_model(std::istream& model,
std::shared_ptr<ov::AlignedBuffer> model_buffer,
Expand All @@ -85,4 +87,3 @@ class Plugin {
};

} // namespace ov

27 changes: 14 additions & 13 deletions src/plugins/intel_cpu/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "cpu_streams_calculation.hpp"
#include "internal_properties.hpp"
#include "itt.h"
#include "openvino/op/paged_attention.hpp"
#include "openvino/runtime/intel_cpu/properties.hpp"
#include "openvino/runtime/internal_properties.hpp"
#include "openvino/runtime/properties.hpp"
Expand All @@ -19,7 +20,6 @@
#include "utils/precision_support.h"
#include "utils/serialize.hpp"
#include "weights_cache.hpp"
#include "openvino/op/paged_attention.hpp"

#if defined(__linux__)
# include <signal.h>
Expand Down Expand Up @@ -200,7 +200,7 @@ static Config::ModelType getModelType(const std::shared_ptr<const Model>& model)
return Config::ModelType::CNN;

if ((op::util::has_op_with_type<op::v13::ScaledDotProductAttention>(model) && model->get_variables().size() > 0) ||
op::util::has_op_with_type<ov::op::PagedAttentionExtension>(model))
op::util::has_op_with_type<ov::op::PagedAttentionExtension>(model))
return Config::ModelType::LLM;

return Config::ModelType::Unknown;
Expand Down Expand Up @@ -446,15 +446,17 @@ ov::Any Plugin::get_ro_property(const std::string& name, const ov::AnyMap& optio

return decltype(ov::supported_properties)::value_type(std::move(supportedProperties));
} else if (ov::internal::supported_properties == name) {
return decltype(ov::internal::supported_properties)::value_type{
return decltype(ov::internal::supported_properties)::value_type {
ov::PropertyName{ov::internal::caching_properties.name(), ov::PropertyMutability::RO},
#if !defined(OPENVINO_ARCH_ARM) && !(defined(__APPLE__) || defined(__MACOSX))
ov::PropertyName{ov::internal::caching_with_mmap.name(), ov::PropertyMutability::RO},
ov::PropertyName{ov::internal::caching_with_mmap.name(), ov::PropertyMutability::RO},
#endif
ov::PropertyName{ov::internal::exclusive_async_requests.name(), ov::PropertyMutability::RW},
ov::PropertyName{ov::internal::compiled_model_runtime_properties.name(), ov::PropertyMutability::RO},
ov::PropertyName{ov::internal::compiled_model_runtime_properties_supported.name(),
ov::PropertyMutability::RO}};
ov::PropertyName{ov::internal::exclusive_async_requests.name(), ov::PropertyMutability::RW},
ov::PropertyName{ov::internal::compiled_model_runtime_properties.name(), ov::PropertyMutability::RO},
ov::PropertyName {
ov::internal::compiled_model_runtime_properties_supported.name(), ov::PropertyMutability::RO
}
};
} else if (name == ov::device::full_name) {
return decltype(ov::device::full_name)::value_type(deviceFullName);
} else if (name == ov::available_devices) {
Expand Down Expand Up @@ -553,18 +555,16 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>&
return res;
}

std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& model_stream,
const ov::AnyMap& config) const {
std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& model_stream, const ov::AnyMap& config) const {
return import_model(model_stream, nullptr, config);
}


std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& model_stream,
std::shared_ptr<ov::AlignedBuffer> model_buffer,
const ov::AnyMap& config) const {
OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::intel_cpu_LT, "import_model");

CacheDecrypt decrypt{ codec_xor };
CacheDecrypt decrypt{codec_xor};
bool decript_from_string = false;
if (config.count(ov::cache_encryption_callbacks.name())) {
auto encryption_callbacks = config.at(ov::cache_encryption_callbacks.name()).as<EncryptionCallbacks>();
Expand All @@ -578,7 +578,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& model_str
[this](const std::shared_ptr<ov::AlignedBuffer>& model, const std::shared_ptr<ov::AlignedBuffer>& weights) {
return get_core()->read_model(model, weights);
},
decrypt, decript_from_string);
decrypt,
decript_from_string);

std::shared_ptr<ov::Model> model;
deserializer >> model;
Expand Down
9 changes: 3 additions & 6 deletions src/plugins/intel_cpu/src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class Plugin : public ov::IPlugin {
std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties,
const ov::SoPtr<ov::IRemoteContext>& context) const override {
OPENVINO_THROW_NOT_IMPLEMENTED(
"compile_model with RemoteContext is not supported by CPU plugin!");
OPENVINO_THROW_NOT_IMPLEMENTED("compile_model with RemoteContext is not supported by CPU plugin!");
};

void set_property(const ov::AnyMap& properties) override;
Expand All @@ -30,8 +29,7 @@ class Plugin : public ov::IPlugin {
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model,
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const override {
OPENVINO_THROW_NOT_IMPLEMENTED(
"import_model with RemoteContext is not supported by CPU plugin!");
OPENVINO_THROW_NOT_IMPLEMENTED("import_model with RemoteContext is not supported by CPU plugin!");
};

std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model,
Expand All @@ -41,8 +39,7 @@ class Plugin : public ov::IPlugin {
std::shared_ptr<ov::AlignedBuffer> model_buffer,
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const override {
OPENVINO_THROW_NOT_IMPLEMENTED(
"import_model with RemoteContext is not supported by CPU plugin!");
OPENVINO_THROW_NOT_IMPLEMENTED("import_model with RemoteContext is not supported by CPU plugin!");
};

ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>& model,
Expand Down
70 changes: 41 additions & 29 deletions src/plugins/intel_cpu/src/utils/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace intel_cpu {
////////// ModelSerializer //////////

ModelSerializer::ModelSerializer(std::ostream& ostream, CacheEncrypt encrypt_fn)
: m_ostream(ostream), m_cache_encrypt(std::move(encrypt_fn)) {}
: m_ostream(ostream),
m_cache_encrypt(std::move(encrypt_fn)) {}

void ModelSerializer::operator<<(const std::shared_ptr<ov::Model>& model) {
auto serialize_info = [&](std::ostream& stream) {
Expand All @@ -35,22 +36,25 @@ ModelDeserializer::ModelDeserializer(std::istream& model_stream,
ModelBuilder fn,
const CacheDecrypt& decrypt_fn,
bool decript_from_string)
: m_istream(model_stream), m_model_builder(std::move(fn)), m_decript_from_string(decript_from_string), m_model_buffer(model_buffer) {
if (m_decript_from_string) {
m_cache_decrypt.m_decrypt_str = decrypt_fn.m_decrypt_str;
} else {
m_cache_decrypt.m_decrypt_char = decrypt_fn.m_decrypt_char;
}
: m_istream(model_stream),
m_model_builder(std::move(fn)),
m_decript_from_string(decript_from_string),
m_model_buffer(model_buffer) {
if (m_decript_from_string) {
m_cache_decrypt.m_decrypt_str = decrypt_fn.m_decrypt_str;
} else {
m_cache_decrypt.m_decrypt_char = decrypt_fn.m_decrypt_char;
}
}

void ModelDeserializer::set_info(pugi::xml_node& root, std::shared_ptr<ov::Model>& model) {}
void ModelDeserializer::set_info(pugi::xml_node& root, std::shared_ptr<ov::Model>& model) {}

void ModelDeserializer::operator>>(std::shared_ptr<ov::Model>& model) {
if (m_model_buffer) {
process_mmap(model, m_model_buffer);
} else {
process_stream(model);
}
void ModelDeserializer::operator>>(std::shared_ptr<ov::Model>& model) {
if (m_model_buffer) {
process_mmap(model, m_model_buffer);
} else {
process_stream(model);
}
}

void ModelDeserializer::process_mmap(std::shared_ptr<ov::Model>& model,
Expand All @@ -77,7 +81,10 @@ void ModelDeserializer::process_mmap(std::shared_ptr<ov::Model>& model,
// Read model input/output precisions.
pugi::xml_document xml_in_out_doc;
if (hdr.custom_data_size > 0lu) {
auto res = xml_in_out_doc.load_buffer(buffer_base + hdr.custom_data_offset, hdr.custom_data_size, pugi::parse_default, pugi::encoding_utf8);
auto res = xml_in_out_doc.load_buffer(buffer_base + hdr.custom_data_offset,
hdr.custom_data_size,
pugi::parse_default,
pugi::encoding_utf8);
if (res.status != pugi::status_ok) {
OPENVINO_THROW("[CPU] Could to deserialize custom data.");
}
Expand All @@ -86,7 +93,10 @@ void ModelDeserializer::process_mmap(std::shared_ptr<ov::Model>& model,
// Map blob content
std::shared_ptr<ov::AlignedBuffer> weights_buf;
if (hdr.consts_size) {
weights_buf = std::make_shared<ov::SharedBuffer<std::shared_ptr<ov::AlignedBuffer>>>(buffer_base + hdr.consts_offset, hdr.consts_size, mmemory);
weights_buf =
std::make_shared<ov::SharedBuffer<std::shared_ptr<ov::AlignedBuffer>>>(buffer_base + hdr.consts_offset,
hdr.consts_size,
mmemory);
}

// XML content
Expand All @@ -103,9 +113,7 @@ void ModelDeserializer::process_mmap(std::shared_ptr<ov::Model>& model,
xml_buff->assign(buffer_base + hdr.model_offset, hdr.model_size);
}
std::shared_ptr<ov::AlignedBuffer> model_buf =
std::make_shared<ov::SharedBuffer<std::shared_ptr<std::string>>>(&((*xml_buff)[0]),
hdr.model_size,
xml_buff);
std::make_shared<ov::SharedBuffer<std::shared_ptr<std::string>>>(&((*xml_buff)[0]), hdr.model_size, xml_buff);

model = m_model_builder(model_buf, weights_buf);

Expand Down Expand Up @@ -150,7 +158,7 @@ void ModelDeserializer::process_stream(std::shared_ptr<ov::Model>& model) {
auto data_blob = std::make_shared<ov::Tensor>(ov::element::u8, ov::Shape({hdr.consts_size}));
m_istream.seekg(hdr.consts_offset);
if (hdr.consts_size) {
m_istream.read(static_cast<char *>(data_blob->data(ov::element::u8)), hdr.consts_size);
m_istream.read(static_cast<char*>(data_blob->data(ov::element::u8)), hdr.consts_size);
}

// read XML content
Expand All @@ -162,16 +170,20 @@ void ModelDeserializer::process_stream(std::shared_ptr<ov::Model>& model) {
if (m_decript_from_string) {
*xml_string = m_cache_decrypt.m_decrypt_str(*xml_string);
} else {
m_cache_decrypt.m_decrypt_char(const_cast<char*>(xml_string->data()), xml_string->data(), xml_string->size());
m_cache_decrypt.m_decrypt_char(const_cast<char*>(xml_string->data()),
xml_string->data(),
xml_string->size());
}
}

auto model_buf = std::make_shared<ov::SharedBuffer<std::shared_ptr<std::string>>>(const_cast<char*>(xml_string->data()),
xml_string->size(),
xml_string);
auto weights_buf = std::make_shared<ov::SharedBuffer<std::shared_ptr<ov::Tensor>>>(reinterpret_cast<char*>(data_blob->data(ov::element::u8)),
hdr.consts_size,
data_blob);
auto model_buf =
std::make_shared<ov::SharedBuffer<std::shared_ptr<std::string>>>(const_cast<char*>(xml_string->data()),
xml_string->size(),
xml_string);
auto weights_buf = std::make_shared<ov::SharedBuffer<std::shared_ptr<ov::Tensor>>>(
reinterpret_cast<char*>(data_blob->data(ov::element::u8)),
hdr.consts_size,
data_blob);

model = m_model_builder(model_buf, weights_buf);

Expand All @@ -180,5 +192,5 @@ void ModelDeserializer::process_stream(std::shared_ptr<ov::Model>& model) {
set_info(root, model);
}

} // namespace intel_cpu
} // namespace ov
} // namespace intel_cpu
} // namespace ov
8 changes: 5 additions & 3 deletions src/plugins/intel_cpu/src/utils/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class ModelSerializer {

class ModelDeserializer {
public:
typedef std::function<std::shared_ptr<ov::Model>(const std::shared_ptr<ov::AlignedBuffer>&, const std::shared_ptr<ov::AlignedBuffer>&)> ModelBuilder;
typedef std::function<std::shared_ptr<ov::Model>(const std::shared_ptr<ov::AlignedBuffer>&,
const std::shared_ptr<ov::AlignedBuffer>&)>
ModelBuilder;

ModelDeserializer(std::istream& model,
std::shared_ptr<ov::AlignedBuffer> model_buffer,
Expand All @@ -55,5 +57,5 @@ class ModelDeserializer {
std::shared_ptr<ov::AlignedBuffer> m_model_buffer;
};

} // namespace intel_cpu
} // namespace ov
} // namespace intel_cpu
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class BlobContainer {
virtual bool release_from_memory() {
OPENVINO_THROW("BlobContainer::release_from_memory() method is not implemented!");
}

virtual ~BlobContainer() = default;
};

class BlobContainerVector : public BlobContainer {
Expand Down Expand Up @@ -147,9 +149,7 @@ class IGraph : public std::enable_shared_from_this<IGraph> {
// first inference starts running
std::mutex _mutex;

<<<<<<< HEAD
<<<<<<< HEAD
std::vector<uint8_t> _blob;
std::unique_ptr<BlobContainer> _blob;

uint32_t _unique_id = 0;
uint32_t _last_submitted_id;
Expand All @@ -161,12 +161,6 @@ class IGraph : public std::enable_shared_from_this<IGraph> {
std::optional<std::size_t> _batch_size = std::nullopt;

Logger _logger;
=======
std::shared_ptr<ov::AlignedBuffer> _blob;
>>>>>>> 25b5c05976 (Keep `shared_ptr` of blob in IGraph to fix `export_model` for import scenario)
=======
std::unique_ptr<BlobContainer> _blob;
>>>>>>> 94e33c4e24 (Add `BlobContainer` class and derivates for each `std::vector<uint8_t>` and `std::shared_ptr<ov::AlignedBuffer>` blob types)
};

} // namespace intel_npu
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ class ICompilerAdapter {
virtual ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const = 0;

virtual ~ICompilerAdapter() = default;

private:
ov::intel_npu::CompilerType _compilerType;
};

//------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 539c459

Please sign in to comment.