@ -45,333 +45,279 @@
//M*/
# include "perf_precomp.hpp"
///////////// Blur////////////////////////
PERFTEST ( Blur )
{
Mat src1 , dst , ocl_dst ;
ocl : : oclMat d_src1 , d_dst ;
using namespace perf ;
using std : : tr1 : : get ;
using std : : tr1 : : tuple ;
Size ksize = Size ( 3 , 3 ) ;
int bordertype = BORDER_CONSTANT ;
int all_type [ ] = { CV_8UC1 , CV_8UC4 } ;
std : : string type_name [ ] = { " CV_8UC1 " , " CV_8UC4 " } ;
for ( int size = Min_Size ; size < = Max_Size ; size * = Multiple )
{
for ( size_t j = 0 ; j < sizeof ( all_type ) / sizeof ( int ) ; j + + )
{
SUBTEST < < size < < ' x ' < < size < < " ; " < < type_name [ j ] ;
///////////// Blur////////////////////////
gen ( src1 , size , size , all_type [ j ] , 0 , 256 ) ;
gen ( dst , size , size , all_type [ j ] , 0 , 256 ) ;
typedef Size_MatType BlurFixture ;
blur ( src1 , dst , ksize , Point ( - 1 , - 1 ) , bordertype ) ;
PERF_TEST_P ( BlurFixture , Blur ,
: : testing : : Combine ( OCL_TYPICAL_MAT_SIZES ,
OCL_PERF_ENUM ( CV_8UC1 , CV_8UC4 ) ) )
{
const Size_MatType_t params = GetParam ( ) ;
const Size srcSize = get < 0 > ( params ) , ksize ( 3 , 3 ) ;
const int type = get < 1 > ( params ) , bordertype = BORDER_CONSTANT ;
CPU_ON ;
blur ( src1 , dst , ksize , Point ( - 1 , - 1 ) , bordertype ) ;
CPU_OFF ;
Mat src ( srcSize , type ) , dst ( srcSize , type ) ;
declare . in ( src , WARMUP_RNG ) . out ( dst ) ;
d_src1 . upload ( src1 ) ;
if ( srcSize = = OCL_SIZE_4000 & & type = = CV_8UC4 )
declare . time ( 5 ) ;
WARMUP_ON ;
ocl : : blur ( d_src1 , d_dst , ksize , Point ( - 1 , - 1 ) , bordertype ) ;
WARMUP_OFF ;
if ( RUN_OCL_IMPL )
{
ocl : : oclMat oclSrc ( src ) , oclDst ( srcSize , type ) ;
GPU_ON ;
ocl : : blur ( d_src1 , d_dst , ksize , Point ( - 1 , - 1 ) , bordertype ) ;
GPU_OFF ;
TEST_CYCLE ( ) cv : : ocl : : blur ( oclSrc , oclDst , ksize , Point ( - 1 , - 1 ) , bordertype ) ;
GPU_FULL_ON ;
d_src1 . upload ( src1 ) ;
ocl : : blur ( d_src1 , d_dst , ksize , Point ( - 1 , - 1 ) , bordertype ) ;
d_dst . download ( ocl_dst ) ;
GPU_FULL_OFF ;
oclDst . download ( dst ) ;
TestSystem : : instance ( ) . ExpectedMatNear ( ocl_dst , dst , 1.0 ) ;
}
SANITY_CHECK ( dst , 1 + DBL_EPSILON ) ;
}
else if ( RUN_PLAIN_IMPL )
{
TEST_CYCLE ( ) cv : : blur ( src , dst , ksize , Point ( - 1 , - 1 ) , bordertype ) ;
SANITY_CHECK ( dst , 1 + DBL_EPSILON ) ;
}
else
OCL_PERF_ELSE
}
///////////// Laplacian////////////////////////
PERFTEST ( Laplacian )
{
Mat src1 , dst , ocl_dst ;
ocl : : oclMat d_src1 , d_dst ;
int ksize = 3 ;
int all_type [ ] = { CV_8UC1 , CV_8UC4 } ;
std : : string type_name [ ] = { " CV_8UC1 " , " CV_8UC4 " } ;
for ( int size = Min_Size ; size < = Max_Size ; size * = Multiple )
{
for ( size_t j = 0 ; j < sizeof ( all_type ) / sizeof ( int ) ; j + + )
{
SUBTEST < < size < < ' x ' < < size < < " ; " < < type_name [ j ] ;
///////////// Laplacian////////////////////////
gen ( src1 , size , size , all_type [ j ] , 0 , 256 ) ;
gen ( dst , size , size , all_type [ j ] , 0 , 256 ) ;
typedef Size_MatType LaplacianFixture ;
Laplacian ( src1 , dst , - 1 , ksize , 1 ) ;
PERF_TEST_P ( LaplacianFixture , Laplacian ,
: : testing : : Combine ( OCL_TYPICAL_MAT_SIZES ,
OCL_PERF_ENUM ( CV_8UC1 , CV_8UC4 ) ) )
{
const Size_MatType_t params = GetParam ( ) ;
const Size srcSize = get < 0 > ( params ) ;
const int type = get < 1 > ( params ) , ksize = 3 ;
CPU_ON ;
Laplacian ( src1 , dst , - 1 , ksize , 1 ) ;
CPU_OFF ;
Mat src ( srcSize , type ) , dst ( srcSize , type ) ;
declare . in ( src , WARMUP_RNG ) . out ( dst ) ;
d_src1 . upload ( src1 ) ;
if ( srcSize = = OCL_SIZE_4000 & & type = = CV_8UC4 )
declare . time ( 6 ) ;
WARMUP_ON ;
ocl : : Laplacian ( d_src1 , d_dst , - 1 , ksize , 1 ) ;
WARMUP_OFF ;
if ( RUN_OCL_IMPL )
{
ocl : : oclMat oclSrc ( src ) , oclDst ( srcSize , type ) ;
GPU_ON ;
ocl : : Laplacian ( d_src1 , d_dst , - 1 , ksize , 1 ) ;
GPU_OFF ;
TEST_CYCLE ( ) cv : : ocl : : Laplacian ( oclSrc , oclDst , - 1 , ksize , 1 ) ;
GPU_FULL_ON ;
d_src1 . upload ( src1 ) ;
ocl : : Laplacian ( d_src1 , d_dst , - 1 , ksize , 1 ) ;
d_dst . download ( ocl_dst ) ;
GPU_FULL_OFF ;
oclDst . download ( dst ) ;
TestSystem : : instance ( ) . ExpectedMatNear ( ocl_dst , dst , 1e-5 ) ;
}
SANITY_CHECK ( dst ) ;
}
else if ( RUN_PLAIN_IMPL )
{
TEST_CYCLE ( ) cv : : Laplacian ( src , dst , - 1 , ksize , 1 ) ;
SANITY_CHECK ( dst ) ;
}
else
OCL_PERF_ELSE
}
///////////// Erode ////////////////////
PERFTEST ( Erode )
{
Mat src , dst , ker , ocl_dst ;
ocl : : oclMat d_src , d_dst ;
int all_type [ ] = { CV_8UC1 , CV_8UC4 , CV_32FC1 , CV_32FC4 } ;
std : : string type_name [ ] = { " CV_8UC1 " , " CV_8UC4 " , " CV_32FC1 " , " CV_32FC4 " } ;
for ( int size = Min_Size ; size < = Max_Size ; size * = Multiple )
{
for ( size_t j = 0 ; j < sizeof ( all_type ) / sizeof ( int ) ; j + + )
{
SUBTEST < < size < < ' x ' < < size < < " ; " < < type_name [ j ] ;
gen ( src , size , size , all_type [ j ] , Scalar : : all ( 0 ) , Scalar : : all ( 256 ) ) ;
ker = getStructuringElement ( MORPH_RECT , Size ( 3 , 3 ) ) ;
typedef Size_MatType ErodeFixture ;
erode ( src , dst , ker ) ;
PERF_TEST_P ( ErodeFixture , Erode ,
: : testing : : Combine ( OCL_TYPICAL_MAT_SIZES ,
OCL_PERF_ENUM ( CV_8UC1 , CV_8UC4 , CV_32FC1 , CV_32FC4 ) ) )
{
const Size_MatType_t params = GetParam ( ) ;
const Size srcSize = get < 0 > ( params ) ;
const int type = get < 1 > ( params ) , ksize = 3 ;
const Mat ker = getStructuringElement ( MORPH_RECT , Size ( ksize , ksize ) ) ;
CPU_ON ;
erode ( src , dst , ker ) ;
CPU_OFF ;
Mat src ( srcSize , type ) , dst ( srcSize , type ) ;
declare . in ( src , WARMUP_RNG ) . out ( dst ) . in ( ker ) ;
d_src . upload ( src ) ;
if ( srcSize = = OCL_SIZE_4000 & & type = = CV_8UC4 )
declare . time ( 5 ) ;
WARMUP_ON ;
ocl : : erode ( d_src , d_dst , ker ) ;
WARMUP_OFF ;
if ( RUN_OCL_IMPL )
{
ocl : : oclMat oclSrc ( src ) , oclDst ( srcSize , type ) , oclKer ( ker ) ;
GPU_ON ;
ocl : : erode ( d_src , d_dst , ker ) ;
GPU_OFF ;
TEST_CYCLE ( ) cv : : ocl : : erode ( oclSrc , oclDst , oclKer ) ;
GPU_FULL_ON ;
d_src . upload ( src ) ;
ocl : : erode ( d_src , d_dst , ker ) ;
d_dst . download ( ocl_dst ) ;
GPU_FULL_OFF ;
oclDst . download ( dst ) ;
TestSystem : : instance ( ) . ExpectedMatNear ( ocl_dst , dst , 1e-5 ) ;
}
SANITY_CHECK ( dst ) ;
}
else if ( RUN_PLAIN_IMPL )
{
TEST_CYCLE ( ) cv : : erode ( src , dst , ker ) ;
SANITY_CHECK ( dst ) ;
}
else
OCL_PERF_ELSE
}
///////////// Sobel ////////////////////////
PERFTEST ( Sobel )
{
Mat src , dst , ocl_dst ;
ocl : : oclMat d_src , d_dst ;
int dx = 1 ;
int dy = 1 ;
int all_type [ ] = { CV_8UC1 , CV_8UC4 } ;
std : : string type_name [ ] = { " CV_8UC1 " , " CV_8UC4 " } ;
for ( int size = Min_Size ; size < = Max_Size ; size * = Multiple )
{
for ( size_t j = 0 ; j < sizeof ( all_type ) / sizeof ( int ) ; j + + )
{
SUBTEST < < size < < ' x ' < < size < < " ; " < < type_name [ j ] ;
gen ( src , size , size , all_type [ j ] , 0 , 256 ) ;
typedef Size_MatType SobelFixture ;
Sobel ( src , dst , - 1 , dx , dy ) ;
PERF_TEST_P ( SobelFixture , Sobel ,
: : testing : : Combine ( OCL_TYPICAL_MAT_SIZES ,
OCL_PERF_ENUM ( CV_8UC1 , CV_8UC4 ) ) )
{
const Size_MatType_t params = GetParam ( ) ;
const Size srcSize = get < 0 > ( params ) ;
const int type = get < 1 > ( params ) , dx = 1 , dy = 1 ;
CPU_ON ;
Sobel ( src , dst , - 1 , dx , dy ) ;
CPU_OFF ;
Mat src ( srcSize , type ) , dst ( srcSize , type ) ;
declare . in ( src , WARMUP_RNG ) . out ( dst ) ;
d_src . upload ( src ) ;
if ( ( srcSize = = OCL_SIZE_2000 & & type = = CV_8UC4 ) | |
( srcSize = = OCL_SIZE_4000 & & type = = CV_8UC1 ) )
declare . time ( 5.5 ) ;
else if ( srcSize = = OCL_SIZE_4000 & & type = = CV_8UC4 )
declare . time ( 20 ) ;
WARMUP_ON ;
ocl : : Sobel ( d_src , d_dst , - 1 , dx , dy ) ;
WARMUP_OFF ;
if ( RUN_OCL_IMPL )
{
ocl : : oclMat oclSrc ( src ) , oclDst ( srcSize , type ) ;
GPU_ON ;
ocl : : Sobel ( d_src , d_dst , - 1 , dx , dy ) ;
GPU_OFF ;
TEST_CYCLE ( ) cv : : ocl : : Sobel ( oclSrc , oclDst , - 1 , dx , dy ) ;
GPU_FULL_ON ;
d_src . upload ( src ) ;
ocl : : Sobel ( d_src , d_dst , - 1 , dx , dy ) ;
d_dst . download ( ocl_dst ) ;
GPU_FULL_OFF ;
oclDst . download ( dst ) ;
TestSystem : : instance ( ) . ExpectedMatNear ( ocl_dst , dst , 1 ) ;
}
SANITY_CHECK ( dst ) ;
}
else if ( RUN_PLAIN_IMPL )
{
TEST_CYCLE ( ) cv : : Sobel ( src , dst , - 1 , dx , dy ) ;
SANITY_CHECK ( dst ) ;
}
else
OCL_PERF_ELSE
}
///////////// Scharr ////////////////////////
PERFTEST ( Scharr )
{
Mat src , dst , ocl_dst ;
ocl : : oclMat d_src , d_dst ;
int dx = 1 ;
int dy = 0 ;
int all_type [ ] = { CV_8UC1 , CV_8UC4 } ;
std : : string type_name [ ] = { " CV_8UC1 " , " CV_8UC4 " } ;
for ( int size = Min_Size ; size < = Max_Size ; size * = Multiple )
{
for ( size_t j = 0 ; j < sizeof ( all_type ) / sizeof ( int ) ; j + + )
{
SUBTEST < < size < < ' x ' < < size < < " ; " < < type_name [ j ] ;
///////////// Scharr ////////////////////////
gen ( src , size , size , all_type [ j ] , 0 , 256 ) ;
typedef Size_MatType ScharrFixture ;
Scharr ( src , dst , - 1 , dx , dy ) ;
PERF_TEST_P ( ScharrFixture , Scharr ,
: : testing : : Combine ( OCL_TYPICAL_MAT_SIZES ,
OCL_PERF_ENUM ( CV_8UC1 , CV_8UC4 ) ) )
{
const Size_MatType_t params = GetParam ( ) ;
const Size srcSize = get < 0 > ( params ) ;
const int type = get < 1 > ( params ) , dx = 1 , dy = 0 ;
CPU_ON ;
Scharr ( src , dst , - 1 , dx , dy ) ;
CPU_OFF ;
Mat src ( srcSize , type ) , dst ( srcSize , type ) ;
declare . in ( src , WARMUP_RNG ) . out ( dst ) ;
d_src . upload ( src ) ;
if ( ( srcSize = = OCL_SIZE_2000 & & type = = CV_8UC4 ) | |
( srcSize = = OCL_SIZE_4000 & & type = = CV_8UC1 ) )
declare . time ( 5.5 ) ;
else if ( srcSize = = OCL_SIZE_4000 & & type = = CV_8UC4 )
declare . time ( 21 ) ;
WARMUP_ON ;
ocl : : Scharr ( d_src , d_dst , - 1 , dx , dy ) ;
WARMUP_OFF ;
if ( RUN_OCL_IMPL )
{
ocl : : oclMat oclSrc ( src ) , oclDst ( srcSize , type ) ;
GPU_ON ;
ocl : : Scharr ( d_src , d_dst , - 1 , dx , dy ) ;
GPU_OFF ;
TEST_CYCLE ( ) cv : : ocl : : Scharr ( oclSrc , oclDst , - 1 , dx , dy ) ;
GPU_FULL_ON ;
d_src . upload ( src ) ;
ocl : : Scharr ( d_src , d_dst , - 1 , dx , dy ) ;
d_dst . download ( ocl_dst ) ;
GPU_FULL_OFF ;
oclDst . download ( dst ) ;
TestSystem : : instance ( ) . ExpectedMatNear ( ocl_dst , dst , 1 ) ;
}
SANITY_CHECK ( dst ) ;
}
else if ( RUN_PLAIN_IMPL )
{
TEST_CYCLE ( ) cv : : Scharr ( src , dst , - 1 , dx , dy ) ;
SANITY_CHECK ( dst ) ;
}
else
OCL_PERF_ELSE
}
///////////// GaussianBlur ////////////////////////
PERFTEST ( GaussianBlur )
{
Mat src , dst , ocl_dst ;
int all_type [ ] = { CV_8UC1 , CV_8UC4 , CV_32FC1 , CV_32FC4 } ;
std : : string type_name [ ] = { " CV_8UC1 " , " CV_8UC4 " , " CV_32FC1 " , " CV_32FC4 " } ;
const int ksize = 7 ;
for ( int size = Min_Size ; size < = Max_Size ; size * = Multiple )
{
for ( size_t j = 0 ; j < sizeof ( all_type ) / sizeof ( int ) ; j + + )
{
SUBTEST < < size < < ' x ' < < size < < " ; " < < type_name [ j ] ;
gen ( src , size , size , all_type [ j ] , 0 , 256 ) ;
typedef Size_MatType GaussianBlurFixture ;
GaussianBlur ( src , dst , Size ( ksize , ksize ) , 0 ) ;
PERF_TEST_P ( GaussianBlurFixture , GaussianBlur ,
: : testing : : Combine ( : : testing : : Values ( OCL_SIZE_1000 , OCL_SIZE_2000 ) ,
OCL_PERF_ENUM ( CV_8UC1 , CV_8UC4 , CV_32FC1 , CV_32FC4 ) ) )
{
const Size_MatType_t params = GetParam ( ) ;
const Size srcSize = get < 0 > ( params ) ;
const int type = get < 1 > ( params ) , ksize = 7 ;
CPU_ON ;
GaussianBlur ( src , dst , Size ( ksize , ksize ) , 0 ) ;
CPU_OFF ;
Mat src ( srcSize , type ) , dst ( srcSize , type ) ;
declare . in ( src , WARMUP_RNG ) . out ( dst ) ;
ocl : : oclMat d_src ( src ) ;
ocl : : oclMat d_dst ;
const double eps = src . depth ( ) = = CV_8U ? 1 + DBL_EPSILON : 3e-4 ;
WARMUP_ON ;
ocl : : GaussianBlur ( d_src , d_dst , Size ( ksize , ksize ) , 0 ) ;
WARMUP_OFF ;
if ( RUN_OCL_IMPL )
{
ocl : : oclMat oclSrc ( src ) , oclDst ( srcSize , type ) ;
GPU_ON ;
ocl : : GaussianBlur ( d_src , d_dst , Size ( ksize , ksize ) , 0 ) ;
GPU_OFF ;
TEST_CYCLE ( ) cv : : ocl : : GaussianBlur ( oclSrc , oclDst , Size ( ksize , ksize ) , 0 ) ;
GPU_FULL_ON ;
d_src . upload ( src ) ;
ocl : : GaussianBlur ( d_src , d_dst , Size ( ksize , ksize ) , 0 ) ;
d_dst . download ( ocl_dst ) ;
GPU_FULL_OFF ;
oclDst . download ( dst ) ;
TestSystem : : instance ( ) . ExpectedMatNear ( ocl_dst , dst , 1.0 ) ;
}
SANITY_CHECK ( dst , eps ) ;
}
else if ( RUN_PLAIN_IMPL )
{
TEST_CYCLE ( ) cv : : GaussianBlur ( src , dst , Size ( ksize , ksize ) , 0 ) ;
SANITY_CHECK ( dst , eps ) ;
}
else
OCL_PERF_ELSE
}
///////////// filter2D////////////////////////
PERFTEST ( filter2D )
{
Mat src ;
for ( int size = Min_Size ; size < = Max_Size ; size * = Multiple )
{
int all_type [ ] = { CV_8UC1 , CV_8UC4 } ;
std : : string type_name [ ] = { " CV_8UC1 " , " CV_8UC4 " } ;
for ( size_t j = 0 ; j < sizeof ( all_type ) / sizeof ( int ) ; j + + )
{
gen ( src , size , size , all_type [ j ] , 0 , 256 ) ;
const int ksize = 3 ;
SUBTEST < < " ksize = " < < ksize < < " ; " < < size < < ' x ' < < size < < " ; " < < type_name [ j ] ;
Mat kernel ;
gen ( kernel , ksize , ksize , CV_32SC1 , - 3.0 , 3.0 ) ;
typedef Size_MatType filter2DFixture ;
Mat dst , ocl_dst ;
cv : : filter2D ( src , dst , - 1 , kernel ) ;
CPU_ON ;
cv : : filter2D ( src , dst , - 1 , kernel ) ;
CPU_OFF ;
ocl : : oclMat d_src ( src ) , d_dst ;
PERF_TEST_P ( filter2DFixture , filter2D ,
: : testing : : Combine ( OCL_TYPICAL_MAT_SIZES ,
OCL_PERF_ENUM ( CV_8UC1 , CV_8UC4 ) ) )
{
const Size_MatType_t params = GetParam ( ) ;
const Size srcSize = get < 0 > ( params ) ;
const int type = get < 1 > ( params ) , ksize = 3 ;
WARMUP_ON ;
ocl : : filter2D ( d_src , d_dst , - 1 , kernel ) ;
WARMUP_OFF ;
Mat src ( srcSize , type ) , dst ( srcSize , type ) , kernel ( ksize , ksize , CV_32SC1 ) ;
declare . in ( src , WARMUP_RNG ) . in ( kernel ) . out ( dst ) ;
randu ( kernel , - 3.0 , 3.0 ) ;
GPU_ON ;
ocl : : filter2D ( d_src , d_dst , - 1 , kernel ) ;
GPU_OFF ;
if ( srcSize = = OCL_SIZE_4000 & & type = = CV_8UC4 )
declare . time ( 8 ) ;
GPU_FULL_ON ;
d_src . upload ( src ) ;
ocl : : filter2D ( d_src , d_dst , - 1 , kernel ) ;
d_dst . download ( ocl_dst ) ;
GPU_FULL_OFF ;
if ( RUN_OCL_IMPL )
{
ocl : : oclMat oclSrc ( src ) , oclDst ( srcSize , type ) , oclKernel ( kernel ) ;
TestSystem : : instance ( ) . ExpectedMatNear ( ocl_dst , dst , 1e-5 ) ;
TEST_CYCLE ( ) cv : : ocl : : filter2D ( oclSrc , oclDst , - 1 , oclKernel ) ;
}
oclDst . download ( dst ) ;
SANITY_CHECK ( dst ) ;
}
else if ( RUN_PLAIN_IMPL )
{
TEST_CYCLE ( ) cv : : filter2D ( src , dst , - 1 , kernel ) ;
SANITY_CHECK ( dst ) ;
}
else
OCL_PERF_ELSE
}