Home | History | Annotate | Download | only in perf
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      5 //  By downloading, copying, installing or using the software you agree to this license.
      6 //  If you do not agree to this license, do not download, install,
      7 //  copy or use the software.
      8 //
      9 //
     10 //                           License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
     14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
     15 // Third party copyrights are property of their respective owners.
     16 //
     17 // Redistribution and use in source and binary forms, with or without modification,
     18 // are permitted provided that the following conditions are met:
     19 //
     20 //   * Redistribution's of source code must retain the above copyright notice,
     21 //     this list of conditions and the following disclaimer.
     22 //
     23 //   * Redistribution's in binary form must reproduce the above copyright notice,
     24 //     this list of conditions and the following disclaimer in the documentation
     25 //     and/or other materials provided with the distribution.
     26 //
     27 //   * The name of the copyright holders may not be used to endorse or promote products
     28 //     derived from this software without specific prior written permission.
     29 //
     30 // This software is provided by the copyright holders and contributors "as is" and
     31 // any express or implied warranties, including, but not limited to, the implied
     32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     33 // In no event shall the Intel Corporation or contributors be liable for any direct,
     34 // indirect, incidental, special, exemplary, or consequential damages
     35 // (including, but not limited to, procurement of substitute goods or services;
     36 // loss of use, data, or profits; or business interruption) however caused
     37 // and on any theory of liability, whether in contract, strict liability,
     38 // or tort (including negligence or otherwise) arising in any way out of
     39 // the use of this software, even if advised of the possibility of such damage.
     40 //
     41 //M*/
     42 
     43 #include "perf_precomp.hpp"
     44 
     45 using namespace std;
     46 using namespace testing;
     47 using namespace perf;
     48 
     49 #define ARITHM_MAT_DEPTH Values(CV_8U, CV_16U, CV_32F, CV_64F)
     50 
     51 //////////////////////////////////////////////////////////////////////
     52 // Merge
     53 
     54 PERF_TEST_P(Sz_Depth_Cn, Merge,
     55             Combine(CUDA_TYPICAL_MAT_SIZES,
     56                     ARITHM_MAT_DEPTH,
     57                     Values(2, 3, 4)))
     58 {
     59     const cv::Size size = GET_PARAM(0);
     60     const int depth = GET_PARAM(1);
     61     const int channels = GET_PARAM(2);
     62 
     63     std::vector<cv::Mat> src(channels);
     64     for (int i = 0; i < channels; ++i)
     65     {
     66         src[i].create(size, depth);
     67         declare.in(src[i], WARMUP_RNG);
     68     }
     69 
     70     if (PERF_RUN_CUDA())
     71     {
     72         std::vector<cv::cuda::GpuMat> d_src(channels);
     73         for (int i = 0; i < channels; ++i)
     74             d_src[i].upload(src[i]);
     75 
     76         cv::cuda::GpuMat dst;
     77 
     78         TEST_CYCLE() cv::cuda::merge(d_src, dst);
     79 
     80         CUDA_SANITY_CHECK(dst, 1e-10);
     81     }
     82     else
     83     {
     84         cv::Mat dst;
     85 
     86         TEST_CYCLE() cv::merge(src, dst);
     87 
     88         CPU_SANITY_CHECK(dst);
     89     }
     90 }
     91 
     92 //////////////////////////////////////////////////////////////////////
     93 // Split
     94 
     95 PERF_TEST_P(Sz_Depth_Cn, Split,
     96             Combine(CUDA_TYPICAL_MAT_SIZES,
     97                     ARITHM_MAT_DEPTH,
     98                     Values(2, 3, 4)))
     99 {
    100     const cv::Size size = GET_PARAM(0);
    101     const int depth = GET_PARAM(1);
    102     const int channels = GET_PARAM(2);
    103 
    104     cv::Mat src(size, CV_MAKE_TYPE(depth, channels));
    105     declare.in(src, WARMUP_RNG);
    106 
    107     if (PERF_RUN_CUDA())
    108     {
    109         const cv::cuda::GpuMat d_src(src);
    110         std::vector<cv::cuda::GpuMat> dst;
    111 
    112         TEST_CYCLE() cv::cuda::split(d_src, dst);
    113 
    114         const cv::cuda::GpuMat& dst0 = dst[0];
    115         const cv::cuda::GpuMat& dst1 = dst[1];
    116 
    117         CUDA_SANITY_CHECK(dst0, 1e-10);
    118         CUDA_SANITY_CHECK(dst1, 1e-10);
    119     }
    120     else
    121     {
    122         std::vector<cv::Mat> dst;
    123 
    124         TEST_CYCLE() cv::split(src, dst);
    125 
    126         const cv::Mat& dst0 = dst[0];
    127         const cv::Mat& dst1 = dst[1];
    128 
    129         CPU_SANITY_CHECK(dst0);
    130         CPU_SANITY_CHECK(dst1);
    131     }
    132 }
    133 
    134 //////////////////////////////////////////////////////////////////////
    135 // Transpose
    136 
    137 PERF_TEST_P(Sz_Type, Transpose,
    138             Combine(CUDA_TYPICAL_MAT_SIZES,
    139                     Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_16SC2, CV_32SC1, CV_32SC2, CV_64FC1)))
    140 {
    141     const cv::Size size = GET_PARAM(0);
    142     const int type = GET_PARAM(1);
    143 
    144     cv::Mat src(size, type);
    145     declare.in(src, WARMUP_RNG);
    146 
    147     if (PERF_RUN_CUDA())
    148     {
    149         const cv::cuda::GpuMat d_src(src);
    150         cv::cuda::GpuMat dst;
    151 
    152         TEST_CYCLE() cv::cuda::transpose(d_src, dst);
    153 
    154         CUDA_SANITY_CHECK(dst, 1e-10);
    155     }
    156     else
    157     {
    158         cv::Mat dst;
    159 
    160         TEST_CYCLE() cv::transpose(src, dst);
    161 
    162         CPU_SANITY_CHECK(dst);
    163     }
    164 }
    165 
    166 //////////////////////////////////////////////////////////////////////
    167 // Flip
    168 
    169 enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
    170 CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
    171 
    172 DEF_PARAM_TEST(Sz_Depth_Cn_Code, cv::Size, MatDepth, MatCn, FlipCode);
    173 
    174 PERF_TEST_P(Sz_Depth_Cn_Code, Flip,
    175             Combine(CUDA_TYPICAL_MAT_SIZES,
    176                     Values(CV_8U, CV_16U, CV_32F),
    177                     CUDA_CHANNELS_1_3_4,
    178                     FlipCode::all()))
    179 {
    180     const cv::Size size = GET_PARAM(0);
    181     const int depth = GET_PARAM(1);
    182     const int channels = GET_PARAM(2);
    183     const int flipCode = GET_PARAM(3);
    184 
    185     const int type = CV_MAKE_TYPE(depth, channels);
    186 
    187     cv::Mat src(size, type);
    188     declare.in(src, WARMUP_RNG);
    189 
    190     if (PERF_RUN_CUDA())
    191     {
    192         const cv::cuda::GpuMat d_src(src);
    193         cv::cuda::GpuMat dst;
    194 
    195         TEST_CYCLE() cv::cuda::flip(d_src, dst, flipCode);
    196 
    197         CUDA_SANITY_CHECK(dst);
    198     }
    199     else
    200     {
    201         cv::Mat dst;
    202 
    203         TEST_CYCLE() cv::flip(src, dst, flipCode);
    204 
    205         CPU_SANITY_CHECK(dst);
    206     }
    207 }
    208 
    209 //////////////////////////////////////////////////////////////////////
    210 // LutOneChannel
    211 
    212 PERF_TEST_P(Sz_Type, LutOneChannel,
    213             Combine(CUDA_TYPICAL_MAT_SIZES,
    214                     Values(CV_8UC1, CV_8UC3)))
    215 {
    216     const cv::Size size = GET_PARAM(0);
    217     const int type = GET_PARAM(1);
    218 
    219     cv::Mat src(size, type);
    220     declare.in(src, WARMUP_RNG);
    221 
    222     cv::Mat lut(1, 256, CV_8UC1);
    223     declare.in(lut, WARMUP_RNG);
    224 
    225     if (PERF_RUN_CUDA())
    226     {
    227         cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
    228 
    229         const cv::cuda::GpuMat d_src(src);
    230         cv::cuda::GpuMat dst;
    231 
    232         TEST_CYCLE() lutAlg->transform(d_src, dst);
    233 
    234         CUDA_SANITY_CHECK(dst);
    235     }
    236     else
    237     {
    238         cv::Mat dst;
    239 
    240         TEST_CYCLE() cv::LUT(src, lut, dst);
    241 
    242         CPU_SANITY_CHECK(dst);
    243     }
    244 }
    245 
    246 //////////////////////////////////////////////////////////////////////
    247 // LutMultiChannel
    248 
    249 PERF_TEST_P(Sz_Type, LutMultiChannel,
    250             Combine(CUDA_TYPICAL_MAT_SIZES,
    251                     Values<MatType>(CV_8UC3)))
    252 {
    253     const cv::Size size = GET_PARAM(0);
    254     const int type = GET_PARAM(1);
    255 
    256     cv::Mat src(size, type);
    257     declare.in(src, WARMUP_RNG);
    258 
    259     cv::Mat lut(1, 256, CV_MAKE_TYPE(CV_8U, src.channels()));
    260     declare.in(lut, WARMUP_RNG);
    261 
    262     if (PERF_RUN_CUDA())
    263     {
    264         cv::Ptr<cv::cuda::LookUpTable> lutAlg = cv::cuda::createLookUpTable(lut);
    265 
    266         const cv::cuda::GpuMat d_src(src);
    267         cv::cuda::GpuMat dst;
    268 
    269         TEST_CYCLE() lutAlg->transform(d_src, dst);
    270 
    271         CUDA_SANITY_CHECK(dst);
    272     }
    273     else
    274     {
    275         cv::Mat dst;
    276 
    277         TEST_CYCLE() cv::LUT(src, lut, dst);
    278 
    279         CPU_SANITY_CHECK(dst);
    280     }
    281 }
    282 
    283 //////////////////////////////////////////////////////////////////////
    284 // CopyMakeBorder
    285 
    286 DEF_PARAM_TEST(Sz_Depth_Cn_Border, cv::Size, MatDepth, MatCn, BorderMode);
    287 
    288 PERF_TEST_P(Sz_Depth_Cn_Border, CopyMakeBorder,
    289             Combine(CUDA_TYPICAL_MAT_SIZES,
    290                     Values(CV_8U, CV_16U, CV_32F),
    291                     CUDA_CHANNELS_1_3_4,
    292                     ALL_BORDER_MODES))
    293 {
    294     const cv::Size size = GET_PARAM(0);
    295     const int depth = GET_PARAM(1);
    296     const int channels = GET_PARAM(2);
    297     const int borderMode = GET_PARAM(3);
    298 
    299     const int type = CV_MAKE_TYPE(depth, channels);
    300 
    301     cv::Mat src(size, type);
    302     declare.in(src, WARMUP_RNG);
    303 
    304     if (PERF_RUN_CUDA())
    305     {
    306         const cv::cuda::GpuMat d_src(src);
    307         cv::cuda::GpuMat dst;
    308 
    309         TEST_CYCLE() cv::cuda::copyMakeBorder(d_src, dst, 5, 5, 5, 5, borderMode);
    310 
    311         CUDA_SANITY_CHECK(dst);
    312     }
    313     else
    314     {
    315         cv::Mat dst;
    316 
    317         TEST_CYCLE() cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode);
    318 
    319         CPU_SANITY_CHECK(dst);
    320     }
    321 }
    322