Home | History | Annotate | Download | only in opencl
      1 // This file is part of OpenCV project.
      2 // It is subject to the license terms in the LICENSE file found in the top-level directory
      3 // of this distribution and at http://opencv.org/license.html.
      4 
      5 // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
      6 // Third party copyrights are property of their respective owners.
      7 
      8 #include "../perf_precomp.hpp"
      9 #include "opencv2/ts/ocl_perf.hpp"
     10 
     11 #ifdef HAVE_OPENCL
     12 
     13 namespace cvtest {
     14 namespace ocl {
     15 
     16 ///////////// 3 channels Vs 4 ////////////////////////
     17 
     18 enum
     19 {
     20     Pure = 0, Split, Convert
     21 };
     22 
     23 CV_ENUM(Modes, Pure, Split, Convert)
     24 
     25 typedef tuple <Size, MatType, Modes> _3vs4Params;
     26 typedef TestBaseWithParam<_3vs4Params> _3vs4_Fixture;
     27 
     28 OCL_PERF_TEST_P(_3vs4_Fixture, Resize,
     29                 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC3, CV_32FC3), Modes::all()))
     30 {
     31     _3vs4Params params = GetParam();
     32     const Size srcSize = get<0>(params);
     33     const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
     34     const int mode = get<2>(params);
     35 
     36     checkDeviceMaxMemoryAllocSize(srcSize, type);
     37 
     38     UMat src(srcSize, type), dst(srcSize, type);
     39     declare.in(src, WARMUP_RNG).out(dst);
     40 
     41     if (mode == Pure)
     42     {
     43         OCL_TEST_CYCLE() resize(src, dst, Size(), 0.5, 0.5, INTER_LINEAR);
     44     }
     45     else if (mode == Split)
     46     {
     47         std::vector<UMat> srcs(3), dsts(3);
     48 
     49         for (int i = 0; i < 3; ++i)
     50         {
     51             dsts[i] = UMat(srcSize, depth);
     52             srcs[i] = UMat(srcSize, depth);
     53         }
     54 
     55         OCL_TEST_CYCLE()
     56         {
     57             split(src, srcs);
     58 
     59             for (size_t i = 0; i < srcs.size(); ++i)
     60                 resize(srcs[i], dsts[i], Size(), 0.5, 0.5, INTER_LINEAR);
     61 
     62             merge(dsts, dst);
     63         }
     64     }
     65     else if (mode == Convert)
     66     {
     67         int type4 = CV_MAKE_TYPE(depth, 4);
     68         UMat src4(srcSize, type4), dst4(srcSize, type4);
     69 
     70         OCL_TEST_CYCLE()
     71         {
     72             cvtColor(src, src4, COLOR_RGB2RGBA);
     73             resize(src4, dst4, Size(), 0.5, 0.5, INTER_LINEAR);
     74             cvtColor(dst4, dst, COLOR_RGBA2RGB);
     75         }
     76     }
     77 
     78     SANITY_CHECK_NOTHING();
     79 }
     80 
     81 OCL_PERF_TEST_P(_3vs4_Fixture, Subtract,
     82                 ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8UC3, CV_32FC3), Modes::all()))
     83 {
     84     _3vs4Params params = GetParam();
     85     const Size srcSize = get<0>(params);
     86     const int type = get<1>(params), depth = CV_MAT_DEPTH(type);
     87     const int mode = get<2>(params);
     88 
     89     checkDeviceMaxMemoryAllocSize(srcSize, type);
     90 
     91     Scalar s(14);
     92     UMat src(srcSize, type), dst(srcSize, type);
     93     declare.in(src, WARMUP_RNG).out(dst);
     94 
     95     if (mode == Pure)
     96     {
     97         OCL_TEST_CYCLE() subtract(src, s, dst);
     98     }
     99     else if (mode == Split)
    100     {
    101         std::vector<UMat> srcs(3), dsts(3);
    102 
    103         for (int i = 0; i < 3; ++i)
    104         {
    105             dsts[i] = UMat(srcSize, depth);
    106             srcs[i] = UMat(srcSize, depth);
    107         }
    108 
    109         OCL_TEST_CYCLE()
    110         {
    111             split(src, srcs);
    112 
    113             for (size_t i = 0; i < srcs.size(); ++i)
    114                 subtract(srcs[i], s, dsts[i]);
    115 
    116             merge(dsts, dst);
    117         }
    118     }
    119     else if (mode == Convert)
    120     {
    121         int type4 = CV_MAKE_TYPE(depth, 4);
    122         UMat src4(srcSize, type4), dst4(srcSize, type4);
    123 
    124         OCL_TEST_CYCLE()
    125         {
    126             cvtColor(src, src4, COLOR_RGB2RGBA);
    127             subtract(src4, s, dst4);
    128             cvtColor(dst4, dst, COLOR_RGBA2RGB);
    129         }
    130     }
    131 
    132     SANITY_CHECK_NOTHING();
    133 }
    134 
    135 } } // namespace cvtest::ocl
    136 
    137 #endif // HAVE_OPENCL
    138