Skip to content

Commit

Permalink
Fix snippets lowering test (add dummy scheduler)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanNovoselov committed Oct 12, 2022
1 parent 1b08a76 commit 2567c13
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/common/snippets/src/op/subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ snippets::Schedule snippets::op::Subgraph::generate(ngraph::pass::Manager& opt,
const auto& outerTileBegin = insertTileBegin(commonParams);
insertTileEnd(commonResults, outerTileBegin, outer_dim, outer_WA, 1, apply_increments);
}
m_body->validate_nodes_and_infer_types();
} else {
throw ngraph_error("Dynamic case is not supported yet");
}
Expand All @@ -522,7 +523,6 @@ snippets::Schedule snippets::op::Subgraph::generate(ngraph::pass::Manager& opt,
// }
// std::cerr << "\n";
// }
m_body->validate_nodes_and_infer_types();

// std::cerr << "Tile after is dumped";
// ov::pass::Serialize("tile_after.xml", "tile_after.bin").run_on_model(m_body);
Expand Down
4 changes: 3 additions & 1 deletion src/common/snippets/tests/include/lowering_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ class DummyGenerator : public ngraph::snippets::Generator {
class LoweringTests : public TransformationTestsF {
protected:
static std::shared_ptr<ngraph::snippets::op::Subgraph> getSubgraph(const std::shared_ptr<Model>& f);
static std::shared_ptr<ngraph::snippets::op::Subgraph> getLoweredSubgraph(const std::shared_ptr<Model>& f);
static std::shared_ptr<ngraph::snippets::op::Subgraph> getLoweredSubgraph(const std::shared_ptr<Model>& f,
const ov::PartialShape& master_shape);
static std::shared_ptr<ngraph::snippets::op::Subgraph> getTokenizedSubgraph(const std::shared_ptr<Model>& f);
ov::PartialShape master_shape{};
};

} // namespace snippets
Expand Down
8 changes: 5 additions & 3 deletions src/common/snippets/tests/src/lowering_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ DummyTargetMachine::DummyTargetMachine() {
jitters[ngraph::snippets::op::Scalar::get_type_info_static()] = dummy_functor;
jitters[ngraph::snippets::op::BroadcastMove::get_type_info_static()] = dummy_functor;
jitters[ngraph::snippets::op::Kernel::get_type_info_static()] = dummy_functor;
jitters[ngraph::snippets::op::Tile::get_type_info_static()] = dummy_functor;
jitters[ngraph::snippets::op::TileScheduler::get_type_info_static()] = dummy_functor;
jitters[ngraph::snippets::op::TileBegin::get_type_info_static()] = dummy_functor;
jitters[ngraph::snippets::op::TileEnd::get_type_info_static()] = dummy_functor;
}

std::shared_ptr<ngraph::snippets::op::Subgraph> LoweringTests::getSubgraph(const std::shared_ptr<Model>& f) {
Expand All @@ -52,9 +52,11 @@ std::shared_ptr<ngraph::snippets::op::Subgraph> LoweringTests::getSubgraph(const
return subgraph;
}

std::shared_ptr<ngraph::snippets::op::Subgraph> LoweringTests::getLoweredSubgraph(const std::shared_ptr<Model> &f) {
std::shared_ptr<ngraph::snippets::op::Subgraph> LoweringTests::getLoweredSubgraph(const std::shared_ptr<Model> &f,
const ov::PartialShape& master_shape) {
auto subgraph = getTokenizedSubgraph(f);
subgraph->set_generator(std::make_shared<DummyGenerator>());
subgraph->set_master_shape(master_shape);
subgraph->generate();
return subgraph;
}
Expand Down
5 changes: 4 additions & 1 deletion src/common/snippets/tests/src/pass/insert_load_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ void InsertLoadStoreTests::SetUp() {
broadcastShapes[0], broadcastShapes[1], broadcastShapes[2]) = this->GetParam();
snippets_function = std::make_shared<EltwiseThreeInputsLoweredFunction>(
std::vector<PartialShape> {inputShapes[0], inputShapes[1], inputShapes[2]}, broadcastShapes);
master_shape = inputShapes[0];
}

TEST_P(InsertLoadStoreTests, ThreeInputsEltwise) {
auto subgraph = getLoweredSubgraph(snippets_function->getOriginal());
PartialShape scheduler_shape({master_shape[master_shape.size() - 2],
master_shape[master_shape.size() - 1]});
auto subgraph = getLoweredSubgraph(snippets_function->getOriginal(), scheduler_shape);
function = subgraph->get_body();
function_ref = snippets_function->getLowered();
}
Expand Down
9 changes: 8 additions & 1 deletion src/common/snippets/tests/src/pass/insert_movebroadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ void InsertMoveBroadcastTests::SetUp() {
std::vector<Shape> broadcastShapes(2);
std::tie(inputShapes[0], inputShapes[1], broadcastShapes[0], broadcastShapes[1]) = this->GetParam();
snippets_function = std::make_shared<AddFunctionLoweredBroadcast>(std::vector<PartialShape> {inputShapes[0], inputShapes[1]}, broadcastShapes);
if (inputShapes[0].size() != inputShapes[1].size())
IE_THROW() << "Expected input shapes of the same size";
master_shape = {};
for (int i = 0; i < inputShapes[0].size(); i++)
master_shape.push_back(static_cast<int64_t>(std::max(inputShapes[0][i], inputShapes[1][i])));
}

TEST_P(InsertMoveBroadcastTests, AddBroadcast) {
auto subgraph = getLoweredSubgraph(snippets_function->getOriginal());
PartialShape scheduler_shape({master_shape[master_shape.size() - 2],
master_shape[master_shape.size() - 1]});
auto subgraph = getLoweredSubgraph(snippets_function->getOriginal(), scheduler_shape);
function = subgraph->get_body();
function_ref = snippets_function->getLowered();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common_test_utils/data_utils.hpp"
#include <snippets/snippets_isa.hpp>
#include "ngraph_functions/builders.hpp"
#include <snippets/op/tile_helpers.hpp>

namespace ov {
namespace test {
Expand All @@ -29,7 +30,24 @@ std::shared_ptr<ov::Model> AddFunctionLoweredBroadcast::initLowered() const {
}
auto add = std::make_shared<op::v1::Add>(add_input0, add_input1);
auto store = std::make_shared<ngraph::snippets::op::Store>(add);
return std::make_shared<ov::Model>(NodeVector{store}, ParameterVector{data0, data1});
ParameterVector input_params {data0, data1};
auto model = std::make_shared<ov::Model>(NodeVector{store}, input_params);

// Create dummy scheduler to pass graph comparison tests
// Note that if there is more than one results, they should be reverted
ResultVector results({model->get_results()[0]});
const auto& innerTileBegin = ngraph::snippets::op::insertTileBegin(input_params);
std::vector<bool> apply_increments(input_params.size() + results.size(), true);
const auto& innerTileEnd = insertTileEnd(results, innerTileBegin, 1, 1, 1, apply_increments);
auto outer_WA = std::accumulate(input_shapes.begin(), input_shapes.end(), 0,
[](int64_t max_val, const PartialShape& ps) {
return std::max(ps[ps.size() - 2].get_length(), max_val);
});
if (outer_WA > 1) {
const auto& outerTileBegin = ngraph::snippets::op::insertTileBegin(input_params);
insertTileEnd(results, outerTileBegin, 0, 1, 1, apply_increments);
}
return model;
}
std::shared_ptr<ov::Model> EltwiseThreeInputsLoweredFunction::initLowered() const {
// todo: implement conversion between std::vector<size_t> and std::vector<Shape>
Expand Down Expand Up @@ -60,12 +78,6 @@ std::shared_ptr<ov::Model> EltwiseThreeInputsLoweredFunction::initLowered() cons
const std::vector<float> const_values = CommonTestUtils::generate_float_numbers(1, -10., 10.);
auto sub_scalar = std::make_shared<ngraph::snippets::op::Scalar>(precision, Shape{1}, const_values[0]);
std::shared_ptr<Node> sub_load;
// Todo: Uncomment when invalid read in vector tile will be fixed
// if (input_shapes[2].back() == 1)
// sub_load = std::make_shared<snippets::op::ScalarLoad>(input_params[2]);
// else
// sub_load = std::make_shared<snippets::op::Load>(input_params[2]);
// remove when the code above is enabled:
sub_load = std::make_shared<ngraph::snippets::op::Load>(input_params[2]);
auto sub = std::make_shared<op::v1::Subtract>(sub_load, sub_scalar);
std::shared_ptr<Node> sub_out;
Expand All @@ -75,7 +87,23 @@ std::shared_ptr<ov::Model> EltwiseThreeInputsLoweredFunction::initLowered() cons
sub_out = std::make_shared<ngraph::snippets::op::BroadcastMove>(sub, broadcast_shapes[2]);
auto mul = std::make_shared<op::v1::Multiply>(add, sub_out);
auto store = std::make_shared<ngraph::snippets::op::Store>(mul);
return std::make_shared<ov::Model>(NodeVector{store}, input_params);
auto model = std::make_shared<ov::Model>(NodeVector{store}, input_params);

// Create dummy scheduler to pass graph comparison tests
// Note that if there is more than one results, they should be reverted
ResultVector results({model->get_results()[0]});
const auto& innerTileBegin = ngraph::snippets::op::insertTileBegin(input_params);
std::vector<bool> apply_increments(input_params.size() + results.size(), true);
const auto& innerTileEnd = insertTileEnd(results, innerTileBegin, 1, 1, 1, apply_increments);
auto outer_WA = std::accumulate(input_shapes.begin(), input_shapes.end(), 0,
[](int64_t max_val, const PartialShape& ps) {
return std::max(ps[ps.size() - 2].get_length(), max_val);
});
if (outer_WA > 1) {
const auto& outerTileBegin = ngraph::snippets::op::insertTileBegin(input_params);
insertTileEnd(results, outerTileBegin, 0, 1, 1, apply_increments);
}
return model;
}
} // namespace snippets
} // namespace test
Expand Down

0 comments on commit 2567c13

Please sign in to comment.