Skip to content

Tutorial for parallel_for_ and Universal Intrinsic (GSoC '21)#20361

Merged
alalek merged 12 commits intoopencv:masterfrom
r0hit05:master
Sep 15, 2021
Merged

Tutorial for parallel_for_ and Universal Intrinsic (GSoC '21)#20361
alalek merged 12 commits intoopencv:masterfrom
r0hit05:master

Conversation

@r0hit05
Copy link
Copy Markdown
Contributor

@r0hit05 r0hit05 commented Jul 5, 2021

This pull request is a part of the Google Summer of Code 2021 project. Here is an overview of the project:

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=linux,docs

@r0hit05 r0hit05 changed the title Tutorial for parallel_for_ and Universal Intrinsic, First Evaluation PR, GSoC '21 Tutorial for parallel_for_ and Universal Intrinsic (GSoC '21) Jul 9, 2021
@r0hit05 r0hit05 marked this pull request as draft July 9, 2021 11:16
@r0hit05 r0hit05 force-pushed the master branch 3 times, most recently from 9ea74ea to 715b9d6 Compare August 12, 2021 15:54
* Added first half of universal intrinsic tutorial
* Fixed warnings in documentation and sample code for parallel_for_new
tutorial
* Restored original parallel_for_ tutorial and table_of_content_core
* Minor changes
* Minor changes in vectorized implementation of 1-D and 2-D convolution
@terfendail
Copy link
Copy Markdown
Contributor

Could you please add new tutorials to the table of content? I mean table_of_content_core.markdown

@r0hit05
Copy link
Copy Markdown
Contributor Author

r0hit05 commented Aug 21, 2021

Could you please add new tutorials to the table of content? I mean table_of_content_core.markdown

Do I remove the old parallel_for_ tutorial from the table of contents? Also, the new parallel_for_ tutorial has the 'new' suffix in the name. Do I need to change that?

@terfendail
Copy link
Copy Markdown
Contributor

I think we should start with both tutorials. Old one could be removed later

@terfendail
Copy link
Copy Markdown
Contributor

I think tutorials are finished so turn the PR to "ready for review"

@terfendail terfendail marked this pull request as ready for review August 23, 2021 15:38
@alalek
Copy link
Copy Markdown
Member

alalek commented Aug 30, 2021

@r0hit2005 Need to fix build errors:

/build/precommit_macosx/opencv/samples/cpp/tutorial_code/core/univ_intrin/univ_intrin.cpp:131:27: error: variable-sized object may not be initialized
                float ans[cols] = {0};
                          ^~~~
/build/precommit_macosx/opencv/samples/cpp/tutorial_code/core/univ_intrin/univ_intrin.cpp:181:15: error: variable-sized object may not be initialized
    float ans[vsrc.cols] = {0};
              ^~~~~~~~~
2 errors generated.
C:\build\precommit_opencl\opencv\samples\cpp\tutorial_code\core\univ_intrin\univ_intrin.cpp(131,27): error C2131: expression did not evaluate to a constant

"variable-sized arrays" is GNU extension and not a part of ISO C++11.

@alalek
Copy link
Copy Markdown
Member

alalek commented Aug 31, 2021

Please use static_cast<T>() or cv::saturate_cast<T>() to resolve these warnings:

C:\build\precommit_windows64\opencv\samples\cpp\tutorial_code\core\univ_intrin\univ_intrin.cpp(11): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data [C:\build\precommit_windows64\build\samples\cpp\example_tutorial_univ_intrin.vcxproj]
C:\build\precommit_windows64\opencv\samples\cpp\tutorial_code\core\univ_intrin\univ_intrin.cpp(63): warning C4244: '=': conversion from 'double' to 'uchar', possible loss of data [C:\build\precommit_windows64\build\samples\cpp\example_tutorial_univ_intrin.vcxproj]

In OpenCV 4.5, the following parallel frameworks are available in that order:

* Intel Threading Building Blocks (3rdparty library, should be explicitly enabled)
* C= Parallel C/C++ Programming Language Extension (3rdparty library, should be explicitly enabled)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

C= Parallel C/C++ Programming Language Extension (3rdparty library, should be explicitly enabled)

It is deprecated and dropped.

![Convolution Animation](images/convolution-example-matrix.gif)


For more information about different kernels and what they do, look [here](https://docs.opencv.org/4.5.2/d7/da8/tutorial_table_of_content_imgproc.html).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://docs.opencv.org/...

Don't put direct links on docs site.
Use Doxygen references instead.

Based on that, we can broadly classify algorithms into two categories:-
1. Algorithms in which only a single thread writes data to a particular memory location.
* In *convolution*, for example, even though multiple threads may read from a pixel at a particular time, only a single thread *writes* to a particular pixel.
<!-- <br> -->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

<!-- <br> -->

needed?


In the tutorial, we used a horizontal gradient filter(as shown in the animation above), which produces an image highlighting the vertical edges.

![result image](images/resimg.png) No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

resimg.png

We don't need lossless format for documentation. Please use .jpg instead.


Sequential Implementation: 0.0953564s
Parallel Implementation: 0.0246762s
Parallel Implentatation(Row Split): 0.0248722s
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Implentatation

typo


The goal of this tutorial is to provide a guide to using the Universal Intrinsics feature to vectorize your C++ code for a faster runtime.
We'll briefly look into _SIMD intrinsics_ and how to work with wide _registers_, followed by a tutorial on the basic operations using wide registers.
The tutorial will only demonstrate basic operations. To know more about Universal Intrinsics, visit the [documentation](https://docs.opencv.org/4.5.3/df/d91/group__core__hal__intrin.html).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How do I refer to the documentation?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use @ref <id>, where <id>:

  • is a tutorial identifier (see the first line of tutorial page)
  • or identifier of code group, for this case it is here

Comment on lines +10 to +17
namespace
{
//! [convolution-sequential]
void conv_seq(Mat src, Mat &dst, Mat kernel)
{
//![convolution-make-borders]
int rows = src.rows, cols = src.cols;
dst = Mat(rows, cols, src.type());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please avoid indentation in namespaces

@r0hit05
Copy link
Copy Markdown
Contributor Author

r0hit05 commented Sep 7, 2021

Should I change the previous tutorial(file_input_output_with_xml_yml) to point to the new parallel_for tutorial?

@alalek
Copy link
Copy Markdown
Member

alalek commented Sep 7, 2021

Yes, please keep next/prev links up-to-date.

@terfendail
Copy link
Copy Markdown
Contributor

As far as I could understand resimg.png was just renamed. Have you committed converted version?

@alalek alalek merged commit 41a2eb5 into opencv:master Sep 15, 2021
@alalek alalek mentioned this pull request Oct 15, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
Tutorial for parallel_for_ and Universal Intrinsic (GSoC '21)

* New parallel_for tutorial

* Universal Intrinsics Draft Tutorial

* Added draft of universal intrinsic tutorial

* * Added final markdown for parallel_for_new
* Added first half of universal intrinsic tutorial
* Fixed warnings in documentation and sample code for parallel_for_new
tutorial
* Restored original parallel_for_ tutorial and table_of_content_core
* Minor changes

* Added demonstration of 1-D vectorized convolution

* * Added 2-D convolution implementation and tutorial
* Minor changes in vectorized implementation of 1-D and 2-D convolution

* Minor changes to univ_intrin tutorial. Added new tutorials to the table of contents

* Minor changes

* Removed variable sized array initializations

* Fixed conversion warnings

* Added doxygen references, minor fixes

* Added jpg image for parallel_for_ doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: documentation Documentation fix or update GSoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants