Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate speedup #6779

Merged
merged 7 commits into from
Jul 30, 2021
Merged

Validate speedup #6779

merged 7 commits into from
Jul 30, 2021

Conversation

pelszkow
Copy link
Contributor

@pelszkow pelszkow commented Jul 23, 2021

Details:

  • move some method to headers which allow it to be inline
  • PartialShape c-tors will consume (move) vector of Dimension
  • initialize map returning by get_type_info_map before main - purge static function member "mutex"
  • find in map and terminate if not found TypeInfo

Tickets:

  • 61261

Output:

  • FakeQuantize::validate_and_infer_types approximately speedup: 20%

@pelszkow pelszkow force-pushed the validate_speedup branch 3 times, most recently from 57cd128 to 528aa91 Compare July 28, 2021 05:31
@pelszkow pelszkow marked this pull request as ready for review July 28, 2021 12:20
@pelszkow pelszkow requested review from a team, tomdol, tsocha, ilyachur and blesniewski July 28, 2021 12:20
Copy link
Contributor

@ilyachur ilyachur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any measurements which show improvements?

@pelszkow
Copy link
Contributor Author

Do you have any measurements which show improvements?
master branch:

./unit-test --gtest_filter="IN*smoke_validation*"                                                                                                                                                                                                                           master
Note: Google Test filter = IN*smoke_validation*
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from INTERPRETER
[ RUN      ] INTERPRETER.smoke_validation_reshape
[[[[[[ 1.73853e+06us ]]]]]]
[       OK ] INTERPRETER.smoke_validation_reshape (1739 ms)
[ RUN      ] INTERPRETER.smoke_validation_fake_quantize
[[[[[[ 653971us ]]]]]]
[       OK ] INTERPRETER.smoke_validation_fake_quantize (654 ms)
[----------] 2 tests from INTERPRETER (2393 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (2393 ms total)
[  PASSED  ] 2 tests.

after this PR:

./unit-test --gtest_filter="IN*smoke_validation*"                                                                                                                                                                                                                 validate_speedup
Note: Google Test filter = IN*smoke_validation*
[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 2 tests from INTERPRETER
[ RUN      ] INTERPRETER.smoke_validation_reshape
[[[[[[ 1.40525e+06us ]]]]]]
[       OK ] INTERPRETER.smoke_validation_reshape (1405 ms)
[ RUN      ] INTERPRETER.smoke_validation_fake_quantize
[[[[[[ 403533us ]]]]]]
[       OK ] INTERPRETER.smoke_validation_fake_quantize (404 ms)
[----------] 2 tests from INTERPRETER (1809 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (1809 ms total)
[  PASSED  ] 2 tests.

Where tests looks like this:

diff --git a/ngraph/test/backend/fake_quantize.in.cpp b/ngraph/test/backend/fake_quantize.in.cpp
index 363e89b31..d5bb49490 100644
--- a/ngraph/test/backend/fake_quantize.in.cpp
+++ b/ngraph/test/backend/fake_quantize.in.cpp
@@ -31,6 +31,31 @@ using namespace ngraph;
 static std::string s_manifest = "${MANIFEST}";
 using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});

+NGRAPH_TEST(${BACKEND_NAME}, smoke_validation_fake_quantize)
+{
+    const Shape data_shape{1, 2, 3, 4};
+    const size_t levels = 4;
+    const auto data = std::make_shared<op::Parameter>(element::f32, data_shape);
+    const auto input_low = op::Constant::create(element::f32, Shape{}, {0.f});
+    const auto input_high = op::Constant::create(element::f32, Shape{}, {23.f});
+    const auto output_low = op::Constant::create(element::f32, Shape{}, {2.f});
+    const auto output_high = op::Constant::create(element::f32, Shape{}, {16.f});
+
+    const auto quantize = std::make_shared<op::FakeQuantize>(
+        data, input_low, input_high, output_low, output_high, levels);
+
+    const auto start_time = std::chrono::high_resolution_clock::now();
+    constexpr auto validation_rounds = 1000000ul;
+    for (size_t i = 0; i < validation_rounds; ++i)
+    {
+        quantize->validate_and_infer_types();
+    }
+    const float duration = std::chrono::duration_cast<std::chrono::microseconds>(
+                               std::chrono::high_resolution_clock::now() - start_time)
+                               .count();
+    std::cerr << "[[[[[[ " << duration << "us ]]]]]]" << std::endl;
+}
+
 namespace
 {
     template <typename T>
diff --git a/ngraph/test/backend/reshape.in.cpp b/ngraph/test/backend/reshape.in.cpp
index f49870bf1..cb30f54a7 100644
--- a/ngraph/test/backend/reshape.in.cpp
+++ b/ngraph/test/backend/reshape.in.cpp
@@ -32,6 +32,26 @@ static string s_manifest = "${MANIFEST}";

 using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});

+NGRAPH_TEST(${BACKEND_NAME}, smoke_validation_reshape)
+{
+    Shape shape_a{2, 2, 3};
+    auto A = make_shared<op::Parameter>(element::f32, shape_a);
+    Shape shape_r{12};
+    auto r = make_shared<op::v1::Reshape>(
+        A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
+
+    const auto start_time = std::chrono::high_resolution_clock::now();
+    constexpr auto validation_rounds = 1000000ul;
+    for (size_t i = 0; i < validation_rounds; ++i)
+    {
+        r->validate_and_infer_types();
+    }
+    const float duration = std::chrono::duration_cast<std::chrono::microseconds>(
+                               std::chrono::high_resolution_clock::now() - start_time)
+                               .count();
+    std::cerr << "[[[[[[ " << duration << "us ]]]]]]" << std::endl;
+}
+
 NGRAPH_TEST(${BACKEND_NAME}, reshape_t2v)
 {
     Shape shape_a{2, 2, 3};

@pelszkow pelszkow requested a review from ilyachur July 29, 2021 07:28
ngraph/core/src/partial_shape.cpp Show resolved Hide resolved
ngraph/core/src/type/element_type.cpp Outdated Show resolved Hide resolved
@pelszkow pelszkow requested a review from tomdol July 29, 2021 09:50
@pelszkow pelszkow force-pushed the validate_speedup branch 3 times, most recently from ecd4b3a to ddc0142 Compare July 30, 2021 04:25
@ilyachur ilyachur enabled auto-merge (squash) July 30, 2021 04:55
@ilyachur ilyachur merged commit 0861a5c into openvinotoolkit:master Jul 30, 2021
rnugmanx pushed a commit to rnugmanx/openvino that referenced this pull request Aug 26, 2021
* Add minor speedup changes.

* inline clip

* reduce clip calls

* more Interval::size - move to header

* terminate instead of throwing exception

* back to throw exception when element type was not found

* rename variable
andrei-cv pushed a commit to andrei-cv/openvino that referenced this pull request Aug 30, 2021
* Add minor speedup changes.

* inline clip

* reduce clip calls

* more Interval::size - move to header

* terminate instead of throwing exception

* back to throw exception when element type was not found

* rename variable
akuporos pushed a commit to akuporos/openvino that referenced this pull request Sep 29, 2021
* Add minor speedup changes.

* inline clip

* reduce clip calls

* more Interval::size - move to header

* terminate instead of throwing exception

* back to throw exception when element type was not found

* rename variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants