forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Snippets] LIR serialization improvements (openvinotoolkit#21291)
- Loading branch information
Showing
12 changed files
with
270 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/common/snippets/include/snippets/lowered/pass/serialize_base.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "pass.hpp" | ||
#include "snippets/lowered/linear_ir.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
/** | ||
* @interface SerializeBase | ||
* @brief Base class for LinearIR serialization passes | ||
* @ingroup snippets | ||
*/ | ||
class SerializeBase : public Pass { | ||
public: | ||
OPENVINO_RTTI("SerializeBase", "Pass") | ||
SerializeBase(const std::string& xml_path); | ||
|
||
protected: | ||
std::string get_bin_path_from_xml(const std::string& xml_path); | ||
|
||
const std::string m_xml_path; | ||
const std::string m_bin_path; | ||
}; | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
30 changes: 30 additions & 0 deletions
30
src/common/snippets/include/snippets/lowered/pass/serialize_control_flow.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "serialize_base.hpp" | ||
#include "snippets/lowered/linear_ir.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
/** | ||
* @interface SerializeControlFlow | ||
* @brief Serializes control flow graph of LinearIR | ||
* @ingroup snippets | ||
*/ | ||
class SerializeControlFlow : public SerializeBase { | ||
public: | ||
OPENVINO_RTTI("SerializeControlFlow", "Pass", SerializeBase) | ||
SerializeControlFlow(const std::string& xml_path) : SerializeBase(xml_path) {} | ||
bool run(LinearIR& linear_ir) override; | ||
}; | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
32 changes: 32 additions & 0 deletions
32
src/common/snippets/include/snippets/lowered/pass/serialize_data_flow.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "serialize_base.hpp" | ||
#include "snippets/lowered/linear_ir.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
/** | ||
* @interface SerializeDataFlow | ||
* @brief Serializes data flow graph of LinearIR | ||
* @attention - This pass can not be run on the LinearIR after tail loop insertion. | ||
* @attention - Control flow operations (e.g. LoopBegin/LoopEnd) are not serialized | ||
* @ingroup snippets | ||
*/ | ||
class SerializeDataFlow : public SerializeBase { | ||
public: | ||
OPENVINO_RTTI("SerializeDataFlow", "Pass", SerializeBase) | ||
SerializeDataFlow(const std::string& xml_path) : SerializeBase(xml_path) {} | ||
bool run(LinearIR& linear_ir) override; | ||
}; | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "snippets/lowered/pass/serialize_base.hpp" | ||
|
||
#include "snippets/itt.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
SerializeBase::SerializeBase(const std::string& xml_path) | ||
: m_xml_path(xml_path), | ||
m_bin_path(get_bin_path_from_xml(xml_path)) {} | ||
|
||
std::string SerializeBase::get_bin_path_from_xml(const std::string& xml_path) { | ||
#if defined(__linux__) | ||
return "/dev/null"; | ||
#else | ||
return ""; | ||
#endif | ||
} | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
55 changes: 55 additions & 0 deletions
55
src/common/snippets/src/lowered/pass/serialize_control_flow.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "snippets/lowered/pass/serialize_control_flow.hpp" | ||
|
||
#include "openvino/pass/serialize.hpp" | ||
#include "snippets/itt.hpp" | ||
#include "snippets/lowered/linear_ir.hpp" | ||
#include "snippets/op/serialization_node.hpp" | ||
#include "snippets/snippets_isa.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
bool SerializeControlFlow::run(LinearIR& linear_ir) { | ||
OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::SerializeControlFlow") | ||
if (linear_ir.empty()) | ||
return false; | ||
|
||
auto first_node = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{}); | ||
first_node->set_friendly_name("Start"); | ||
first_node->get_rt_info()["execTimeMcs"] = 0; | ||
std::shared_ptr<Node> serialization_node = first_node; | ||
|
||
// This map allows to get LoopBegin serialization node by original LoopBegin node | ||
// It is used to draw an edge between LoopBegin and LoopEnd serialization nodes | ||
std::map<std::shared_ptr<snippets::op::LoopBegin>, std::shared_ptr<Node>> loops_map; | ||
for (const auto& expr : linear_ir) { | ||
const auto node = expr->get_node(); | ||
if (auto loop_end = ov::as_type_ptr<snippets::op::LoopEnd>(node)) { | ||
OPENVINO_ASSERT(loops_map.count(loop_end->get_loop_begin()), | ||
"Serialization can't find LoopBegin that corresponds to LoopEnd with friendly name ", | ||
loop_end->get_friendly_name()); | ||
auto loop_begin_serialization_node = loops_map.at(loop_end->get_loop_begin()); | ||
serialization_node = std::make_shared<op::SerializationNode>(ov::OutputVector{serialization_node, loop_begin_serialization_node}, expr); | ||
} else { | ||
serialization_node = std::make_shared<op::SerializationNode>(ov::OutputVector{serialization_node}, expr); | ||
if (auto loop_begin = ov::as_type_ptr<snippets::op::LoopBegin>(node)) { | ||
loops_map[loop_begin] = serialization_node; | ||
} | ||
} | ||
} | ||
auto last_node = std::make_shared<ov::op::v0::Result>(serialization_node); | ||
last_node->set_friendly_name("End"); | ||
const auto model = std::make_shared<ov::Model>(ResultVector{last_node}, ParameterVector{first_node}, "Lowered_IR_Control_Flow"); | ||
return ov::pass::Serialize(m_xml_path, m_bin_path).run_on_model(model); | ||
} | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
57 changes: 57 additions & 0 deletions
57
src/common/snippets/src/lowered/pass/serialize_data_flow.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "snippets/lowered/pass/serialize_data_flow.hpp" | ||
|
||
#include "openvino/pass/serialize.hpp" | ||
#include "snippets/itt.hpp" | ||
#include "snippets/lowered/linear_ir.hpp" | ||
#include "snippets/op/serialization_node.hpp" | ||
#include "snippets/snippets_isa.hpp" | ||
|
||
namespace ov { | ||
namespace snippets { | ||
namespace lowered { | ||
namespace pass { | ||
|
||
bool SerializeDataFlow::run(LinearIR& linear_ir) { | ||
OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::SerializeDataFlow") | ||
if (linear_ir.empty()) | ||
return false; | ||
|
||
ov::ResultVector results; | ||
ov::ParameterVector parameters; | ||
std::map<ExpressionPtr, std::shared_ptr<Node>> ops_map; | ||
const auto serialization_mode = op::SerializationNode::SerializationMode::DATA_FLOW; | ||
for (const auto& expr : linear_ir) { | ||
const auto node = expr->get_node(); | ||
ov::OutputVector inputs(expr->get_input_count()); | ||
for (size_t i = 0; i < expr->get_input_count(); ++i) { | ||
const auto& input_expr = expr->get_input_port_connector(i)->get_source().get_expr(); | ||
OPENVINO_ASSERT(ops_map.count(input_expr), "input node wasn't found during serialization"); | ||
inputs[i] = ops_map[input_expr]->output(expr->get_input_port_connector(i)->get_source().get_index()); | ||
} | ||
if (auto ioexpr = std::dynamic_pointer_cast<IOExpression>(expr)) { | ||
if (ioexpr->get_type() == IOExpression::io_type::INPUT) { | ||
const auto parameter = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{}); | ||
ops_map[ioexpr] = parameter; | ||
parameters.push_back(parameter); | ||
} else { | ||
const auto result = std::make_shared<ov::op::v0::Result>(inputs[0]); | ||
ops_map[ioexpr] = result; | ||
results.push_back(result); | ||
} | ||
} else { | ||
const auto serialization_node = std::make_shared<op::SerializationNode>(inputs, expr, serialization_mode); | ||
ops_map[expr] = serialization_node; | ||
} | ||
} | ||
const auto model = std::make_shared<ov::Model>(results, parameters, "Lowered_IR_Data_Flow"); | ||
return ov::pass::Serialize(m_xml_path, m_bin_path).run_on_model(model); | ||
} | ||
|
||
} // namespace pass | ||
} // namespace lowered | ||
} // namespace snippets | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.