Skip to content

Commit

Permalink
Force move data from vector to stream
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-intel committed Sep 10, 2024
1 parent 9969f9f commit bf88d1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/plugins/intel_npu/src/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ov_add_plugin(NAME ${NPU_PLUGIN_TARGET}
VERSION_DEFINES_FOR ${NPU_PLUGIN_ENGINE_SOURCE_FILE}
)

set_target_properties(${TARGET_NAME} PROPERTIES CXX_STANDARD 20)
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})

Expand Down
31 changes: 29 additions & 2 deletions src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,37 @@ std::shared_ptr<ov::ISyncInferRequest> CompiledModel::create_sync_infer_request(
"the \"ov::ISyncInferRequest\" class");
}

template <typename T>
auto extract_vector_data(std::vector<T>& vec) {
union U {
std::vector<T> _v;
~U() {}
} u = {std::move(vec)};
return;
};

template <class ElemT, class TraitsT>
class custom_string : public std::basic_string<ElemT, TraitsT> {
public:
using base = std::basic_string<ElemT, TraitsT>;

custom_string(ElemT* p, size_t size, size_t capacity) {
bool [[maybe_unused]] b = base::_Move_assign_from_buffer(p, size, capacity);
}
};
using custom_string_char = custom_string<char, std::char_traits<char>>;

void CompiledModel::export_model(std::ostream& stream) const {
_logger.debug("CompiledModel::export_model");
const auto&& blob = _compiler->getCompiledNetwork(_networkPtr);
stream.write(reinterpret_cast<const char*>(blob.data()), blob.size());
auto blob = std::move(_compiler->getCompiledNetwork(_networkPtr));
auto ptr = blob.data();
auto length = blob.size();
auto cap = blob.capacity();
extract_vector_data(blob);
custom_string_char cs((char*)ptr, length, cap);
std::ostringstream oss(std::move(cs));
*((std::ostringstream*)&stream) = std::move(oss);

std::stringstream str;
str << "Blob size: " << blob.size() << ", hash: " << std::hex << hash(blob);
_logger.info(str.str().c_str());
Expand Down

0 comments on commit bf88d1f

Please sign in to comment.