Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@seanm
Copy link
Contributor

@seanm seanm commented Jun 2, 2023

This removes a bunch of pre-C++11 workrarounds that are no longer necessary as C++11 is now required.

It is a nice clean up and simplification.

force_builders=Custom
build_image:Custom=centos:7
buildworker:Custom=linux-1

@asmorkalov asmorkalov requested a review from opencv-alalek June 3, 2023 07:34
@vpisarev vpisarev self-requested a review June 6, 2023 09:49
@vpisarev
Copy link
Contributor

vpisarev commented Jun 6, 2023

@seanm, I welcome those changes and believe something like this should be done. But maybe we should target 5.x first and do it slightly more aggressive, including C++ 14 and/or C++ 17 features.

Also, one of the things where some of our hacks should be removed in favor of a standard C++ feature is singletons. We have quite a few of them and could possibly replace them with std::call_once + std::once_flag.

@opencv-alalek, what do you think?

@seanm
Copy link
Contributor Author

seanm commented Jun 6, 2023

But maybe we should target 5.x first...

Why? 4.x already has #error "OpenCV 4.x+ requires enabled C++11 support". This PR doesn't increase any requirements. All the code removed is already dead because of that existing #error.

...do it slightly more aggressive, including C++ 14 and/or C++ 17 features

That's a whole other discussion. I'm not looking to drop C++11, I'm looking to drop C++03 and older. Increasing the minimum language dialect requires wider discussion I'd imagine, but I'm not at all involved in this project's governance...

@vpisarev
Copy link
Contributor

vpisarev commented Jun 9, 2023

the major reason is that until 5.0 is released, we backport some patches to 3.4, which does not require C++ 11.

For 5.0 we already decided to make C++ 14 the minimum required standard. Maybe we will raise it up to C++ 17, we will see.

@seanm
Copy link
Contributor Author

seanm commented Jun 12, 2023

Well, I disagree, but it's up to you. I assume github allows you to merge this into either branch?

@seanm
Copy link
Contributor Author

seanm commented Jun 29, 2023

Do I have to rebase my commits onto the 5.x branch? Or can everything be done from github?

@mshabunin
Copy link
Contributor

This patch breaks windows builds and documentation build:

/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_/how_to_use_OpenCV_parallel_for_.markdown:174: warning: block marked with [mandelbrot-parallel-call] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_.cpp, found it 0 times
/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:107: warning: block marked with [convolution-parallel] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times
/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:114: warning: block marked with [overload-full] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times
/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:117: warning: block marked with [convolution-parallel-function] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times
/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:122: warning: block marked with [overload-row-split] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times
/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:125: warning: block marked with [convolution-parallel-function-row] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times

@seanm
Copy link
Contributor Author

seanm commented Jul 7, 2023

This patch breaks windows builds and documentation build:

I think I've just fixed the doc build...

@seanm seanm force-pushed the c++11-simplifications branch 2 times, most recently from f69dcc4 to c27f024 Compare July 10, 2023 03:43
@mshabunin
Copy link
Contributor

mshabunin commented Jul 10, 2023

There are still issues with Windows build (Visual Studio 2019 Developer Command Prompt v16.11.21)

C:\build\precommit_windows64\4.x\opencv\modules\core\include\opencv2/core/cvdef.h(752): 
fatal error C1189: #error:  "OpenCV 4.x+ requires enabled C++11 support" 
(compiling source file C:\build\precommit_windows64\4.x\opencv\modules\imgproc\src\imgwarp.avx2.cpp) 

Perhaps we need some special handling for MSVC - https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ , but if we choose this way, we can still break user's aplications with our cvdef.hpp. So alternatively we need to use old _MSVC_LANG macro (https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170#microsoft-specific-predefined-macros). Example from vulkan header:

 #if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))

@seanm
Copy link
Contributor Author

seanm commented Jul 10, 2023

Perhaps we need some special handling for MSVC - https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ , but if we choose this way, we can still break user's aplications with our cvdef.hpp. So alternatively we need to use old _MSVC_LANG macro (https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170#microsoft-specific-predefined-macros). Example from vulkan header:

Interesting. I've updated my commit with something like the vulkan header.

I don't have Windows though, so this may take me a few trys with the help of github CI...

@seanm seanm force-pushed the c++11-simplifications branch from c27f024 to 5cfe4de Compare July 10, 2023 19:53
@seanm seanm changed the title C++11 simplifications Removed all pre-C++11 code, workarounds, and branches Jul 10, 2023
@seanm seanm force-pushed the c++11-simplifications branch from 5cfe4de to de976c3 Compare August 11, 2023 13:15
@seanm seanm force-pushed the c++11-simplifications branch from de976c3 to 4ab4fd0 Compare August 11, 2023 16:00
@mshabunin
Copy link
Contributor

Good, ifdef part is passing now, but several compilation issues have risen in cap_msmf and some opencv_contrib modules.
https://pullrequest.opencv.org/buildbot/builders/precommit_windows64/builds/102452/steps/compile%20release/logs/stdio
😮‍💨 I hope that most of them can be resolved by including correct headers or minor modifications, but there is possibility that some parts need to be rewritten to comply with this picky compiler and its C++ standard vision 🙂 .

@seanm
Copy link
Contributor Author

seanm commented Aug 11, 2023

Good, ifdef part is passing now, but several compilation issues have risen in cap_msmf and some opencv_contrib modules. https://pullrequest.opencv.org/buildbot/builders/precommit_windows64/builds/102452/steps/compile%20release/logs/stdio 😮‍💨 I hope that most of them can be resolved by including correct headers or minor modifications, but there is possibility that some parts need to be rewritten to comply with this picky compiler and its C++ standard vision 🙂 .

Seems most are due to missing headers, due to me removing the include in cvdef.h. I'll fix them.

But some are from opencv_contrib which seems to be a different repro. I can fix them too, but I wonder how much other code out there is expecting to be automatically included...

@seanm seanm force-pushed the c++11-simplifications branch from 4ab4fd0 to 301c9b8 Compare August 12, 2023 15:55
@seanm
Copy link
Contributor Author

seanm commented Aug 16, 2023

Actually, by including <array> in the appropriate .pch files I think I've fixed the remaining issues... CI seems to be green now.

@seanm seanm force-pushed the c++11-simplifications branch from 301c9b8 to 5dc01fd Compare September 8, 2023 17:25
@seanm seanm force-pushed the c++11-simplifications branch from 5dc01fd to bf4b6ca Compare October 6, 2023 14:36
@seanm seanm force-pushed the c++11-simplifications branch from bf4b6ca to eb91f6b Compare November 9, 2023 22:55
Comment on lines 172 to 176
Here, the range represents the total number of operations to be executed, so the total number of pixels in the image.
To set the number of threads, you can use: @ref cv::setNumThreads. You can also specify the number of splitting using the
nstripes parameter in @ref cv::parallel_for_. For instance, if your processor has 4 threads, setting `cv::setNumThreads(2)`
or setting `nstripes=2` should be the same as by default it will use all the processor threads available but will split the
workload only on two threads.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please restore setNumThreads related description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

This allowed removing a lot of dead code.

Updated some documentation consequently.
@seanm seanm force-pushed the c++11-simplifications branch from eb91f6b to 0d71e26 Compare November 10, 2023 19:29
@asmorkalov
Copy link
Contributor

Documentation warnings on Buildbot:

/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:114: warning: block marked with [overload-full] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times
/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:117: warning: block marked with [convolution-parallel-function] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times
/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:122: warning: block marked with [overload-row-split] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times
/build/precommit_docs/4.x/opencv/doc/tutorials/core/how_to_use_OpenCV_parallel_for_new/how_to_use_OpenCV_parallel_for_new.markdown:125: warning: block marked with [convolution-parallel-function-row] for \snippet should appear twice in file how_to_use_OpenCV_parallel_for_new.cpp, found it 0 times

