Skip to content

Commit f743603

Browse files
author
Woody Chow
committed
Fallback to single threaded version of IPP gaussian blur / bilateral filter when the mutlithreaded version cannot be called.
1 parent d22fb5f commit f743603

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

modules/imgproc/src/smooth.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
22412241
#endif
22422242

22432243
#ifdef HAVE_IPP
2244+
#define IPP_DISABLE_FILTERING_INMEM_PARTIAL 1 // IW 2017u2 has bug which doesn't allow use of partial inMem with tiling
22442245
#define IPP_GAUSSIANBLUR_PARALLEL 1
22452246

22462247
#ifdef HAVE_IPP_IW
@@ -2319,26 +2320,23 @@ static bool ipp_GaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
23192320
if(!ippBorder.m_borderType)
23202321
return false;
23212322

2322-
// IW 2017u2 has bug which doesn't allow use of partial inMem with tiling
2323-
if((((ippBorder.m_borderFlags)&ippBorderInMem) && ((ippBorder.m_borderFlags)&ippBorderInMem) != ippBorderInMem)) {
2324-
return false;
2325-
}
2326-
2327-
bool ok;
2328-
ipp_gaussianBlurParallel invoker(iwSrc, iwDst, ksize.width, (float) sigma1, ippBorder, &ok);
2329-
2330-
if(!ok)
2331-
return false;
2332-
2333-
const Range range(0, (int) iwDst.m_size.height);
2323+
const bool disableThreading = IPP_DISABLE_FILTERING_INMEM_PARTIAL &&
2324+
((ippBorder.m_borderFlags)&ippBorderInMem) && ((ippBorder.m_borderFlags)&ippBorderInMem) != ippBorderInMem;
23342325
const int threads = ippiSuggestThreadsNum(iwDst, 2);
2335-
if(IPP_GAUSSIANBLUR_PARALLEL && threads > 1)
2326+
if(!disableThreading && IPP_GAUSSIANBLUR_PARALLEL && threads > 1) {
2327+
bool ok;
2328+
ipp_gaussianBlurParallel invoker(iwSrc, iwDst, ksize.width, (float) sigma1, ippBorder, &ok);
2329+
2330+
if(!ok)
2331+
return false;
2332+
const Range range(0, (int) iwDst.m_size.height);
23362333
parallel_for_(range, invoker, threads*4);
2337-
else
2338-
invoker(range);
23392334

2340-
if(!ok)
2341-
return false;
2335+
if(!ok)
2336+
return false;
2337+
} else {
2338+
CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterGaussian, &iwSrc, &iwDst, ksize.width, (float) sigma1, ippBorder);
2339+
}
23422340
}
23432341
catch (::ipp::IwException ex)
23442342
{
@@ -4321,24 +4319,23 @@ static bool ipp_bilateralFilter(Mat &src, Mat &dst, int d, double sigmaColor, do
43214319
if(!ippBorder.m_borderType)
43224320
return false;
43234321

4324-
// IW 2017u2 has bug which doesn't allow use of partial inMem with tiling
4325-
if((((ippBorder.m_borderFlags)&ippBorderInMem) && ((ippBorder.m_borderFlags)&ippBorderInMem) != ippBorderInMem))
4326-
return false;
4327-
4328-
bool ok = true;
4329-
int threads = ippiSuggestThreadsNum(iwDst, 2);
4330-
Range range(0, (int)iwDst.m_size.height);
4331-
ipp_bilateralFilterParallel invoker(iwSrc, iwDst, radius, valSquareSigma, posSquareSigma, ippBorder, &ok);
4332-
if(!ok)
4333-
return false;
4322+
const bool disableThreading = IPP_DISABLE_FILTERING_INMEM_PARTIAL &&
4323+
((ippBorder.m_borderFlags)&ippBorderInMem) && ((ippBorder.m_borderFlags)&ippBorderInMem) != ippBorderInMem;
4324+
const int threads = ippiSuggestThreadsNum(iwDst, 2);
4325+
if(!disableThreading && IPP_BILATERAL_PARALLEL && threads > 1) {
4326+
bool ok = true;
4327+
Range range(0, (int)iwDst.m_size.height);
4328+
ipp_bilateralFilterParallel invoker(iwSrc, iwDst, radius, valSquareSigma, posSquareSigma, ippBorder, &ok);
4329+
if(!ok)
4330+
return false;
43344331

4335-
if(IPP_BILATERAL_PARALLEL && threads > 1)
43364332
parallel_for_(range, invoker, threads*4);
4337-
else
4338-
invoker(range);
43394333

4340-
if(!ok)
4341-
return false;
4334+
if(!ok)
4335+
return false;
4336+
} else {
4337+
CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterBilateral, &iwSrc, &iwDst, radius, valSquareSigma, posSquareSigma, ippiFilterBilateralGauss, ippDistNormL1, ippBorder);
4338+
}
43424339
}
43434340
catch (::ipp::IwException)
43444341
{

0 commit comments

Comments
 (0)