forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CPU] Code generation: FakeQuantize decomposition & common transforma…
…tions - tests #2
- Loading branch information
Showing
6 changed files
with
306 additions
and
54 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/tests/functional/inference_engine/snippets/src/pass/fake_quantize_decomposition_test.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,58 @@ | ||
// Copyright (C) 2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "common_test_utils/ngraph_test_utils.hpp" | ||
#include "snippets/pass/common_optimizations.hpp" | ||
#include "snippets/pass/constant_folding.hpp" | ||
#include "fake_quantize_function.hpp" | ||
|
||
// TODO: to dbug only | ||
#include "snippets/op/subgraph.hpp" | ||
|
||
namespace ov { | ||
namespace test { | ||
namespace snippets { | ||
|
||
namespace { | ||
std::shared_ptr<ngraph::snippets::op::Subgraph> getSubgraph(const std::shared_ptr<Model>& f) { | ||
std::shared_ptr<ngraph::snippets::op::Subgraph> subgraph; | ||
for (const auto& op : f->get_ops()) { | ||
auto tmp_subgraph = as_type_ptr<ngraph::snippets::op::Subgraph>(op); | ||
if (tmp_subgraph != nullptr) { | ||
NGRAPH_CHECK(subgraph == nullptr, "function contains more than one subgraph"); | ||
subgraph = tmp_subgraph; | ||
} | ||
} | ||
return subgraph; | ||
} | ||
} // namespace | ||
|
||
class FakeQuantizeDecompositionTest : public TransformationTestsF { | ||
public: | ||
void register_passes() { | ||
manager.register_pass<ngraph::snippets::pass::CommonOptimizations>(); | ||
manager.register_pass<ngraph::snippets::pass::ConstantFolding>(); | ||
} | ||
|
||
void TearDown() override { | ||
TransformationTestsF::TearDown(); | ||
|
||
auto body = getSubgraph(function)->get_body(); | ||
auto body_ref = getSubgraph(function_ref)->get_body(); | ||
auto res = comparator.compare(body, body_ref); | ||
ASSERT_TRUE(res.valid) << res.message; | ||
} | ||
}; | ||
|
||
TEST_F(FakeQuantizeDecompositionTest, smoke_Snippets_FakeQuantizeDecomposition) { | ||
function = FakeQuantizeFunction::getSubgraphWithFakeQuantize({1, 3, 299, 299}, element::f32, {{}, {}, {}, {}}, true); | ||
function_ref = FakeQuantizeFunction::getSubgraphWithDecomposedFakeQuantize({1, 3, 299, 299}, element::f32, {{}, {}, {}, {}}, true); | ||
register_passes(); | ||
} | ||
|
||
} // namespace snippets | ||
} // namespace test | ||
} // 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
40 changes: 40 additions & 0 deletions
40
src/tests/ngraph_helpers/snippets_ngraph_functions/include/fake_quantize_function.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,40 @@ | ||
// Copyright (C) 2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "ngraph/ngraph.hpp" | ||
|
||
namespace ov { | ||
namespace test { | ||
namespace snippets { | ||
|
||
class FakeQuantizeFunction { | ||
public: | ||
// Parameter => [service ops for workaround to add FakeQuantize to Snippet] => FakeQuantize => Result | ||
static std::shared_ptr<ov::Model> get( | ||
const ngraph::Shape& inputShape, | ||
const element::Type inputType, | ||
const std::vector<ngraph::Shape>& fakeQuantizeShapes, | ||
const float zeroPoint); | ||
|
||
// Parameter => Subgraph (Parameter => FakeQuantize => Result) => Result | ||
static std::shared_ptr<ov::Model> getSubgraphWithFakeQuantize( | ||
const ngraph::Shape& inputShape, | ||
const element::Type inputType, | ||
const std::vector<ngraph::Shape>& fakeQuantizeShapes, | ||
const float zeroPoint); | ||
|
||
// Parameter => Subgraph (Parameter => element-wise ops from FakeQuantize decomposition results => Result) => Result | ||
static std::shared_ptr<ov::Model> getSubgraphWithDecomposedFakeQuantize( | ||
const ngraph::Shape& inputShape, | ||
const element::Type inputType, | ||
const std::vector<ngraph::Shape>& fakeQuantizeShapes, | ||
const float zeroPoint); | ||
}; | ||
|
||
} // namespace snippets | ||
} // namespace test | ||
} // namespace ov | ||
|
Oops, something went wrong.