@seanm
Copy link
Contributor Author

seanm commented Nov 11, 2023

Documentation warnings on Buildbot:

Yeah, that's because I brought back the comments you asked me to. :) CI was green before.


@note Although values of a pixel in a particular stripe may depend on pixel values outside the stripe, these are only read only operations and hence will not cause undefined behaviour.

C++11 standard allows a parallel implementation with a lambda expression:
Copy link
Contributor

Choose a reason for hiding this comment

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

The following documentation describes operator() overloading and other steps of the old version. I propose not to remove pre-C++11 code, but just remove ifdefs for C++11.

sz = kernel.rows / 2;
}

//! [overload-full]
Copy link
Contributor

Choose a reason for hiding this comment

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

There is reference to overload-full block in markdown.

//! [convolution-parallel-function]
}

//! [conv-parallel-row-split]
Copy link
Contributor

Choose a reason for hiding this comment

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

The same.

int sz = kernel.rows / 2;
copyMakeBorder(src, src, sz, sz, sz, sz, BORDER_REPLICATE);

//! [convolution-parallel-function]
Copy link
Contributor

Choose a reason for hiding this comment

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

The same,

sz = kernel.rows / 2;
}

//! [overload-row-split]
Copy link
Contributor

Choose a reason for hiding this comment

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

The same. See CI warnings.

@asmorkalov
Copy link
Contributor

@seanm friendly reminder.

@seanm
Copy link
Contributor Author

seanm commented Jan 10, 2024

@seanm friendly reminder.

I don't understand what it is you want to do in those documentation files. And I'm not familiar with the file's syntax nor the meaning of those tags. Nor am I familiar with the classes the document is describing. I think I give up at this point. Feel free to take what I've started and continue it.

@mshabunin mshabunin requested a review from asmorkalov January 16, 2024 10:06
@mshabunin
Copy link
Contributor

mshabunin commented Jan 19, 2024

@asmorkalov , tutorial_how_to_use_OpenCV_parallel_for_ is considered obsolete and is kept only for link preservation (as I understand). It is not listed in the corresponding section: https://docs.opencv.org/4.x/de/d7a/tutorial_table_of_content_core.html

tutorial_how_to_use_OpenCV_parallel_for_new is the new and updated tutorial.

See #20361

@asmorkalov asmorkalov merged commit e64857c into opencv:4.x Jan 19, 2024
@seanm
Copy link
Contributor Author

seanm commented Jan 19, 2024

I thought you didn't want this merged until 5.x?

@mshabunin
Copy link
Contributor

3.4 branch is considered EOL now (https://github.com/opencv/opencv/wiki/Branches), so we don't need to do backporting anymore (it was the main concern originally). And forward porting to 5.x will be done by the OpenCV team on a regular basis.

I believe there is still no decision on minimal C++ standard for 5.x.

@asmorkalov asmorkalov mentioned this pull request Jan 23, 2024
JStech pushed a commit to JStech/opencv that referenced this pull request Jan 28, 2024
Removed all pre-C++11 code, workarounds, and branches opencv#23736

This removes a bunch of pre-C++11 workrarounds that are no longer necessary as C++11 is now required.
It is a nice clean up and simplification.

* No longer unconditionally #include <array> in cvdef.h, include explicitly where needed
* Removed deprecated CV_NODISCARD, already unused in the codebase
* Removed some pre-C++11 workarounds, and simplified some backwards compat defines
* Removed CV_CXX_STD_ARRAY
* Removed CV_CXX_MOVE_SEMANTICS and CV_CXX_MOVE
* Removed all tests of CV_CXX11, now assume it's always true. This allowed removing a lot of dead code.
* Updated some documentation consequently.
* Removed all tests of CV_CXX11, now assume it's always true
* Fixed links.

---------

Co-authored-by: Maksim Shabunin <[email protected]>
Co-authored-by: Alexander Smorkalov <[email protected]>
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