Skip to content

Commit

Permalink
fix coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
xczhai committed Sep 26, 2023
1 parent 7064bf9 commit ee9ff4f
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/frontends/paddle/src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,27 @@ bool normalize_framework_node(const std::shared_ptr<FrameworkNode>& node,
return true;
}

std::istream* variant_to_stream_ptr(const ov::Any& variant, std::ifstream& ext_stream, std::stringstream& ext_stream2) {
std::istream* variant_to_stream_ptr(const ov::Any& variant, std::ifstream& ext_ifstream, std::stringstream& ext_sstream) {
if (variant.is<std::istream*>()) {
return variant.as<std::istream*>();
} else if (variant.is<std::shared_ptr<ngraph::runtime::AlignedBuffer>>()) {
auto& aligned_weights_buffer = variant.as<std::shared_ptr<ngraph::runtime::AlignedBuffer>>();
auto filesize = aligned_weights_buffer->size();
auto buf_ptr = aligned_weights_buffer->get_ptr<char>();
ext_stream2.write(buf_ptr, filesize);
FRONT_END_INITIALIZATION_CHECK(ext_stream2 && ext_stream2.good(), "[dbg] Cannot open model file.");
return &ext_stream2;
ext_sstream.write(aligned_weights_buffer->get_ptr<char>(), aligned_weights_buffer->size());
FRONT_END_INITIALIZATION_CHECK(ext_sstream && ext_sstream.good(), "Cannot open ov::tensor.");
return &ext_sstream;
} else if (variant.is<std::string>()) {
const auto& model_path = variant.as<std::string>();
ext_stream.open(model_path, std::ios::in | std::ifstream::binary);
}
ext_ifstream.open(model_path, std::ios::in | std::ifstream::binary);
}
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
else if (variant.is<std::wstring>()) {
const auto& model_path = variant.as<std::wstring>();
ext_stream.open(model_path.c_str(), std::ios::in | std::ifstream::binary);
ext_ifstream.open(model_path.c_str(), std::ios::in | std::ifstream::binary);
}
#endif

FRONT_END_INITIALIZATION_CHECK(ext_stream && ext_stream.is_open(), "Cannot open model file.");
return &ext_stream;
FRONT_END_INITIALIZATION_CHECK(ext_ifstream && ext_ifstream.is_open(), "Cannot open model file.");
return &ext_ifstream;
}
} // namespace

Expand Down Expand Up @@ -430,10 +428,10 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& variants) const
}
} else if (variants.size() == 2 + extra_variants_num) {
// The case when .pdmodel and .pdparams files are provided
std::ifstream model_stream, weights_stream;
std::stringstream model_stream2, weights_stream2;
std::istream* p_model_stream = paddle::variant_to_stream_ptr(variants[0], model_stream, model_stream2);
std::istream* p_weights_stream = paddle::variant_to_stream_ptr(variants[1], weights_stream, weights_stream2);
std::ifstream model_ifstream, weights_ifstream;
std::stringstream model_sstream, weights_sstream;
std::istream* p_model_stream = paddle::variant_to_stream_ptr(variants[0], model_ifstream, model_sstream);
std::istream* p_weights_stream = paddle::variant_to_stream_ptr(variants[1], weights_ifstream, weights_sstream);
if (p_model_stream && p_weights_stream) {
return std::make_shared<InputModel>(std::vector<std::istream*>{p_model_stream, p_weights_stream},
m_telemetry);
Expand Down

0 comments on commit ee9ff4f

Please sign in to comment.