Skip to content

Commit bad149d

Browse files
committed
Merge pull request opencv#8828 from woodychow:multithreaded_gaussian
2 parents f935a16 + f743603 commit bad149d

File tree

1 file changed

+79
-16
lines changed

1 file changed

+79
-16
lines changed

modules/imgproc/src/smooth.cpp

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,54 @@ 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
2245+
#define IPP_GAUSSIANBLUR_PARALLEL 1
2246+
2247+
#ifdef HAVE_IPP_IW
2248+
2249+
class ipp_gaussianBlurParallel: public ParallelLoopBody
2250+
{
2251+
public:
2252+
ipp_gaussianBlurParallel(::ipp::IwiImage &src, ::ipp::IwiImage &dst, int kernelSize, float sigma, ::ipp::IwiBorderType &border, bool *pOk):
2253+
m_src(src), m_dst(dst), m_kernelSize(kernelSize), m_sigma(sigma), m_border(border), m_pOk(pOk) {
2254+
*m_pOk = true;
2255+
}
2256+
~ipp_gaussianBlurParallel()
2257+
{
2258+
}
2259+
2260+
virtual void operator() (const Range& range) const
2261+
{
2262+
CV_INSTRUMENT_REGION_IPP()
2263+
2264+
if(!*m_pOk)
2265+
return;
2266+
2267+
try
2268+
{
2269+
::ipp::IwiRoi roi = ::ipp::IwiRect(0, range.start, m_dst.m_size.width, range.end - range.start);
2270+
CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterGaussian, &m_src, &m_dst, m_kernelSize, m_sigma, m_border, &roi);
2271+
}
2272+
catch(::ipp::IwException e)
2273+
{
2274+
*m_pOk = false;
2275+
return;
2276+
}
2277+
}
2278+
private:
2279+
::ipp::IwiImage &m_src;
2280+
::ipp::IwiImage &m_dst;
2281+
2282+
int m_kernelSize;
2283+
float m_sigma;
2284+
::ipp::IwiBorderType &m_border;
2285+
2286+
volatile bool *m_pOk;
2287+
const ipp_gaussianBlurParallel& operator= (const ipp_gaussianBlurParallel&);
2288+
};
2289+
2290+
#endif
2291+
22442292
static bool ipp_GaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
22452293
double sigma1, double sigma2, int borderType )
22462294
{
@@ -2272,7 +2320,23 @@ static bool ipp_GaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
22722320
if(!ippBorder.m_borderType)
22732321
return false;
22742322

2275-
CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterGaussian, &iwSrc, &iwDst, ksize.width, (float)sigma1, ippBorder);
2323+
const bool disableThreading = IPP_DISABLE_FILTERING_INMEM_PARTIAL &&
2324+
((ippBorder.m_borderFlags)&ippBorderInMem) && ((ippBorder.m_borderFlags)&ippBorderInMem) != ippBorderInMem;
2325+
const int threads = ippiSuggestThreadsNum(iwDst, 2);
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);
2333+
parallel_for_(range, invoker, threads*4);
2334+
2335+
if(!ok)
2336+
return false;
2337+
} else {
2338+
CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterGaussian, &iwSrc, &iwDst, ksize.width, (float) sigma1, ippBorder);
2339+
}
22762340
}
22772341
catch (::ipp::IwException ex)
22782342
{
@@ -4255,24 +4319,23 @@ static bool ipp_bilateralFilter(Mat &src, Mat &dst, int d, double sigmaColor, do
42554319
if(!ippBorder.m_borderType)
42564320
return false;
42574321

4258-
// IW 2017u2 has bug which doesn't allow use of partial inMem with tiling
4259-
if((((ippBorder.m_borderFlags)&ippBorderInMem) && ((ippBorder.m_borderFlags)&ippBorderInMem) != ippBorderInMem))
4260-
return false;
4261-
4262-
bool ok = true;
4263-
int threads = ippiSuggestThreadsNum(iwDst, 2);
4264-
Range range(0, (int)iwDst.m_size.height);
4265-
ipp_bilateralFilterParallel invoker(iwSrc, iwDst, radius, valSquareSigma, posSquareSigma, ippBorder, &ok);
4266-
if(!ok)
4267-
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;
42684331

4269-
if(IPP_BILATERAL_PARALLEL && threads > 1)
42704332
parallel_for_(range, invoker, threads*4);
4271-
else
4272-
invoker(range);
42734333

4274-
if(!ok)
4275-
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+
}
42764339
}
42774340
catch (::ipp::IwException)
42784341
{

0 commit comments

Comments
 (0)