Skip to content

Commit

Permalink
Merge branch 'master' into zheng/skip_target_layers_in_sit
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemySkrebkov authored Dec 13, 2024
2 parents adb599a + 59984e9 commit 854d3e6
Show file tree
Hide file tree
Showing 19 changed files with 554 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ make sure to :doc:`install OpenVINO with GenAI <../../get-started/install-openvi
image_write("baseline.bmp", image)
For more information, refer to the
`Python sample <https://github.com/openvinotoolkit/openvino.genai/tree/master/samples/python/text2image/>`__
`Python sample <https://github.com/openvinotoolkit/openvino.genai/tree/master/samples/python/image_generation>`__

.. tab-item:: C++
:sync: cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "itt.hpp"
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
#include "openvino/op/ops.hpp"
#include "openvino/pass/constant_folding.hpp"
#include "openvino/pass/manager.hpp"
Expand Down Expand Up @@ -1405,6 +1406,13 @@ bool fuse_type_to_constant(const std::shared_ptr<ov::Node>& node,
new_const->validate_and_infer_types();
new_const->set_friendly_name(constant->get_friendly_name());
ov::copy_runtime_info(constant, new_const);

const auto& rt_info = node->get_rt_info();
auto weightless_caching_attr = rt_info.find(ov::WeightlessCacheAttribute::get_type_info_static());
if (weightless_caching_attr != rt_info.end()) {
new_const->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()] =
weightless_caching_attr->second;
}
return true;
}
return false;
Expand Down
36 changes: 36 additions & 0 deletions src/common/transformations/tests/utils/convert_precision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "common_test_utils/ov_test_utils.hpp"
#include "openvino/core/model.hpp"
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
#include "openvino/opsets/opset1.hpp"
#include "openvino/opsets/opset10.hpp"
#include "openvino/opsets/opset15.hpp"
Expand Down Expand Up @@ -2702,3 +2703,38 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_orig_types
FunctionsComparator::Result result = func_comparator(model_ref, model);
ASSERT_TRUE(result.valid) << result.message;
}

TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_weightless_cache_info_as_rt_attribute) {
pass::Manager manager;

auto some_value = opset10::Constant::create(element::f32, Shape{1}, {2});
auto& node_rt_info = some_value->get_rt_info();
ov::WeightlessCacheAttribute attr(element::f32.size(), 0, element::f32);
node_rt_info[ov::WeightlessCacheAttribute::get_type_info_static()] = attr;

ov::ParameterVector inputParams;
ov::ResultVector results;
results.push_back(std::make_shared<ov::op::v0::Result>(some_value->output(0)));
auto model = std::make_shared<ov::Model>(results, inputParams);

type_to_fuse_map empty_type_to_fuse_map = {};
bool keep_precision_sensitive_in_fp32 = false;
bool convert_input_output_precision = false;
bool store_original_precision_as_rt_attribute = true;
manager.register_pass<pass::ConvertPrecision>(precisions_map{{element::f32, element::f16}},
empty_type_to_fuse_map,
keep_precision_sensitive_in_fp32,
convert_input_output_precision,
store_original_precision_as_rt_attribute);
manager.run_passes(model);

const auto& ops = model->get_ops();
auto it = std::find_if(ops.begin(), ops.end(), [](const std::shared_ptr<Node>& node) {
return ov::op::util::is_constant(node);
});

ASSERT_TRUE(it != ops.end());
const auto& new_rt_info = (*it)->get_rt_info();
auto weightless_caching_attr_it = new_rt_info.find(ov::WeightlessCacheAttribute::get_type_info_static());
ASSERT_TRUE(weightless_caching_attr_it != new_rt_info.end());
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include "openvino/core/core_visibility.hpp"
#include "openvino/core/node.hpp"
#include "openvino/core/runtime_attribute.hpp"

namespace ov {
Expand All @@ -25,14 +26,16 @@ class OPENVINO_API WeightlessCacheAttribute : public RuntimeAttribute {

WeightlessCacheAttribute() = delete;

WeightlessCacheAttribute(size_t original_size, size_t bin_offset)
WeightlessCacheAttribute(size_t original_size, size_t bin_offset, ov::element::Type original_dtype)
: original_size(original_size),
bin_offset(bin_offset) {}
bin_offset(bin_offset),
original_dtype(original_dtype) {}

bool is_copyable() const override;

size_t original_size;
size_t bin_offset;
ov::element::Type original_dtype;
};

} // namespace ov
30 changes: 26 additions & 4 deletions src/core/include/openvino/core/graph_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "openvino/op/parameter.hpp"
#include "openvino/pass/serialize.hpp"

#ifdef OPENVINO_CPP_VER_17
# include <filesystem>
#endif

namespace ov {

OPENVINO_API
Expand Down Expand Up @@ -288,27 +292,45 @@ bool replace_node_update_name(const std::shared_ptr<Node>& target, const std::sh
/// \param bin_path Path where .bin file will be saved (optional).
/// The same name as for xml_path will be used by default.
/// \param version Version of the generated IR (optional).
/// \{
OPENVINO_API
void serialize(const std::shared_ptr<const ov::Model>& m,
const std::string& xml_path,
const std::string& bin_path = "",
ov::pass::Serialize::Version version = ov::pass::Serialize::Version::UNSPECIFIED);

#ifdef OPENVINO_CPP_VER_17
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
void serialize(const std::shared_ptr<const ov::Model>& m,
const Path& xml_path,
const Path& bin_path = {""},
ov::pass::Serialize::Version version = ov::pass::Serialize::Version::UNSPECIFIED) {
serialize(m, xml_path.string(), bin_path.string(), version);
}
#endif
/// \}

/// \brief Save given model into IR. Floating point weights are compressed to FP16 by default.
/// This method saves a model to IR applying all necessary transformations that usually applied
/// in model conversion flow provided by mo tool. Paricularly, floatting point weights are compressed to FP16.
/// in model conversion flow provided by mo tool. Particularly, floating point weights are compressed to FP16.
/// \param model Model which will be converted to IR representation.
/// \param output_model Path to the output model file, must have extension .xml
/// \param compress_to_fp16 Whether to compress floatting point weights to FP16 (true by default)
/// \param compress_to_fp16 Whether to compress floating point weights to FP16 (true by default)
OPENVINO_API
void save_model(const std::shared_ptr<const ov::Model>& model,
const std::string& output_model,
bool compress_to_fp16 = true);

#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT)
OPENVINO_API
void save_model(const std::shared_ptr<const ov::Model>& model,
const std::wstring& output_model,
bool compress_to_fp16 = true);
#endif
} // namespace ov

#ifdef OPENVINO_CPP_VER_17
template <class Path, std::enable_if_t<std::is_same_v<Path, std::filesystem::path>>* = nullptr>
void save_model(const std::shared_ptr<const ov::Model>& model, const Path& output_model, bool compress_to_fp16 = true) {
save_model(model, output_model.string(), compress_to_fp16);
}
#endif
} // namespace ov
11 changes: 11 additions & 0 deletions src/core/include/openvino/pass/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "openvino/opsets/opset.hpp"
#include "openvino/pass/pass.hpp"

#ifdef OPENVINO_CPP_VER_17
# include <filesystem>
#endif

namespace ov {
namespace pass {

Expand All @@ -35,6 +39,13 @@ class OPENVINO_API Serialize : public ov::pass::ModelPass {

Serialize(const std::string& xmlPath, const std::string& binPath, Version version = Version::UNSPECIFIED);

#ifdef OPENVINO_CPP_VER_17
Serialize(const std::filesystem::path& xmlPath,
const std::filesystem::path& binPath,
Version version = Version::UNSPECIFIED)
: Serialize(xmlPath.string(), binPath.string(), version) {}
#endif

private:
std::ostream* m_xmlFile;
std::ostream* m_binFile;
Expand Down
41 changes: 41 additions & 0 deletions src/core/tests/pass/serialization/deterministicity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,47 @@ TEST_P(SerializationDeterministicityInputOutputTest, FromIrModel) {
EXPECT_TRUE(files_equal(xml_2, xml_1));
}

#ifdef OPENVINO_CPP_VER_17
TEST_P(SerializationDeterministicityInputOutputTest, FromOvModelBybPath) {
auto irVersion = GetParam();

std::shared_ptr<ov::Model> modelRef;
{
auto parameter0 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 3, 22, 22});
parameter0->set_friendly_name("input0");
auto result0 = std::make_shared<ov::opset1::Result>(parameter0);
result0->set_friendly_name("output0");
auto parameter1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 3, 22, 22});
parameter1->set_friendly_name("input1");
auto result1 = std::make_shared<ov::opset1::Result>(parameter1);
result1->set_friendly_name("output1");
modelRef =
std::make_shared<ov::Model>(ov::NodeVector{result0, result1}, ov::ParameterVector{parameter0, parameter1});
}

auto& expected1 = modelRef;
const auto out_xml_path = std::filesystem::path(m_out_xml_path_1);
const auto out_bin_path = std::filesystem::path(m_out_bin_path_1);
ov::pass::Serialize(out_xml_path, out_bin_path, irVersion).run_on_model(modelRef);
auto expected2 = ov::test::readModel(m_out_xml_path_1, m_out_bin_path_1);

ov::pass::Serialize(m_out_xml_path_2, m_out_bin_path_2, irVersion).run_on_model(expected2);

EXPECT_EQ(input0Name, expected1->input(0).get_node()->get_friendly_name());
EXPECT_EQ(input1Name, expected1->input(1).get_node()->get_friendly_name());
EXPECT_EQ(output0Name, expected1->output(0).get_node()->get_friendly_name());
EXPECT_EQ(output1Name, expected1->output(1).get_node()->get_friendly_name());
EXPECT_EQ(input0Name, expected2->input(0).get_node()->get_friendly_name());
EXPECT_EQ(input1Name, expected2->input(1).get_node()->get_friendly_name());
EXPECT_EQ(output0Name, expected2->output(0).get_node()->get_friendly_name());
EXPECT_EQ(output1Name, expected2->output(1).get_node()->get_friendly_name());

std::ifstream xml_1(m_out_xml_path_1, std::ios::in | std::ios::binary);
std::ifstream xml_2(m_out_xml_path_2, std::ios::in | std::ios::binary);
EXPECT_TRUE(files_equal(xml_1, xml_2));
}
#endif

INSTANTIATE_TEST_SUITE_P(DeterministicityInputOutput,
SerializationDeterministicityInputOutputTest,
::testing::Values(ov::pass::Serialize::Version::IR_V10, ov::pass::Serialize::Version::IR_V11));
17 changes: 17 additions & 0 deletions src/core/tests/pass/serialization/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ TEST_P(SerializationTest, SaveModel) {
});
}

#ifdef OPENVINO_CPP_VER_17
TEST_P(SerializationTest, CompareFunctionsByPath) {
const auto out_xml_path = std::filesystem::path(m_out_xml_path);
const auto out_bin_path = std::filesystem::path(m_out_bin_path);
CompareSerialized([&out_xml_path, &out_bin_path](const auto& m) {
ov::pass::Serialize(out_xml_path, out_bin_path).run_on_model(m);
});
}

TEST_P(SerializationTest, SaveModelByPath) {
const auto out_xml_path = std::filesystem::path(m_out_xml_path);
CompareSerialized([&out_xml_path](const auto& m) {
ov::save_model(m, out_xml_path, false);
});
}
#endif

INSTANTIATE_TEST_SUITE_P(
IRSerialization,
SerializationTest,
Expand Down
6 changes: 4 additions & 2 deletions src/frontends/ir/src/ir_deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,12 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:
}
const auto size = dn.attribute("size");
const auto offset = dn.attribute("offset");
if (size && offset) {
const auto element_type = dn.attribute("element_type");
if (size && offset && element_type) {
rtInfo[ov::WeightlessCacheAttribute::get_type_info_static()] =
ov::WeightlessCacheAttribute(static_cast<size_t>(pugixml::get_uint64_attr(dn, "size")),
static_cast<size_t>(pugixml::get_uint64_attr(dn, "offset")));
static_cast<size_t>(pugixml::get_uint64_attr(dn, "offset")),
ov::element::Type(pugixml::get_str_attr(dn, "element_type")));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,58 @@ std::set<std::vector<element::Type>> jit_logical_and_emitter::get_supported_prec
return {{element::f32, element::f32}};
}

/// LOGICAL_OR ///
jit_logical_or_emitter::jit_logical_or_emitter(dnnl::impl::cpu::aarch64::jit_generator* host,
dnnl::impl::cpu::aarch64::cpu_isa_t host_isa,
const std::shared_ptr<ov::Node>& node)
: jit_emitter(host, host_isa, node, get_arithmetic_binary_exec_precision(node)) {
prepare_table();
}

jit_logical_or_emitter::jit_logical_or_emitter(dnnl::impl::cpu::aarch64::jit_generator* host,
dnnl::impl::cpu::aarch64::cpu_isa_t host_isa,
const ov::element::Type exec_prc)
: jit_emitter(host, host_isa, exec_prc) {
prepare_table();
}

size_t jit_logical_or_emitter::get_inputs_count() const { return 2; }

size_t jit_logical_or_emitter::get_aux_vecs_count() const { return 1; }

size_t jit_logical_or_emitter::get_aux_gprs_count() const { return 1; }

void jit_logical_or_emitter::emit_impl(const std::vector<size_t> &in_vec_idxs, const std::vector<size_t> &out_vec_idxs) const {
if (host_isa_ == dnnl::impl::cpu::aarch64::asimd) {
emit_isa<dnnl::impl::cpu::aarch64::asimd>(in_vec_idxs, out_vec_idxs);
} else {
OV_CPU_JIT_EMITTER_THROW("Can't create jit eltwise kernel");
}
}

template <dnnl::impl::cpu::aarch64::cpu_isa_t isa>
void jit_logical_or_emitter::emit_isa(const std::vector<size_t> &in_vec_idxs, const std::vector<size_t> &out_vec_idxs) const {
OV_CPU_JIT_EMITTER_ASSERT(exec_prc_ == ov::element::f32, "unsupported precision: " + exec_prc_.to_string());

using TReg = typename dnnl::impl::cpu::aarch64::cpu_isa_traits<isa>::TReg;
const TReg src1 = TReg(in_vec_idxs[0]);
const TReg src2 = TReg(in_vec_idxs[1]);
const TReg dst = TReg(out_vec_idxs[0]);
const TReg aux = TReg(aux_vec_idxs[0]);

h->orr(dst.b16, src1.b16, src2.b16);
h->ld1r(aux.s, table_val2("one"));
h->and_(dst.b16, dst.b16, aux.b16);
}

void jit_logical_or_emitter::register_table_entries() {
push_arg_entry_of("one", 0x3f800000, true);
}

std::set<std::vector<element::Type>> jit_logical_or_emitter::get_supported_precisions(const std::shared_ptr<ov::Node>& node) {
return {{element::f32, element::f32}};
}

/// LOGICAL_NOT ///
jit_logical_not_emitter::jit_logical_not_emitter(dnnl::impl::cpu::aarch64::jit_generator* host,
dnnl::impl::cpu::aarch64::cpu_isa_t host_isa,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,34 @@ class jit_logical_and_emitter : public jit_emitter {
void register_table_entries() override;
};

class jit_logical_or_emitter : public jit_emitter {
public:
jit_logical_or_emitter(dnnl::impl::cpu::aarch64::jit_generator *host,
dnnl::impl::cpu::aarch64::cpu_isa_t host_isa,
const ov::element::Type exec_prc = ov::element::f32);

jit_logical_or_emitter(dnnl::impl::cpu::aarch64::jit_generator *host,
dnnl::impl::cpu::aarch64::cpu_isa_t host_isa,
const std::shared_ptr<ov::Node>& n);

size_t get_inputs_count() const override;

size_t get_aux_vecs_count() const override;

size_t get_aux_gprs_count() const override;

static std::set<std::vector<element::Type>> get_supported_precisions(
const std::shared_ptr<ov::Node>& node = nullptr);

private:
void emit_impl(const std::vector<size_t> &in_vec_idxs, const std::vector<size_t> &out_vec_idxs) const override;

template <dnnl::impl::cpu::aarch64::cpu_isa_t isa>
void emit_isa(const std::vector<size_t> &in_vec_idxs, const std::vector<size_t> &out_vec_idxs) const;

void register_table_entries() override;
};

class jit_logical_not_emitter : public jit_emitter {
public:
jit_logical_not_emitter(dnnl::impl::cpu::aarch64::jit_generator* host,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ bool JitEltwiseExecutor::isSupported(
Algorithm::EltwiseIsNaN,
Algorithm::EltwiseLessEqual,
Algorithm::EltwiseLogicalAnd,
Algorithm::EltwiseLogicalOr,
Algorithm::EltwiseLogicalNot,
Algorithm::EltwiseLogicalXor,
Algorithm::EltwiseMaximum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ std::shared_ptr<jit_emitter> jit_uni_eltwise_generic<isa>::create_eltwise_emitte
OV_CASE(Algorithm::EltwiseIsInf, ov::intel_cpu::aarch64::jit_is_inf_emitter),
OV_CASE(Algorithm::EltwiseLessEqual, ov::intel_cpu::aarch64::jit_less_equal_emitter),
OV_CASE(Algorithm::EltwiseLogicalAnd, ov::intel_cpu::aarch64::jit_logical_and_emitter),
OV_CASE(Algorithm::EltwiseLogicalOr, ov::intel_cpu::aarch64::jit_logical_or_emitter),
OV_CASE(Algorithm::EltwiseLogicalNot, ov::intel_cpu::aarch64::jit_logical_not_emitter),
OV_CASE(Algorithm::EltwiseLogicalXor, ov::intel_cpu::aarch64::jit_logical_xor_emitter),
OV_CASE(Algorithm::EltwiseIsNaN, ov::intel_cpu::aarch64::jit_is_nan_emitter),
Expand Down Expand Up @@ -845,6 +846,7 @@ std::set<std::vector<element::Type>> eltwise_precision_helper::get_supported_pre
OV_CASE(Algorithm::EltwiseIsNaN, jit_is_nan_emitter),
OV_CASE(Algorithm::EltwiseLessEqual, jit_less_equal_emitter),
OV_CASE(Algorithm::EltwiseLogicalAnd, jit_logical_and_emitter),
OV_CASE(Algorithm::EltwiseLogicalOr, jit_logical_or_emitter),
OV_CASE(Algorithm::EltwiseLogicalNot, jit_logical_not_emitter),
OV_CASE(Algorithm::EltwiseLogicalXor, jit_logical_xor_emitter),
OV_CASE(Algorithm::EltwiseMaximum, jit_maximum_emitter),
Expand Down
Loading

0 comments on commit 854d3e6

Please sign in to comment.