Skip to content

Fix ipp_GaussianBlur will not be called with IPP enabled flag(ENABLE_…#22073

Closed
bwang30 wants to merge 1 commit intoopencv:4.xfrom
bwang30:opencv-smooth-ippfix
Closed

Fix ipp_GaussianBlur will not be called with IPP enabled flag(ENABLE_…#22073
bwang30 wants to merge 1 commit intoopencv:4.xfrom
bwang30:opencv-smooth-ippfix

Conversation

@bwang30
Copy link
Copy Markdown
Contributor

@bwang30 bwang30 commented Jun 6, 2022

Fix the issue:
Enabled ENABLE_IPP_GAUSSIAN_BLUR and flag "NE"(result no equal), OpenCV still can't step into use IPP for smoothing acceleration.

It is necessary to provide faster smooth processing with Intel IPP. In the testing on my computer(ICE lake), IPP is faster:

image

@alalek
Copy link
Copy Markdown
Member

alalek commented Jun 6, 2022

@bwang30 Thank you for contribution!

Could you provide small code snippet in PR's description which is used for evaluation? (which describes used src size, src/dst data type, ROI, GaussianBlur parameters, IPP NE flag setting)

@bwang30
Copy link
Copy Markdown
Contributor Author

bwang30 commented Jun 6, 2022

@alalek Thanks for the review. According to my debug, no matter what I set of ipp flag, OpenCV goes into this condition and return:

if(sdepth == CV_8U && ((borderType & BORDER_ISOLATED) || !_src.isSubmatrix()))

because ipp_GaussianBlur is behind of this part of code, but logically we should try to step into Intel IPP code first if we chose enabling IPP and setting ipp NE flag on for those special platforms have better performance with Intel IPP

I compiled opencv with flag WITH_IPP=ON and enabled ENABLE_IPP_GAUSSIAN_BLUR, set IPP NE flag in the envoroment varaiables. I tested more than 100 images, resized all of them to 1920x1080, src/dst data type is CV_8UC3, ROI is the whole image, and parameters are set as the code snippet:

vector<cv::Mat> srcData;
for (auto imgpath : sInputFiles)
{
    Mat img = cv::imread(imgpath, cv::IMREAD_COLOR);
    cv::Size dsize(1920, 1080);
    cv::Mat img_resized;
    cv::resize(img, img_resized, dsize, 0, 0, cv::INTER_CUBIC);
    srcData.push_back(img);
}
vector<cv::Mat> dstData(srcData.size());

cv::Size kernelsize(7, 7);
double SigmaX = 1;
double SigmaY = 1;

for (int i = 0; i < srcData.size(); i++)
{
      cv::GaussianBlur(srcData[i], dstData[i], kernelsize, SigmaX, SigmaY, bordertype);
}

@alalek
Copy link
Copy Markdown
Member

alalek commented Jun 8, 2022

sdepth == CV_8U

OpenCV for some functions (list is growing) provides guarantee of "bit-exact" result for 8U (or other integer data type) input (between platforms or used optimizations). There is no floating point computations internally, "softfloat" is used instead. This is enabled by default.

There is no IPP processing with the same result, so IPP code path is not used here.

setUseIPP_NotExact() call is related to IPP behavior, so this hint can't bypass "bit-exact" OpenCV requirement.
At first we need some OpenCV-specific hint to allow bypassing of "bit-exact" requirement in favor of speed. This need to be discussed with OpenCV dev team.

@bwang30
Copy link
Copy Markdown
Contributor Author

bwang30 commented Jun 9, 2022

@alalek Thanks for your clarification. But I still have a question here:
To my understanding, you said 8U smoothing is one of "bit-exact" result functions in your list which uses "softfloat" for float calculation. So I suppose regarding of 8U smooth, OpenCV should not step into the ipp_GaussianBlur function. But as the code shows:

if(sdepth == CV_8U && ((borderType & BORDER_ISOLATED) || !_src.isSubmatrix()))

We just need to make _src as a submatrix and enable flag ENABLE_IPP_GAUSSIAN_BLUR, then opencv will step into ipp_GaussianBlur and get NotExact result. Is that the correct behavior?

BTW, IPP provides much better performance, I hope OpenCV can enable this feature for those functions IPP supports even the result is not bit-exact matching.

@asmorkalov
Copy link
Copy Markdown
Contributor

@eplankin Are there any changes related to Gaussian Blur in the last IPP update? Does it pass OpenCV tests now?

@eplankin
Copy link
Copy Markdown
Contributor

eplankin commented Apr 14, 2023

@asmorkalov AFAIK issues with bit-exactness haven't been fixed yet.
Are there any special test cases for IPP that should pass? Or running the whole GaussianBlur_Bitexact test suite with enabled ENABLE_IPP_GAUSSIAN_BLUR is enough to check whether there are still problems with bit-exactness in IPP or not?

asmorkalov added a commit that referenced this pull request Jul 12, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation #25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces #22073
Possibly related issue: #24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
@asmorkalov
Copy link
Copy Markdown
Contributor

Replaced by #25792

@asmorkalov asmorkalov closed this Jul 18, 2024
fengyuentau pushed a commit to fengyuentau/opencv that referenced this pull request Aug 15, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
savuor pushed a commit to savuor/opencv that referenced this pull request Nov 1, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
savuor pushed a commit to savuor/opencv that referenced this pull request Nov 5, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
savuor pushed a commit to savuor/opencv that referenced this pull request Nov 8, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
savuor pushed a commit to savuor/opencv that referenced this pull request Nov 21, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants